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

View File

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

View File

@ -1,5 +1,10 @@
do 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 -- Returns the current value of the investigator counter from the playmat
---@return Integer. Number of investigators currently set on the counter ---@return Integer. Number of investigators currently set on the counter
@ -14,90 +19,87 @@ do
end end
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain -- 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 -- fixed objects will be ignored, as will anything the player has tagged with 'displacement_excluded'
-- 'displacement_excluded' ---@param playerColor Color Color of the player requesting the shift for messages
---@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
PlayAreaApi.shiftContentsUp = function(playerColor) PlayAreaApi.shiftContentsUp = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsUp", playerColor) return internal.getPlayArea().call("shiftContentsUp", playerColor)
end end
PlayAreaApi.shiftContentsDown = function(playerColor) PlayAreaApi.shiftContentsDown = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsDown", playerColor) return internal.getPlayArea().call("shiftContentsDown", playerColor)
end end
PlayAreaApi.shiftContentsLeft = function(playerColor) PlayAreaApi.shiftContentsLeft = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsLeft", playerColor) return internal.getPlayArea().call("shiftContentsLeft", playerColor)
end end
PlayAreaApi.shiftContentsRight = function(playerColor) PlayAreaApi.shiftContentsRight = function(playerColor)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("shiftContentsRight", playerColor) return internal.getPlayArea().call("shiftContentsRight", playerColor)
end end
-- Reset the play area's tracking of which cards have had tokens spawned. -- Reset the play area's tracking of which cards have had tokens spawned.
PlayAreaApi.resetSpawnedCards = function() PlayAreaApi.resetSpawnedCards = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("resetSpawnedCards") return internal.getPlayArea().call("resetSpawnedCards")
end end
-- Event to be called when the current scenario has changed. -- Event to be called when the current scenario has changed.
---@param scenarioName Name of the new scenario ---@param scenarioName Name of the new scenario
PlayAreaApi.onScenarioChanged = function(scenarioName) PlayAreaApi.onScenarioChanged = function(scenarioName)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("onScenarioChanged", scenarioName) internal.getPlayArea().call("onScenarioChanged", scenarioName)
end end
-- Sets this playmat's snap points to limit snapping to locations or not. -- 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. -- 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. ---@param matchTypes Boolean Whether snap points should only snap for the matching card types.
PlayAreaApi.setLimitSnapsByType = function(matchCardTypes) PlayAreaApi.setLimitSnapsByType = function(matchCardTypes)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("setLimitSnapsByType", matchCardTypes) internal.getPlayArea().call("setLimitSnapsByType", matchCardTypes)
end end
-- Receiver for the Global tryObjectEnterContainer event. Used to clear vector lines from dragged -- Receiver for the Global tryObjectEnterContainer event. Used to clear vector lines from dragged
-- cards before they're destroyed by entering the container -- cards before they're destroyed by entering the container
PlayAreaApi.tryObjectEnterContainer = function(container, object) PlayAreaApi.tryObjectEnterContainer = function(container, object)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("tryObjectEnterContainer", internal.getPlayArea().call("tryObjectEnterContainer", { container = container, object = object })
{ container = container, object = object })
end end
-- counts the VP on locations in the play area -- counts the VP on locations in the play area
PlayAreaApi.countVP = function() PlayAreaApi.countVP = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("countVP") return internal.getPlayArea().call("countVP")
end end
-- highlights all locations in the play area without metadata -- highlights all locations in the play area without metadata
---@param state Boolean True if highlighting should be enabled ---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightMissingData = function(state) PlayAreaApi.highlightMissingData = function(state)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("highlightMissingData", state) return internal.getPlayArea().call("highlightMissingData", state)
end end
-- highlights all locations in the play area with VP -- highlights all locations in the play area with VP
---@param state Boolean True if highlighting should be enabled ---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightCountedVP = function(state) PlayAreaApi.highlightCountedVP = function(state)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("highlightCountedVP", state) return internal.getPlayArea().call("highlightCountedVP", state)
end end
-- Checks if an object is in the play area (returns true or false) -- Checks if an object is in the play area (returns true or false)
PlayAreaApi.isInPlayArea = function(object) PlayAreaApi.isInPlayArea = function(object)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("isInPlayArea", object) return internal.getPlayArea().call("isInPlayArea", object)
end end
PlayAreaApi.getSurface = function() PlayAreaApi.getSurface = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).getCustomObject().image return internal.getPlayArea().getCustomObject().image
end end
PlayAreaApi.updateSurface = function(url) PlayAreaApi.updateSurface = function(url)
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("updateSurface", url) return internal.getPlayArea().call("updateSurface", url)
end end
-- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the -- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the
-- data to the local token manager instance. -- data to the local token manager instance.
---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call ---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call
PlayAreaApi.updateLocations = function(args) PlayAreaApi.updateLocations = function(args)
Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).call("updateLocations", args) internal.getPlayArea().call("updateLocations", args)
end end
PlayAreaApi.getCustomDataHelper = function() PlayAreaApi.getCustomDataHelper = function()
return Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayArea"}).getVar("customDataHelper") return internal.getPlayArea().getVar("customDataHelper")
end end
return PlayAreaApi return PlayAreaApi