clean up helper update to dynamic references
This commit is contained in:
parent
3292f2a2d1
commit
4c0c025319
@ -67,6 +67,7 @@
|
|||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
"Tags": [
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore",
|
||||||
"displacement_excluded"
|
"displacement_excluded"
|
||||||
],
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
"Nickname": "Clue tokens",
|
"Nickname": "Clue tokens",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": 2.857,
|
"posX": 2.857,
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
"Nickname": "Connection markers",
|
"Nickname": "Connection markers",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": -51,
|
"posX": -51,
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
"Tags": [
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore",
|
||||||
"displacement_excluded"
|
"displacement_excluded"
|
||||||
],
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
|
@ -36,10 +36,14 @@
|
|||||||
"LuaScript": "require(\"core/DoomCounter\")",
|
"LuaScript": "require(\"core/DoomCounter\")",
|
||||||
"LuaScriptState": "[0,{\"Agenda\":true,\"Playarea\":true,\"Playermats\":true}]",
|
"LuaScriptState": "[0,{\"Agenda\":true,\"Playarea\":true,\"Playermats\":true}]",
|
||||||
"MeasureMovement": false,
|
"MeasureMovement": false,
|
||||||
|
"Memo": "{\"matColor\":\"Mythos\",\"type\":\"DoomCounter\"}",
|
||||||
"Name": "Custom_Token",
|
"Name": "Custom_Token",
|
||||||
"Nickname": "Doom Counter",
|
"Nickname": "Doom Counter",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": -5.3,
|
"posX": -5.3,
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
"Nickname": "Doom tokens",
|
"Nickname": "Doom tokens",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": -55.48,
|
"posX": -55.48,
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
"Nickname": "Doom tokens",
|
"Nickname": "Doom tokens",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": 2.761,
|
"posX": 2.761,
|
||||||
|
@ -37,9 +37,12 @@
|
|||||||
"LuaScriptState": "false",
|
"LuaScriptState": "false",
|
||||||
"MeasureMovement": false,
|
"MeasureMovement": false,
|
||||||
"Name": "Custom_Token",
|
"Name": "Custom_Token",
|
||||||
"Nickname": "Master Clue Counter\n",
|
"Nickname": "Master Clue Counter",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": true,
|
"Tooltip": true,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": -5.3,
|
"posX": -5.3,
|
||||||
|
@ -67,6 +67,9 @@
|
|||||||
"Nickname": "Mythos Area",
|
"Nickname": "Mythos Area",
|
||||||
"Snap": true,
|
"Snap": true,
|
||||||
"Sticky": true,
|
"Sticky": true,
|
||||||
|
"Tags": [
|
||||||
|
"CleanUpHelper_ignore"
|
||||||
|
],
|
||||||
"Tooltip": false,
|
"Tooltip": false,
|
||||||
"Transform": {
|
"Transform": {
|
||||||
"posX": -1.309,
|
"posX": -1.309,
|
||||||
|
@ -10,43 +10,15 @@ local playmatApi = require("playermat/PlaymatApi")
|
|||||||
local soundCubeApi = require("core/SoundCubeApi")
|
local soundCubeApi = require("core/SoundCubeApi")
|
||||||
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
||||||
|
|
||||||
-- these objects will be ignored
|
|
||||||
local IGNORE_GUIDS = {
|
|
||||||
-- big playmat, change image panel and investigator counter
|
|
||||||
"b7b45b", "f182ee", "721ba2",
|
|
||||||
-- bless/curse manager
|
|
||||||
"afa06b", "bd0253", "5933fb",
|
|
||||||
-- stuff on mythos area
|
|
||||||
"85c4c6", "4a3aa4", "fea079", "b015d8", "11e0cf", "9f334f", "70b9f6", "0a5a29",
|
|
||||||
-- doom/location token bag
|
|
||||||
"47ffc3", "170f10",
|
|
||||||
-- table
|
|
||||||
"4ee1f2"
|
|
||||||
}
|
|
||||||
|
|
||||||
-- objects with this tag will be ignored
|
-- objects with this tag will be ignored
|
||||||
local IGNORE_TAG = "CleanUpHelper_ignore"
|
local IGNORE_TAG = "CleanUpHelper_ignore"
|
||||||
|
|
||||||
-- colors and order for following tables
|
-- colors and order for following tables
|
||||||
local COLORS = { "White", "Orange", "Green", "Red", "Mythos" }
|
local COLORS = { "White", "Orange", "Green", "Red", "Mythos" }
|
||||||
|
|
||||||
-- counter GUIDS (4x damage and 4x horror)
|
|
||||||
local DAMAGE_HORROR_GUIDS = {
|
|
||||||
"eb08d6", "e64eec", "1f5a0a", "591a45",
|
|
||||||
"468e88", "0257d9", "7b5729", "beb964",
|
|
||||||
}
|
|
||||||
|
|
||||||
local campaignLog
|
local campaignLog
|
||||||
local RESET_VALUES = {}
|
local RESET_VALUES = {}
|
||||||
|
|
||||||
-- GUIDS of objects (in order of ownership relating to 'COLORS')
|
|
||||||
local PLAYERMAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
|
|
||||||
local RESOURCE_GUIDS = { "4406f0", "816d84", "cd15ac", "a4b60d" }
|
|
||||||
local TRACKER_GUIDS = { "e598c2", "b4a5f7", "af7ed7", "e74881" }
|
|
||||||
local CLUE_GUIDS = { "d86b7c", "1769ed", "032300", "37be78" }
|
|
||||||
local CLUE_CLICKER_GUIDS = { "db85d6", "3f22e5", "891403", "4111de" }
|
|
||||||
local TRASHCAN_GUIDS = { "147e80", "f7b6c8", "5f896a", "4b8594", "70b9f6" }
|
|
||||||
|
|
||||||
-- values for physics.cast (4 entries for player zones, 5th entry for mythos area, 6th for campaign log)
|
-- values for physics.cast (4 entries for player zones, 5th entry for mythos area, 6th for campaign log)
|
||||||
local PHYSICS_POSITION = {
|
local PHYSICS_POSITION = {
|
||||||
{ -54.5, 2, 21 },
|
{ -54.5, 2, 21 },
|
||||||
@ -131,14 +103,6 @@ function onLoad(savedData)
|
|||||||
buttonParameters.position.z = 1.1
|
buttonParameters.position.z = 1.1
|
||||||
buttonParameters.width = 1550
|
buttonParameters.width = 1550
|
||||||
self.createButton(buttonParameters)
|
self.createButton(buttonParameters)
|
||||||
|
|
||||||
-- create single table for ignoring
|
|
||||||
for _, v in ipairs(CLUE_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
for _, v in ipairs(CLUE_CLICKER_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
for _, v in ipairs(RESOURCE_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
for _, v in ipairs(TRASHCAN_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
for _, v in ipairs(PLAYERMAT_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
for _, v in ipairs(DAMAGE_HORROR_GUIDS) do table.insert(IGNORE_GUIDS, v) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
@ -178,13 +142,8 @@ function cleanUp(_, color)
|
|||||||
getTrauma()
|
getTrauma()
|
||||||
|
|
||||||
-- delay to account for potential state change
|
-- delay to account for potential state change
|
||||||
Wait.time(function()
|
Wait.time(updateCounters, 0.2)
|
||||||
updateCounters(RESOURCE_GUIDS, 5, "Resource")
|
|
||||||
updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clicker")
|
|
||||||
updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror")
|
|
||||||
end, 0.2)
|
|
||||||
|
|
||||||
resetSkillTrackers()
|
|
||||||
resetDoomCounter()
|
resetDoomCounter()
|
||||||
blessCurseManagerApi.removeAll(color)
|
blessCurseManagerApi.removeAll(color)
|
||||||
removeLines()
|
removeLines()
|
||||||
@ -200,39 +159,20 @@ end
|
|||||||
-- modular functions, called by other functions
|
-- modular functions, called by other functions
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
function updateCounters(tableOfGUIDs, newValues, info)
|
function updateCounters()
|
||||||
-- instead of a table, this will be used if just a single value is provided
|
playmatApi.updateCounter("All", "ResourceCounter" , 5)
|
||||||
local singleValue = tonumber(newValues)
|
playmatApi.updateCounter("All", "ClickableClueCounter" , 0)
|
||||||
|
playmatApi.resetSkillTracker("All")
|
||||||
|
|
||||||
for i, guid in ipairs(tableOfGUIDs) do
|
for i = 1, 4 do
|
||||||
local TOKEN = getObjectFromGUID(guid)
|
playmatApi.updateCounter(COLORS[i], "DamageCounter", RESET_VALUES.Damage[i])
|
||||||
local newValue = singleValue or newValues[i]
|
playmatApi.updateCounter(COLORS[i], "HorrorCounter", RESET_VALUES.Horror[i])
|
||||||
|
|
||||||
if TOKEN ~= nil then
|
|
||||||
TOKEN.call("updateVal", newValue)
|
|
||||||
else
|
|
||||||
printToAll(info .. ": No. " .. i .. " could not be found.", "Yellow")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set investigator skill trackers to "1, 1, 1, 1"
|
|
||||||
function resetSkillTrackers()
|
|
||||||
for i, guid in ipairs(TRACKER_GUIDS) do
|
|
||||||
local obj = getObjectFromGUID(guid)
|
|
||||||
|
|
||||||
if obj ~= nil then
|
|
||||||
obj.call("updateStats", { 1, 1, 1, 1 })
|
|
||||||
else
|
|
||||||
printToAll("Skill tracker for " .. COLORS[i] .. " playmat could not be found.", "Yellow")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset doom on agenda
|
-- reset doom on agenda
|
||||||
function resetDoomCounter()
|
function resetDoomCounter()
|
||||||
local doomCounter = getObjectFromGUID("85c4c6")
|
local doomCounter = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "DoomCounter"})
|
||||||
|
|
||||||
if doomCounter ~= nil then
|
if doomCounter ~= nil then
|
||||||
doomCounter.call("updateVal")
|
doomCounter.call("updateVal")
|
||||||
else
|
else
|
||||||
@ -240,19 +180,19 @@ function resetDoomCounter()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- gets the GUID of a custom data helper (if present) and adds it to the ignore list
|
-- adds the ignore tag to the custom data helper
|
||||||
function ignoreCustomDataHelper()
|
function ignoreCustomDataHelper()
|
||||||
local customDataHelper = playAreaApi.getCustomDataHelper()
|
local customDataHelper = playAreaApi.getCustomDataHelper()
|
||||||
if customDataHelper then
|
if customDataHelper then
|
||||||
table.insert(IGNORE_GUIDS, customDataHelper.getGUID())
|
customDataHelper.addTag(IGNORE_TAG)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- read values for trauma from campaign log if enabled
|
-- read values for trauma from campaign log if enabled
|
||||||
function getTrauma()
|
function getTrauma()
|
||||||
RESET_VALUES = {
|
RESET_VALUES = {
|
||||||
0, 0, 0, 0,
|
Damage = { 0, 0, 0, 0 },
|
||||||
0, 0, 0, 0
|
Horror = { 0, 0, 0, 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
-- stop here if trauma import is disabled
|
-- stop here if trauma import is disabled
|
||||||
@ -279,7 +219,14 @@ function loadTrauma()
|
|||||||
|
|
||||||
if trauma ~= nil then
|
if trauma ~= nil then
|
||||||
printToAll("Trauma values found in campaign log!", "Green")
|
printToAll("Trauma values found in campaign log!", "Green")
|
||||||
RESET_VALUES = campaignLog.call("returnTrauma")
|
trauma = campaignLog.call("returnTrauma")
|
||||||
|
for i = 1, 8 do
|
||||||
|
if i < 5 then
|
||||||
|
RESET_VALUES.Damage[i] = trauma[i]
|
||||||
|
else
|
||||||
|
RESET_VALUES.Horror[i-4] = trauma[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
loadingFailedBefore = false
|
loadingFailedBefore = false
|
||||||
elseif loadingFailedBefore then
|
elseif loadingFailedBefore then
|
||||||
printToAll("Trauma values could not be found in campaign log!", "Yellow")
|
printToAll("Trauma values could not be found in campaign log!", "Yellow")
|
||||||
@ -302,7 +249,7 @@ end
|
|||||||
-- remove drawn lines
|
-- remove drawn lines
|
||||||
function removeLines()
|
function removeLines()
|
||||||
if options["removeDrawnLines"] then
|
if options["removeDrawnLines"] then
|
||||||
printToAll("Removing vector lines...", "White")
|
printToAll("Removing global vector lines...", "White")
|
||||||
Global.setVectorLines({})
|
Global.setVectorLines({})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -311,30 +258,30 @@ end
|
|||||||
function discardHands()
|
function discardHands()
|
||||||
if not options["tidyPlayermats"] then return end
|
if not options["tidyPlayermats"] then return end
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
|
local trash = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Trash"})
|
||||||
if trashcan == nil then return end
|
if trash == nil then return end
|
||||||
local hand = Player[playmatApi.getPlayerColor(COLORS[i])].getHandObjects()
|
local hand = Player[playmatApi.getPlayerColor(COLORS[i])].getHandObjects()
|
||||||
for j = #hand, 1, -1 do
|
for j = #hand, 1, -1 do
|
||||||
trashcan.putObject(hand[j])
|
trash.putObject(hand[j])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- clean up for play area
|
-- clean up for play area
|
||||||
function tidyPlayareaCoroutine()
|
function tidyPlayareaCoroutine()
|
||||||
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[5])
|
local trash = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "Trash"})
|
||||||
local PLAYMATZONE = getObjectFromGUID("a2f932")
|
local playAreaZone = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayAreaZone"})
|
||||||
|
|
||||||
if PLAYMATZONE == nil then
|
if playAreaZone == nil then
|
||||||
printToAll("Scripting zone for main play area could not be found!", "Red")
|
printToAll("Scripting zone for main play area could not be found!", "Red")
|
||||||
elseif trashcan == nil then
|
elseif trash == nil then
|
||||||
printToAll("Trashcan for main play area could not be found!", "Red")
|
printToAll("Trashcan for main play area could not be found!", "Red")
|
||||||
else
|
else
|
||||||
for _, obj in ipairs(PLAYMATZONE.getObjects()) do
|
for _, obj in ipairs(playAreaZone.getObjects()) do
|
||||||
-- ignore these elements
|
-- ignore these elements
|
||||||
if not tableContains(IGNORE_GUIDS, obj.getGUID()) and obj.hasTag(IGNORE_TAG) == false then
|
if obj.hasTag(IGNORE_TAG) == false then
|
||||||
coroutine.yield(0)
|
coroutine.yield(0)
|
||||||
trashcan.putObject(obj)
|
trash.putObject(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -352,34 +299,32 @@ function tidyPlayerMatCoroutine()
|
|||||||
-- delay for animation purpose
|
-- delay for animation purpose
|
||||||
for k = 1, 30 do coroutine.yield(0) end
|
for k = 1, 30 do coroutine.yield(0) end
|
||||||
|
|
||||||
-- get respective trashcan
|
-- get respective trash
|
||||||
local trashcan = getObjectFromGUID(TRASHCAN_GUIDS[i])
|
local trash = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Trash"})
|
||||||
if trashcan == nil then
|
if trash == nil then
|
||||||
printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red")
|
printToAll("Trashcan for " .. COLORS[i] .. " playmat could not be found!", "Red")
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, entry in ipairs(findObjects(i)) do
|
for _, entry in ipairs(findObjects(i)) do
|
||||||
local obj = entry.hit_object
|
local obj = entry.hit_object
|
||||||
local desc_low = string.lower(obj.getDescription())
|
|
||||||
|
|
||||||
-- ignore these elements
|
-- ignore these elements
|
||||||
if not tableContains(IGNORE_GUIDS, obj.getGUID())
|
if obj.hasTag(IGNORE_TAG) == false
|
||||||
and obj.hasTag(IGNORE_TAG) == false
|
and obj.hasTag("ActionToken") == false
|
||||||
and desc_low ~= "chaos bag"
|
and obj.hasTag("chaosBag") == false then
|
||||||
and desc_low ~= "action token" then
|
|
||||||
coroutine.yield(0)
|
coroutine.yield(0)
|
||||||
trashcan.putObject(obj)
|
trash.putObject(obj)
|
||||||
|
|
||||||
-- flip action tokens back to ready
|
-- flip action tokens back to ready
|
||||||
elseif desc_low == "action token" and obj.is_face_down then
|
elseif obj.hasTag("ActionToken") == false and obj.is_face_down then
|
||||||
obj.flip()
|
obj.flip()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset "activeInvestigatorId"
|
-- reset "activeInvestigatorId"
|
||||||
if i < 5 then
|
if i < 5 then
|
||||||
local playermat = getObjectFromGUID(PLAYERMAT_GUIDS[i])
|
local playermat = Global.call("getObjectFromMemo", {matColor = COLORS[i], type = "Playermat"})
|
||||||
if playermat then
|
if playermat then
|
||||||
playermat.setVar("activeInvestigatorId", "00000")
|
playermat.setVar("activeInvestigatorId", "00000")
|
||||||
end
|
end
|
||||||
@ -387,7 +332,7 @@ function tidyPlayerMatCoroutine()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local datahelper = getObjectFromGUID("708279")
|
local datahelper = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "DataHelper"})
|
||||||
if datahelper then
|
if datahelper then
|
||||||
datahelper.setTable("SPAWNED_PLAYER_CARD_GUIDS", {})
|
datahelper.setTable("SPAWNED_PLAYER_CARD_GUIDS", {})
|
||||||
end
|
end
|
||||||
@ -412,13 +357,3 @@ function findObjects(num)
|
|||||||
debug = false
|
debug = false
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- search a table for a value, return true if found (else returns false)
|
|
||||||
function tableContains(table, value)
|
|
||||||
for _, v in ipairs(table) do
|
|
||||||
if v == value then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
@ -16,8 +16,8 @@ function searchSelf()
|
|||||||
|
|
||||||
for _, obj in ipairs(searchArea(self.getPosition(), { 2.5, 0.5, 3.5 })) do
|
for _, obj in ipairs(searchArea(self.getPosition(), { 2.5, 0.5, 3.5 })) do
|
||||||
local obj = obj.hit_object
|
local obj = obj.hit_object
|
||||||
if obj.getCustomObject().image ==
|
local image = obj.getCustomObject().image
|
||||||
"http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/" then
|
if image == "http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/" then
|
||||||
foundTokens = foundTokens + math.abs(obj.getQuantity())
|
foundTokens = foundTokens + math.abs(obj.getQuantity())
|
||||||
obj.destruct()
|
obj.destruct()
|
||||||
elseif obj.getMemo() == "resourceCounter" then
|
elseif obj.getMemo() == "resourceCounter" then
|
||||||
@ -47,7 +47,7 @@ end
|
|||||||
function takeAll(playerColor)
|
function takeAll(playerColor)
|
||||||
searchSelf()
|
searchSelf()
|
||||||
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
|
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
|
||||||
playmatApi.gainResources(foundTokens, matColor)
|
playmatApi.updateCounter(matColor, "ResourceCounter", foundTokens)
|
||||||
|
|
||||||
if clickableResourceCounter then
|
if clickableResourceCounter then
|
||||||
clickableResourceCounter.call("updateVal", 0)
|
clickableResourceCounter.call("updateVal", 0)
|
||||||
|
@ -7,66 +7,65 @@ local modValue = 5 -- level 0 Well Connected
|
|||||||
local loopId = nil
|
local loopId = nil
|
||||||
|
|
||||||
local b_display = {
|
local b_display = {
|
||||||
click_function = "toggleCounter",
|
click_function = "toggleCounter",
|
||||||
function_owner = self,
|
function_owner = self,
|
||||||
position = {0.88,0.5,-1.33},
|
position = { 0.88, 0.5, -1.33 },
|
||||||
font_size = 150,
|
font_size = 150,
|
||||||
width = 175,
|
width = 175,
|
||||||
height = 175
|
height = 175
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLoad(saved_data)
|
function onLoad(saved_data)
|
||||||
local notes = JSON.decode(self.getGMNotes())
|
local notes = JSON.decode(self.getGMNotes())
|
||||||
|
|
||||||
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
|
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
|
||||||
modValue = 4 -- Well Connected (3)
|
modValue = 4 -- Well Connected (3)
|
||||||
end
|
end
|
||||||
|
|
||||||
if saved_data != '' then
|
if saved_data != '' then
|
||||||
local loaded_data = JSON.decode(saved_data)
|
local loaded_data = JSON.decode(saved_data)
|
||||||
display = not loaded_data.saved_display
|
display = not loaded_data.saved_display
|
||||||
|
|
||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
toggleCounter()
|
toggleCounter()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.addContextMenuItem('Toggle Counter', toggleCounter)
|
self.addContextMenuItem('Toggle Counter', toggleCounter)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onSave()
|
function onSave()
|
||||||
return JSON.encode({saved_display = display})
|
return JSON.encode({ saved_display = display })
|
||||||
end
|
end
|
||||||
|
|
||||||
function toggleCounter()
|
function toggleCounter()
|
||||||
display = not display
|
display = not display
|
||||||
|
|
||||||
if display then
|
if display then
|
||||||
createUpdateDisplay()
|
createUpdateDisplay()
|
||||||
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
|
loopId = Wait.time(createUpdateDisplay, 2, -1)
|
||||||
else
|
else
|
||||||
if loopId ~= nil then
|
if loopId ~= nil then
|
||||||
Wait.stop(loopId)
|
Wait.stop(loopId)
|
||||||
end
|
|
||||||
|
|
||||||
self.clearButtons()
|
|
||||||
loopId = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.clearButtons()
|
||||||
|
loopId = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function createUpdateDisplay()
|
function createUpdateDisplay()
|
||||||
count = math.max(math.floor(getPlayerResources() / modValue), 0)
|
count = math.max(math.floor(getPlayerResources() / modValue), 0)
|
||||||
|
|
||||||
b_display.label = tostring(count)
|
b_display.label = tostring(count)
|
||||||
|
|
||||||
if loopId == nil then
|
if loopId == nil then
|
||||||
self.createButton(b_display)
|
self.createButton(b_display)
|
||||||
else
|
else
|
||||||
self.editButton(b_display)
|
self.editButton(b_display)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function getPlayerResources()
|
function getPlayerResources()
|
||||||
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
|
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
|
||||||
|
return playmatApi.getCounterValue(matColor, "ResourceCounter")
|
||||||
return playmatApi.getResourceCount(matColor)
|
end
|
||||||
end
|
|
||||||
|
@ -63,6 +63,7 @@ activeInvestigatorId = "00000"
|
|||||||
|
|
||||||
-- table of type-object reference pairs of all owned objects
|
-- table of type-object reference pairs of all owned objects
|
||||||
local ownedObjects = {}
|
local ownedObjects = {}
|
||||||
|
local matColor = JSON.decode(self.getMemo()).matColor
|
||||||
|
|
||||||
-- variable to track the status of the "Show Draw Button" option
|
-- variable to track the status of the "Show Draw Button" option
|
||||||
local isDrawButtonVisible = false
|
local isDrawButtonVisible = false
|
||||||
@ -83,7 +84,6 @@ function onLoad(save_state)
|
|||||||
self.interactable = DEBUG
|
self.interactable = DEBUG
|
||||||
|
|
||||||
-- get object references to owned objects
|
-- get object references to owned objects
|
||||||
local matColor= JSON.decode(self.getMemo()).matColor
|
|
||||||
ownedObjects = Global.call("getObjectsForMatColor", matColor)
|
ownedObjects = Global.call("getObjectsForMatColor", matColor)
|
||||||
|
|
||||||
-- button creation
|
-- button creation
|
||||||
@ -392,10 +392,10 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
|||||||
|
|
||||||
-- gain a resource (or two if playing Jenny Barnes)
|
-- gain a resource (or two if playing Jenny Barnes)
|
||||||
if string.match(activeInvestigatorId, "%d%d%d%d%d") == "02003" then
|
if string.match(activeInvestigatorId, "%d%d%d%d%d") == "02003" then
|
||||||
gainResources(2)
|
updateCounter({type = "ResourceCounter", modifier = 2})
|
||||||
printToColor("Gaining 2 resources (Jenny)", messageColor)
|
printToColor("Gaining 2 resources (Jenny)", messageColor)
|
||||||
else
|
else
|
||||||
gainResources(1)
|
updateCounter({type = "ResourceCounter", modifier = 1})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw a card (with handling for Patrice and Forced Learning)
|
-- draw a card (with handling for Patrice and Forced Learning)
|
||||||
@ -421,18 +421,6 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- adds the specified amount of resources to the resource counter
|
|
||||||
function gainResources(amount)
|
|
||||||
local count = ownedObjects.ResourceCounter.getVar("val")
|
|
||||||
local add = tonumber(amount) or 0
|
|
||||||
ownedObjects.ResourceCounter.call("updateVal", count + add)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- returns the resource counter amount
|
|
||||||
function getResourceCount()
|
|
||||||
return ownedObjects.ResourceCounter.getVar("val")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- function for "draw 1 button" (that can be added via option panel)
|
-- function for "draw 1 button" (that can be added via option panel)
|
||||||
function doDrawOne(_, color)
|
function doDrawOne(_, color)
|
||||||
-- send messages to player who clicked button if no seated player found
|
-- send messages to player who clicked button if no seated player found
|
||||||
@ -822,6 +810,40 @@ function setObjectState(obj, stateId)
|
|||||||
if obj.getStateId() ~= stateId then obj.setState(stateId) end
|
if obj.getStateId() ~= stateId then obj.setState(stateId) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------
|
||||||
|
-- manipulation of owned objects
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
-- updates the specific owned counter
|
||||||
|
---@param param Table Contains the information to update:
|
||||||
|
--- type: String Counter to target
|
||||||
|
--- newValue: Number Value to set the counter to
|
||||||
|
--- modifier: Number If newValue is not provided, the existing value will be adjusted by this modifier
|
||||||
|
function updateCounter(param)
|
||||||
|
local counter = ownedObjects[param.type]
|
||||||
|
if counter ~= nil then
|
||||||
|
counter.call("updateVal", param.newValue or (counter.getVar("val") + param.modifier))
|
||||||
|
else
|
||||||
|
printToAll(param.type .. " for " .. matColor .. " could not be found.", "Yellow")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- returns the resource counter amount
|
||||||
|
---@param type String Counter to target
|
||||||
|
function getCounterValue(type)
|
||||||
|
return ownedObjects.type.getVar("val")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set investigator skill tracker to "1, 1, 1, 1"
|
||||||
|
function resetSkillTracker()
|
||||||
|
local obj = ownedObjects.InvestigatorSkillTracker
|
||||||
|
if obj ~= nil then
|
||||||
|
obj.call("updateStats", { 1, 1, 1, 1 })
|
||||||
|
else
|
||||||
|
printToAll("Skill tracker for " .. matColor .. " playmat could not be found.", "Yellow")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- calls to 'Global' / functions for calls from outside
|
-- calls to 'Global' / functions for calls from outside
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
@ -150,17 +150,34 @@ do
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Adds the specified amount of resources to the requested playermat's resource counter
|
-- updates the specified owned counter
|
||||||
PlaymatApi.gainResources = function(amount, matColor)
|
---@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.
|
||||||
|
---@param type String Counter to target
|
||||||
|
---@param newValue Number Value to set the counter to
|
||||||
|
---@param modifier Number If newValue is not provided, the existing value will be adjusted by this modifier
|
||||||
|
PlaymatApi.updateCounter = function(matColor, type, newValue, modifier)
|
||||||
for _, mat in ipairs(internal.getMatForColor(matColor)) do
|
for _, mat in ipairs(internal.getMatForColor(matColor)) do
|
||||||
mat.call("gainResources", amount)
|
mat.call("updateCounter", {type = type, newValue = newValue, modifier = modifier})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns the resource counter amount for the requested playermat
|
-- returns the resource counter amount
|
||||||
PlaymatApi.getResourceCount = function(matColor)
|
---@param matColor String Color of the playermat
|
||||||
|
---@param type String Counter to target
|
||||||
|
PlaymatApi.getCounterValue = function(matColor, type)
|
||||||
local mat = Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"})
|
local mat = Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"})
|
||||||
return mat.call("getResourceCount")
|
return mat.call("getCounterValue", type)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- resets the specified skill tracker to "1, 1, 1, 1"
|
||||||
|
---@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.
|
||||||
|
PlaymatApi.resetSkillTracker = function(matColor)
|
||||||
|
for _, mat in ipairs(internal.getMatForColor(matColor)) do
|
||||||
|
mat.call("resetSkillTracker")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Discard a non-hidden card from the corresponding player's hand
|
-- Discard a non-hidden card from the corresponding player's hand
|
||||||
@ -186,17 +203,15 @@ do
|
|||||||
---@return: Array of playermat objects. If a single mat is requested, will return a single-element
|
---@return: Array of playermat objects. If a single mat is requested, will return a single-element
|
||||||
-- array to simplify processing by consumers.
|
-- array to simplify processing by consumers.
|
||||||
internal.getMatForColor = function(matColor)
|
internal.getMatForColor = function(matColor)
|
||||||
local targetMat = Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"})
|
|
||||||
if targetMat != nil then
|
|
||||||
return { targetMatGuid }
|
|
||||||
end
|
|
||||||
if matColor == "All" then
|
if matColor == "All" then
|
||||||
return {
|
return {
|
||||||
Global.call("getObjectFromMemo", {matColor = White, type = "Playermat"}),
|
Global.call("getObjectFromMemo", {matColor = "White", type = "Playermat"}),
|
||||||
Global.call("getObjectFromMemo", {matColor = Orange, type = "Playermat"}),
|
Global.call("getObjectFromMemo", {matColor = "Orange", type = "Playermat"}),
|
||||||
Global.call("getObjectFromMemo", {matColor = Green, type = "Playermat"}),
|
Global.call("getObjectFromMemo", {matColor = "Green", type = "Playermat"}),
|
||||||
Global.call("getObjectFromMemo", {matColor = Red, type = "Playermat"})
|
Global.call("getObjectFromMemo", {matColor = "Red", type = "Playermat"})
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return { Global.call("getObjectFromMemo", {matColor = matColor, type = "Playermat"}) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user