updated summoned servitor

This commit is contained in:
Chr1Z93 2023-05-11 14:12:56 +02:00
parent 43fce75b7d
commit ec08810143
3 changed files with 175 additions and 303 deletions

View File

@ -103,12 +103,11 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo
-- If cards are spread too close together TTS groups them weirdly, selecting multiples
-- when hovering over a single card. This distance is the minimum to avoid that
local spreadDistance = 1.15
if (zone == "SetAside4" and #zoneCards < 6) then
if (zone == "SetAside4") then
-- SetAside4 is reserved for customization cards, and we want them spread on the table
-- so their checkboxes are visible
-- TO-DO: take into account that spreading will make multiple rows
-- (unclear if this is affected by the user's local setting)
-- -> To avoid weird positioning, there will only be a spread if less than 6 upgradesheets are spawned
-- (this is affected by the user's local settings!)
if (playerColor == "White") then
deckPos.z = deckPos.z + (#zoneCards - 1) * spreadDistance
elseif (playerColor == "Green") then
@ -164,7 +163,7 @@ function deckSpawned(deck, playerColor)
end
end
-- Conver the Raven Quill's selections from card IDs to card names. This could be more elegant
-- Converts the Raven Quill's selections from card IDs to card names. This could be more elegant
-- but the inputs are very static so we're using some brute force.
---@param selectionString String provided by ArkhamDB, indicates the customization selections
-- Should be either a single card ID or two separated by a ^ (e.g. XXXXX^YYYYY)
@ -176,6 +175,13 @@ function convertRavenQuillSelections(selectionString)
end
end
-- Converts Grizzled's selections from a single string with "^".
---@param selectionString String provided by ArkhamDB, indicates the customization selections
-- Should be two Traits separated by a ^ (e.g. XXXXX^YYYYY)
function convertGrizzledSelections(selectionString)
return selectionString:gsub("%^", ", ")
end
-- Returns the simple name of a card given its ID. This will find the card and strip any trailing
-- SCED-specific suffixes such as (Taboo) or (Level)
function getCardName(cardId)
@ -337,29 +343,34 @@ function handleCustomizableUpgrades(cardList, customizations)
local index_xp = {}
-- get the index and xp values (looks like this: X|X,X|X, ..)
-- input string from arkhamDb is split by ","
-- input string from ArkhamDB is split by ","
for str in string.gmatch(customizations["cus_" .. baseId], "([^,]+)") do
table.insert(index_xp, str)
end
-- split each pair and assign it to the proper position in markedBoxes
local inputCount = 0
for _, entry in ipairs(index_xp) do
-- counter increments from 1 to 3 and indicates the part of the string we are on
-- usually: 1 = row, 2 = amount of check boxes, 3 = entry in inputfield
local counter = 0
local index = 0
local row = 0
-- if found number is 0, then only get inputvalue
for str in string.gmatch(entry, "([^|]+)") do
-- parsing the string for each row
for str in entry:gmatch("([^|]+)") do
counter = counter + 1
if counter == 1 then
index = tonumber(str) + 1
row = tonumber(str) + 1
elseif counter == 2 then
markedBoxes[index] = tonumber(str)
markedBoxes[row] = tonumber(str)
elseif counter == 3 and str ~= "" then
if baseId == "09042" then
str = convertRavenQuillSelections(str)
elseif baseId == "09101" then
str = convertGrizzledSelections(str)
end
-- input the found string in the first non-empty index
for i = 1, 6 do
if inputValues[i] == "" then
inputValues[i] = str
@ -373,6 +384,11 @@ function handleCustomizableUpgrades(cardList, customizations)
log(markedBoxes)
log(inputValues)
-- remove first entry from markedBoxes for cards with inputfield in row "0"
if markedBoxes[1] == 0 and inputValues[1] ~= "" and baseId ~= "09080" then
table.remove(markedBoxes, 1)
end
-- write the loaded values to the save_data of the sheets
card.data["LuaScriptState"] = JSON.encode({ markedBoxes, inputValues })
end

View File

@ -1,16 +1,14 @@
-- Customizable Cards: Summoned Servitor
-- Color information for buttons
boxSize = 35
boxSize = 35
-- static values
x_1 = -0.935
x_offset = 0.068
y_visible = 0.25
y_invisible = -0.5
x_1 = -0.935
x_offset = 0.068
-- z-values (lines on the sheet)
posZ = {
posZ = {
-0.92,
-0.625,
-0.33,
@ -22,249 +20,17 @@ posZ = {
}
-- box setup (amount of boxes per line and amount of marked boxes in that line)
existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 }
inputBoxes = {}
existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 }
inputBoxes = {}
-- Locations of the slot selectors
local SLOT_ICON_POSITIONS = {
SLOT_ICON_POSITIONS = {
arcane = { x = 0.160, z = 0.65 },
ally = { x = -0.073, z = 0.65 }
}
-- These match with ArkhamDB's way of storing the data in the dropdown menu
local slotIndices = { arcane = "1", ally = "0", none = "" }
SLOT_INDICES = { arcane = "1", ally = "0", none = "" }
selectedSlot = SLOT_INDICES.none
local selectedSlot = slotIndices.none
-- override 'marked boxes' for debugging ('all' or 'none')
markDEBUG = ""
-- save state when going into bags / decks
function onDestroy() self.script_state = onSave() end
function onSave() return JSON.encode({ markedBoxes, { selectedSlot } }) end
-- Startup procedure
function onLoad(saved_data)
if saved_data ~= "" and markDEBUG == "" then
local loaded_data = JSON.decode(saved_data)
markedBoxes = loaded_data[1]
selectedSlot = loaded_data[2][1]
else
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
selectedSlot = ""
end
makeData()
createButtonsAndBoxes()
updateSlotDisplay()
self.addContextMenuItem("Reset Inputs", function() updateState() end)
self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end)
self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end)
self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end)
end
function updateState(markedBoxesNew)
if markedBoxesNew then markedBoxes = markedBoxesNew end
makeData()
createButtonsAndBoxes()
updateSlotDisplay()
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
-- repeat this for each entry (= line) in inputBoxes
local totalCount = 0
for i = 1, #inputBoxes do
-- repeat this for each textbox per line
for j = 1, inputBoxes[i] do
totalCount = totalCount + 1
Data.textbox[totalCount] = {}
Data.textbox[totalCount].pos = inputPos[totalCount]
Data.textbox[totalCount].width = inputWidth[totalCount]
Data.textbox[totalCount].value = inputValues[totalCount]
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
-- updates saved value for given text box
function click_textbox(i, value, selected)
if selected == false then
inputValues[i] = value
end
end
function createButtonsAndBoxes()
self.clearButtons()
self.clearInputs()
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
for i, box_data in ipairs(Data.textbox) do
local funcName = "textbox" .. i
local func = function(_, _, val, sel) click_textbox(i, val, sel) end
self.setVar(funcName, func)
self.createInput({
input_function = funcName,
function_owner = self,
label = "Click to type",
alignment = 2,
position = box_data.pos,
scale = buttonScale,
width = box_data.width,
height = (inputFontsize * 1) + 24,
font_size = inputFontsize,
color = "White",
font_color = buttonFontColor,
value = box_data.value
})
end
makeSlotSelectionButtons()
end
-- Creates the invisible buttons overlaying the slot words
function makeSlotSelectionButtons()
local buttonPositions = { x = -1 * SLOT_ICON_POSITIONS.arcane.x, y = 0.2, z = SLOT_ICON_POSITIONS.arcane.z }
local buttonData = {
click_function = "click_arcane",
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_ally"
buttonPositions.x = -1 * SLOT_ICON_POSITIONS.ally.x
buttonData.position = buttonPositions
self.createButton(buttonData)
end
function click_arcane()
if selectedSlot == slotIndices.arcane then
selectedSlot = slotIndices.none
else
selectedSlot = slotIndices.arcane
end
updateSlotDisplay()
end
function click_ally()
if selectedSlot == slotIndices.ally then
selectedSlot = slotIndices.none
else
selectedSlot = slotIndices.ally
end
updateSlotDisplay()
end
-- Refresh the vector circles indicating a slot is selected.
function updateSlotDisplay()
local box = {}
local center = {}
center = SLOT_ICON_POSITIONS["arcane"]
local arcaneVecList = {
Vector(center.x + 0.12, 0.3, center.z + 0.05),
Vector(center.x - 0.12, 0.3, center.z + 0.05),
Vector(center.x - 0.12, 0.3, center.z - 0.05),
Vector(center.x + 0.12, 0.3, center.z - 0.05),
Vector(center.x + 0.12, 0.3, center.z + 0.05),
}
center = SLOT_ICON_POSITIONS["ally"]
local allyVecList = {
Vector(center.x + 0.07, 0.3, center.z + 0.05),
Vector(center.x - 0.07, 0.3, center.z + 0.05),
Vector(center.x - 0.07, 0.3, center.z - 0.05),
Vector(center.x + 0.07, 0.3, center.z - 0.05),
Vector(center.x + 0.07, 0.3, center.z + 0.05),
}
local arcaneVecColor = { 0.5, 0.5, 0.5, 0.75 }
local allyVecColor = { 0.5, 0.5, 0.5, 0.75 }
if selectedSlot == slotIndices.arcane then
arcaneVecColor = { 0.597, 0.195, 0.796 }
elseif selectedSlot == slotIndices.ally then
allyVecColor = { 0.597, 0.195, 0.796 }
end
self.setVectorLines({
{
points = arcaneVecList,
color = arcaneVecColor,
thickness = 0.02,
},
{
points = allyVecList,
color = allyVecColor,
thickness = 0.02,
},
})
end
require("playercards/customizable/UpgradeSheetLibrary")

View File

@ -1,51 +1,41 @@
--[[ EXAMPLE CONFIGURATION
-- Color information for buttons
boxSize = 40
-- static values
x_1 = -0.933
x_offset = 0.075
Y_VISIBLE = 0.25
Y_INVISIBLE = -0.5
-- z-values (lines on the sheet)
posZ = {
-0.892,
-0.665,
-0.430,
-0.092,
0.142,
0.376,
0.815
-- used for Summoned Servitor and Living Ink
VECTOR_COLOR = {
unselected = { 0.5, 0.5, 0.5, 0.75 },
selected = { 0.597, 0.195, 0.796 }
}
-- box setup (amount of boxes per line and amount of marked boxes in that line)
existingBoxes = { 1, 1, 1, 1, 2, 4, 5 }
inputBoxes = {}]]
-- static values
y_visible = 0.25
y_invisible = -0.5
-- used for Summoned Servitor
-- these match with ArkhamDB's way of storing the data in the dropdown menu
SLOT_INDICES = { arcane = "1", ally = "0", none = "" }
-- override 'marked boxes' for debugging ('all' or 'none')
markDEBUG = ""
DEBUG = ""
-- save state when going into bags / decks
function onDestroy() self.script_state = onSave() end
function onSave() return JSON.encode({ markedBoxes, inputValues }) end
function onSave() return JSON.encode({ markedBoxes, inputValues}) end
-- Startup procedure
function onLoad(saved_data)
if saved_data ~= "" and markDEBUG == "" then
local loaded_data = JSON.decode(saved_data)
markedBoxes = loaded_data[1]
inputValues = loaded_data[2]
function onLoad(savedData)
if savedData ~= "" and DEBUG == "" then
local loadedData = JSON.decode(savedData)
markedBoxes = loadedData[1]
inputValues = loadedData[2]
else
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
inputValues = { "", "", "", "", "" }
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
inputValues = { "", "", "", "", "" }
end
selfId = getSelfId()
makeData()
createButtonsAndBoxes()
maybeUpdateSlotDisplay()
self.addContextMenuItem("Reset Inputs", function() updateState({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) end)
self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end)
@ -53,17 +43,21 @@ function onLoad(saved_data)
self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end)
end
function getSelfId()
local metadata = JSON.decode(self.getGMNotes())
return metadata.id
end
function updateState(markedBoxesNew)
if markedBoxesNew then markedBoxes = markedBoxesNew end
makeData()
createButtonsAndBoxes()
maybeUpdateSlotDisplay()
end
-- create Data
function makeData()
Data = {}
Data.checkbox = {}
Data.textbox = {}
Data = { checkbox = {}, textbox = {} }
-- repeat this for each entry (= line) in existingBoxes
local totalCount = 0
@ -77,11 +71,11 @@ function makeData()
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
if (DEBUG == "all") or (markedBoxes[i] >= j and DEBUG ~= "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].pos.y = Y_INVISIBLE
Data.checkbox[totalCount].state = false
end
end
@ -105,12 +99,12 @@ end
function click_checkbox(tableIndex)
local row = Data.checkbox[tableIndex].row
if Data.checkbox[tableIndex].state == true then
Data.checkbox[tableIndex].pos.y = y_invisible
if Data.checkbox[tableIndex].state 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].pos.y = Y_VISIBLE
Data.checkbox[tableIndex].state = true
markedBoxes[row] = markedBoxes[row] + 1
end
@ -141,10 +135,10 @@ function createButtonsAndBoxes()
click_function = funcName,
function_owner = self,
position = box_data.pos,
height = boxSize,
width = boxSize,
font_size = box_data.size,
scale = { 1, 1, 1 },
height = boxSize * 10,
width = boxSize * 10,
font_size = 1000,
scale = { 0.1, 0.1, 0.1 },
color = { 0, 0, 0 },
font_color = { 0, 0, 0 }
})
@ -161,13 +155,109 @@ function createButtonsAndBoxes()
label = "Click to type",
alignment = 2,
position = box_data.pos,
scale = buttonScale,
width = box_data.width,
height = (inputFontsize * 1) + 24,
font_size = inputFontsize,
scale = { 0.1, 0.1, 0.1 },
width = box_data.width * 10,
height = inputFontsize * 10 + 50,
font_size = inputFontsize * 10,
color = "White",
font_color = buttonFontColor,
value = box_data.value
})
end
maybeMakeSlotSelectionButtons()
end
---------------------------------------------------------
-- Living Ink related functions
---------------------------------------------------------
---------------------------------------------------------
-- Summoned Servitor related functions
---------------------------------------------------------
-- Creates the invisible buttons overlaying the slot words
function maybeMakeSlotSelectionButtons()
if selfId ~= "09080-c" then return end
local buttonData = {
click_function = "click_arcane",
function_owner = self,
position = { x = -1 * SLOT_ICON_POSITIONS.arcane.x, y = 0.2, z = SLOT_ICON_POSITIONS.arcane.z },
height = 130,
width = 130,
color = { 0, 0, 0, 0 },
}
self.createButton(buttonData)
buttonData.click_function = "click_ally"
buttonData.position.x = -1 * SLOT_ICON_POSITIONS.ally.x
self.createButton(buttonData)
end
function click_arcane()
if inputValues[1] == SLOT_INDICES.arcane then
inputValues[1] = SLOT_INDICES.none
else
inputValues[1] = SLOT_INDICES.arcane
end
maybeUpdateSlotDisplay()
end
function click_ally()
if inputValues[1] == SLOT_INDICES.ally then
inputValues[1] = SLOT_INDICES.none
else
inputValues[1] = SLOT_INDICES.ally
end
maybeUpdateSlotDisplay()
end
-- Refresh the vector circles indicating a slot is selected.
function maybeUpdateSlotDisplay()
if selfId ~= "09080-c" then return end
local center
center = SLOT_ICON_POSITIONS["arcane"]
local arcaneVecList = {
Vector(center.x + 0.12, 0.3, center.z + 0.05),
Vector(center.x - 0.12, 0.3, center.z + 0.05),
Vector(center.x - 0.12, 0.3, center.z - 0.05),
Vector(center.x + 0.12, 0.3, center.z - 0.05),
Vector(center.x + 0.12, 0.3, center.z + 0.05),
}
center = SLOT_ICON_POSITIONS["ally"]
local allyVecList = {
Vector(center.x + 0.07, 0.3, center.z + 0.05),
Vector(center.x - 0.07, 0.3, center.z + 0.05),
Vector(center.x - 0.07, 0.3, center.z - 0.05),
Vector(center.x + 0.07, 0.3, center.z - 0.05),
Vector(center.x + 0.07, 0.3, center.z + 0.05),
}
local arcaneVecColor = VECTOR_COLOR.unselected
local allyVecColor = VECTOR_COLOR.unselected
if inputValues[1] == SLOT_INDICES.arcane then
arcaneVecColor = VECTOR_COLOR.selected
elseif inputValues[1] == SLOT_INDICES.ally then
allyVecColor = VECTOR_COLOR.selected
end
self.setVectorLines({
{
points = arcaneVecList,
color = arcaneVecColor,
thickness = 0.02,
},
{
points = allyVecList,
color = allyVecColor,
thickness = 0.02,
}
})
end