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
-- updated by: Chr1Z
-- original by: -
-- original by: bankey
-- description: displays cards in it with cost/skill icons
information = {
version = "1.6",
last_updated = "09.11.2022"
local information = {
version = "1.7",
last_updated = "24.11.2022"
}
option_text = {
local option_text = {
"Ancestral Knowledge",
"Astronomical Atlas",
"Crystallizer of Dreams",
@ -17,7 +17,7 @@ option_text = {
"Wooden Sledge"
}
imageList = {
local imageList = {
-- Ancestral Knowledge
"http://cloud-3.steamusercontent.com/ugc/1915746489207287888/2F9F6F211ED0F98E66C9D35D93221E4C7FB6DD3C/",
-- Astronomical Atlas
@ -88,8 +88,23 @@ end
function onObjectLeaveContainer(container, object)
if container == self then
local guid = object.getGUID()
local found = false
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
recreateButtons()
end
@ -109,14 +124,15 @@ function findCard(guid, name, GMNotes)
local cost = ""
local icons = {}
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 then
if GMNotes ~= "" then cost = metadata.cost end
if cost == nil or cost == "" then cost = "" end
name = "[" .. cost .. "] " .. name
displayName = "[" .. cost .. "] " .. displayName
end
if showIcons then
@ -133,15 +149,15 @@ function findCard(guid, name, GMNotes)
for i = 1, 5 do
if icons[i] ~= nil and icons[i] ~= "" then
if found == false then
name = name .. "\n" .. IconTypes[i] .. ": " .. icons[i]
displayName = displayName .. "\n" .. IconTypes[i] .. ": " .. icons[i]
found = true
else
name = name .. " " .. IconTypes[i] .. ": " .. icons[i]
displayName = displayName .. " " .. IconTypes[i] .. ": " .. icons[i]
end
end
end
end
table.insert(cardsInBag, { name = name, id = guid })
table.insert(cardsInBag, { name = name, displayName = displayName, id = guid })
end
-- recreates buttons with up-to-date labels
@ -150,18 +166,17 @@ function recreateButtons()
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
local id = card.id
local funcName = "removeCard" .. id
self.setVar(funcName, function() removeCard(id) end)
self.createButton({
label = card.name,
click_function = "removeCard" .. card.id,
label = card.displayName,
click_function = funcName,
function_owner = self,
position = { 0, 0, verticalPosition },
height = 200,
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
end
@ -177,7 +192,7 @@ function recreateButtons()
height = 0,
width = 0,
font_size = 225,
font_color = { 1, 1, 1, 1 }
font_color = { 1, 1, 1 }
})
end