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-03-10 09:56:22 -04:00
|
|
|
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
|
|
require("core/DoomCounter")
|
|
|
|
end)
|
2023-01-29 19:31:52 -05:00
|
|
|
__bundle_register("core/DoomCounter", function(require, _LOADED, __bundle_register, __bundle_modules)
|
2024-01-06 21:32:29 -05:00
|
|
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
2024-02-04 10:51:51 -05:00
|
|
|
local playAreaApi = require("core/PlayAreaApi")
|
|
|
|
local searchLib = require("util/SearchLib")
|
2024-01-06 21:32:29 -05:00
|
|
|
|
2023-01-29 19:31:52 -05:00
|
|
|
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 ~= "" 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
|
|
|
|
|
2023-04-22 16:56:01 -04:00
|
|
|
-- adds the provided number to the current count
|
|
|
|
function addVal(number)
|
|
|
|
val = val + number
|
2024-02-04 10:51:51 -05:00
|
|
|
updateVal(val)
|
2023-04-22 16:56:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
-- sets the current count to the provided number
|
2023-01-29 19:31:52 -05:00
|
|
|
function updateVal(number)
|
|
|
|
val = number or 0
|
|
|
|
self.editButton({ index = 0, label = tostring(val) })
|
2024-02-04 10:51:51 -05:00
|
|
|
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
|
2023-01-29 19:31:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
-- called by "Reset" button to remove doom
|
|
|
|
function startReset()
|
|
|
|
if options.Agenda then
|
2024-02-04 10:51:51 -05:00
|
|
|
-- omitting the number will broadcast a special message just for this case
|
|
|
|
updateVal()
|
2023-01-29 19:31:52 -05:00
|
|
|
end
|
2024-01-06 21:32:29 -05:00
|
|
|
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
|
|
|
if doomInPlayCounter then
|
|
|
|
doomInPlayCounter.call("removeDoom", options)
|
2023-01-29 19:31:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-04 10:51:51 -05:00
|
|
|
-- 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
|
|
|
|
|
2023-01-29 19:31:52 -05:00
|
|
|
-- 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)
|
2024-01-06 21:32:29 -05:00
|
|
|
__bundle_register("core/GUIDReferenceApi", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
|
|
do
|
|
|
|
local GUIDReferenceApi = {}
|
|
|
|
|
|
|
|
local function getGuidHandler()
|
|
|
|
return getObjectFromGUID("123456")
|
|
|
|
end
|
|
|
|
|
2024-02-17 19:48:30 -05:00
|
|
|
---@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
|
2024-01-06 21:32:29 -05:00
|
|
|
GUIDReferenceApi.getObjectByOwnerAndType = function(owner, type)
|
|
|
|
return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type })
|
|
|
|
end
|
|
|
|
|
|
|
|
-- returns all matching objects as a table with references
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param type string Type of object to search for
|
|
|
|
---@return table: List of object references to matching objects
|
2024-01-06 21:32:29 -05:00
|
|
|
GUIDReferenceApi.getObjectsByType = function(type)
|
|
|
|
return getGuidHandler().call("getObjectsByType", type)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- returns all matching objects as a table with references
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param owner string Parent object for this search
|
|
|
|
---@return table: List of object references to matching objects
|
2024-01-06 21:32:29 -05:00
|
|
|
GUIDReferenceApi.getObjectsByOwner = function(owner)
|
|
|
|
return getGuidHandler().call("getObjectsByOwner", owner)
|
|
|
|
end
|
|
|
|
|
2024-02-04 10:51:51 -05:00
|
|
|
-- sends new information to the reference handler to edit the main index
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param owner string Parent of the object
|
|
|
|
---@param type string Type of the object
|
|
|
|
---@param guid string GUID of the object
|
2024-02-04 10:51:51 -05:00
|
|
|
GUIDReferenceApi.editIndex = function(owner, type, guid)
|
|
|
|
return getGuidHandler().call("editIndex", {
|
|
|
|
owner = owner,
|
|
|
|
type = type,
|
|
|
|
guid = guid
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2024-01-06 21:32:29 -05:00
|
|
|
return GUIDReferenceApi
|
|
|
|
end
|
|
|
|
end)
|
2024-02-04 10:51:51 -05:00
|
|
|
__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 playmat
|
2024-02-17 19:48:30 -05:00
|
|
|
---@return number: Number of investigators currently set on the counter
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.getInvestigatorCount = function()
|
|
|
|
return getInvestigatorCounter().getVar("val")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Updates the current value of the investigator counter from the playmat
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param count number Number of investigators to set on the counter
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.setInvestigatorCount = function(count)
|
|
|
|
getInvestigatorCounter().call("updateVal", count)
|
|
|
|
end
|
|
|
|
|
2024-02-17 19:48:30 -05:00
|
|
|
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
|
2024-02-04 10:51:51 -05:00
|
|
|
-- fixed objects will be ignored, as will anything the player has tagged with 'displacement_excluded'
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param playerColor string Color of the player requesting the shift for messages
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.shiftContentsUp = function(playerColor)
|
2024-02-17 19:48:30 -05:00
|
|
|
getPlayArea().call("shiftContentsUp", playerColor)
|
2024-02-04 10:51:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
PlayAreaApi.shiftContentsDown = function(playerColor)
|
2024-02-17 19:48:30 -05:00
|
|
|
getPlayArea().call("shiftContentsDown", playerColor)
|
2024-02-04 10:51:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
PlayAreaApi.shiftContentsLeft = function(playerColor)
|
2024-02-17 19:48:30 -05:00
|
|
|
getPlayArea().call("shiftContentsLeft", playerColor)
|
2024-02-04 10:51:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
PlayAreaApi.shiftContentsRight = function(playerColor)
|
2024-02-17 19:48:30 -05:00
|
|
|
getPlayArea().call("shiftContentsRight", playerColor)
|
2024-02-04 10:51:51 -05:00
|
|
|
end
|
|
|
|
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param state boolean This controls whether location connections should be drawn
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.setConnectionDrawState = function(state)
|
|
|
|
getPlayArea().call("setConnectionDrawState", state)
|
|
|
|
end
|
|
|
|
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param color string Connection color to be used for location connections
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.setConnectionColor = function(color)
|
|
|
|
getPlayArea().call("setConnectionColor", color)
|
|
|
|
end
|
|
|
|
|
2024-02-17 19:48:30 -05:00
|
|
|
-- Event to be called when the current scenario has changed
|
|
|
|
---@param scenarioName string Name of the new scenario
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.onScenarioChanged = function(scenarioName)
|
|
|
|
getPlayArea().call("onScenarioChanged", scenarioName)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Sets this playmat's snap points to limit snapping to locations or not.
|
|
|
|
-- If matchTypes is false, snap points will be reset to snap all cards.
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param matchCardTypes boolean Whether snap points should only snap for the matching card types
|
2024-02-04 10:51:51 -05:00
|
|
|
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
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param state boolean True if highlighting should be enabled
|
2024-02-04 10:51:51 -05:00
|
|
|
PlayAreaApi.highlightMissingData = function(state)
|
|
|
|
return getPlayArea().call("highlightMissingData", state)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- highlights all locations in the play area with VP
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param state boolean True if highlighting should be enabled
|
2024-02-04 10:51:51 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
PlayAreaApi.getSurface = function()
|
|
|
|
return getPlayArea().getCustomObject().image
|
|
|
|
end
|
|
|
|
|
|
|
|
PlayAreaApi.updateSurface = function(url)
|
|
|
|
return getPlayArea().call("updateSurface", url)
|
|
|
|
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.
|
2024-02-17 19:48:30 -05:00
|
|
|
---@param args table Single-value array holding the GUID of the Custom Data Helper making the call
|
2024-02-04 10:51:51 -05:00
|
|
|
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 = {
|
|
|
|
isActionToken = function(x) return x.getDescription() == "Action Token" end,
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
-- performs the actual search and returns a filtered list of object references
|
2024-02-17 19:48:30 -05:00
|
|
|
---@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
|
2024-02-04 10:51:51 -05:00
|
|
|
local function returnSearchResult(pos, rot, size, filter, direction, maxDistance)
|
2024-02-17 19:48:30 -05:00
|
|
|
local filterFunc
|
|
|
|
if filter then
|
|
|
|
filterFunc = filterFunctions[filter]
|
|
|
|
end
|
2024-02-04 10:51:51 -05:00
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
|
|
-- filtering the result
|
|
|
|
local objList = {}
|
|
|
|
for _, v in ipairs(searchResult) do
|
2024-02-17 19:48:30 -05:00
|
|
|
if not filter or filterFunc(v.hit_object) then
|
2024-02-04 10:51:51 -05:00
|
|
|
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)
|
|
|
|
pos = obj.getPosition()
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
direction = { 0, -1, 0 }
|
|
|
|
maxDistance = pos.y
|
|
|
|
return returnSearchResult(pos, _, size, filter, direction, maxDistance)
|
|
|
|
end
|
|
|
|
|
|
|
|
return SearchLib
|
|
|
|
end
|
|
|
|
end)
|
2023-01-29 19:31:52 -05:00
|
|
|
return __bundle_require("__root")
|