diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index c7e67f26..c9731451 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -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,55 @@ 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(matchTypes) + 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 + +-- Simple method to check if the given point is in a specified area. Local use only, +-- @param point Vector. Point to check, only x and z values are relevant +-- @param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample +-- bounds definition. +-- @return Boolean. True if the point is in the area defined by bounds +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) diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua new file mode 100644 index 00000000..489387e4 --- /dev/null +++ b/src/playermat/PlaymatApi.ttslua @@ -0,0 +1,47 @@ +do + local PlaymatApi = { } + local internal = { } + + local MAT_IDS = { + White = "8b081b", + Orange = "bd0ff4", + Green = "383d8b", + Red = "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 matchCardTypes 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", 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) + local targetMatGuid = MAT_IDS[matColor] + if targetMatGuid != nil then + return { getObjectFromGUID(targetMatGuid) } + end + if matColor == "All" then + return { + getObjectFromGUID(MAT_IDS.White), + getObjectFromGUID(MAT_IDS.Orange), + getObjectFromGUID(MAT_IDS.Green), + getObjectFromGUID(MAT_IDS.Red), + } + end + end + + return PlaymatApi +end