Add method to enable or disable card type snap point tagging on a playmat
This uses the new object API concept to provide a layer of indirection between an object and others which might call() to methods on it. Example usage: local playmatApi = require("playermat/PlaymatApi") playmatApi.setLimitSnapsByType(tag, "All")
This commit is contained in:
parent
02cf7da07c
commit
8478003860
@ -1,5 +1,5 @@
|
||||
-- set true to enable debug logging and show Physics.cast()
|
||||
local DEBUG = false
|
||||
local DEBUG = true
|
||||
|
||||
-- we use this to turn off collision handling until onLoad() is complete
|
||||
local COLLISION_ENABLED = false
|
||||
@ -16,6 +16,27 @@ local DISCARD_BUTTON_OFFSETS = {
|
||||
{0.91, 0.1, -0.945}
|
||||
}
|
||||
|
||||
local MAIN_PLAY_AREA = {
|
||||
upperLeft = {
|
||||
x = 1.98,
|
||||
z = 0.736,
|
||||
},
|
||||
lowerRight = {
|
||||
x = -0.79,
|
||||
z = -0.39,
|
||||
}
|
||||
}
|
||||
local INVESTIGATOR_AREA = {
|
||||
upperLeft = {
|
||||
x = -1.084,
|
||||
z = 0.06517
|
||||
},
|
||||
lowerRight = {
|
||||
x = -1.258,
|
||||
z = -0.0805,
|
||||
}
|
||||
}
|
||||
|
||||
local PLAY_ZONE_ROTATION = self.getRotation()
|
||||
|
||||
local TRASHCAN
|
||||
@ -627,6 +648,56 @@ function spawnToken(position, tokenType)
|
||||
Global.call('spawnToken', {position, tokenType, PLAY_ZONE_ROTATION})
|
||||
end
|
||||
|
||||
-- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes
|
||||
-- is true, the main card slot snap points will only snap assets, while the investigator area point
|
||||
-- will only snap Investigators. 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.
|
||||
function setLimitSnapsByType(params)
|
||||
local matchTypes = params.matchTypes
|
||||
if matchTypes then
|
||||
log("Set true")
|
||||
else
|
||||
log("Set false")
|
||||
end
|
||||
local snaps = self.getSnapPoints()
|
||||
for i, snap in ipairs(snaps) do
|
||||
local snapPos = snap.position
|
||||
if inArea(snapPos, MAIN_PLAY_AREA) then
|
||||
local snapTags = snaps[i].tags
|
||||
if matchTypes then
|
||||
if snapTags == nil then
|
||||
snaps[i].tags = { "Asset" }
|
||||
else
|
||||
table.insert(snaps[i].tags, "Asset")
|
||||
end
|
||||
else
|
||||
snaps[i].tags = nil
|
||||
end
|
||||
end
|
||||
if inArea(snapPos, INVESTIGATOR_AREA) then
|
||||
local snapTags = snaps[i].tags
|
||||
if matchTypes then
|
||||
if snapTags == nil then
|
||||
snaps[i].tags = { "Investigator" }
|
||||
else
|
||||
table.insert(snaps[i].tags, "Investigator")
|
||||
end
|
||||
else
|
||||
snaps[i].tags = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
self.setSnapPoints(snaps)
|
||||
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
|
||||
|
||||
-- called by custom data helpers to add player card data
|
||||
---@param args table Contains only one entry, the GUID of the custom data helper
|
||||
function updatePlayerCards(args)
|
||||
|
48
src/playermat/PlaymatApi.ttslua
Normal file
48
src/playermat/PlaymatApi.ttslua
Normal file
@ -0,0 +1,48 @@
|
||||
do
|
||||
local PlaymatApi = { }
|
||||
local internal = { }
|
||||
|
||||
local WHITE_MAT_GUID = "8b081b"
|
||||
local ORANGE_MAT_GUID = "bd0ff4"
|
||||
local GREEN_MAT_GUID = "383d8b"
|
||||
local RED_MAT_GUID = "0840d5"
|
||||
|
||||
-- Sets the requested playermat's snap points to limit snapping to matching card types or not. If
|
||||
-- matchTypes is true, the main card slot snap points will only snap assets, while the
|
||||
-- investigator area point will only snap Investigators. 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 matColor String for one of the active player colors - White, Orange, Green, Red. Also
|
||||
-- accepts "All" as a special value which will apply the setting to all four mats.
|
||||
PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor)
|
||||
for _, mat in ipairs(internal.getMatForColor(matColor)) do
|
||||
mat.call("setLimitSnapsByType", { matchTypes = matchCardTypes })
|
||||
end
|
||||
end
|
||||
|
||||
-- Convenience function to look up a mat's object by color, or get all mats.
|
||||
-- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also
|
||||
-- accepts "All" as a special value which will return all four mats.
|
||||
-- @return Array of playermat objects. If a single mat is requested, will return a single-element
|
||||
-- array to simplify processing by consumers.
|
||||
internal.getMatForColor = function(matColor)
|
||||
if matColor == "White" then
|
||||
return { getObjectFromGUID(WHITE_MAT_GUID) }
|
||||
elseif matColor == "Orange" then
|
||||
return { getObjectFromGUID(ORANGE_MAT_GUID) }
|
||||
elseif matColor == "Green" then
|
||||
return { getObjectFromGUID(GREEN_MAT_GUID) }
|
||||
elseif matColor == "Red" then
|
||||
return { getObjectFromGUID(RED_MAT_GUID) }
|
||||
elseif matColor == "All" then
|
||||
return {
|
||||
getObjectFromGUID(WHITE_MAT_GUID),
|
||||
getObjectFromGUID(ORANGE_MAT_GUID),
|
||||
getObjectFromGUID(GREEN_MAT_GUID),
|
||||
getObjectFromGUID(RED_MAT_GUID),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return PlaymatApi
|
||||
end
|
Loading…
Reference in New Issue
Block a user