resolving comments

This commit is contained in:
Chr1Z93 2023-01-03 23:47:34 +01:00
parent 19b69a3cee
commit efbf9e885f
4 changed files with 56 additions and 82 deletions

View File

@ -33,8 +33,8 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "require(\"core/GenericCounter\")",
"LuaScriptState": "0", "LuaScriptState": "0",
"LuaScript_path": "TokenSource.124381/ResourceCounter.498ec0.ttslua",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Custom_Token", "Name": "Custom_Token",
"Nickname": "Resource Counter", "Nickname": "Resource Counter",

View File

@ -1,43 +0,0 @@
value = 0
function onSave() return JSON.encode(value) end
function onLoad(savedData)
if savedData ~= "" then
value = JSON.decode(savedData)
end
self.createButton({
label = tostring(value),
click_function = "addOrSubtract",
function_owner = self,
position = { 0, 0.06, 0.1 },
height = 600,
width = 1000,
scale = { 1.5, 1.5, 1.5 },
font_size = 600,
font_color = { 1, 1, 1, 100 },
color = { 0, 0, 0, 0 }
})
self.addContextMenuItem("Value from description", function(color) setToDescription(color) end)
end
function setToDescription(color)
local newValue = tonumber(self.getDescription())
if type(newValue) == "number" and newValue <= 99 and newValue >= 0 then
updateVal(newValue)
else
printToColor("Description does not contain a valid one or two digit number!", color, "Red")
end
end
function addOrSubtract(_, _, isRightClick)
local mod = isRightClick and -1 or 1
newValue = math.min(math.max(value + mod, 0), 99)
updateVal(newValue)
end
function updateVal(newValue)
value = newValue
self.editButton({ index = 0, label = tostring(newValue) })
end

View File

@ -4,47 +4,57 @@ val = 0
function onSave() return JSON.encode(val) end function onSave() return JSON.encode(val) end
function onLoad(saved_data) function onLoad(savedData)
if saved_data ~= nil then if savedData ~= nil then
val = JSON.decode(saved_data) val = JSON.decode(savedData)
end end
local name = self.getName() local name = self.getName()
local position = {} local position = {}
if name == "Damage" or name == "Resources" then if name == "Damage" or name == "Resources" or name == "Resource Counter" then
position = { 0, 0.06, 0.1 } position = { 0, 0.06, 0.1 }
elseif name == "Horror" then elseif name == "Horror" then
position = { -0.025, 0.06, -0.025 } position = { -0.025, 0.06, -0.025 }
else else
position = { 0, 0.06, 0 } position = { 0, 0.06, 0 }
end end
self.createButton({ self.createButton({
label = tostring(val), label = tostring(val),
click_function = "addOrSubtract", click_function = "addOrSubtract",
function_owner = self, function_owner = self,
position = position, position = position,
height = 600, height = 600,
width = 1000, width = 1000,
scale = { 1.5, 1.5, 1.5 }, scale = { 1.5, 1.5, 1.5 },
font_size = 600, font_size = 600,
font_color = { 1, 1, 1, 100 }, font_color = { 1, 1, 1, 100 },
color = { 0, 0, 0, 0 } color = { 0, 0, 0, 0 }
}) })
if name == "Resource Counter" then
self.addContextMenuItem("Set to description", function(color) setToDescription(color) end)
end
end
function setToDescription(color)
local newVal = tonumber(self.getDescription())
if type(newVal) == "number" and newVal <= 99 and newVal >= 0 then
updateVal(newVal)
else
printToColor("Description does not contain a valid number!", color, "Orange")
end
end end
function updateVal(newVal) function updateVal(newVal)
if tonumber(newVal) then if tonumber(newVal) then
val = newVal val = newVal
self.editButton({ self.editButton({ index = 0, label = tostring(val) })
index = 0, end
label = tostring(val)
})
end
end end
function addOrSubtract(_, _, alt_click) function addOrSubtract(_, _, isRightClick)
val = math.min(math.max(val + (alt_click and -1 or 1), MIN_VALUE), MAX_VALUE) val = math.min(math.max(val + (isRightClick and -1 or 1), MIN_VALUE), MAX_VALUE)
self.editButton({ index = 0, label = tostring(val) }) self.editButton({ index = 0, label = tostring(val) })
end end

View File

@ -409,15 +409,17 @@ function replenishTokens(card, count, replenish)
-- get current amount of resource tokens on the card -- get current amount of resource tokens on the card
local search = searchArea(cardPos, { 2.5, 0.5, 3.5 }) local search = searchArea(cardPos, { 2.5, 0.5, 3.5 })
local clickableResourceCounter = nil
local foundTokens = 0 local foundTokens = 0
for _, obj in ipairs(search) do for _, obj in ipairs(search) do
local obj = obj.hit_object local obj = obj.hit_object
if obj.getCustomObject().image == "http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/" then if obj.getCustomObject().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.getName() == "Resource Counter" then elseif obj.getName() == "Resource Counter" then
foundTokens = obj.getVar("value") foundTokens = obj.getVar("val")
obj.destruct() clickableResourceCounter = obj
break break
end end
end end
@ -438,7 +440,12 @@ function replenishTokens(card, count, replenish)
local newCount = foundTokens + replenish local newCount = foundTokens + replenish
if newCount > count then newCount = count end if newCount > count then newCount = count end
tokenManager.spawnTokenGroup(card, "resource", newCount)
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", newCount)
else
tokenManager.spawnTokenGroup(card, "resource", newCount)
end
end end
function syncCustomizableMetadata(card) function syncCustomizableMetadata(card)