Skip to content

Commit 800de18

Browse files
committed
Update the statDesc part to export a generic formatted stat data.
1 parent bb15ab0 commit 800de18

File tree

3 files changed

+117
-41
lines changed

3 files changed

+117
-41
lines changed

src/Export/Scripts/modScalability.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ loadStatFile("stat_descriptions.csd")
66
local out = io.open("../Data/ModScalability.lua", "w")
77
out:write('-- This file is automatically generated, do not edit!\n')
88
out:write('-- Item data (c) Grinding Gear Games\n\nreturn {\n')
9-
local scalabilityLines = describeScalability("stat_descriptions.csd")
9+
local statsOnMods = describeStatOnMod("stat_descriptions.csd")
1010
local lines = { }
11-
for line, _ in pairs(scalabilityLines) do
11+
for line, _ in pairs(statsOnMods) do
1212
table.insert(lines, line)
1313
end
1414
table.sort(lines)
1515
for _, line in ipairs(lines) do
16-
local scalability = scalabilityLines[line]
17-
out:write('\t["', line, '"] = { ')
18-
for i, scalable in ipairs(scalability) do
19-
out:write("{ isScalable = "..tostring(scalable.isScalable))
20-
if scalable.formats then
21-
out:write(', formats = { ')
22-
for j, format in ipairs(scalable.formats) do
23-
out:write('"'..format..'"')
24-
if j < #scalable.formats then out:write(", ") end
25-
end
26-
out:write(" }")
27-
end
28-
out:write(" }")
29-
if i < #scalability then out:write(", ") end
30-
end
31-
out:write(" },\n")
16+
local modStatFormattings = statsOnMods[line]
17+
-- out:write('\t["', line, '"] = { ')
18+
-- for _, formatting in ipairs(modStatFormattings) do
19+
-- out:write("{ isScalable = "..tostring(scalable.isScalable))
20+
-- if scalable.formats then
21+
-- out:write(', formats = { ')
22+
-- for j, format in ipairs(scalable.formats) do
23+
-- out:write('"'..format..'"')
24+
-- if j < #scalable.formats then out:write(", ") end
25+
-- end
26+
-- out:write(" }")
27+
-- end
28+
-- out:write(" }")
29+
-- if i < #stats then out:write(", ") end
30+
-- end
31+
-- out:write(" },\n")
3232
end
3333

3434
out:write('}')

src/Export/statdesc.lua

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -408,40 +408,110 @@ function describeMod(mod)
408408
return out, orders
409409
end
410410

411-
function describeScalability(fileName)
411+
-- stats placed in statDesc order, order gives order in mods, and sign gives which use a postive sign.
412+
--[Mod] = { { order = { 1, 2 }, sign = { 1 }, formats = { general = { "cononicalLine" }, [1] = { "formatA", "formatB", "formatC", etc }, [2] = {#2 stat formats}, }, "statA", "statB" }, { }, { }}
413+
function describeStatOnMod(fileName)
412414
local out = { }
413-
local stats = dat("stats")
414-
for stat, statDescription in pairs(statDescriptors[fileName]) do
415-
local scalability = { }
415+
local uniqueStatDescriptors = {}
416+
for _, statDescription in pairs(statDescriptors[fileName]) do
417+
uniqueStatDescriptors[statDescription] = true
418+
end
419+
for statDescription, _ in pairs(uniqueStatDescriptors) do
416420
if statDescription.stats then
417-
for i, stat in ipairs(statDescription.stats) do
418-
table.insert(scalability, stats:GetRow("Id", stat).IsScalable)
419-
end
420421
for _, wordings in ipairs(statDescription[1]) do
421-
local wordingFormats = {}
422-
local inOrderScalability = { }
422+
local formats = {}
423+
local order = { }
424+
local signs = { }
423425
for _, format in ipairs(wordings) do
424426
if type(format.v) == "number" then
425-
if wordingFormats[tonumber(format.v)] then
426-
table.insert(wordingFormats[tonumber(format.v)], format.k)
427+
if formats[tonumber(format.v)] then
428+
table.insert(formats[tonumber(format.v)], format.k)
429+
else
430+
formats[tonumber(format.v)] = { format.k }
431+
end
432+
else
433+
if formats.general then
434+
table.insert(formats.general, format.k)
427435
else
428-
wordingFormats[tonumber(format.v)] = { format.k }
436+
formats.general = { format.k }
429437
end
430438
end
431439
end
432-
local strippedLine = wordings.text:gsub("[%+%-]?(%b{})", function(num)
440+
local strippedLine = wordings.text:gsub("([%+%-]?)(%b{})", function(sign, num)
433441
local statNum = (num:match("%d") or 0) + 1
434-
table.insert(inOrderScalability, { isScalable = scalability[statNum], formats = wordingFormats[statNum] })
442+
if sign == "+" or num:match("%+") then table.insert(signs, statNum) end
443+
table.insert(order, statNum)
435444
return "#"
436445
end)
437-
if out[strippedLine] then -- we want to use the format with the least oddites in it. If their are less formats then that will be used instead.
438-
for j, priorScalability in ipairs(out[strippedLine]) do
439-
if (priorScalability.formats and #priorScalability.formats or 0) > (wordingFormats[j] and #wordingFormats[j] or 0) then
440-
out[strippedLine][j] = inOrderScalability[j]
446+
-- find values that are set and no present on the item.
447+
local values = { }
448+
for i, limit in ipairs(wordings.limit) do
449+
local present
450+
for _, statNum in ipairs(order) do
451+
if statNum == i then
452+
present = true
453+
end
454+
end
455+
if not present then
456+
values[i] = { }
457+
if limit[1] == "#" and limit[2] == "#" then
458+
values[i].min = -math.huge
459+
values[i].max = math.huge
460+
elseif limit[1] == "#" then
461+
values[i].min = -math.huge
462+
values[i].max = limit[2]
463+
elseif limit[2] == "#" then
464+
values[i].min = limit[1]
465+
values[i].max = math.huge
466+
elseif limit[1] ~= "!" then
467+
values[i].min = limit[1]
468+
values[i].max = limit[2]
469+
break -- won't get smaller
470+
else
471+
values[i] = nil
472+
break
473+
end
474+
for _, wordings in ipairs(statDescription[1]) do
475+
for j, limit in ipairs(wordings.limit) do
476+
if i ~= j then
477+
if limit[1] == "#" and type(limit[2]) == "number" then
478+
if limit[2] > values[i].min and limit[2] < values[i].max then
479+
values[i].min = limit[2] + 1
480+
end
481+
elseif type(limit[1]) == "number" and limit[2] == "#" then
482+
if limit[1] > values[i].min and limit[1] < values[i].max then
483+
values[i].max = limit[1] - 1
484+
end
485+
elseif type(limit[1]) == "number" and type(limit[2]) == "number" then
486+
if limit[2] > values[i].min and limit[2] < values[i].max then
487+
values[i].min = limit[2] + 1
488+
end
489+
if limit[1] > values[i].min and limit[1] < values[i].max then
490+
values[i].max = limit[1] - 1
491+
end
492+
end
493+
end
494+
end
495+
end
496+
end
497+
end
498+
for i = 1, #values do
499+
if values[i] then
500+
if values[i].max == values[i].min then
501+
values[i] = values[i].min
502+
elseif values[i].min == -math.huge and values[i].max ~= math.huge then
503+
values[i] = values[i].max
504+
elseif values[i].min ~= -math.huge and values[i].max == math.huge then
505+
values[i] = values[i].min
506+
else
507+
values[i] = nil
441508
end
442509
end
443-
else -- no present
444-
out[strippedLine] = inOrderScalability
510+
end
511+
if out[strippedLine] then
512+
table.insert(out[strippedLine], { order = order, signs = signs, formats = formats, values = values, unpack(statDescription.stats)})
513+
else
514+
out[strippedLine] = { { order = order, signs = signs, formats = formats, values = values, unpack(statDescription.stats)} }
445515
end
446516
end
447517
end

src/Modules/ItemTools.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ local function antonymFunc(num, word)
6969
return antonym and (num.." "..antonym) or ("-"..num.." "..word)
7070
end
7171

72-
-- Apply range value (0 to 1) to a modifier that has a range: "(x-x)" or "(x-x) to (x-x)"
73-
function itemLib.applyRange(line, range, valueScalar, baseValueScalar)
72+
-- takes a line and a given ranges and returns the given line with the values that refer to given stats and a string where these values have been replace by #, it will return nothing if it can find a valid match.
73+
function itemLib.getStrippedLine(line, range)
7474
-- stripLines down to # inplace of any number and store numbers inside values also remove all + signs are kept if value is positive
7575
local values = { }
7676
local strippedLine = line:gsub("([%+-]?)%((%-?%d+%.?%d*)%-(%-?%d+%.?%d*)%)", function(sign, min, max)
@@ -158,7 +158,13 @@ function itemLib.applyRange(line, range, valueScalar, baseValueScalar)
158158
return
159159
end
160160

161-
local scalableLine, scalableValues = findScalableLine(strippedLine, values)
161+
return findScalableLine(strippedLine, values)
162+
end
163+
164+
165+
-- Apply range value (0 to 1) to a modifier that has a range: "(x-x)" or "(x-x) to (x-x)"
166+
function itemLib.applyRange(line, range, valueScalar, baseValueScalar)
167+
local scalableLine, scalableValues = itemLib.getStrippedLine(line, range)
162168

163169
if scalableLine then -- found scalability data
164170
for i, scalability in ipairs(data.modScalability[scalableLine:gsub("+#", "#")]) do

0 commit comments

Comments
 (0)