both Well Connected 0 and Well Connected 3 now share the same script, removes unecessary index from button, updates getResourceCount playmat api function, adds onSave() function, updates button look and position

This commit is contained in:
bankey 2023-08-30 09:37:23 -04:00
parent 7f58638ef8
commit c678537581
4 changed files with 31 additions and 68 deletions

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "require(\"playercards/cards/WellConnected3\")",
"LuaScript": "require(\"playercards/cards/WellConnected\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",

View File

@ -1,23 +1,41 @@
-- this script is shared between both the level 0 and the upgraded level 3 version of the card
local playmatApi = require("playermat/PlaymatApi")
local display = false
local count = 0
local modValue = 5
local modValue = 5 -- level 0 Well Connected
local loopId = nil
local b_display = {
index = 0,
click_function = 'none',
click_function = "toggleCounter",
function_owner = self,
position = {-0.25,1,-0.75},
font_color = {1,1,1,100},
font_size = 250,
width = 0,
height = 0
position = {0.88,0.5,-1.33},
font_size = 150,
width = 175,
height = 175
}
function onLoad()
self.addContextMenuItem('Toggle Counter', toggleCounter)
function onLoad(saved_data)
local notes = JSON.decode(self.getGMNotes())
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
modValue = 4 -- Well Connected (3)
end
if saved_data != '' then
local loaded_data = JSON.decode(saved_data)
display = not loaded_data.saved_display
toggleCounter()
end
self.addContextMenuItem('Toggle Counter', toggleCounter)
end
function onSave()
local data_to_save = {saved_display = display}
local saved_data = JSON.encode(data_to_save)
return saved_data
end
function toggleCounter()

View File

@ -1,52 +0,0 @@
local playmatApi = require("playermat/PlaymatApi")
local display = false
local count = 0
local modValue = 4
local loopId = nil
local b_display = {
index = 0,
click_function = 'none',
function_owner = self,
position = {-0.25,1,-0.75},
font_color = {1,1,1,100},
font_size = 250,
width = 0,
height = 0
}
function onLoad()
self.addContextMenuItem('Toggle Counter', toggleCounter)
end
function toggleCounter()
display = not display
if display then
createUpdateDisplay()
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
else
Wait.stop(loopId)
self.clearButtons()
loopId = nil
end
end
function createUpdateDisplay()
count = math.max(math.floor(getPlayerResources() / modValue), 0)
b_display.label = tostring(count)
if loopId == nil then
self.createButton(b_display)
else
self.editButton(b_display)
end
end
function getPlayerResources()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
return playmatApi.getResourceCount(matColor)
end

View File

@ -180,11 +180,8 @@ do
-- Returns the resource counter amount for the requested playermat
PlaymatApi.getResourceCount = function(matColor)
local resources = 0
for _, mat in ipairs(internal.getMatForColor(matColor)) do
resources = resources + mat.call("getResourceCount")
end
return resources
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("getResourceCount")
end
-- Discard a non-hidden card from the corresponding player's hand