SCED/src/accessories/ChaosBagManager.ttslua

83 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-03-03 00:39:20 +01:00
local TOKEN_IDS = {
2022-11-24 17:32:29 +01:00
-- first row
2023-03-03 00:39:20 +01:00
"p1", "0", "m1", "m2", "m3", "m4",
2022-11-24 17:32:29 +01:00
-- second row
2023-03-03 00:39:20 +01:00
"m5", "m6", "m7", "m8", "frost",
2022-11-24 17:32:29 +01:00
-- third row
2023-03-03 00:39:20 +01:00
"blue", "skull", "cultist", "tablet", "elder", "red"
2022-11-10 23:59:55 -08:00
}
local BUTTON_TOOLTIP = {
2022-11-24 17:32:29 +01:00
-- first row
"+1", "0", "-1", "-2", "-3", "-4",
-- second row
"-5", "-6", "-7", "-8", "Frost",
-- third row
"Elder Sign", "Skull", "Cultist", "Tablet", "Elder Thing", "Auto-fail"
2022-11-10 23:59:55 -08:00
}
local BUTTON_POSITION = {
2022-11-24 17:32:29 +01:00
-- first row
-1.90, -1.14, -0.38, 0.38, 1.14, 1.90,
-- second row
-1.90, -1.14, -0.38, 0.38, 1.90,
-- third row
-1.90, -1.14, -0.38, 0.38, 1.14, 1.90
2022-11-10 23:59:55 -08:00
}
-- common button parameters
2022-11-12 15:36:48 +01:00
local buttonParameters = {}
buttonParameters.function_owner = self
2023-01-03 22:05:38 +01:00
buttonParameters.color = { 0, 0, 0, 0 }
2022-11-12 15:36:48 +01:00
buttonParameters.width = 300
buttonParameters.height = 300
2022-11-10 23:59:55 -08:00
2022-11-24 17:32:29 +01:00
local name
local tokens = {}
2022-11-12 15:36:48 +01:00
function onLoad()
2022-11-24 17:32:29 +01:00
-- create buttons for tokens
for i = 1, #BUTTON_POSITION do
local funcName = "buttonClick" .. i
2023-01-01 17:55:21 +01:00
self.setVar(funcName, function(_, _, isRightClick) buttonClick(i, isRightClick) end)
2022-11-24 17:32:29 +01:00
buttonParameters.click_function = funcName
buttonParameters.tooltip = BUTTON_TOOLTIP[i]
buttonParameters.position = { x = BUTTON_POSITION[i], y = 0, z = 0 }
if i < 7 then
buttonParameters.position.z = -0.778
2023-01-01 17:55:21 +01:00
elseif i > 11 then
buttonParameters.position.z = 0.755
2022-11-10 23:59:55 -08:00
end
2022-11-24 17:32:29 +01:00
self.createButton(buttonParameters)
end
2022-11-10 23:59:55 -08:00
end
-- click function for buttons
2023-01-01 17:55:21 +01:00
function buttonClick(index, isRightClick)
2023-03-03 00:39:20 +01:00
local tokenId = TOKEN_IDS[index]
2022-11-24 17:32:29 +01:00
if isRightClick then
2023-03-03 00:39:20 +01:00
Global.call("removeChaosToken", tokenId)
else
local tokens = {}
local name = BUTTON_TOOLTIP[index]
local chaosbag = Global.call("findChaosBag")
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == name then table.insert(tokens, v.guid) end
2022-11-10 23:59:55 -08:00
end
2022-11-24 17:32:29 +01:00
-- spawn token (only 8 frost tokens allowed)
2023-03-03 00:39:20 +01:00
if tokenId == "frost" and #tokens == 8 then
2022-11-24 17:32:29 +01:00
printToAll("The maximum of 8 Frost tokens is already in the bag.", "Yellow")
return
2022-11-10 23:59:55 -08:00
end
2022-11-12 15:36:48 +01:00
2023-03-03 00:39:20 +01:00
Global.call("spawnChaosToken", tokenId)
printToAll("Adding " .. name .. " token (in bag: " .. #tokens + 1 .. ")", "White")
2022-11-24 17:32:29 +01:00
end
2022-11-12 15:36:48 +01:00
end