More API Updates
Added even more utilization of existing APIs, as well as expanding them a bit to cover a couple of more cases. Also, changed the get/setInvestigatorCount methods to live directly in the PlayAreaApi, since there didn't seem to be any reason to keep them in the PlayArea script.
This commit is contained in:
parent
7659de4c59
commit
79f7861f1e
@ -8,6 +8,7 @@ local soundCubeApi = require("core/SoundCubeApi")
|
||||
local playmatApi = require("playermat/PlaymatApi")
|
||||
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||
local playAreaAPI = require("core/PlayAreaApi")
|
||||
|
||||
-- these objects will be ignored
|
||||
local IGNORE_GUIDS = {
|
||||
@ -231,7 +232,7 @@ end
|
||||
-- gets the GUID of a custom data helper (if present) and adds it to the ignore list
|
||||
function ignoreCustomDataHelper()
|
||||
local playArea = getObjectFromGUID("721ba2")
|
||||
local customDataHelper = playArea.getVar("customDataHelper")
|
||||
local customDataHelper = playAreaAPI.getCustomDataHelper()
|
||||
if customDataHelper then table.insert(IGNORE_GUIDS, customDataHelper.getGUID()) end
|
||||
end
|
||||
|
||||
|
@ -54,5 +54,11 @@ do
|
||||
return Global.call("drawChaosToken", params)
|
||||
end
|
||||
|
||||
-- returns a Table List of chaos token ids in the current chaos bag
|
||||
-- requires copying the data into a new table because TTS is weird about handling table return values in Global
|
||||
ChaosBagApi.getIdUrlMap = function()
|
||||
return Global.getTable("ID_URL_MAP")
|
||||
end
|
||||
|
||||
return ChaosBagApi
|
||||
end
|
@ -504,20 +504,6 @@ function shiftContents(playerColor, direction)
|
||||
Wait.time(drawBaseConnections, 0.1)
|
||||
end
|
||||
|
||||
-- Returns the current value of the investigator counter from the playmat
|
||||
---@return. Number of investigators currently set on the counter
|
||||
function getInvestigatorCount()
|
||||
local investigatorCounter = getObjectFromGUID("f182ee")
|
||||
return investigatorCounter.getVar("val")
|
||||
end
|
||||
|
||||
-- Updates the current value of the investigator counter from the playmat
|
||||
---@param count Number of investigators to set on the counter
|
||||
function setInvestigatorCount(count)
|
||||
local investigatorCounter = getObjectFromGUID("f182ee")
|
||||
return investigatorCounter.call("updateVal", count)
|
||||
end
|
||||
|
||||
-- Check to see if the given object is within the bounds of the play area, based solely on the X and
|
||||
-- Z coordinates, ignoring height
|
||||
---@param object Object Object to check
|
||||
|
@ -2,17 +2,18 @@ do
|
||||
local PlayAreaApi = { }
|
||||
|
||||
local PLAY_AREA_GUID = "721ba2"
|
||||
local INVESTIGATOR_COUNTER_GUID = "f182ee"
|
||||
|
||||
-- Returns the current value of the investigator counter from the playmat
|
||||
---@return Integer. Number of investigators currently set on the counter
|
||||
PlayAreaApi.getInvestigatorCount = function()
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).call("getInvestigatorCount")
|
||||
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).getVar("val")
|
||||
end
|
||||
|
||||
-- Updates the current value of the investigator counter from the playmat
|
||||
---@param count Number of investigators to set on the counter
|
||||
PlayAreaApi.setInvestigatorCount = function(count)
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).call("setInvestigatorCount", count)
|
||||
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).call("updateVal", count)
|
||||
end
|
||||
|
||||
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
|
||||
@ -83,5 +84,30 @@ do
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).call("isInPlayArea", object)
|
||||
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)
|
||||
getObjectFromGUID(PLAY_AREA_GUID).call("updateLocations", args)
|
||||
end
|
||||
|
||||
PlayAreaApi.getCustomDataHelper = function()
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).getVar("customDataHelper")
|
||||
end
|
||||
|
||||
PlayAreaApi.getCustomObject = function()
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).getCustomObject()
|
||||
end
|
||||
|
||||
PlayAreaApi.setCustomObject = function(customInfo)
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).setCustomObject(customInfo)
|
||||
end
|
||||
|
||||
PlayAreaApi.reload = function()
|
||||
return getObjectFromGUID(PLAY_AREA_GUID).reload()
|
||||
end
|
||||
|
||||
|
||||
|
||||
return PlayAreaApi
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
local controlActive = false
|
||||
local DEFAULT_URL = "http://cloud-3.steamusercontent.com/ugc/998015670465071049/FFAE162920D67CF38045EFBD3B85AD0F916147B2/"
|
||||
local playAreaAPI = require("core/PlayAreaApi")
|
||||
|
||||
-- parameters for open/close button for reusing
|
||||
local buttonParameters = {}
|
||||
@ -70,8 +71,7 @@ function none() end
|
||||
|
||||
-- main function (can be called by other objects)
|
||||
function updateSurface(newURL)
|
||||
local playArea = getObjectFromGUID("721ba2")
|
||||
local customInfo = playArea.getCustomObject()
|
||||
local customInfo = playAreaAPI.getCustomObject()
|
||||
|
||||
if newURL ~= "" and newURL ~= nil and newURL ~= DEFAULT_URL then
|
||||
customInfo.image = newURL
|
||||
@ -80,18 +80,18 @@ function updateSurface(newURL)
|
||||
customInfo.image = DEFAULT_URL
|
||||
broadcastToAll("Default Playmat Image Applied", { 0.2, 0.9, 0.2 })
|
||||
end
|
||||
|
||||
playArea.setCustomObject(customInfo)
|
||||
|
||||
playAreaAPI.setCustomObject(customInfo)
|
||||
|
||||
-- get custom data helper and call the playarea with it after reloading
|
||||
local customDataHelper = playArea.getVar("customDataHelper")
|
||||
local customDataHelper = playAreaAPI.getCustomDataHelper()
|
||||
local guid
|
||||
|
||||
if customDataHelper then guid = customDataHelper.getGUID() end
|
||||
playArea = playArea.reload()
|
||||
playAreaAPI.reload()
|
||||
|
||||
if guid ~= nil then
|
||||
Wait.time(function() playArea.call("updateLocations", { guid }) end, 1)
|
||||
Wait.time(function() playAreaAPI.updateLocations({ guid }) end, 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
do
|
||||
local tokenSpawnTracker = require("core/token/TokenSpawnTrackerApi")
|
||||
local playArea = require("core/PlayAreaApi")
|
||||
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
local optionPanelApi = require("core/OptionPanelApi")
|
||||
|
||||
local PLAYER_CARD_TOKEN_OFFSETS = {
|
||||
[1] = {
|
||||
@ -141,7 +142,7 @@ do
|
||||
---@param extraUses Table A table of <use type>=<count> which will modify the number of tokens
|
||||
--- spawned for that type. e.g. Akachi's playmat should pass "Charge"=1
|
||||
TokenManager.spawnForCard = function(card, extraUses)
|
||||
if tokenSpawnTracker.hasSpawnedTokens(card.getGUID()) then
|
||||
if tokenSpawnTrackerApi.hasSpawnedTokens(card.getGUID()) then
|
||||
return
|
||||
end
|
||||
local metadata = JSON.decode(card.getGMNotes())
|
||||
@ -161,7 +162,7 @@ do
|
||||
---@param shiftDown Number An offset for the z-value of this group of tokens
|
||||
---@param subType Number Subtype of token to spawn. This will only differ from the tokenName for resource tokens
|
||||
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown, subType)
|
||||
local optionPanel = Global.getTable("optionPanel")
|
||||
local optionPanel = optionPanelApi.getOptions()
|
||||
|
||||
if tokenType == "damage" or tokenType == "horror" then
|
||||
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
|
||||
@ -303,7 +304,7 @@ do
|
||||
-- callers.
|
||||
---@param card Object Card object to reset the tokens for
|
||||
TokenManager.resetTokensSpawned = function(card)
|
||||
tokenSpawnTracker.resetTokensSpawned(card.getGUID())
|
||||
tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID())
|
||||
end
|
||||
|
||||
-- Pushes new player card data into the local copy of the Data Helper player data.
|
||||
@ -369,14 +370,14 @@ do
|
||||
type = useInfo.type
|
||||
token = useInfo.token
|
||||
tokenCount = (useInfo.count or 0)
|
||||
+ (useInfo.countPerInvestigator or 0) * playArea.getInvestigatorCount()
|
||||
+ (useInfo.countPerInvestigator or 0) * playAreaApi.getInvestigatorCount()
|
||||
if extraUses ~= nil and extraUses[type] ~= nil then
|
||||
tokenCount = tokenCount + extraUses[type]
|
||||
end
|
||||
-- Shift each spawned group after the first down so they don't pile on each other
|
||||
TokenManager.spawnTokenGroup(card, token, tokenCount, (i - 1) * 0.8, type)
|
||||
end
|
||||
tokenSpawnTracker.markTokensSpawned(card.getGUID())
|
||||
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
|
||||
end
|
||||
|
||||
-- Spawn tokens for a card based on the data helper data. This will consider the face up/down state
|
||||
@ -403,7 +404,7 @@ do
|
||||
tokenCount = playerData.tokenCount
|
||||
--log("Spawning data helper tokens for "..card.getName()..'['..card.getDescription()..']: '..tokenCount.."x "..token)
|
||||
TokenManager.spawnTokenGroup(card, token, tokenCount)
|
||||
tokenSpawnTracker.markTokensSpawned(card.getGUID())
|
||||
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
|
||||
end
|
||||
|
||||
-- Spawn tokens for a location using data retrieved from the Data Helper.
|
||||
@ -414,7 +415,7 @@ do
|
||||
local clueCount = internal.getClueCountFromData(card, locationData)
|
||||
if clueCount > 0 then
|
||||
TokenManager.spawnTokenGroup(card, "clue", clueCount)
|
||||
tokenSpawnTracker.markTokensSpawned(card.getGUID())
|
||||
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
|
||||
end
|
||||
end
|
||||
|
||||
@ -440,7 +441,7 @@ do
|
||||
if locationData.type == 'fixed' then
|
||||
return locationData.value
|
||||
elseif locationData.type == 'perPlayer' then
|
||||
return locationData.value * playArea.getInvestigatorCount()
|
||||
return locationData.value * playAreaApi.getInvestigatorCount()
|
||||
end
|
||||
error('unexpected location type: ' .. locationData.type)
|
||||
end
|
||||
|
8
src/playercards/AllCardsBagApi.ttslua
Normal file
8
src/playercards/AllCardsBagApi.ttslua
Normal file
@ -0,0 +1,8 @@
|
||||
do
|
||||
local AllCardsBagApi = {}
|
||||
local ALL_CARDS_BAG_GUID = "15bb07"
|
||||
|
||||
|
||||
|
||||
return AllCardsBagApi
|
||||
end
|
@ -70,17 +70,16 @@ Thus it should be implemented like this:
|
||||
|
||||
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
||||
local tokenArrangerApi = require("accessories/TokenArrangerApi")
|
||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||
local sealedTokens = {}
|
||||
local ID_URL_MAP = {}
|
||||
local tokensInBag = {}
|
||||
|
||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||
|
||||
function onSave() return JSON.encode(sealedTokens) end
|
||||
|
||||
function onLoad(savedData)
|
||||
sealedTokens = JSON.decode(savedData) or {}
|
||||
ID_URL_MAP = Global.getTable("ID_URL_MAP")
|
||||
ID_URL_MAP = chaosBagApi.getIdUrlMap()
|
||||
generateContextMenu()
|
||||
self.addTag("CardThatSeals")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user