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