ah_sce_unpacked/unpacked/Checker_white Token Spawn Tracker e3ffc9.ttslua

108 lines
3.0 KiB
Plaintext
Raw Normal View History

2023-01-29 19:31:52 -05:00
-- 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)
2024-01-06 21:32:29 -05:00
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
require("core/token/TokenSpawnTracker")
end)
2023-01-29 19:31:52 -05:00
__bundle_register("core/token/TokenSpawnTracker", function(require, _LOADED, __bundle_register, __bundle_modules)
2024-01-06 21:32:29 -05:00
local spawnedCardGuids = {}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:29 -05:00
function onSave() return JSON.encode({ cards = spawnedCardGuids }) end
2023-01-29 19:31:52 -05:00
function onLoad(saveState)
if saveState ~= nil then
2024-01-06 21:32:29 -05:00
local saveTable = JSON.decode(saveState) or {}
spawnedCardGuids = saveTable.cards or {}
2023-01-29 19:31:52 -05:00
end
createResetMenuItems()
end
function createResetMenuItems()
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(cardGuid)
spawnedCardGuids[cardGuid] = nil
end
2024-01-06 21:32:29 -05:00
function resetAll() spawnedCardGuids = {} end
function resetAllLocations() resetSpecificTypes("Location") end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:29 -05:00
function resetAllAssetAndEvents() resetSpecificTypes("Asset", "Event") end
function resetSpecificTypes(type1, type2)
local resetList = {}
2023-01-29 19:31:52 -05:00
for cardGuid, _ in pairs(spawnedCardGuids) do
local card = getObjectFromGUID(cardGuid)
if card ~= nil then
2024-01-06 21:32:29 -05:00
local cardMetadata = JSON.decode(card.getGMNotes()) or {}
2023-01-29 19:31:52 -05:00
-- Check this by type rather than the PlayerCard tag so we don't reset weaknesses
2024-01-06 21:32:29 -05:00
if cardMetadata.type == type1 or cardMetadata.type == type2 then
2023-01-29 19:31:52 -05:00
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)
2024-01-06 21:32:29 -05:00
if zone.type == "Hand" and enterObject.type == "Card" then
2023-01-29 19:31:52 -05:00
resetTokensSpawned(enterObject.getGUID())
end
end
end)
return __bundle_require("__root")