updated code

This commit is contained in:
Chr1Z93 2024-10-24 16:17:59 +02:00
parent 40a3bba7ce
commit 2c4428daa3
2 changed files with 44 additions and 104 deletions

View File

@ -85,7 +85,7 @@
},
"tooltip": "None",
"value": [
"Arkham Horror LCG SCE 4.0.0 - ??/??/2024"
"Arkham Horror LCG SCE 4.0.0 - 11/01/2024"
]
},
{

View File

@ -1,14 +1,5 @@
---@diagnostic disable
function onload(saved_data)
sheetLocked = self.script_state.sheetLocked or false
local inverseScale = { x = math.floor(100 / self.getScale().x) / 100, y = math.floor(100 / self.getScale().z) / 100 }
scale = self.script_state.scale or inverseScale
flip = self.script_state.flip or "False"
fields = self.script_state.fields or {}
checks = self.script_state.checks or {}
decals = self.script_state.decals or {}
height = self.script_state.height or 0.5
locks = self.script_state.locks or { fields = false, checks = false, decals = false }
function onLoad(savedData)
lookupInputIndexToInfo = {}
lookupButtonIndexToInfo = {}
lookupFieldIndices = {}
@ -18,18 +9,21 @@ function onload(saved_data)
lastFieldLockedMessage = 0
buttonIndex = 0
inputIndex = 0
if saved_data ~= "" then
local loadedData = JSON.decode(saved_data)
-- load saved data if possible
local loadedData = JSON.decode(savedData) or {}
sheetLocked = loadedData.sheetLocked or false
flip = loadedData.flip or "False"
height = loadedData.height or 0.5
fields = loadedData.fields or {}
checks = loadedData.checks or {}
decals = loadedData.decals or {}
scale = loadedData.scale or inverseScale
wasCommitted = loadedData.wasCommitted or false
local selfScale = self.getScale()
scale = loadedData.scale or { x = math.floor(100 / selfScale.x) / 100, y = math.floor(100 / selfScale.z) / 100 }
locks = loadedData.locks or { fields = false, checks = false, decals = false }
end
if (not getCommited()) then
if not wasCommitted then
self.addContextMenuItem("Edit Layout", showEditPanel)
self.addContextMenuItem("Commit Layout", showCommitPanel)
nudgeDistance = self.script_state.nudgeDistance or 0.1
@ -80,14 +74,10 @@ end
function toggleAllLocks(ply, pos, obj)
if (locks.fields and locks.checks and locks.decals) then
locks.fields = false
locks.checks = false
locks.decals = false
locks.fields, locks.checks, locks.decals = false, false, false
broadcastToColor("Unlocked everything", ply)
else
locks.fields = true
locks.checks = true
locks.decals = true
locks.fields, locks.checks, locks.decals = true, true, true
broadcastToColor("Locked everything", ply)
end
updateSave()
@ -96,46 +86,31 @@ function toggleAllLocks(ply, pos, obj)
end
function toggleLockFields(ply, pos, obj)
if (locks.fields) then
locks.fields = false
broadcastToColor("Unlocked texts", ply)
else
locks.fields = true
broadcastToColor("Locked texts", ply)
end
locks.fields = not locks.fields
broadcastToColor(locks.fields and "Locked texts" or "Unlocked texts", ply)
updateSave()
makeContextMenuItems()
refresh()
end
function toggleLockChecks(ply, pos, obj)
if (locks.checks) then
locks.checks = false
broadcastToColor("Unlocked checkboxes", ply)
else
locks.checks = true
broadcastToColor("Locked checkboxes", ply)
end
locks.checks = not locks.checks
broadcastToColor(locks.checks and "Locked checkboxes" or "Unlocked checkboxes", ply)
updateSave()
makeContextMenuItems()
refresh()
end
function toggleLockDecals(ply, pos, obj)
if (locks.decals) then
locks.decals = false
broadcastToColor("Unlocked images", ply)
else
locks.decals = true
broadcastToColor("Locked images", ply)
end
locks.decals = not locks.decals
broadcastToColor(locks.decals and "Locked images" or "Unlocked images", ply)
updateSave()
makeContextMenuItems()
refresh()
end
function updateSave()
local data_to_save = {
self.script_state = JSON.encode({
scale = scale,
height = height,
fields = fields,
@ -143,15 +118,10 @@ function updateSave()
decals = decals,
flip = flip,
sheetLocked = sheetLocked,
locks = locks
}
if (not getCommited()) then
data_to_save.nudgeDistance = nudgeDistance
else
data_to_save.nudgeDistance = nil
end
saved_data = JSON.encode(data_to_save)
self.script_state = saved_data
locks = locks,
nudgeDistance = not wasCommitted and nudgeDistance or nil,
wasCommitted = wasCommitted
})
end
function null() end
@ -179,7 +149,7 @@ function createAll()
end
function createAllCoroutine()
if (not getCommited()) then
if not wasCommitted then
UI.setAttribute(getPanelId("Loading"), "active", "True")
end
coroutine.yield(0)
@ -231,8 +201,7 @@ function createAllCoroutine()
fieldScale.x = -fieldScale.x
end
local vsum = 0
local fontSize = field.font
fontSize = math.min(field.size.y - 24, fontSize)
local fontSize = math.min(field.size.y - 24, field.font)
local color = getFieldTextColor(fieldID)
for x = 1, field.array.x do
vsum = 0
@ -344,10 +313,7 @@ function createAllCoroutine()
createDecals()
for decalID, decal in pairs(decals) do
lookupDecalIndices[decalID] = {
inputs = {},
selectionButtons = {}
}
lookupDecalIndices[decalID] = { inputs = {}, selectionButtons = {} }
local pos = getDecalPosition(decalID)
if (decal.locked ~= "True" and not sheetLocked and not locks.decals and not editingSheet) then
local func = 'MarumEditableSetURL_' .. decalID
@ -378,10 +344,7 @@ function createAllCoroutine()
end
for checkID, check in pairs(checks) do
lookupCheckIndices[checkID] = {
buttons = {},
selectionButtons = {}
}
lookupCheckIndices[checkID] = { buttons = {}, selectionButtons = {} }
local rotationZ = 0
local checkScale = { x = scale.x * check.size.x, y = 1, z = scale.y * check.size.y }
local upright = self.getTransformUp().y > 0
@ -438,7 +401,7 @@ function createAllCoroutine()
end
end
end
if (not getCommited() and editingSheet) then
if not wasCommitted and editingSheet then
createSelectionButtons()
end
creating = false
@ -485,12 +448,7 @@ function revertFieldSum(args)
local ply = args[2]
local selected = args[4]
if (not selected) then
Wait.frames(
function()
recalculateVSums(fieldID)
end,
1
)
Wait.frames(function() recalculateVSums(fieldID) end, 1)
else
if (lastFieldLockedMessage ~= fieldID) then
broadcastToColor("This text is reserved for the total sum", ply, { r = 1, g = 1, b = 0 })
@ -549,8 +507,7 @@ function getCheckPosition(checkID, x, y)
return {
x = (check.pos.x + (x - 1) * check.distance.x) * mul * scale.x,
y = height + 0.002,
z = (check.pos.y + (y - 1) * check.distance.y) *
mul * scale.y
z = (check.pos.y + (y - 1) * check.distance.y) * mul * scale.y
}
end
@ -831,8 +788,7 @@ function updateFieldNameContentAndTooltip(fieldID)
self.editInput({
index = v.index - 1,
value = field.value[v.arrayID],
tooltip = getFieldTooltip(fieldID,
v.arrayID)
tooltip = getFieldTooltip(fieldID, v.arrayID)
})
end
local name = "T" .. fieldID
@ -842,16 +798,8 @@ function updateFieldNameContentAndTooltip(fieldID)
end
end
function getCommited()
return true
end
--$
function getCommited()
return false
end
function get_line_count(str)
local lines = 1
for i = 1, #str do
@ -1419,8 +1367,7 @@ function refreshEditPanel()
UI.setAttribute(attrId("PreviousPage"), "interactable", tostring(page > 1))
UI.setAttribute(attrId("FirstPage"), "interactable", tostring(page > 1))
if (subpages > 1) then
UI.setAttribute(attrId("Pages"), "text", page .. " (" .. selectedArrayId .. "/" .. subpages ..
") / " .. pageCount)
UI.setAttribute(attrId("Pages"), "text", page .. " (" .. selectedArrayId .. "/" .. subpages .. ") / " .. pageCount)
else
UI.setAttribute(attrId("Pages"), "text", page .. " / " .. pageCount)
end
@ -1435,6 +1382,8 @@ function commit(ply)
if (Global.getVar("MarumEditableSheetGUID", self.guid)) then
Global.setVar("MarumEditableSheetGUID", nil)
end
wasCommitted = true
updateSave()
self.script_code = codeSplit[1]
self.reload()
end
@ -1515,9 +1464,8 @@ function showCommitPanel(ply, value, id)
getObjectFromGUID(previousGUID).call("closePanel")
end
end
Player[ply].showConfirmDialog(
"Do you want to lock the current layout and remove editing related code? You will still be able to change the contents of unlocked fields.",
commit)
Player[ply].showConfirmDialog("Do you want to lock the current layout and remove editing related code? " ..
"You will still be able to change the contents of unlocked fields.", commit)
end
function removeMESPanel()
@ -3501,13 +3449,5 @@ function waitForUiLoaded(callback)
callback()
return nil
end
return Wait.condition(
function()
callback()
end,
function()
return UI.loading == false
end
)
return Wait.condition(callback, function() return UI.loading == false end)
end