api cleanup

This commit is contained in:
Chr1Z93 2023-09-30 00:31:23 +02:00
parent a87b63516a
commit 947bf1dc4c
3 changed files with 71 additions and 85 deletions

View File

@ -1,9 +1,14 @@
do
local BlessCurseManagerApi = {}
local internal = {}
internal.getManager = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
end
-- removes all taken tokens and resets the counts
BlessCurseManagerApi.removeTakenTokensAndReset = function()
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
local BlessCurseManager = internal.getManager()
Wait.time(function() BlessCurseManager.call("removeTakenTokens", "Bless") end, 0.05)
Wait.time(function() BlessCurseManager.call("removeTakenTokens", "Curse") end, 0.10)
Wait.time(function() BlessCurseManager.call("doReset", "White") end, 0.15)
@ -11,35 +16,30 @@ do
-- updates the internal count (called by cards that seal bless/curse tokens)
BlessCurseManagerApi.sealedToken = function(type, guid)
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
BlessCurseManager.call("sealedToken", { type = type, guid = guid })
internal.getManager().call("sealedToken", { type = type, guid = guid })
end
-- updates the internal count (called by cards that seal bless/curse tokens)
BlessCurseManagerApi.releasedToken = function(type, guid)
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
BlessCurseManager.call("releasedToken", { type = type, guid = guid })
internal.getManager().call("releasedToken", { type = type, guid = guid })
end
-- broadcasts the current status for bless/curse tokens
---@param playerColor String Color of the player to show the broadcast to
BlessCurseManagerApi.broadcastStatus = function(playerColor)
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
BlessCurseManager.call("broadcastStatus", playerColor)
internal.getManager().call("broadcastStatus", playerColor)
end
-- removes all bless / curse tokens from the chaos bag and play
---@param playerColor String Color of the player to show the broadcast to
BlessCurseManagerApi.removeAll = function(playerColor)
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
BlessCurseManager.call("doRemove", playerColor)
internal.getManager().call("doRemove", playerColor)
end
-- adds Wendy's menu to the hovered card (allows sealing of tokens)
---@param color String Color of the player to show the broadcast to
BlessCurseManagerApi.addWendysMenu = function(playerColor, hoveredObject)
local BlessCurseManager = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "BlessCurseManager"})
BlessCurseManager.call("addMenuOptions", { playerColor = playerColor, hoveredObject = hoveredObject })
internal.getManager().call("addMenuOptions", { playerColor = playerColor, hoveredObject = hoveredObject })
end
return BlessCurseManagerApi

View File

@ -1,20 +1,9 @@
-- common parameters
local castParameters = {}
castParameters.direction = { 0, 1, 0 }
castParameters.type = 3
castParameters.max_distance = 0
local playmatApi = require("playermat/PlaymatApi")
local zone
local ZONE, TRASH
local doomURL = "https://i.imgur.com/EoL7yaZ.png"
local IGNORE_TAG = "DoomCounter_ignore"
-- playermats 1 to 4
local originAndSize = {
{ origin = { -55, 1.6, 16.5 }, size = { 12, 1, 25 } },
{ origin = { -55, 1.6, -16.5 }, size = { 12, 1, 25 } },
{ origin = { -25, 1.6, 27 }, size = { 25, 1, 12 } },
{ origin = { -25, 1.6, -27 }, size = { 25, 1, 12 } }
}
local COLORS = { "White", "Orange", "Green", "Red" }
-- create button, context menu and start loop
function onLoad()
@ -31,33 +20,32 @@ function onLoad()
color = { 0, 0, 0, 0 }
})
zone = getObjectFromGUID("a2f932")
trash = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "Trash"})
ZONE = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayAreaZone"})
loopID = Wait.time(countDoom, 2, -1)
end
-- main function
function countDoom()
local doom = 0
for i = 1, 5 do doom = doom + search(i) end
for i = 1, 5 do
if i = 5 then
objList = ZONE.getObjects()
else
objList = playmatApi.searchAroundPlaymat(COLORS[i])
end
doom = doom + countDoomFromList(objList)
end
self.editButton({ index = 0, label = tostring(doom) })
end
-- searches playermats (num = 1-4) or the scripting zone (num = 5)
function search(num)
local val = 0
if num == 5 then
for _, obj in ipairs(zone.getObjects()) do
val = val + isDoom(obj)
function countDoomFromList(objList)
local count = 0
for _, obj in ipairs(objList) do
count = count + isDoom(obj)
end
else
castParameters.origin = originAndSize[num].origin
castParameters.size = originAndSize[num].size
for _, obj in ipairs(Physics.cast(castParameters)) do
val = val + isDoom(obj.hit_object)
end
end
return val
return count
end
-- checks an object for the doom image and gets quantity (for stacks)
@ -73,34 +61,30 @@ end
-- removes doom from playermats / playarea
function removeDoom(options)
local trashCan = getObjectFromGUID("70b9f6")
local count = 0
if options.Playermats then
for i = 1, 4 do
castParameters.origin = originAndSize[i].origin
castParameters.size = originAndSize[i].size
for _, obj in ipairs(Physics.cast(castParameters)) do
local obj = obj.hit_object
local amount = isDoom(obj)
if amount > 0 then
trashCan.putObject(obj)
count = count + amount
end
end
count = removeDoomFromList(playmatApi.searchAroundPlaymat(COLORS[i]))
end
broadcastToAll(count .. " doom removed from Playermats.", "White")
end
local count = 0
if options.Playarea then
for _, obj in ipairs(zone.getObjects()) do
count = removeDoomFromList(ZONE.getObjects())
broadcastToAll(count .. " doom removed from Playerarea.", "White")
end
end
-- removes doom from provided object list and returns the removed amount
function removeDoomFromList(objList)
local count = 0
for _, obj in ipairs(objList) do
local amount = isDoom(obj)
if amount > 0 then
trashCan.putObject(obj)
TRASH.putObject(obj)
count = count + amount
end
end
broadcastToAll(count .. " doom removed from Playarea.", "White")
end
return count
end

View File

@ -1,5 +1,10 @@
do
local PlayAreaApi = { }
local PlayAreaApi = {}
local internal = {}
internal.getPlayArea = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"})
end
-- Returns the current value of the investigator counter from the playmat
---@return Integer. Number of investigators currently set on the counter
@ -14,90 +19,87 @@ do
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 Color of the player requesting the shift. Used solely to send an error
--- message in the unlikely case that the scripting zone has been deleted
-- fixed objects will be ignored, as will anything the player has tagged with 'displacement_excluded'
---@param playerColor Color Color of the player requesting the shift for messages
PlayAreaApi.shiftContentsUp = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsUp", playerColor)
return internal.getPlayArea().call("shiftContentsUp", playerColor)
end
PlayAreaApi.shiftContentsDown = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsDown", playerColor)
return internal.getPlayArea().call("shiftContentsDown", playerColor)
end
PlayAreaApi.shiftContentsLeft = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsLeft", playerColor)
return internal.getPlayArea().call("shiftContentsLeft", playerColor)
end
PlayAreaApi.shiftContentsRight = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsRight", playerColor)
return internal.getPlayArea().call("shiftContentsRight", playerColor)
end
-- Reset the play area's tracking of which cards have had tokens spawned.
PlayAreaApi.resetSpawnedCards = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("resetSpawnedCards")
return internal.getPlayArea().call("resetSpawnedCards")
end
-- Event to be called when the current scenario has changed.
---@param scenarioName Name of the new scenario
PlayAreaApi.onScenarioChanged = function(scenarioName)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("onScenarioChanged", scenarioName)
internal.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.
---@param matchTypes Boolean Whether snap points should only snap for the matching card types.
PlayAreaApi.setLimitSnapsByType = function(matchCardTypes)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("setLimitSnapsByType", matchCardTypes)
internal.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)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("tryObjectEnterContainer",
{ container = container, object = object })
internal.getPlayArea().call("tryObjectEnterContainer", { container = container, object = object })
end
-- counts the VP on locations in the play area
PlayAreaApi.countVP = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("countVP")
return internal.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 Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("highlightMissingData", state)
return internal.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 Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("highlightCountedVP", state)
return internal.getPlayArea().call("highlightCountedVP", state)
end
-- Checks if an object is in the play area (returns true or false)
PlayAreaApi.isInPlayArea = function(object)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("isInPlayArea", object)
return internal.getPlayArea().call("isInPlayArea", object)
end
PlayAreaApi.getSurface = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).getCustomObject().image
return internal.getPlayArea().getCustomObject().image
end
PlayAreaApi.updateSurface = function(url)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("updateSurface", url)
return internal.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.
---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call
PlayAreaApi.updateLocations = function(args)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("updateLocations", args)
internal.getPlayArea().call("updateLocations", args)
end
PlayAreaApi.getCustomDataHelper = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).getVar("customDataHelper")
return internal.getPlayArea().getVar("customDataHelper")
end
return PlayAreaApi