Merge pull request #576 from argonui/attachment-helper
Updated Attachment Helper
This commit is contained in:
commit
c30536dfe5
@ -35,7 +35,7 @@
|
|||||||
"LayoutGroupSortIndex": 0,
|
"LayoutGroupSortIndex": 0,
|
||||||
"Locked": false,
|
"Locked": false,
|
||||||
"LuaScript": "require(\"accessories/AttachmentHelper\")",
|
"LuaScript": "require(\"accessories/AttachmentHelper\")",
|
||||||
"LuaScriptState": "[[],true,true]",
|
"LuaScriptState": "[[],true]",
|
||||||
"MaterialIndex": -1,
|
"MaterialIndex": -1,
|
||||||
"MeasureMovement": false,
|
"MeasureMovement": false,
|
||||||
"MeshIndex": -1,
|
"MeshIndex": -1,
|
||||||
@ -54,7 +54,7 @@
|
|||||||
"posZ": -19.636,
|
"posZ": -19.636,
|
||||||
"rotX": 0,
|
"rotX": 0,
|
||||||
"rotY": 270,
|
"rotY": 270,
|
||||||
"rotZ": 359,
|
"rotZ": 0,
|
||||||
"scaleX": 0.8,
|
"scaleX": 0.8,
|
||||||
"scaleY": 1,
|
"scaleY": 1,
|
||||||
"scaleZ": 0.8
|
"scaleZ": 0.8
|
||||||
|
@ -1,97 +1,110 @@
|
|||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
local fontColor
|
local fontColor, lastRejectedName
|
||||||
local BACKGROUNDS = {
|
local BACKGROUNDS = {
|
||||||
{
|
{
|
||||||
title = "Ancestral Knowledge",
|
title = "Ancestral Knowledge",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1915746489207287888/2F9F6F211ED0F98E66C9D35D93221E4C7FB6DD3C/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1915746489207287888/2F9F6F211ED0F98E66C9D35D93221E4C7FB6DD3C/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Astronomical Atlas",
|
title = "Astronomical Atlas",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1754695853007989004/9153BC204FC707AE564ECFAC063A11CB8C2B5D1E/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1754695853007989004/9153BC204FC707AE564ECFAC063A11CB8C2B5D1E/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Backpack",
|
title = "Backpack",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2018212896278691928/F55BEFFC2540109C6333179532F583B367FF2EBC/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2018212896278691928/F55BEFFC2540109C6333179532F583B367FF2EBC/",
|
||||||
fontcolor = { 0, 0, 0 }
|
fontcolor = { 0, 0, 0 },
|
||||||
|
icons = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Bewitching",
|
||||||
|
url = "http://cloud-3.steamusercontent.com/ugc/2342503480966345423/F2070B5479C814F35780373966D77D91767A97CC/",
|
||||||
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Binder's Jar",
|
title = "Binder's Jar",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228642191/4C149527851C1DBB3015F93DE91667937A3F91DD/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228642191/4C149527851C1DBB3015F93DE91667937A3F91DD/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Crystallizer of Dreams",
|
title = "Crystallizer of Dreams",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1915746489207280958/100F16441939E5E23818651D1EB5C209BF3125B9/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1915746489207280958/100F16441939E5E23818651D1EB5C209BF3125B9/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Diana Stanley",
|
title = "Diana Stanley",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919071208/1AB7222850201630826BFFBA8F2BD0065E2D572F/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919071208/1AB7222850201630826BFFBA8F2BD0065E2D572F/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Gloria Goldberg",
|
title = "Gloria Goldberg",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919102502/453D4426118C8A6DE2EA281184716E26CA924C84/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919102502/453D4426118C8A6DE2EA281184716E26CA924C84/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Ikiaq",
|
title = "Ikiaq",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228198966/5A408D8D760221DEA164E986B9BE1F79C4803071/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228198966/5A408D8D760221DEA164E986B9BE1F79C4803071/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Katja Eastbank",
|
title = "Katja Eastbank",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228203475/62EEE12F4DB1EB80D79B087677459B954380215F/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228203475/62EEE12F4DB1EB80D79B087677459B954380215F/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Ravenous",
|
title = "Ravenous",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228208075/EAC598A450BEE504A7FE179288F1FBBF7ABFA3E0/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228208075/EAC598A450BEE504A7FE179288F1FBBF7ABFA3E0/",
|
||||||
fontcolor = { 0, 0, 0 }
|
fontcolor = { 0, 0, 0 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Sefina Rousseau",
|
title = "Sefina Rousseau",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919099826/3C3CBFFAADB2ACA9957C736491F470AE906CC953/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1754695635919099826/3C3CBFFAADB2ACA9957C736491F470AE906CC953/",
|
||||||
fontcolor = { 0, 0, 0 }
|
fontcolor = { 0, 0, 0 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Stick to the Plan",
|
title = "Stick to the Plan",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2018214163838897493/8E38B96C5A8D703A59009A932432CBE21ABE63A2/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2018214163838897493/8E38B96C5A8D703A59009A932432CBE21ABE63A2/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Subject 5U-21",
|
title = "Subject 5U-21",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228199363/CE43D58F37C9F48BDD6E6E145FE29BADEFF4DBC5/",
|
url = "http://cloud-3.steamusercontent.com/ugc/2021606446228199363/CE43D58F37C9F48BDD6E6E145FE29BADEFF4DBC5/",
|
||||||
fontcolor = { 1, 1, 1 }
|
fontcolor = { 1, 1, 1 },
|
||||||
|
icons = false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Wooden Sledge",
|
title = "Wooden Sledge",
|
||||||
url = "http://cloud-3.steamusercontent.com/ugc/1750192233783143973/D526236AAE16BDBB98D3F30E27BAFC1D3E21F4AC/",
|
url = "http://cloud-3.steamusercontent.com/ugc/1750192233783143973/D526236AAE16BDBB98D3F30E27BAFC1D3E21F4AC/",
|
||||||
fontcolor = { 0, 0, 0 }
|
fontcolor = { 0, 0, 0 },
|
||||||
|
icons = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- save state and options to restore onLoad
|
-- save state and options to restore onLoad
|
||||||
function onSave() return JSON.encode({ cardsInBag, showCost, showIcons }) end
|
function onSave() return JSON.encode({ cardsInBag, showIcons }) end
|
||||||
|
|
||||||
-- load variables and create context menu
|
-- load variables and create context menu
|
||||||
function onLoad(savedData)
|
function onLoad(savedData)
|
||||||
local loadedData = JSON.decode(savedData)
|
local loadedData = JSON.decode(savedData)
|
||||||
cardsInBag = loadedData[1] or {}
|
cardsInBag = loadedData[1]
|
||||||
showCost = loadedData[2] or true
|
showIcons = loadedData[2]
|
||||||
showIcons = loadedData[3] or true
|
|
||||||
fontColor = getFontColor()
|
fontColor = getFontColor()
|
||||||
recreateButtons()
|
recreateButtons()
|
||||||
|
|
||||||
self.addContextMenuItem("Select image", selectImage)
|
self.addContextMenuItem("Select image", selectImage)
|
||||||
self.addContextMenuItem("Toggle cost", function(color)
|
|
||||||
showCost = not showCost
|
|
||||||
printToColor("Show cost of cards: " .. tostring(showCost), color, "White")
|
|
||||||
refresh()
|
|
||||||
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")
|
||||||
@ -124,6 +137,7 @@ function onDrop(playerColor)
|
|||||||
for _, bgInfo in ipairs(BACKGROUNDS) do
|
for _, bgInfo in ipairs(BACKGROUNDS) do
|
||||||
if bgInfo.title == syncName then
|
if bgInfo.title == syncName then
|
||||||
printToColor("Background for '" .. syncName .. "' loaded!", playerColor, "Green")
|
printToColor("Background for '" .. syncName .. "' loaded!", playerColor, "Green")
|
||||||
|
showIcons = bgInfo.icons
|
||||||
updateImage(bgInfo.url)
|
updateImage(bgInfo.url)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -141,13 +155,14 @@ function selectImage(color)
|
|||||||
|
|
||||||
-- prompt user to select option
|
-- prompt user to select option
|
||||||
Player[color].showOptionsDialog("Select image:", options, 1, function(_, optionIndex)
|
Player[color].showOptionsDialog("Select image:", options, 1, function(_, optionIndex)
|
||||||
|
showIcons = BACKGROUNDS[optionIndex].icons
|
||||||
updateImage(BACKGROUNDS[optionIndex].url)
|
updateImage(BACKGROUNDS[optionIndex].url)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sets background to the provided URL
|
-- sets background to the provided URL
|
||||||
function updateImage(url)
|
function updateImage(url)
|
||||||
self.script_state = JSON.encode({ cardsInBag, showCost, showIcons })
|
self.script_state = JSON.encode({ cardsInBag, showIcons })
|
||||||
local customInfo = self.getCustomObject()
|
local customInfo = self.getCustomObject()
|
||||||
customInfo.diffuse = url
|
customInfo.diffuse = url
|
||||||
self.setCustomObject(customInfo)
|
self.setCustomObject(customInfo)
|
||||||
@ -155,23 +170,28 @@ function updateImage(url)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- only allow cards to enter, split decks and reject other objects
|
-- only allow cards to enter, split decks and reject other objects
|
||||||
function onObjectEnterContainer(container, object)
|
function tryObjectEnter(object)
|
||||||
if container ~= self then return end
|
-- block repeated collisions
|
||||||
|
if object.getName() == lastRejectedName then return end
|
||||||
|
|
||||||
if object.type == "Deck" then
|
if object.type == "Deck" then
|
||||||
takeDeckOut(object.getGUID(), self.getPosition() + Vector(0, 0.1, 0))
|
local pos = self.getPosition()
|
||||||
|
for i = 1, #object.getObjects() do
|
||||||
|
local card = object.takeObject({ position = pos + Vector(0, 0.1 * i, 0), smooth = false })
|
||||||
|
findCard(card.getGUID(), card.getName(), card.getGMNotes())
|
||||||
|
self.putObject(card)
|
||||||
|
end
|
||||||
|
recreateButtons()
|
||||||
|
return false
|
||||||
elseif object.type ~= "Card" then
|
elseif object.type ~= "Card" then
|
||||||
broadcastToAll("The 'Attachment Helper' is meant to be used for cards.", "White")
|
broadcastToAll("The 'Attachment Helper' only supports cards.", "Orange")
|
||||||
|
lastRejectedName = object.getName()
|
||||||
|
Wait.time(function() lastRejectedName = nil end, 1)
|
||||||
|
return false
|
||||||
else
|
else
|
||||||
findCard(object.getGUID(), object.getName(), object.getGMNotes())
|
findCard(object.getGUID(), object.getName(), object.getGMNotes())
|
||||||
recreateButtons()
|
recreateButtons()
|
||||||
end
|
return true
|
||||||
end
|
|
||||||
|
|
||||||
-- takes the deck out and splits in into single cards
|
|
||||||
function takeDeckOut(guid, pos)
|
|
||||||
local deck = self.takeObject({ guid = guid, position = pos, smooth = false })
|
|
||||||
for i = 1, #deck.getObjects() do
|
|
||||||
self.putObject(deck.takeObject({ position = pos + Vector(0, 0.1 * i, 0), smooth = false }))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -181,7 +201,7 @@ function onObjectLeaveContainer(container, object)
|
|||||||
local guid = object.getGUID()
|
local guid = object.getGUID()
|
||||||
local found = false
|
local found = false
|
||||||
for i, card in ipairs(cardsInBag) do
|
for i, card in ipairs(cardsInBag) do
|
||||||
if card.id == guid then
|
if card.guid == guid then
|
||||||
table.remove(cardsInBag, i)
|
table.remove(cardsInBag, i)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@ -212,22 +232,16 @@ 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 icons = {}
|
local icons = {}
|
||||||
local metadata = {}
|
local metadata = JSON.decode(GMNotes) or {}
|
||||||
local displayName = name
|
local buttonLabel = name or "unnamed"
|
||||||
|
|
||||||
if displayName == nil or displayName == "" then displayName = "unnamed" end
|
if metadata.cost then
|
||||||
if showCost or showIcons then metadata = JSON.decode(GMNotes) end
|
buttonLabel = "[" .. metadata.cost .. "] " .. buttonLabel
|
||||||
|
|
||||||
if showCost then
|
|
||||||
if GMNotes ~= "" then cost = metadata.cost end
|
|
||||||
if cost == nil or cost == "" then cost = "–" end
|
|
||||||
displayName = "[" .. cost .. "] " .. displayName
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if showIcons then
|
if showIcons then
|
||||||
if GMNotes ~= "" then
|
if metadata ~= {} then
|
||||||
icons[1] = metadata.wildIcons
|
icons[1] = metadata.wildIcons
|
||||||
icons[2] = metadata.willpowerIcons
|
icons[2] = metadata.willpowerIcons
|
||||||
icons[3] = metadata.intellectIcons
|
icons[3] = metadata.intellectIcons
|
||||||
@ -240,15 +254,16 @@ 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
|
||||||
displayName = displayName .. "\n" .. IconTypes[i] .. ": " .. icons[i]
|
buttonLabel = buttonLabel .. "\n"
|
||||||
found = true
|
found = true
|
||||||
else
|
else
|
||||||
displayName = displayName .. " " .. IconTypes[i] .. ": " .. icons[i]
|
buttonLabel = buttonLabel .. " "
|
||||||
end
|
end
|
||||||
|
buttonLabel = buttonLabel .. IconTypes[i] .. ": " .. icons[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(cardsInBag, { name = name, displayName = displayName, id = guid })
|
table.insert(cardsInBag, { buttonLabel = buttonLabel, hasIcons = (#icons > 0), name = name, guid = guid })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- recreates buttons with up-to-date labels
|
-- recreates buttons with up-to-date labels
|
||||||
@ -256,20 +271,36 @@ function recreateButtons()
|
|||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
local verticalPosition = 1.65
|
local verticalPosition = 1.65
|
||||||
|
|
||||||
for _, card in ipairs(cardsInBag) do
|
-- create buttons for the last 7 cards that entered
|
||||||
local id = card.id
|
for i = #cardsInBag, 1, -1 do
|
||||||
local funcName = "removeCard" .. id
|
if (i + 7) == #cardsInBag then
|
||||||
self.setVar(funcName, function() removeCard(id) end)
|
printToAll("Only displaying buttons for the last 7 cards.", "Orange")
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
local card = cardsInBag[i]
|
||||||
|
|
||||||
|
-- click function
|
||||||
|
local funcName = "removeCard" .. card.guid
|
||||||
|
self.setVar(funcName, function() removeCard(card.guid) end)
|
||||||
|
|
||||||
|
-- font size
|
||||||
|
local fontSize = 100
|
||||||
|
if card.hasIcons or string.len(card.buttonLabel) > 20 then
|
||||||
|
fontSize = 75
|
||||||
|
end
|
||||||
|
|
||||||
|
-- button creation
|
||||||
self.createButton({
|
self.createButton({
|
||||||
label = card.displayName,
|
label = card.buttonLabel,
|
||||||
click_function = funcName,
|
click_function = funcName,
|
||||||
function_owner = self,
|
function_owner = self,
|
||||||
position = { 0, -0.1, verticalPosition },
|
position = { 0, -0.1, verticalPosition },
|
||||||
height = 200,
|
height = 200,
|
||||||
width = 1200,
|
width = 1200,
|
||||||
font_size = string.len(card.displayName) > 20 and 75 or 100
|
font_size = fontSize
|
||||||
})
|
})
|
||||||
verticalPosition = verticalPosition - 0.5
|
verticalPosition = verticalPosition - 0.485
|
||||||
end
|
end
|
||||||
|
|
||||||
local countLabel = #cardsInBag
|
local countLabel = #cardsInBag
|
||||||
@ -280,7 +311,7 @@ function recreateButtons()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.createButton({
|
self.createButton({
|
||||||
label = countLabel,
|
label = tostring(countLabel),
|
||||||
click_function = "none",
|
click_function = "none",
|
||||||
function_owner = self,
|
function_owner = self,
|
||||||
position = { 0, -0.1, -1.7 },
|
position = { 0, -0.1, -1.7 },
|
||||||
|
Loading…
Reference in New Issue
Block a user