Merge pull request #148 from argonui/resource-counter-token
Option: Clickable resource tokens
This commit is contained in:
commit
fe13216c57
@ -18,7 +18,8 @@
|
|||||||
"Damage.cd2a02",
|
"Damage.cd2a02",
|
||||||
"Horror.36be72",
|
"Horror.36be72",
|
||||||
"ClueDoom.a3fb6c",
|
"ClueDoom.a3fb6c",
|
||||||
"Resource.00d19a"
|
"Resource.00d19a",
|
||||||
|
"ResourceCounter.498ec0"
|
||||||
],
|
],
|
||||||
"ContainedObjects_path": "TokenSource.124381",
|
"ContainedObjects_path": "TokenSource.124381",
|
||||||
"Description": "",
|
"Description": "",
|
||||||
|
57
objects/TokenSource.124381/ResourceCounter.498ec0.json
Normal file
57
objects/TokenSource.124381/ResourceCounter.498ec0.json
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"AltLookAngle": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"Autoraise": true,
|
||||||
|
"ColorDiffuse": {
|
||||||
|
"b": 1,
|
||||||
|
"g": 1,
|
||||||
|
"r": 1
|
||||||
|
},
|
||||||
|
"CustomImage": {
|
||||||
|
"CustomToken": {
|
||||||
|
"MergeDistancePixels": 5,
|
||||||
|
"Stackable": false,
|
||||||
|
"StandUp": false,
|
||||||
|
"Thickness": 0.1
|
||||||
|
},
|
||||||
|
"ImageScalar": 1,
|
||||||
|
"ImageSecondaryURL": "",
|
||||||
|
"ImageURL": "http://cloud-3.steamusercontent.com/ugc/949599153663401115/EAA6D40FC6E15204BBE551BCDED35CC8C75111BF/",
|
||||||
|
"WidthScale": 0
|
||||||
|
},
|
||||||
|
"Description": "0",
|
||||||
|
"DragSelectable": true,
|
||||||
|
"GMNotes": "resourceCounter",
|
||||||
|
"GUID": "498ec0",
|
||||||
|
"Grid": true,
|
||||||
|
"GridProjection": false,
|
||||||
|
"Hands": false,
|
||||||
|
"HideWhenFaceDown": false,
|
||||||
|
"IgnoreFoW": false,
|
||||||
|
"LayoutGroupSortIndex": 0,
|
||||||
|
"Locked": false,
|
||||||
|
"LuaScript": "require(\"core/GenericCounter\")",
|
||||||
|
"LuaScriptState": "0",
|
||||||
|
"MeasureMovement": false,
|
||||||
|
"Name": "Custom_Token",
|
||||||
|
"Nickname": "Resource Counter",
|
||||||
|
"Snap": false,
|
||||||
|
"Sticky": true,
|
||||||
|
"Tooltip": false,
|
||||||
|
"Transform": {
|
||||||
|
"posX": 0,
|
||||||
|
"posY": 3,
|
||||||
|
"posZ": 0,
|
||||||
|
"rotX": 0,
|
||||||
|
"rotY": 270,
|
||||||
|
"rotZ": 0,
|
||||||
|
"scaleX": 0.26,
|
||||||
|
"scaleY": 1,
|
||||||
|
"scaleZ": 0.26
|
||||||
|
},
|
||||||
|
"Value": 0,
|
||||||
|
"XmlUI": ""
|
||||||
|
}
|
@ -1,50 +1,52 @@
|
|||||||
MIN_VALUE = -99
|
MIN_VALUE = 0
|
||||||
MAX_VALUE = 999
|
MAX_VALUE = 99
|
||||||
val = 0
|
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 }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.addContextMenuItem("Add 5", function() updateVal(val + 5) end)
|
||||||
|
self.addContextMenuItem("Subtract 5", function() updateVal(val - 5) end)
|
||||||
|
self.addContextMenuItem("Add 10", function() updateVal(val + 10) end)
|
||||||
|
self.addContextMenuItem("Subtract 10", function() updateVal(val - 10) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateVal(newVal)
|
function updateVal(newVal)
|
||||||
if tonumber(newVal) then
|
if tonumber(newVal) then
|
||||||
val = newVal
|
val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE)
|
||||||
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
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
local tokenManager = require("core/token/TokenManager")
|
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- general setup
|
-- general setup
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
@ -36,6 +34,7 @@ local IS_RESHUFFLING = false
|
|||||||
local bagSearchers = {}
|
local bagSearchers = {}
|
||||||
local hideTitleSplashWaitFunctionId = nil
|
local hideTitleSplashWaitFunctionId = nil
|
||||||
local playmatAPI = require("playermat/PlaymatApi")
|
local playmatAPI = require("playermat/PlaymatApi")
|
||||||
|
local tokenManager = require("core/token/TokenManager")
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- data for tokens
|
-- data for tokens
|
||||||
@ -819,6 +818,10 @@ function applyOptionPanelChange(id, state)
|
|||||||
-- update master clue counter
|
-- update master clue counter
|
||||||
getObjectFromGUID("4a3aa4").setVar("useClickableCounters", state)
|
getObjectFromGUID("4a3aa4").setVar("useClickableCounters", state)
|
||||||
|
|
||||||
|
-- option: Clickable resource counters
|
||||||
|
elseif id == "useResourceCounters" then
|
||||||
|
optionPanel[id] = state
|
||||||
|
|
||||||
-- option: Show Title on placing scenarios
|
-- option: Show Title on placing scenarios
|
||||||
elseif id == "showTitleSplash" then
|
elseif id == "showTitleSplash" then
|
||||||
optionPanel[id] = state
|
optionPanel[id] = state
|
||||||
|
@ -149,8 +149,12 @@ do
|
|||||||
-- spawned state object rather than spawning multiple tokens
|
-- spawned state object rather than spawning multiple tokens
|
||||||
---@param shiftDown An offset for the z-value of this group of tokens
|
---@param shiftDown An offset for the z-value of this group of tokens
|
||||||
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown)
|
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown)
|
||||||
|
local optionPanel = Global.getTable("optionPanel")
|
||||||
|
|
||||||
if tokenType == "damage" or tokenType == "horror" then
|
if tokenType == "damage" or tokenType == "horror" then
|
||||||
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
|
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
|
||||||
|
elseif tokenType == "resource" and optionPanel["useResourceCounters"] then
|
||||||
|
TokenManager.spawnResourceCounterToken(card, tokenCount)
|
||||||
else
|
else
|
||||||
TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown)
|
TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown)
|
||||||
end
|
end
|
||||||
@ -184,6 +188,14 @@ do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TokenManager.spawnResourceCounterToken = function(card, tokenCount)
|
||||||
|
local pos = card.positionToWorld(card.positionToLocal(card.getPosition()) + Vector(0, 0.2, -0.5))
|
||||||
|
local rot = card.getRotation()
|
||||||
|
TokenManager.spawnToken(pos, "resourceCounter", rot, function(spawned)
|
||||||
|
spawned.call("updateVal", tokenCount)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- Spawns a number of tokens.
|
-- Spawns a number of tokens.
|
||||||
---@param tokenType String type of token to spawn, valid values are resource", "doom", or "clue".
|
---@param tokenType String type of token to spawn, valid values are resource", "doom", or "clue".
|
||||||
-- Other types should use spawnCounterToken()
|
-- Other types should use spawnCounterToken()
|
||||||
|
@ -409,12 +409,18 @@ 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
|
||||||
|
foundTokens = obj.getVar("val")
|
||||||
|
clickableResourceCounter = obj
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -434,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)
|
||||||
|
@ -142,6 +142,20 @@
|
|||||||
</Cell>
|
</Cell>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
<!-- Option: use clickable resource counters -->
|
||||||
|
<Row class="option-text">
|
||||||
|
<Cell class="option-text">
|
||||||
|
<VerticalLayout class="text-column">
|
||||||
|
<Text class="option-header">Use clickable resource counters</Text>
|
||||||
|
<Text class="description">This enables spawning of clickable resource tokens for player cards.</Text>
|
||||||
|
</VerticalLayout>
|
||||||
|
</Cell>
|
||||||
|
<Cell class="option-button">
|
||||||
|
<Toggle id="useResourceCounters"
|
||||||
|
onValueChanged="onClick_toggleOption(useResourceCounters)"/>
|
||||||
|
</Cell>
|
||||||
|
</Row>
|
||||||
|
|
||||||
<!-- Option: splash scenario name on setup -->
|
<!-- Option: splash scenario name on setup -->
|
||||||
<Row class="option-text">
|
<Row class="option-text">
|
||||||
<Cell class="option-text">
|
<Cell class="option-text">
|
||||||
|
Loading…
Reference in New Issue
Block a user