Merge pull request #67 from argonui/attachmenthelper-update

Attachment Helper: resolving issues/bugfixing
This commit is contained in:
Buhallin 2022-11-24 11:11:53 -08:00 committed by GitHub
commit bdb3053f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 155 additions and 532 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,13 +1,13 @@
-- 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",
@ -17,7 +17,7 @@ option_text = {
"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
@ -88,8 +88,23 @@ end
function onObjectLeaveContainer(container, object) function onObjectLeaveContainer(container, object)
if container == self then if container == self then
local guid = object.getGUID() local guid = object.getGUID()
local found = false
for i, card in ipairs(cardsInBag) do for i, card in ipairs(cardsInBag) do
if card.id == guid then table.remove(cardsInBag, i) end if card.id == guid then
table.remove(cardsInBag, i)
found = true
break
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 end
recreateButtons() recreateButtons()
end end
@ -109,14 +124,15 @@ 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 end
if showIcons then if showIcons then
@ -133,15 +149,15 @@ function findCard(guid, name, GMNotes)
for i = 1, 5 do for i = 1, 5 do
if icons[i] ~= nil and icons[i] ~= "" then if icons[i] ~= nil and icons[i] ~= "" then
if found == false then if found == false then
name = name .. "\n" .. IconTypes[i] .. ": " .. icons[i] displayName = displayName .. "\n" .. IconTypes[i] .. ": " .. icons[i]
found = true found = true
else else
name = name .. " " .. IconTypes[i] .. ": " .. icons[i] displayName = displayName .. " " .. IconTypes[i] .. ": " .. icons[i]
end end
end end
end end
end end
table.insert(cardsInBag, { name = name, id = guid }) 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
@ -150,18 +166,17 @@ function recreateButtons()
local verticalPosition = 1.65 local verticalPosition = 1.65
for _, card in ipairs(cardsInBag) do for _, card in ipairs(cardsInBag) do
if _G['removeCard' .. card.id] == nil then local id = card.id
_G['removeCard' .. card.id] = function() removeCard(card.id) end local funcName = "removeCard" .. id
end self.setVar(funcName, function() removeCard(id) end)
self.createButton({ self.createButton({
label = card.name, label = card.displayName,
click_function = "removeCard" .. card.id, click_function = funcName,
function_owner = self, function_owner = self,
position = { 0, 0, verticalPosition }, position = { 0, 0, verticalPosition },
height = 200, height = 200,
width = 1200, width = 1200,
font_size = string.len(card.name) > 20 and 75 or 100 font_size = string.len(card.displayName) > 20 and 75 or 100
}) })
verticalPosition = verticalPosition - 0.5 verticalPosition = verticalPosition - 0.5
end end
@ -177,7 +192,7 @@ function recreateButtons()
height = 0, height = 0,
width = 0, width = 0,
font_size = 225, font_size = 225,
font_color = { 1, 1, 1, 1 } font_color = { 1, 1, 1 }
}) })
end end