86 lines
2.4 KiB
Plaintext
86 lines
2.4 KiB
Plaintext
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 onLoad(savedData)
|
|
if savedData and savedData ~= "" then
|
|
local loadedData = JSON.decode(savedData)
|
|
phaseId = loadedData.phaseId
|
|
broadcastChange = loadedData.broadcastChange
|
|
else
|
|
phaseId = 1
|
|
broadcastChange = false
|
|
end
|
|
|
|
self.createButton(
|
|
{
|
|
tooltip = "change phase",
|
|
click_function = 'changeState',
|
|
function_owner = self,
|
|
width = 600,
|
|
height = 600
|
|
})
|
|
|
|
self.addContextMenuItem("toggle broadcasting", updateBroadcast)
|
|
end
|
|
|
|
function updateBroadcast()
|
|
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
|