resolving issues/bugfixing

This commit is contained in:
Chr1Z93 2022-11-24 14:33:29 +01:00
parent 3cf51936f2
commit 86d87cb45b
2 changed files with 155 additions and 532 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,37 +1,37 @@
-- Attachment Helper -- Attachment Helper
-- updated by: Chr1Z -- updated by: Chr1Z
-- original by: - -- original by: bankey
-- description: displays cards in it with cost/skill icons -- description: displays cards in it with cost/skill icons
information = { local information = {
version = "1.6", version = "1.7",
last_updated = "09.11.2022" last_updated = "24.11.2022"
} }
option_text = { local option_text = {
"Ancestral Knowledge", "Ancestral Knowledge",
"Astronomical Atlas", "Astronomical Atlas",
"Crystallizer of Dreams", "Crystallizer of Dreams",
"Diana Stanley", "Diana Stanley",
"Gloria Goldberg", "Gloria Goldberg",
"Sefina Rousseau", "Sefina Rousseau",
"Wooden Sledge" "Wooden Sledge"
} }
imageList = { local imageList = {
-- Ancestral Knowledge -- Ancestral Knowledge
"http://cloud-3.steamusercontent.com/ugc/1915746489207287888/2F9F6F211ED0F98E66C9D35D93221E4C7FB6DD3C/", "http://cloud-3.steamusercontent.com/ugc/1915746489207287888/2F9F6F211ED0F98E66C9D35D93221E4C7FB6DD3C/",
-- Astronomical Atlas -- Astronomical Atlas
"http://cloud-3.steamusercontent.com/ugc/1754695853007989004/9153BC204FC707AE564ECFAC063A11CB8C2B5D1E/", "http://cloud-3.steamusercontent.com/ugc/1754695853007989004/9153BC204FC707AE564ECFAC063A11CB8C2B5D1E/",
-- Crystallizer of Dreams -- Crystallizer of Dreams
"http://cloud-3.steamusercontent.com/ugc/1915746489207280958/100F16441939E5E23818651D1EB5C209BF3125B9/", "http://cloud-3.steamusercontent.com/ugc/1915746489207280958/100F16441939E5E23818651D1EB5C209BF3125B9/",
-- Diana Stanley -- Diana Stanley
"http://cloud-3.steamusercontent.com/ugc/1754695635919071208/1AB7222850201630826BFFBA8F2BD0065E2D572F/", "http://cloud-3.steamusercontent.com/ugc/1754695635919071208/1AB7222850201630826BFFBA8F2BD0065E2D572F/",
-- Gloria Goldberg -- Gloria Goldberg
"http://cloud-3.steamusercontent.com/ugc/1754695635919102502/453D4426118C8A6DE2EA281184716E26CA924C84/", "http://cloud-3.steamusercontent.com/ugc/1754695635919102502/453D4426118C8A6DE2EA281184716E26CA924C84/",
-- Sefina Rousseau -- Sefina Rousseau
"http://cloud-3.steamusercontent.com/ugc/1754695635919099826/3C3CBFFAADB2ACA9957C736491F470AE906CC953/", "http://cloud-3.steamusercontent.com/ugc/1754695635919099826/3C3CBFFAADB2ACA9957C736491F470AE906CC953/",
-- Wooden Sledge -- Wooden Sledge
"http://cloud-3.steamusercontent.com/ugc/1750192233783143973/D526236AAE16BDBB98D3F30E27BAFC1D3E21F4AC/" "http://cloud-3.steamusercontent.com/ugc/1750192233783143973/D526236AAE16BDBB98D3F30E27BAFC1D3E21F4AC/"
} }
-- save state and options to restore onLoad -- save state and options to restore onLoad
@ -39,154 +39,169 @@ function onSave() return JSON.encode({ cardsInBag, showCost, showIcons }) end
-- load variables and create context menu -- load variables and create context menu
function onLoad(saved_data) function onLoad(saved_data)
local loaded_data = JSON.decode(saved_data) local loaded_data = JSON.decode(saved_data)
cardsInBag = loaded_data[1] or {} cardsInBag = loaded_data[1] or {}
showCost = loaded_data[2] or true showCost = loaded_data[2] or true
showIcons = loaded_data[3] or true showIcons = loaded_data[3] or true
recreateButtons() recreateButtons()
self.addContextMenuItem("Select image", selectImage) self.addContextMenuItem("Select image", selectImage)
self.addContextMenuItem("Toggle cost", function(color) self.addContextMenuItem("Toggle cost", function(color)
showCost = not showCost showCost = not showCost
printToColor("Show cost of cards: " .. tostring(showCost), color, "White") printToColor("Show cost of cards: " .. tostring(showCost), color, "White")
refresh() refresh()
end) end)
self.addContextMenuItem("Toggle skill icons", function(color) self.addContextMenuItem("Toggle skill icons", function(color)
showIcons = not showIcons showIcons = not showIcons
printToColor("Show skill icons of cards: " .. tostring(showIcons), color, "White") printToColor("Show skill icons of cards: " .. tostring(showIcons), color, "White")
refresh() refresh()
end) end)
self.addContextMenuItem("More Information", function() self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White") printToAll("------------------------------", "White")
printToAll("Attachment Helper v" .. information["version"] .. " by Chr1Z", "Orange") printToAll("Attachment Helper v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("original by: bankey", "White") printToAll("original by: bankey", "White")
printToAll("last updated: " .. information["last_updated"], "White") printToAll("last updated: " .. information["last_updated"], "White")
end) end)
end end
function selectImage(color) function selectImage(color)
Player[color].showOptionsDialog("Select image:", option_text, 1, function(_, option_index) Player[color].showOptionsDialog("Select image:", option_text, 1, function(_, option_index)
local customInfo = self.getCustomObject() local customInfo = self.getCustomObject()
customInfo.diffuse = imageList[option_index] customInfo.diffuse = imageList[option_index]
self.setCustomObject(customInfo) self.setCustomObject(customInfo)
self.reload() self.reload()
end) end)
end end
-- called for every card that enters -- called for every card that enters
function onObjectEnterContainer(container, object) function onObjectEnterContainer(container, object)
if container == self then if container == self then
findCard(object.getGUID(), object.getName(), object.getGMNotes()) findCard(object.getGUID(), object.getName(), object.getGMNotes())
recreateButtons() recreateButtons()
end end
end end
-- removes leaving cards from the "cardInBag" table -- removes leaving cards from the "cardInBag" table
function onObjectLeaveContainer(container, object) function onObjectLeaveContainer(container, object)
if container == self then if container == self then
local guid = object.getGUID() local guid = object.getGUID()
for i, card in ipairs(cardsInBag) do local found = false
if card.id == guid then table.remove(cardsInBag, i) end for i, card in ipairs(cardsInBag) do
end if card.id == guid then
recreateButtons() table.remove(cardsInBag, i)
found = true
break
end
end end
if found ~= true then
local name = object.getName()
for i, card in ipairs(cardsInBag) do
if card.name == name then
table.remove(cardsInBag, i)
break
end
end
end
recreateButtons()
end
end end
-- refreshes displayed buttons based on contained cards -- refreshes displayed buttons based on contained cards
function refresh() function refresh()
cardsInBag = {} cardsInBag = {}
for _, object in ipairs(self.getObjects()) do for _, object in ipairs(self.getObjects()) do
findCard(object.guid, object.name, object.gm_notes) findCard(object.guid, object.name, object.gm_notes)
end end
recreateButtons() recreateButtons()
end end
-- gets cost and icons for a card -- gets cost and icons for a card
function findCard(guid, name, GMNotes) function findCard(guid, name, GMNotes)
local cost = "" local cost = ""
local icons = {} local icons = {}
local metadata = {} local metadata = {}
local displayName = name
if name == nil or name == "" then name = "unnamed" end if displayName == nil or displayName == "" then displayName = "unnamed" end
if showCost or showIcons then metadata = JSON.decode(GMNotes) end if showCost or showIcons then metadata = JSON.decode(GMNotes) end
if showCost then if showCost then
if GMNotes ~= "" then cost = metadata.cost end if GMNotes ~= "" then cost = metadata.cost end
if cost == nil or cost == "" then cost = "" end if cost == nil or cost == "" then cost = "" end
name = "[" .. cost .. "] " .. name displayName = "[" .. cost .. "] " .. displayName
end
if showIcons then
if GMNotes ~= "" then
icons[1] = metadata.wildIcons
icons[2] = metadata.willpowerIcons
icons[3] = metadata.intellectIcons
icons[4] = metadata.combatIcons
icons[5] = metadata.agilityIcons
end end
if showIcons then local IconTypes = { "Wild", "Willpower", "Intellect", "Combat", "Agility" }
if GMNotes ~= "" then local found = false
icons[1] = metadata.wildIcons for i = 1, 5 do
icons[2] = metadata.willpowerIcons if icons[i] ~= nil and icons[i] ~= "" then
icons[3] = metadata.intellectIcons if found == false then
icons[4] = metadata.combatIcons displayName = displayName .. "\n" .. IconTypes[i] .. ": " .. icons[i]
icons[5] = metadata.agilityIcons found = true
end else
displayName = displayName .. " " .. IconTypes[i] .. ": " .. icons[i]
local IconTypes = { "Wild", "Willpower", "Intellect", "Combat", "Agility" }
local found = false
for i = 1, 5 do
if icons[i] ~= nil and icons[i] ~= "" then
if found == false then
name = name .. "\n" .. IconTypes[i] .. ": " .. icons[i]
found = true
else
name = name .. " " .. IconTypes[i] .. ": " .. icons[i]
end
end
end end
end
end end
table.insert(cardsInBag, { name = name, id = guid }) end
table.insert(cardsInBag, { name = name, displayName = displayName, id = guid })
end end
-- recreates buttons with up-to-date labels -- recreates buttons with up-to-date labels
function recreateButtons() function recreateButtons()
self.clearButtons() self.clearButtons()
local verticalPosition = 1.65 local verticalPosition = 1.65
for _, card in ipairs(cardsInBag) do
if _G['removeCard' .. card.id] == nil then
_G['removeCard' .. card.id] = function() removeCard(card.id) end
end
self.createButton({
label = card.name,
click_function = "removeCard" .. card.id,
function_owner = self,
position = { 0, 0, verticalPosition },
height = 200,
width = 1200,
font_size = string.len(card.name) > 20 and 75 or 100
})
verticalPosition = verticalPosition - 0.5
end
local countLabel = '\nAttachment\nHelper\n' .. information["version"]
if #cardsInBag ~= 0 then countLabel = #cardsInBag end
for _, card in ipairs(cardsInBag) do
local id = card.id
local funcName = "removeCard" .. id
self.setVar(funcName, function() removeCard(id) end)
self.createButton({ self.createButton({
label = countLabel, label = card.displayName,
click_function = "none", click_function = funcName,
function_owner = self, function_owner = self,
position = { 0, 0, -1.35 }, position = { 0, 0, verticalPosition },
height = 0, height = 200,
width = 0, width = 1200,
font_size = 225, font_size = string.len(card.displayName) > 20 and 75 or 100
font_color = { 1, 1, 1, 1 }
}) })
verticalPosition = verticalPosition - 0.5
end
local countLabel = '\nAttachment\nHelper\n' .. information["version"]
if #cardsInBag ~= 0 then countLabel = #cardsInBag end
self.createButton({
label = countLabel,
click_function = "none",
function_owner = self,
position = { 0, 0, -1.35 },
height = 0,
width = 0,
font_size = 225,
font_color = { 1, 1, 1 }
})
end end
-- click-function for buttons to take a card out of the bag -- click-function for buttons to take a card out of the bag
function removeCard(cardGUID) function removeCard(cardGUID)
self.takeObject({ self.takeObject({
guid = cardGUID, guid = cardGUID,
rotation = self.getRotation(), rotation = self.getRotation(),
position = self.getPosition() + Vector(0, 0.25, 0), position = self.getPosition() + Vector(0, 0.25, 0),
callback_function = function(obj) obj.resting = true end callback_function = function(obj) obj.resting = true end
}) })
end end