updated living ink

This commit is contained in:
Chr1Z93 2023-05-11 14:34:55 +02:00
parent ec08810143
commit 0f55556c4d
2 changed files with 124 additions and 238 deletions

View File

@ -1,16 +1,14 @@
-- Customizable Cards: Living Ink -- Customizable Cards: Living Ink
-- Size information for buttons -- Size information for buttons
boxSize = 40 boxSize = 40
-- static values -- static values
x_1 = -0.935 x_1 = -0.935
x_offset = 0.075 x_offset = 0.075
y_visible = 0.25
y_invisible = -0.5
-- z-values (lines on the sheet) -- z-values (lines on the sheet)
posZ = { posZ = {
-0.69, -0.69,
-0.355, -0.355,
0.0855, 0.0855,
@ -21,240 +19,15 @@ posZ = {
} }
-- box setup (amount of boxes per line and amount of marked boxes in that line) -- box setup (amount of boxes per line and amount of marked boxes in that line)
existingBoxes = { 1, 1, 2, 2, 3, 3, 3 } existingBoxes = { 1, 1, 2, 2, 3, 3, 3 }
inputBoxes = {}
-- override 'marked boxes' for debugging ('all' or 'none')
markDEBUG = ""
-- Locations of the skill selectors -- Locations of the skill selectors
local SKILL_ICON_POSITIONS = { SKILL_ICON_POSITIONS = {
willpower = { x = 0.085, z = -0.88 }, willpower = { x = 0.085, z = -0.88 },
intellect = { x = -0.183, z = -0.88 }, intellect = { x = -0.183, z = -0.88 },
combat = { x = -0.473, z = -0.88 }, combat = { x = -0.473, z = -0.88 },
agility = { x = -0.74, z = -0.88 }, agility = { x = -0.74, z = -0.88 },
} }
local selectedSkills = { require("playercards/customizable/UpgradeSheetLibrary")
willpower = false,
intellect = false,
combat = false,
agility = false
}
-- save state when going into bags / decks
function onDestroy() self.script_state = onSave() end
function onSave()
local skillArray = {}
for skill, isSelected in pairs(selectedSkills) do
if (isSelected) then
table.insert(skillArray, skill)
end
end
return JSON.encode({ markedBoxes, skillArray })
end
-- Startup procedure
function onLoad(saved_data)
if saved_data ~= "" and markDEBUG == "" then
local loaded_data = JSON.decode(saved_data)
markedBoxes = loaded_data[1]
log(loaded_data[2])
for _, skill in ipairs(loaded_data[2]) do
if (skill ~= "") then
log("Skill from load " .. skill)
selectedSkills[skill] = true
end
end
else
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
inputValues = { "", "", "", "", "" }
local selectedSkills = {
willpower = false,
intellect = false,
combat = false,
agility = false
}
end
makeData()
createButtonsAndBoxes()
self.addContextMenuItem("Reset Inputs", function() updateState() end)
self.addContextMenuItem("Scale: normal", function() updateScale(1) end)
self.addContextMenuItem("Scale: double", function() updateScale(2) end)
self.addContextMenuItem("Scale: triple", function() updateScale(3) end)
updateSkillDisplay()
end
function updateScale(scale)
self.setScale({ scale, 1, scale })
updateSkillDisplay()
end
function updateState(markedBoxesNew)
if markedBoxesNew then markedBoxes = markedBoxesNew end
makeData()
createButtonsAndBoxes()
updateSkillDisplay()
end
-- create Data
function makeData()
Data = {}
Data.checkbox = {}
Data.textbox = {}
-- repeat this for each entry (= line) in existingBoxes
local totalCount = 0
for i = 1, #existingBoxes do
-- repeat this for each checkbox per line
for j = 1, existingBoxes[i] do
totalCount = totalCount + 1
Data.checkbox[totalCount] = {}
Data.checkbox[totalCount].pos = {}
Data.checkbox[totalCount].pos.x = x_1 + j * x_offset
Data.checkbox[totalCount].pos.z = posZ[i]
Data.checkbox[totalCount].row = i
if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then
Data.checkbox[totalCount].pos.y = y_visible
Data.checkbox[totalCount].state = true
else
Data.checkbox[totalCount].pos.y = y_invisible
Data.checkbox[totalCount].state = false
end
end
end
end
-- checks or unchecks the given box
function click_checkbox(tableIndex)
local row = Data.checkbox[tableIndex].row
if Data.checkbox[tableIndex].state == true then
Data.checkbox[tableIndex].pos.y = y_invisible
Data.checkbox[tableIndex].state = false
markedBoxes[row] = markedBoxes[row] - 1
else
Data.checkbox[tableIndex].pos.y = y_visible
Data.checkbox[tableIndex].state = true
markedBoxes[row] = markedBoxes[row] + 1
end
self.editButton({
index = tableIndex - 1,
position = Data.checkbox[tableIndex].pos
})
end
function click_willpower()
selectedSkills.willpower = not selectedSkills.willpower
updateSkillDisplay()
end
function click_intellect()
selectedSkills.intellect = not selectedSkills.intellect
updateSkillDisplay()
end
function click_combat()
selectedSkills.combat = not selectedSkills.combat
updateSkillDisplay()
end
function click_agility()
selectedSkills.agility = not selectedSkills.agility
updateSkillDisplay()
end
function createButtonsAndBoxes()
self.clearButtons()
for i, box_data in ipairs(Data.checkbox) do
local funcName = "checkbox" .. i
local func = function() click_checkbox(i) end
self.setVar(funcName, func)
self.createButton({
click_function = funcName,
function_owner = self,
position = box_data.pos,
height = boxSize,
width = boxSize,
font_size = box_data.size,
scale = { 1, 1, 1 },
color = { 0, 0, 0 },
font_color = { 0, 0, 0 }
})
end
makeSkillSelectionButtons()
end
-- Creates the invisible buttons overlaying the skill icons
function makeSkillSelectionButtons()
local buttonPositions = { x = -1 * SKILL_ICON_POSITIONS.willpower.x, y = 0.2, z = SKILL_ICON_POSITIONS.willpower.z }
local buttonData = {
click_function = "click_willpower",
function_owner = self,
position = buttonPositions,
height = 130,
width = 130,
scale = { 1, 1, 1 },
color = { 0, 0, 0, 0 },
}
self.createButton(buttonData)
buttonData.click_function = "click_intellect"
buttonPositions.x = -1 * SKILL_ICON_POSITIONS.intellect.x
buttonData.position = buttonPositions
self.createButton(buttonData)
buttonData.click_function = "click_combat"
buttonPositions.x = -1 * SKILL_ICON_POSITIONS.combat.x
buttonData.position = buttonPositions
self.createButton(buttonData)
buttonData.click_function = "click_agility"
buttonPositions.x = -1 * SKILL_ICON_POSITIONS.agility.x
buttonData.position = buttonPositions
self.createButton(buttonData)
end
-- Refresh the vector circles indicating a skill is selected. Since we can only have one table of
-- vectors set, have to refresh all 4 at once
function updateSkillDisplay()
local circles = {}
for skill, isSelected in pairs(selectedSkills) do
if isSelected then
local circle = getCircleVector(SKILL_ICON_POSITIONS[skill])
if circle ~= nil then
table.insert(circles, circle)
end
end
end
self.setVectorLines(circles)
end
function getCircleVector(center)
local diameter = Vector(0, 0, 0.1)
local pointOfOrigin = Vector(center.x, 0.3, center.z)
-- Declare Results vectors
local vec = Vector(0, 0, 0)
local vecList = {}
local arcStep = 5
for i = 0, 360, arcStep do
diameter:rotateOver('y', arcStep)
vec = pointOfOrigin + diameter
vec.y = pointOfOrigin.y
table.insert(vecList, vec)
end
return {
points = vecList,
color = { 0.597, 0.195, 0.796 },
thickness = 0.02,
}
end

View File

@ -18,7 +18,17 @@ DEBUG = ""
-- save state when going into bags / decks -- save state when going into bags / decks
function onDestroy() self.script_state = onSave() end function onDestroy() self.script_state = onSave() end
function onSave() return JSON.encode({ markedBoxes, inputValues}) end function onSave()
if selfId == "09079-c" then
inputValues = {}
for skill, isSelected in pairs(selectedSkills) do
if isSelected then
table.insert(inputValues, skill)
end
end
end
return JSON.encode({ markedBoxes, inputValues })
end
-- Startup procedure -- Startup procedure
function onLoad(savedData) function onLoad(savedData)
@ -27,14 +37,16 @@ function onLoad(savedData)
markedBoxes = loadedData[1] markedBoxes = loadedData[1]
inputValues = loadedData[2] inputValues = loadedData[2]
else else
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
inputValues = { "", "", "", "", "" } inputValues = { "", "", "", "", "" }
end end
selfId = getSelfId() selfId = getSelfId()
makeData() makeData()
createButtonsAndBoxes() createButtonsAndBoxes()
maybeLoadSkills()
maybeUpdateSkillDisplay()
maybeUpdateSlotDisplay() maybeUpdateSlotDisplay()
self.addContextMenuItem("Reset Inputs", function() updateState({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) end) self.addContextMenuItem("Reset Inputs", function() updateState({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) end)
@ -52,6 +64,7 @@ function updateState(markedBoxesNew)
if markedBoxesNew then markedBoxes = markedBoxesNew end if markedBoxesNew then markedBoxes = markedBoxesNew end
makeData() makeData()
createButtonsAndBoxes() createButtonsAndBoxes()
maybeUpdateSkillDisplay()
maybeUpdateSlotDisplay() maybeUpdateSlotDisplay()
end end
@ -165,6 +178,7 @@ function createButtonsAndBoxes()
}) })
end end
maybeMakeSkillSelectionButtons()
maybeMakeSlotSelectionButtons() maybeMakeSlotSelectionButtons()
end end
@ -172,7 +186,106 @@ end
-- Living Ink related functions -- Living Ink related functions
--------------------------------------------------------- ---------------------------------------------------------
function maybeLoadSkills()
if selfId ~= "09079-c" then return end
selectedSkills = {
willpower = false,
intellect = false,
combat = false,
agility = false
}
for _, skill in ipairs(inputValues) do
if skill ~= "" then
selectedSkills[skill] = true
end
end
end
function click_willpower()
selectedSkills.willpower = not selectedSkills.willpower
maybeUpdateSkillDisplay()
end
function click_intellect()
selectedSkills.intellect = not selectedSkills.intellect
maybeUpdateSkillDisplay()
end
function click_combat()
selectedSkills.combat = not selectedSkills.combat
maybeUpdateSkillDisplay()
end
function click_agility()
selectedSkills.agility = not selectedSkills.agility
maybeUpdateSkillDisplay()
end
-- Creates the invisible buttons overlaying the skill icons
function maybeMakeSkillSelectionButtons()
if selfId ~= "09079-c" then return end
local buttonData = {
click_function = "click_willpower",
function_owner = self,
position = { x = -1 * SKILL_ICON_POSITIONS.willpower.x, y = 0.2, z = SKILL_ICON_POSITIONS.willpower.z },
height = 130,
width = 130,
scale = { 1, 1, 1 },
color = { 0, 0, 0, 0 },
}
self.createButton(buttonData)
buttonData.click_function = "click_intellect"
buttonData.position.x = -1 * SKILL_ICON_POSITIONS.intellect.x
self.createButton(buttonData)
buttonData.click_function = "click_combat"
buttonData.position.x = -1 * SKILL_ICON_POSITIONS.combat.x
self.createButton(buttonData)
buttonData.click_function = "click_agility"
buttonData.position.x = -1 * SKILL_ICON_POSITIONS.agility.x
self.createButton(buttonData)
end
-- Refresh the vector circles indicating a skill is selected. Since we can only have one table of
-- vectors set, have to refresh all 4 at once
function maybeUpdateSkillDisplay()
if selfId ~= "09079-c" then return end
local circles = {}
for skill, isSelected in pairs(selectedSkills) do
if isSelected then
local circle = getCircleVector(SKILL_ICON_POSITIONS[skill])
if circle ~= nil then
table.insert(circles, circle)
end
end
end
self.setVectorLines(circles)
end
function getCircleVector(center)
local diameter = Vector(0, 0, 0.1)
local pointOfOrigin = Vector(center.x, 0.3, center.z)
-- Declare Results vectors
local vec = Vector(0, 0, 0)
local vecList = {}
local arcStep = 5
for i = 0, 360, arcStep do
diameter:rotateOver('y', arcStep)
vec = pointOfOrigin + diameter
vec.y = pointOfOrigin.y
table.insert(vecList, vec)
end
return {
points = vecList,
color = VECTOR_COLOR.selected,
thickness = 0.02,
}
end
--------------------------------------------------------- ---------------------------------------------------------
-- Summoned Servitor related functions -- Summoned Servitor related functions