Skip to content

Commit 32c3a34

Browse files
committed
added support for list templates
1 parent e39b5c6 commit 32c3a34

4 files changed

Lines changed: 611 additions & 1 deletion

File tree

Manager/Console/BuildTemplates.lua

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
local _, ADDON = ...
2+
3+
------------------------------------------------------------
4+
5+
local function Pad(s, n)
6+
return string.rep(" ", n - string.len(s)) .. s
7+
end
8+
9+
------------------------------------------------------------
10+
11+
local function GetNote(prefix, tbl)
12+
if #tbl > 0 then
13+
return prefix .. table.concat(tbl, " ")
14+
end
15+
return ""
16+
end
17+
18+
------------------------------------------------------------
19+
20+
local function SortList(a, b)
21+
if a.boss == b.boss then
22+
return a.id < b.id
23+
else
24+
return a.boss < b.boss
25+
end
26+
end
27+
28+
------------------------------------------------------------
29+
30+
local function GetText(list, fn)
31+
local lastboss = 0
32+
33+
-- add header
34+
local s = 'local _, ADDON = ...\r\n' ..
35+
'\r\n' ..
36+
'------------------------------------------------------------\r\n' ..
37+
'\r\n' ..
38+
'local items = {\r\n'
39+
40+
-- add body
41+
for _,item in ipairs(list) do
42+
43+
-- add some lines between bosses
44+
if item.boss ~= lastboss then
45+
s = s .. '\r\n -- Boss ' .. item.boss .. '\r\n'
46+
lastboss = item.boss
47+
end
48+
49+
-- get note
50+
local note = GetNote(" BIS: ", item.bis) .. GetNote(" OPT: ", item.opt)
51+
52+
-- write line
53+
s = s .. ' [' .. Pad(item.id, 6) .. '] ' ..
54+
'= {boss = ' .. Pad(item.boss, 4) ..
55+
', slot = ' .. Pad(item.slot, 2) ..
56+
', xtype = ' .. Pad(item.xtype, 2) ..
57+
', account = ?' ..
58+
', cost = ' .. Pad(item.cost, 4) ..
59+
', note = "' .. note:sub(2) .. '"' ..
60+
'}, -- ' .. item.name .. '\r\n'
61+
end
62+
63+
-- add footer
64+
s = s .. '}\r\n' ..
65+
'\r\n' ..
66+
'------------------------------------------------------------\r\n' ..
67+
'\r\n' ..
68+
'-- export items\r\n' ..
69+
'ADDON.InitGroup.Items = ADDON.InitGroup.Items or {}\r\n' ..
70+
'for k,v in pairs(items) do\r\n' ..
71+
' ADDON.InitGroup.Items[k] = v\r\n' ..
72+
'end\r\n' ..
73+
'items = nil\r\n'
74+
75+
return s
76+
end
77+
78+
------------------------------------------------------------
79+
80+
local function BuildTemplates()
81+
for file in io.popen("dir /b Templates\\*_Template.lua 2> nul"):lines() do
82+
print("Loading " .. file .. "...")
83+
84+
-- load template and get table!
85+
GetTemplateTable = nil
86+
dofile("Templates/" .. file)
87+
if type(GetTemplateTable) == "function" then
88+
89+
-- call external function
90+
local tbl = GetTemplateTable()
91+
92+
-- convert to sorted list
93+
local list = {}
94+
for k,v in pairs(tbl) do
95+
v.id = k
96+
table.insert(list, v)
97+
end
98+
table.sort(list, SortList)
99+
100+
-- get text
101+
local fn = file:sub(1, -14)
102+
local s = GetText(list, fn)
103+
print("Writing " .. fn .. ".lua to Output...")
104+
105+
-- write text
106+
local f1 = assert(io.open("Output/" .. fn .. ".lua", "w+b"))
107+
f1:write(s)
108+
f1:close()
109+
else
110+
print("WARNING: GetTemplateTable() not found, skipping file!")
111+
end
112+
113+
print()
114+
end
115+
116+
ADDON.Pause()
117+
end
118+
119+
------------------------------------------------------------
120+
121+
-- export
122+
ADDON.BuildTemplates = BuildTemplates

Manager/Console/Main.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ local function ShowAdvanced()
8383
print("================")
8484
print()
8585
print("1. Translate Items")
86+
print("2. Build Templates")
8687
print("0. Back")
8788
print()
88-
local d = ADDON.Choice("Answer", "10")
89+
local d = ADDON.Choice("Answer", "120")
8990
print()
9091

9192
if d == "1" then
@@ -94,6 +95,10 @@ local function ShowAdvanced()
9495
ADDON.Groups = nil
9596
end
9697

98+
if d == "2" then
99+
ADDON.BuildTemplates()
100+
end
101+
97102
until d == "0"
98103
end
99104

@@ -154,6 +159,7 @@ ADDON.LoadFile("Console/ImportWTF.lua")
154159
ADDON.LoadFile("Console/ExportAddon.lua")
155160
ADDON.LoadFile("Console/ExportHTML.lua")
156161
ADDON.LoadFile("Console/TranslateItems.lua")
162+
ADDON.LoadFile("Console/BuildTemplates.lua")
157163
ADDON.LoadFile("Console/Menu.lua")
158164

159165
-- load configuarion

0 commit comments

Comments
 (0)