Skip to content

Commit 14b366e

Browse files
Handle implicits, post mods and statorder (#175)
1 parent 4f84efa commit 14b366e

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

src/Export/Scripts/uModsToText.lua

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,50 @@ local itemTypes = {
4444
"flask",
4545
"soulcore",
4646
}
47+
local function writeMods(out, statOrder)
48+
local orders = { }
49+
for order, _ in pairs(statOrder) do
50+
table.insert(orders, order)
51+
end
52+
table.sort(orders)
53+
for _, order in pairs(orders) do
54+
for _, line in ipairs(statOrder[order]) do
55+
out:write(line, "\n")
56+
end
57+
end
58+
end
4759

4860
local uniqueMods = LoadModule("../Data/ModItemExlusive.lua")
4961
for _, name in ipairs(itemTypes) do
5062
local out = io.open("../Data/Uniques/"..name..".lua", "w")
63+
local statOrder = {}
64+
local postModLines = {}
65+
local modLines = 0
66+
local implicits
5167
for line in io.lines("Uniques/"..name..".lua") do
52-
local specName, _ = line:match("^([%a ]+): (.+)$")
53-
if not specName and line ~= "]],[[" then
68+
if implicits then -- remove 1 downs to 0
69+
implicits = implicits - 1
70+
end
71+
local specName, specVal = line:match("^([%a ]+): (.+)$")
72+
if line:match("]],") then -- start new unique
73+
writeMods(out, statOrder)
74+
for _, line in ipairs(postModLines) do
75+
out:write(line, "\n")
76+
end
77+
out:write(line, "\n")
78+
statOrder = { }
79+
postModLines = { }
80+
modLines = 0
81+
elseif not specName then
82+
local prefix = ""
5483
local variantString = line:match("({variant:[%d,]+})")
5584
local fractured = line:match("({fractured})") or ""
5685
local modName, legacy = line:gsub("{.+}", ""):match("^([%a%d_]+)([%[%]-,%d]*)")
5786
local mod = uniqueMods[modName]
5887
if mod then
88+
modLines = modLines + 1
5989
if variantString then
60-
out:write(variantString)
90+
prefix = prefix ..variantString
6191
end
6292
local tags = {}
6393
if isValueInArray({"amulet", "ring"}, name) then
@@ -68,9 +98,9 @@ for _, name in ipairs(itemTypes) do
6898
end
6999
end
70100
if tags[1] then
71-
out:write("{tags:" .. table.concat(tags, ",") .. "}")
101+
prefix = prefix.."{tags:"..table.concat(tags, ",").."}"
72102
end
73-
out:write(fractured)
103+
prefix = prefix..fractured
74104
local legacyMod
75105
if legacy ~= "" then
76106
local values = { }
@@ -89,14 +119,34 @@ for _, name in ipairs(itemTypes) do
89119
stats.Type = mod.Type
90120
end
91121
legacyMod = describeStats(stats)
122+
end
123+
for i, line in ipairs(legacyMod or mod) do
124+
local order = mod.statOrder[i]
125+
if statOrder[order] then
126+
table.insert(statOrder[order], prefix..line)
127+
else
128+
statOrder[order] = { prefix..line }
129+
end
92130
end
93-
out:write(table.concat(legacyMod or mod, "\n" .. (variantString or "")), "\n")
94131
else
95-
out:write(line, "\n")
132+
if modLines > 0 then -- treat as post line e.g. mirrored
133+
table.insert(postModLines, line)
134+
else
135+
out:write(line, "\n")
136+
end
96137
end
97138
else
139+
if specName == "Implicits" then
140+
implicits = tonumber(specVal)
141+
end
98142
out:write(line, "\n")
99143
end
144+
if implicits and implicits == 0 then
145+
writeMods(out, statOrder)
146+
implicits = nil
147+
statOrder = { }
148+
modLines = 0
149+
end
100150
end
101151
out:close()
102152
end

0 commit comments

Comments
 (0)