Merge pull request #976 from argonui/upgradesheet-saving
Upgradesheets: updated save function
This commit is contained in:
commit
cd84bd89bc
@ -21,10 +21,8 @@
|
||||
|
||||
local playermatApi = require("playermat/PlayermatApi")
|
||||
|
||||
-- Y position for UI elements. Visibility of checkboxes moves the checkbox inside the card object
|
||||
-- when not selected.
|
||||
-- Y position for UI elements
|
||||
local Y_VISIBLE = 0.25
|
||||
local Y_INVISIBLE = -0.5
|
||||
|
||||
-- Variable to check whether UI finished loading
|
||||
local isLoading = true
|
||||
@ -39,16 +37,10 @@ local VECTOR_COLOR = {
|
||||
local SUMMONED_SERVITOR_SLOT_INDICES = { arcane = "1", ally = "0", none = "" }
|
||||
|
||||
local rowCheckboxFirstIndex = {}
|
||||
local rowInputIndex = { }
|
||||
local selectedUpgrades = {}
|
||||
|
||||
-- save state when going into bags / decks
|
||||
function onDestroy() self.script_state = onSave() end
|
||||
|
||||
function onSave()
|
||||
return JSON.encode({
|
||||
selections = selectedUpgrades
|
||||
})
|
||||
function updateSave()
|
||||
self.script_state = JSON.encode({ selections = selectedUpgrades })
|
||||
end
|
||||
|
||||
-- Startup procedure
|
||||
@ -107,6 +99,7 @@ end
|
||||
|
||||
function resetSelections()
|
||||
selectedUpgrades = {}
|
||||
updateSave()
|
||||
updateDisplay()
|
||||
end
|
||||
|
||||
@ -159,12 +152,6 @@ end
|
||||
|
||||
function createRowTextField(rowIndex)
|
||||
local textField = customizations[rowIndex].textField
|
||||
|
||||
rowInputIndex[rowIndex] = 0
|
||||
local previousInputs = self.getInputs()
|
||||
if previousInputs ~= nil then
|
||||
rowInputIndex[rowIndex] = #previousInputs
|
||||
end
|
||||
local funcName = "textbox" .. rowIndex
|
||||
local func = function(player, value) clickTextbox(rowIndex, value) end
|
||||
self.setVar(funcName, func)
|
||||
@ -195,7 +182,7 @@ function translatePosition(posX, posZ)
|
||||
-- position values are made strings to be usabled by the XML, height (z) is always -22
|
||||
local translatedPosX = tostring(posX * -100)
|
||||
local translatedPosY = tostring(posZ * 100)
|
||||
local combinedPos = translatedPosX .. " " .. translatedPosY .. " " .. -22
|
||||
local combinedPos = translatedPosX .. " " .. translatedPosY .. " -22"
|
||||
return combinedPos
|
||||
end
|
||||
|
||||
@ -236,7 +223,6 @@ function updateCheckboxes(rowIndex)
|
||||
end
|
||||
|
||||
function updateTextField(rowIndex)
|
||||
local inputIndex = rowInputIndex[rowIndex]
|
||||
if selectedUpgrades[rowIndex] ~= nil and selectedUpgrades[rowIndex].text ~= nil then
|
||||
waitForUILoad(rowIndex, "text", selectedUpgrades[rowIndex].text)
|
||||
end
|
||||
@ -248,15 +234,13 @@ function waitForUILoad(id, attribute, value)
|
||||
function()
|
||||
Wait.frames(
|
||||
function()
|
||||
isLoading = false;
|
||||
isLoading = false
|
||||
self.UI.setAttribute(id, attribute, value)
|
||||
end,
|
||||
1
|
||||
)
|
||||
end,
|
||||
function()
|
||||
return not self.UI.loading
|
||||
end
|
||||
function() return not self.UI.loading end
|
||||
)
|
||||
else
|
||||
self.UI.setAttribute(id, attribute, value)
|
||||
@ -274,6 +258,7 @@ function clickCheckbox(row, col)
|
||||
selectedUpgrades[row].xp = col
|
||||
end
|
||||
updateCheckboxes(row)
|
||||
updateSave()
|
||||
playermatApi.syncAllCustomizableCards()
|
||||
end
|
||||
|
||||
@ -283,6 +268,7 @@ function clickTextbox(rowIndex, value)
|
||||
selectedUpgrades[rowIndex] = {}
|
||||
end
|
||||
selectedUpgrades[rowIndex].text = value:gsub("^%s*(.-)%s*$", "%1")
|
||||
updateSave()
|
||||
-- Editing isn't actually done yet, and will block the update. Wait a frame so it's finished
|
||||
Wait.frames(function() updateRowDisplay(rowIndex) end, 1)
|
||||
end
|
||||
@ -355,6 +341,7 @@ function updateSelectedLivingInkSkillText()
|
||||
selectedUpgrades[1] = {}
|
||||
end
|
||||
selectedUpgrades[1].text = skillString
|
||||
updateSave()
|
||||
end
|
||||
|
||||
-- Refresh the vector circles indicating a skill is selected. Since we can only have one table of
|
||||
@ -426,6 +413,7 @@ function clickArcane()
|
||||
else
|
||||
selectedUpgrades[6].text = SUMMONED_SERVITOR_SLOT_INDICES.arcane
|
||||
end
|
||||
updateSave()
|
||||
maybeUpdateServitorSlotDisplay()
|
||||
end
|
||||
|
||||
@ -439,6 +427,7 @@ function clickAlly()
|
||||
else
|
||||
selectedUpgrades[6].text = SUMMONED_SERVITOR_SLOT_INDICES.ally
|
||||
end
|
||||
updateSave()
|
||||
maybeUpdateServitorSlotDisplay()
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user