Skip to content

Commit 722e752

Browse files
author
David Medgyesy
committed
Fix saving inactive config sets against the active set's placeholders
Saving compared every set's inputs with defaults resolved from the active set, so an input of another set was dropped when it equalled the active set's placeholder. A saved string placeholder was also loaded as an input.
1 parent bfee69d commit 722e752

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎spec/System/TestConfigTab_spec.lua‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,26 @@ describe("TestConfig", function()
354354
build.configTab:SetActiveConfigSet(3)
355355
assert.are.equals(placeholderValue, build.configTab.configSets[3].placeholder.testVar)
356356
end)
357+
358+
it("Saves an input of an inactive config set that equals the active set's placeholder", function()
359+
local other = build.configTab:NewConfigSet(nil, "Other")
360+
build.configTab.configSets[1].placeholder.sigilOfPowerStages = 3
361+
other.input.sigilOfPowerStages = 3
362+
363+
loadBuildFromXML(build:SaveDB("code"))
364+
365+
assert.are.equals(1, build.configTab.activeConfigSetId)
366+
assert.are.equals(3, build.configTab.configSets[other.id].input.sigilOfPowerStages)
367+
end)
368+
369+
it("Loads a saved string placeholder as a placeholder", function()
370+
build.configTab.placeholder.testPlaceholder = "test"
371+
372+
loadBuildFromXML(build:SaveDB("code"))
373+
374+
assert.are.equals("test", build.configTab.placeholder.testPlaceholder)
375+
assert.is_nil(build.configTab.input.testPlaceholder)
376+
end)
357377
end)
358378

359379
describe("Default values", function()

‎src/Classes/ConfigTab.lua‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ function ConfigTabClass:Load(xml, fileName)
875875
if node.attrib.number then
876876
self.configSets[configSetId].placeholder[node.attrib.name] = tonumber(node.attrib.number)
877877
elseif node.attrib.string then
878-
self.configSets[configSetId].input[node.attrib.name] = node.attrib.string
878+
self.configSets[configSetId].placeholder[node.attrib.name] = node.attrib.string
879879
else
880880
launch:ShowErrMsg("^1Error parsing '%s': 'Placeholder' element missing number", fileName)
881881
return true
@@ -940,9 +940,10 @@ function ConfigTabClass:Load(xml, fileName)
940940
self:ResetUndo()
941941
end
942942

943-
function ConfigTabClass:GetDefaultState(var, varType)
944-
if self.configSets[self.activeConfigSetId].placeholder[var] ~= nil then
945-
return self.configSets[self.activeConfigSetId].placeholder[var]
943+
function ConfigTabClass:GetDefaultState(var, varType, configSetId)
944+
local placeholder = self.configSets[configSetId or self.activeConfigSetId].placeholder[var]
945+
if placeholder ~= nil then
946+
return placeholder
946947
end
947948

948949
if self.defaultState[var] ~= nil then
@@ -970,7 +971,7 @@ function ConfigTabClass:Save(xml)
970971
t_insert(xml, child)
971972

972973
for k, v in pairsSortByKey(configSet.input) do
973-
if v ~= self:GetDefaultState(k, type(v)) then
974+
if v ~= self:GetDefaultState(k, type(v), configSetId) then
974975
local node = { elem = "Input", attrib = { name = k } }
975976
if type(v) == "number" then
976977
node.attrib.number = tostring(v)

0 commit comments

Comments
 (0)