ah_sce_unpacked/unpacked/Bag OptionPanel Source 830bd0/Custom_Token Chaos Bag Manager 023240.ttslua
2023-04-22 16:56:01 -04:00

131 lines
3.5 KiB
Plaintext

-- Bundled by luabundle {"version":"1.6.0"}
local __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)
local loadingPlaceholder = {[{}] = true}
local register
local modules = {}
local require
local loaded = {}
register = function(name, body)
if not modules[name] then
modules[name] = body
end
end
require = function(name)
local loadedModule = loaded[name]
if loadedModule then
if loadedModule == loadingPlaceholder then
return nil
end
else
if not modules[name] then
if not superRequire then
local identifier = type(name) == 'string' and '\"' .. name .. '\"' or tostring(name)
error('Tried to require ' .. identifier .. ', but no such module has been registered')
else
return superRequire(name)
end
end
loaded[name] = loadingPlaceholder
loadedModule = modules[name](require, loaded, register, modules)
loaded[name] = loadedModule
end
return loadedModule
end
return require, loaded, register, modules
end)(nil)
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
require("accessories/ChaosBagManager")
end)
__bundle_register("accessories/ChaosBagManager", function(require, _LOADED, __bundle_register, __bundle_modules)
local TOKEN_IDS = {
-- first row
"p1", "0", "m1", "m2", "m3", "m4",
-- second row
"m5", "m6", "m7", "m8", "frost",
-- third row
"blue", "skull", "cultist", "tablet", "elder", "red"
}
local BUTTON_TOOLTIP = {
-- 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"
}
local BUTTON_POSITION = {
-- 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
}
-- common button parameters
local buttonParameters = {}
buttonParameters.function_owner = self
buttonParameters.color = { 0, 0, 0, 0 }
buttonParameters.width = 300
buttonParameters.height = 300
local name
local tokens = {}
function onLoad()
-- create buttons for tokens
for i = 1, #BUTTON_POSITION do
local funcName = "buttonClick" .. i
self.setVar(funcName, function(_, _, isRightClick) buttonClick(i, isRightClick) end)
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
elseif i > 11 then
buttonParameters.position.z = 0.755
end
self.createButton(buttonParameters)
end
end
-- click function for buttons
function buttonClick(index, isRightClick)
local tokenId = TOKEN_IDS[index]
if isRightClick then
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
end
-- spawn token (only 8 frost tokens allowed)
if tokenId == "frost" and #tokens == 8 then
printToAll("The maximum of 8 Frost tokens is already in the bag.", "Yellow")
return
end
Global.call("spawnChaosToken", tokenId)
printToAll("Adding " .. name .. " token (in bag: " .. #tokens + 1 .. ")", "White")
end
end
end)
return __bundle_require("__root")