optimization of loop functions
This commit is contained in:
parent
8c3e87867b
commit
da63663ef2
@ -351,6 +351,10 @@
|
||||
"Nickname": "Playermat 4: Red",
|
||||
"Snap": true,
|
||||
"Sticky": true,
|
||||
"Tags": [
|
||||
"Red",
|
||||
"Playermat"
|
||||
],
|
||||
"Tooltip": false,
|
||||
"Transform": {
|
||||
"posX": -30.35,
|
||||
|
@ -64,7 +64,7 @@ function startReset()
|
||||
if options.Agenda then
|
||||
updateVal(0)
|
||||
end
|
||||
local DoomInPlayCounter = getObjectFromMemo({matColor = "Mythos", type = "DoomInPlayCounter"})
|
||||
local DoomInPlayCounter = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "DoomInPlayCounter"})
|
||||
if DoomInPlayCounter then
|
||||
DoomInPlayCounter.call("removeDoom", options)
|
||||
end
|
||||
|
@ -3,12 +3,21 @@ local playmatApi = require("playermat/PlaymatApi")
|
||||
local ZONE, TRASH, loopID
|
||||
local doomURL = "https://i.imgur.com/EoL7yaZ.png"
|
||||
local IGNORE_TAG = "DoomCounter_ignore"
|
||||
local COLORS = { "White", "Orange", "Green", "Red" }
|
||||
local TOTAL_PLAY_AREA = {
|
||||
upperLeft = {
|
||||
x = -10,
|
||||
z = -35
|
||||
},
|
||||
lowerRight = {
|
||||
x = -60,
|
||||
z = 35
|
||||
}
|
||||
}
|
||||
|
||||
-- create button, context menu and start loop
|
||||
function onLoad()
|
||||
self.createButton({
|
||||
label = tostring(0),
|
||||
label = "0",
|
||||
click_function = "none",
|
||||
function_owner = self,
|
||||
position = { 0, 0.06, 0 },
|
||||
@ -27,49 +36,21 @@ end
|
||||
|
||||
-- main function
|
||||
function countDoom()
|
||||
local objList = {}
|
||||
|
||||
-- get doom objects in play area zone
|
||||
for _, obj in ipairs(ZONE.getObjects()) do
|
||||
if filterDoom(obj) then
|
||||
table.insert(objList, obj)
|
||||
end
|
||||
end
|
||||
|
||||
-- get doom objects on playmats
|
||||
for i = 1, 4 do
|
||||
local playmatList = playmatApi.searchAroundPlaymat(COLORS[i])
|
||||
for _, obj in ipairs(playmatList) do
|
||||
if filterDoom(obj) then
|
||||
table.insert(objList, obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local doom = countDoomFromList(objList)
|
||||
self.editButton({ index = 0, label = tostring(doom) })
|
||||
end
|
||||
|
||||
function countDoomFromList(objList)
|
||||
local count = 0
|
||||
for _, obj in ipairs(objList) do
|
||||
|
||||
-- get doom in play
|
||||
for _, obj in ipairs(getObjects()) do
|
||||
count = count + getDoomAmount(obj)
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
function filterDoom(obj)
|
||||
if (obj.is_face_down and obj.getCustomObject().image_bottom == doomURL)
|
||||
or (obj.name == "Custom_Token" and obj.getCustomObject().image == doomURL) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
self.editButton({ index = 0, label = tostring(count) })
|
||||
end
|
||||
|
||||
-- gets quantity (for stacks) of doom
|
||||
function getDoomAmount(obj)
|
||||
if not obj.hasTag(IGNORE_TAG) then
|
||||
if (obj.is_face_down and obj.getCustomObject().image_bottom == doomURL)
|
||||
and not obj.hasTag(IGNORE_TAG)
|
||||
and inArea(obj.getPosition(), TOTAL_PLAY_AREA) then
|
||||
return math.abs(obj.getQuantity())
|
||||
else
|
||||
return 0
|
||||
@ -81,9 +62,7 @@ function removeDoom(options)
|
||||
local count = 0
|
||||
|
||||
if options.Playermats then
|
||||
for i = 1, 4 do
|
||||
count = removeDoomFromList(playmatApi.searchAroundPlaymat(COLORS[i]))
|
||||
end
|
||||
count = removeDoomFromList(playmatApi.searchAroundPlaymat("All"))
|
||||
broadcastToAll(count .. " doom removed from Playermats.", "White")
|
||||
end
|
||||
|
||||
@ -105,3 +84,10 @@ function removeDoomFromList(objList)
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
function inArea(point, bounds)
|
||||
return (point.x < bounds.upperLeft.x
|
||||
and point.x > bounds.lowerRight.x
|
||||
and point.z > bounds.upperLeft.z
|
||||
and point.z < bounds.lowerRight.z)
|
||||
end
|
||||
|
@ -23,8 +23,7 @@ function onLoad(savedData)
|
||||
font_color = { 0, 0, 0, 100 },
|
||||
color = { 0, 0, 0, 0 }
|
||||
})
|
||||
|
||||
loopID = Wait.time(sumClues, 2, -1)
|
||||
Wait.time(sumClues, 2, -1)
|
||||
end
|
||||
|
||||
-- removes all player clues by calling the respective function from the counting bowls / clickers
|
||||
|
@ -148,9 +148,7 @@ function onLoad(saveState)
|
||||
end
|
||||
|
||||
showDrawButton(isDrawButtonVisible)
|
||||
|
||||
collisionEnabled = true
|
||||
|
||||
math.randomseed(os.time())
|
||||
end
|
||||
|
||||
@ -166,7 +164,7 @@ function searchArea(origin, size, filter)
|
||||
orientation = self.getRotation(),
|
||||
type = 3,
|
||||
size = size,
|
||||
max_distance = 1
|
||||
max_distance = 0
|
||||
})
|
||||
|
||||
local objList = {}
|
||||
@ -188,6 +186,7 @@ function searchAroundSelf(filter)
|
||||
local bounds = self.getBoundsNormalized()
|
||||
-- Increase the width to cover the set aside zone
|
||||
bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER
|
||||
bounds.size.y = 1
|
||||
-- Since the cast is centered on the position, shift left or right to keep the non-set aside edge
|
||||
-- of the cast at the edge of the playmat
|
||||
-- setAsideDirection accounts for the set aside zone being on the left or right, depending on the
|
||||
@ -618,17 +617,17 @@ function spawnTokensFor(object)
|
||||
tokenManager.spawnForCard(object, extraUses)
|
||||
end
|
||||
|
||||
function onCollisionEnter(collision_info)
|
||||
local object = collision_info.collision_object
|
||||
|
||||
-- detect if "Dream-Enhancing Serum" is placed
|
||||
if object.getName() == "Dream-Enhancing Serum" then isDES = true end
|
||||
function onCollisionEnter(collisionInfo)
|
||||
local object = collisionInfo.collision_object
|
||||
|
||||
-- only continue if loading is completed
|
||||
if not collisionEnabled then return end
|
||||
|
||||
-- only continue for cards
|
||||
if object.type ~= "Card" then return end
|
||||
if not isCard(object) then return end
|
||||
|
||||
-- detect if "Dream-Enhancing Serum" is placed
|
||||
if object.getName() == "Dream-Enhancing Serum" then isDES = true end
|
||||
|
||||
maybeUpdateActiveInvestigator(object)
|
||||
syncCustomizableMetadata(object)
|
||||
@ -643,8 +642,8 @@ function onCollisionEnter(collision_info)
|
||||
end
|
||||
|
||||
-- detect if "Dream-Enhancing Serum" is removed
|
||||
function onCollisionExit(collision_info)
|
||||
if collision_info.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end
|
||||
function onCollisionExit(collisionInfo)
|
||||
if collisionInfo.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end
|
||||
end
|
||||
|
||||
-- checks if tokens should be spawned for the provided card
|
||||
@ -680,14 +679,12 @@ function shouldSpawnTokens(card)
|
||||
end
|
||||
|
||||
function onObjectEnterContainer(container, object)
|
||||
Wait.frames(function() resetTokensIfInDeckZone(container, object) end, 1)
|
||||
end
|
||||
if not isCard(object) then return end
|
||||
|
||||
function resetTokensIfInDeckZone(container, object)
|
||||
local pos = self.positionToLocal(container.getPosition())
|
||||
if inArea(pos, DECK_DISCARD_AREA) then
|
||||
local localCardPos = self.positionToLocal(object.getPosition())
|
||||
if inArea(localCardPos, DECK_DISCARD_AREA) then
|
||||
tokenManager.resetTokensSpawned(object)
|
||||
removeTokensFromObject(container)
|
||||
removeTokensFromObject(object)
|
||||
end
|
||||
end
|
||||
|
||||
@ -702,7 +699,7 @@ function removeTokensFromObject(object)
|
||||
obj.getLock() == false and
|
||||
obj.getDescription() ~= "Action Token" and
|
||||
not tokenChecker.isChaosToken(obj) then
|
||||
ownedObjects.TrashCan.putObject(obj)
|
||||
ownedObjects.Trash.putObject(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -170,13 +170,17 @@ do
|
||||
end
|
||||
|
||||
-- finds all objects on the playmat and associated set aside zone and returns a table
|
||||
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||
---@param filter Function Optional filter function (return true for desired objects)
|
||||
PlaymatApi.searchAroundPlaymat = function(matColor, filter)
|
||||
local objList = {}
|
||||
for _, mat in pairs(internal.getMatForColor(matColor)) do
|
||||
return mat.call("searchAroundSelf", filter)
|
||||
for _, obj in ipairs(mat.call("searchAroundSelf", filter)) do
|
||||
table.insert(objList, obj)
|
||||
end
|
||||
end
|
||||
return objList
|
||||
end
|
||||
|
||||
-- Discard a non-hidden card from the corresponding player's hand
|
||||
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||
|
Loading…
Reference in New Issue
Block a user