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