-- 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("chaosbag/ChaosBagManager") end) __bundle_register("chaosbag/ChaosBagManager", function(require, _LOADED, __bundle_register, __bundle_modules) local chaosBagApi = require("chaosbag/ChaosBagApi") 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_X = { -- first row -0.9, -0.54, -0.18, 0.18, 0.54, 0.9, -- second row -0.9, -0.54, -0.18, 0.18, 0.9, -- third row -0.9, -0.54, -0.18, 0.18, 0.54, 0.9 } local BUTTON_POSITION_Z = { -0.298, 0.05, 0.399 } -- common button parameters local buttonParameters = {} buttonParameters.function_owner = self buttonParameters.color = { 0, 0, 0, 0 } buttonParameters.width = 160 buttonParameters.height = 160 function onLoad() -- create buttons for tokens for i = 1, #BUTTON_POSITION_X 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_X[i], y = 0 } if i < 7 then buttonParameters.position.z = BUTTON_POSITION_Z[1] elseif i < 12 then buttonParameters.position.z = BUTTON_POSITION_Z[2] else buttonParameters.position.z = BUTTON_POSITION_Z[3] end self.createButton(buttonParameters) end end -- click function for buttons function buttonClick(index, isRightClick) local tokenId = TOKEN_IDS[index] if isRightClick then chaosBagApi.removeChaosToken(tokenId) else local tokens = {} local name = BUTTON_TOOLTIP[index] local chaosbag = chaosBagApi.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 chaosBagApi.spawnChaosToken(tokenId) printToAll("Adding " .. name .. " token (in bag: " .. #tokens + 1 .. ")", "White") end end end) __bundle_register("chaosbag/ChaosBagApi", function(require, _LOADED, __bundle_register, __bundle_modules) do local ChaosBagApi = {} -- respawns the chaos bag with a new state of tokens ---@param tokenList table List of chaos token ids ChaosBagApi.setChaosBagState = function(tokenList) Global.call("setChaosBagState", tokenList) end -- returns a Table List of chaos token ids in the current chaos bag -- requires copying the data into a new table because TTS is weird about handling table return values in Global ChaosBagApi.getChaosBagState = function() local chaosBagContentsCatcher = Global.call("getChaosBagState") local chaosBagContents = {} for _, v in ipairs(chaosBagContentsCatcher) do table.insert(chaosBagContents, v) end return chaosBagContents end -- checks scripting zone for chaos bag (also called by a lot of objects!) ChaosBagApi.findChaosBag = function() return Global.call("findChaosBag") end -- returns a table of object references to the tokens in play (does not include sealed tokens!) ChaosBagApi.getTokensInPlay = function() return Global.call("getChaosTokensinPlay") end -- returns all sealed tokens on cards to the chaos bag ---@param playerColor string Color of the player to show the broadcast to ChaosBagApi.releaseAllSealedTokens = function(playerColor) Global.call("releaseAllSealedTokens", playerColor) end -- returns all drawn tokens to the chaos bag ChaosBagApi.returnChaosTokens = function() Global.call("returnChaosTokens") end -- removes the specified chaos token from the chaos bag ---@param id string ID of the chaos token ChaosBagApi.removeChaosToken = function(id) Global.call("removeChaosToken", id) end -- returns a chaos token to the bag and calls all relevant functions ---@param token tts__Object Chaos token to return ---@param fromBag boolean whether or not the token to return was in the middle of being drawn (true) or elsewhere (false) ChaosBagApi.returnChaosTokenToBag = function(token, fromBag) Global.call("returnChaosTokenToBag", { token = token, fromBag = fromBag }) end -- spawns the specified chaos token and puts it into the chaos bag ---@param id string ID of the chaos token ChaosBagApi.spawnChaosToken = function(id) Global.call("spawnChaosToken", id) end -- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens -- are drawn or replaced a TTS bug can cause those tokens to vanish. Any functions which change the -- contents of the bag should check this method before doing so. -- This method will broadcast a message to all players if the bag is being searched. ---@return any: True if the bag is manipulated, false if it should be blocked. ChaosBagApi.canTouchChaosTokens = function() return Global.call("canTouchChaosTokens") end -- draws a chaos token to a playermat ---@param mat tts__Object Playermat that triggered this ---@param drawAdditional boolean Controls whether additional tokens should be drawn ---@param tokenType? string Name of token (e.g. "Bless") to be drawn from the bag ---@param guidToBeResolved? string GUID of the sealed token to be resolved instead of drawing a token from the bag ---@param takeParameters? table Position and rotation of the location where the new token should be drawn to, usually to replace a returned token ---@return tts__Object: Object reference to the token that was drawn ChaosBagApi.drawChaosToken = function(mat, drawAdditional, tokenType, guidToBeResolved, takeParameters) return Global.call("drawChaosToken", { mat = mat, drawAdditional = drawAdditional, tokenType = tokenType, guidToBeResolved = guidToBeResolved, takeParameters = takeParameters }) end -- returns a Table List of chaos token ids in the current chaos bag -- requires copying the data into a new table because TTS is weird about handling table return values in Global ChaosBagApi.getIdUrlMap = function() return Global.getTable("ID_URL_MAP") end return ChaosBagApi end end) return __bundle_require("__root")