ah_sce_unpacked/unpacked/Checker_white Token Spawn Tracker e3ffc9.ttslua
2024-07-27 21:47:52 -04:00

106 lines
2.9 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("core/token/TokenSpawnTracker")
end)
__bundle_register("core/token/TokenSpawnTracker", function(require, _LOADED, __bundle_register, __bundle_modules)
local spawnedCardGuids = {}
function onSave() return JSON.encode({ cards = spawnedCardGuids }) end
function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData) or {}
spawnedCardGuids = loadedData.cards or {}
end
-- context menu entries
self.addContextMenuItem("Reset All", resetAll)
self.addContextMenuItem("Reset Locations", resetAllLocations)
self.addContextMenuItem("Reset Player Cards", resetAllAssetAndEvents)
end
function hasSpawnedTokens(cardGuid)
return spawnedCardGuids[cardGuid] == true
end
function markTokensSpawned(cardGuid)
spawnedCardGuids[cardGuid] = true
end
function resetTokensSpawned(card)
spawnedCardGuids[card.getGUID()] = nil
end
function resetAll() spawnedCardGuids = {} end
function resetAllLocations() resetSpecificTypes("Location") end
function resetAllAssetAndEvents() resetSpecificTypes("Asset", "Event") end
function resetSpecificTypes(type1, type2)
local resetList = {}
for cardGuid, _ in pairs(spawnedCardGuids) do
local card = getObjectFromGUID(cardGuid)
if card ~= nil then
local cardMetadata = JSON.decode(card.getGMNotes()) or {}
-- Check this by type rather than the PlayerCard tag so we don't reset weaknesses
if cardMetadata.type == type1 or cardMetadata.type == type2 then
resetList[cardGuid] = true
end
end
end
for cardGuid, _ in pairs(resetList) do
spawnedCardGuids[cardGuid] = nil
end
end
-- Listener to reset card token spawns when they enter a hand.
function onObjectEnterZone(zone, enterObject)
if zone.type == "Hand" and enterObject.type == "Card" then
resetTokensSpawned(enterObject)
end
end
end)
return __bundle_require("__root")