ah_sce_unpacked/unpacked/Custom_Tile Phase Tracker d0c8fa.ttslua
2024-07-27 21:47:52 -04:00

140 lines
3.8 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/PhaseTracker")
end)
__bundle_register("accessories/PhaseTracker", function(require, _LOADED, __bundle_register, __bundle_modules)
local phaseNames = {
"I. Mythos Phase",
"II. Investigation Phase",
"III. Enemy Phase",
"IV. Upkeep Phase"
}
local phaseImages = {
"http://cloud-3.steamusercontent.com/ugc/933819604050849085/9E22AFD7B0157140FC177DBCCBCB1D61D6A0329F/",
"http://cloud-3.steamusercontent.com/ugc/933819604050885611/845B5AA915F30492B5F34864698B9C3627FA5763/",
"http://cloud-3.steamusercontent.com/ugc/982233321870235122/492996D07ABF6DDA4B605A3013C4892839DCF1F3/",
"http://cloud-3.steamusercontent.com/ugc/982233321870237261/C287CAED2423970F33E72D6C7415CBEC6794C533/"
}
function onSave()
return JSON.encode({
phaseId = phaseId,
broadcastChange = broadcastChange
})
end
function loadFromSaveTable(savedData)
for var, val in pairs(JSON.decode(savedData)) do
_G[var] = val
end
end
function onLoad(savedData)
if savedData and savedData ~= "" then
loadFromSaveTable(savedData)
else
phaseId = 1
broadcastChange = false
end
self.createButton(
{
tooltip = "change phase",
click_function = 'changeState',
function_owner = self,
width = 600,
height = 600,
color = { r = 0, g = 0, b = 0, a = 0 }
})
self.addContextMenuItem("Toggle Broadcasting", updateBroadcast)
end
function updateBroadcast(playerColor)
Player[playerColor].clearSelectedObjects()
for _, tracker in ipairs(getObjectsWithTag("LinkedPhaseTracker")) do
tracker.setVar("broadcastChange", not broadcastChange)
end
broadcastToAll("Broadcasting phase changes has been " .. (broadcastChange and "enabled." or "disabled."))
end
function changeState(_, _, isRightClick)
-- get newId for all trackers
local newId = phaseId + (isRightClick and -1 or 1)
if newId == 0 then
newId = 4
elseif newId == 5 then
newId = 1
end
-- broadcast if option is enabled
if broadcastChange then
broadcastToAll(phaseNames[newId])
end
-- manipulate data and then respawn
local data = self.getData()
data["CustomImage"]["ImageURL"] = phaseImages[newId]
data["CustomImage"]["ImageSecondaryURL"] = phaseImages[newId]
data["LuaScriptState"] = "{\"broadcastChange\":" .. tostring(broadcastChange) .. ",\"phaseId\":" .. newId .. "}"
-- update all trackers with tag
for _, tracker in ipairs(getObjectsWithTag("LinkedPhaseTracker")) do
local pos = tracker.getPosition()
local rot = tracker.getRotation()
local scale = tracker.getScale()
tracker.destruct()
spawnObjectData(
{
data = data,
position = pos,
rotation = rot,
scale = scale
}
)
end
end
end)
return __bundle_require("__root")