437 lines
14 KiB
Plaintext
437 lines
14 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/DoomCounter")
|
|
end)
|
|
__bundle_register("core/DoomCounter", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
|
local playAreaApi = require("core/PlayAreaApi")
|
|
local searchLib = require("util/SearchLib")
|
|
|
|
local optionsVisible = false
|
|
local options = {
|
|
Agenda = true,
|
|
Playarea = true,
|
|
Playermats = true
|
|
}
|
|
|
|
val = 0
|
|
|
|
-- save current value and options
|
|
function onSave() return JSON.encode({ val, options }) end
|
|
|
|
function onLoad(savedData)
|
|
if savedData and savedData ~= "" then
|
|
local loadedData = JSON.decode(savedData)
|
|
val = loadedData[1]
|
|
options = loadedData[2]
|
|
|
|
-- restore state for option panel
|
|
for key, bool in pairs(options) do
|
|
self.UI.setAttribute("option" .. key, "isOn", not bool)
|
|
end
|
|
end
|
|
|
|
self.createButton({
|
|
label = tostring(val),
|
|
click_function = "addOrSubtract",
|
|
function_owner = self,
|
|
position = { 0, 0.06, 0 },
|
|
height = 800,
|
|
width = 800,
|
|
font_size = 650,
|
|
scale = { 1.5, 1.5, 1.5 },
|
|
font_color = { 1, 1, 1, 95 },
|
|
color = { 0, 0, 0, 0 }
|
|
})
|
|
end
|
|
|
|
-- called by the invisible button to change displayed value
|
|
function addOrSubtract(_, _, isRightClick)
|
|
local newVal = math.min(math.max(val + (isRightClick and -1 or 1), 0), 99)
|
|
if val ~= newVal then
|
|
updateVal(newVal)
|
|
end
|
|
end
|
|
|
|
-- adds the provided number to the current count
|
|
function addVal(number)
|
|
val = val + number
|
|
updateVal(val)
|
|
end
|
|
|
|
-- sets the current count to the provided number
|
|
function updateVal(number)
|
|
val = number or 0
|
|
self.editButton({ index = 0, label = tostring(val) })
|
|
if number then
|
|
broadcastDoom(val)
|
|
else
|
|
broadcastToAll("0 doom on the agenda", "White")
|
|
end
|
|
end
|
|
|
|
-- called by updateVal and addVal to broadcast total doom in play, including doom threshold
|
|
function broadcastDoom(val)
|
|
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
|
local doomInPlay = doomInPlayCounter.call("countDoomInPlay") + val
|
|
local doomThreshold = getDoomThreshold()
|
|
|
|
if doomThreshold then
|
|
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. "/" .. doomThreshold .. " in play)", "White")
|
|
else
|
|
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. " in play)", "White")
|
|
end
|
|
end
|
|
|
|
-- called by "Reset" button to remove doom
|
|
function startReset()
|
|
if options.Agenda then
|
|
-- omitting the number will broadcast a special message just for this case
|
|
updateVal()
|
|
end
|
|
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
|
if doomInPlayCounter then
|
|
doomInPlayCounter.call("removeDoom", options)
|
|
end
|
|
end
|
|
|
|
-- get doom threshold from top card of Agenda deck
|
|
function getDoomThreshold()
|
|
local agendaPos = { -2.72, 1.6, 0.37 }
|
|
local searchResult = searchLib.atPosition(agendaPos, "isCardOrDeck")
|
|
|
|
if #searchResult == 1 then
|
|
local obj = searchResult[1]
|
|
if obj.type == "Card" then
|
|
return getDoomThresholdFromGMNotes(obj.getGMNotes())
|
|
else
|
|
-- handle agenda deck
|
|
local containedObjects = obj.getData().ContainedObjects
|
|
local topCardData = containedObjects[#containedObjects]
|
|
return getDoomThresholdFromGMNotes(topCardData.GMNotes)
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
-- decodes the gm notes and return the doom treshhold
|
|
function getDoomThresholdFromGMNotes(notes)
|
|
local metadata = JSON.decode(notes) or {}
|
|
if metadata.doomThresholdPerInvestigator then
|
|
return metadata.doomThresholdPerInvestigator * playAreaApi.getInvestigatorCount() + metadata.doomThreshold
|
|
else
|
|
return metadata.doomThreshold
|
|
end
|
|
end
|
|
|
|
-- XML UI functions
|
|
function optionClick(_, optionName)
|
|
options[optionName] = not options[optionName]
|
|
printToAll("Doom removal of " .. optionName .. (options[optionName] and " enabled" or " disabled"))
|
|
end
|
|
|
|
function toggleOptions()
|
|
optionsVisible = not optionsVisible
|
|
|
|
if optionsVisible then
|
|
self.UI.show("Options")
|
|
else
|
|
self.UI.hide("Options")
|
|
end
|
|
end
|
|
end)
|
|
__bundle_register("core/GUIDReferenceApi", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
do
|
|
local GUIDReferenceApi = {}
|
|
|
|
local function getGuidHandler()
|
|
return getObjectFromGUID("123456")
|
|
end
|
|
|
|
-- Returns the matching object
|
|
---@param owner string Parent object for this search
|
|
---@param type string Type of object to search for
|
|
---@return any: Object reference to the matching object
|
|
GUIDReferenceApi.getObjectByOwnerAndType = function(owner, type)
|
|
return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type })
|
|
end
|
|
|
|
-- Returns all matching objects as a table with references
|
|
---@param type string Type of object to search for
|
|
---@return table: List of object references to matching objects
|
|
GUIDReferenceApi.getObjectsByType = function(type)
|
|
return getGuidHandler().call("getObjectsByType", type)
|
|
end
|
|
|
|
-- Returns all matching objects as a table with references
|
|
---@param owner string Parent object for this search
|
|
---@return table: List of object references to matching objects
|
|
GUIDReferenceApi.getObjectsByOwner = function(owner)
|
|
return getGuidHandler().call("getObjectsByOwner", owner)
|
|
end
|
|
|
|
-- Sends new information to the reference handler to edit the main index
|
|
---@param owner string Parent of the object
|
|
---@param type string Type of the object
|
|
---@param guid string GUID of the object
|
|
GUIDReferenceApi.editIndex = function(owner, type, guid)
|
|
return getGuidHandler().call("editIndex", {
|
|
owner = owner,
|
|
type = type,
|
|
guid = guid
|
|
})
|
|
end
|
|
|
|
-- Returns the owner of an object or the object it's located on
|
|
---@param object tts__GameObject Object for this search
|
|
---@return string: Parent of the object or object it's located on
|
|
GUIDReferenceApi.getOwnerOfObject = function(object)
|
|
return getGuidHandler().call("getOwnerOfObject", object)
|
|
end
|
|
|
|
return GUIDReferenceApi
|
|
end
|
|
end)
|
|
__bundle_register("core/PlayAreaApi", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
do
|
|
local PlayAreaApi = {}
|
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
|
|
|
local function getPlayArea()
|
|
return guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayArea")
|
|
end
|
|
|
|
local function getInvestigatorCounter()
|
|
return guidReferenceApi.getObjectByOwnerAndType("Mythos", "InvestigatorCounter")
|
|
end
|
|
|
|
-- Returns the current value of the investigator counter from the playermat
|
|
---@return number: Number of investigators currently set on the counter
|
|
PlayAreaApi.getInvestigatorCount = function()
|
|
return getInvestigatorCounter().getVar("val")
|
|
end
|
|
|
|
-- Updates the current value of the investigator counter from the playermat
|
|
---@param count number Number of investigators to set on the counter
|
|
PlayAreaApi.setInvestigatorCount = function(count)
|
|
getInvestigatorCounter().call("updateVal", count)
|
|
end
|
|
|
|
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
|
|
-- fixed objects will be ignored, as will anything the player has tagged with 'displacement_excluded'
|
|
---@param playerColor string Color of the player requesting the shift for messages
|
|
PlayAreaApi.shiftContentsUp = function(playerColor)
|
|
getPlayArea().call("shiftContentsUp", playerColor)
|
|
end
|
|
|
|
PlayAreaApi.shiftContentsDown = function(playerColor)
|
|
getPlayArea().call("shiftContentsDown", playerColor)
|
|
end
|
|
|
|
PlayAreaApi.shiftContentsLeft = function(playerColor)
|
|
getPlayArea().call("shiftContentsLeft", playerColor)
|
|
end
|
|
|
|
PlayAreaApi.shiftContentsRight = function(playerColor)
|
|
getPlayArea().call("shiftContentsRight", playerColor)
|
|
end
|
|
|
|
---@param state boolean This controls whether location connections should be drawn
|
|
PlayAreaApi.setConnectionDrawState = function(state)
|
|
getPlayArea().call("setConnectionDrawState", state)
|
|
end
|
|
|
|
---@param color string Connection color to be used for location connections
|
|
PlayAreaApi.setConnectionColor = function(color)
|
|
getPlayArea().call("setConnectionColor", color)
|
|
end
|
|
|
|
-- Event to be called when the current scenario has changed
|
|
---@param scenarioName string Name of the new scenario
|
|
PlayAreaApi.onScenarioChanged = function(scenarioName)
|
|
getPlayArea().call("onScenarioChanged", scenarioName)
|
|
end
|
|
|
|
-- Sets this playermat's snap points to limit snapping to locations or not.
|
|
-- If matchTypes is false, snap points will be reset to snap all cards.
|
|
---@param matchCardTypes boolean Whether snap points should only snap for the matching card types
|
|
PlayAreaApi.setLimitSnapsByType = function(matchCardTypes)
|
|
getPlayArea().call("setLimitSnapsByType", matchCardTypes)
|
|
end
|
|
|
|
-- Receiver for the Global tryObjectEnterContainer event. Used to clear vector lines from dragged
|
|
-- cards before they're destroyed by entering the container
|
|
PlayAreaApi.tryObjectEnterContainer = function(container, object)
|
|
getPlayArea().call("tryObjectEnterContainer", { container = container, object = object })
|
|
end
|
|
|
|
-- Counts the VP on locations in the play area
|
|
PlayAreaApi.countVP = function()
|
|
return getPlayArea().call("countVP")
|
|
end
|
|
|
|
-- Highlights all locations in the play area without metadata
|
|
---@param state boolean True if highlighting should be enabled
|
|
PlayAreaApi.highlightMissingData = function(state)
|
|
return getPlayArea().call("highlightMissingData", state)
|
|
end
|
|
|
|
-- Highlights all locations in the play area with VP
|
|
---@param state boolean True if highlighting should be enabled
|
|
PlayAreaApi.highlightCountedVP = function(state)
|
|
return getPlayArea().call("countVP", state)
|
|
end
|
|
|
|
-- Checks if an object is in the play area (returns true or false)
|
|
PlayAreaApi.isInPlayArea = function(object)
|
|
return getPlayArea().call("isInPlayArea", object)
|
|
end
|
|
|
|
-- Returns the current surface of the play area
|
|
PlayAreaApi.getSurface = function()
|
|
return getPlayArea().getCustomObject().image
|
|
end
|
|
|
|
-- Updates the surface of the play area
|
|
PlayAreaApi.updateSurface = function(url)
|
|
return getPlayArea().call("updateSurface", url)
|
|
end
|
|
|
|
-- Returns a deep copy of the currently tracked locations
|
|
PlayAreaApi.getTrackedLocations = function()
|
|
local t = {}
|
|
for k, v in pairs(getPlayArea().call("getTrackedLocations", {})) do
|
|
t[k] = v
|
|
end
|
|
return t
|
|
end
|
|
|
|
-- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the
|
|
-- data to the local token manager instance.
|
|
---@param args table Single-value array holding the GUID of the Custom Data Helper making the call
|
|
PlayAreaApi.updateLocations = function(args)
|
|
getPlayArea().call("updateLocations", args)
|
|
end
|
|
|
|
PlayAreaApi.getCustomDataHelper = function()
|
|
return getPlayArea().getVar("customDataHelper")
|
|
end
|
|
|
|
return PlayAreaApi
|
|
end
|
|
end)
|
|
__bundle_register("util/SearchLib", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
do
|
|
local SearchLib = {}
|
|
local filterFunctions = {
|
|
isCard = function(x) return x.type == "Card" end,
|
|
isDeck = function(x) return x.type == "Deck" end,
|
|
isCardOrDeck = function(x) return x.type == "Card" or x.type == "Deck" end,
|
|
isClue = function(x) return x.memo == "clueDoom" and x.is_face_down == false end,
|
|
isTileOrToken = function(x) return x.type == "Tile" end,
|
|
isUniversalToken = function(x) return x.getMemo() == "universalActionAbility" end,
|
|
}
|
|
|
|
-- performs the actual search and returns a filtered list of object references
|
|
---@param pos tts__Vector Global position
|
|
---@param rot? tts__Vector Global rotation
|
|
---@param size table Size
|
|
---@param filter? string Name of the filter function
|
|
---@param direction? table Direction (positive is up)
|
|
---@param maxDistance? number Distance for the cast
|
|
local function returnSearchResult(pos, rot, size, filter, direction, maxDistance)
|
|
local filterFunc
|
|
if filter then
|
|
filterFunc = filterFunctions[filter]
|
|
end
|
|
local searchResult = Physics.cast({
|
|
origin = pos,
|
|
direction = direction or { 0, 1, 0 },
|
|
orientation = rot or { 0, 0, 0 },
|
|
type = 3,
|
|
size = size,
|
|
max_distance = maxDistance or 0
|
|
})
|
|
|
|
-- filter the result for matching objects
|
|
local objList = {}
|
|
for _, v in ipairs(searchResult) do
|
|
if not filter or filterFunc(v.hit_object) then
|
|
table.insert(objList, v.hit_object)
|
|
end
|
|
end
|
|
return objList
|
|
end
|
|
|
|
-- searches the specified area
|
|
SearchLib.inArea = function(pos, rot, size, filter)
|
|
return returnSearchResult(pos, rot, size, filter)
|
|
end
|
|
|
|
-- searches the area on an object
|
|
SearchLib.onObject = function(obj, filter)
|
|
local pos = obj.getPosition()
|
|
local size = obj.getBounds().size:setAt("y", 1)
|
|
return returnSearchResult(pos, _, size, filter)
|
|
end
|
|
|
|
-- searches the specified position (a single point)
|
|
SearchLib.atPosition = function(pos, filter)
|
|
local size = { 0.1, 2, 0.1 }
|
|
return returnSearchResult(pos, _, size, filter)
|
|
end
|
|
|
|
-- searches below the specified position (downwards until y = 0)
|
|
SearchLib.belowPosition = function(pos, filter)
|
|
local size = { 0.1, 2, 0.1 }
|
|
local direction = { 0, -1, 0 }
|
|
local maxDistance = pos.y
|
|
return returnSearchResult(pos, _, size, filter, direction, maxDistance)
|
|
end
|
|
|
|
return SearchLib
|
|
end
|
|
end)
|
|
return __bundle_require("__root") |