resolving requested changes
This commit is contained in:
parent
9d508882ee
commit
1b2f70b59b
@ -1,103 +1,10 @@
|
|||||||
function onload(saved_data)
|
-- button calls respective function in "Global"
|
||||||
light_mode = false
|
function onLoad()
|
||||||
|
|
||||||
if saved_data ~= "" then
|
|
||||||
local loaded_data = JSON.decode(saved_data)
|
|
||||||
light_mode = loaded_data[1]
|
|
||||||
end
|
|
||||||
createAll()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- functions delegated to Global
|
|
||||||
function printStats(object, player, isRightClick)
|
|
||||||
-- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET)
|
|
||||||
if isRightClick then
|
|
||||||
Global.call("resetStats")
|
|
||||||
else
|
|
||||||
Global.call("printStats")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function updateSave()
|
|
||||||
local data_to_save = {light_mode }
|
|
||||||
saved_data = JSON.encode(data_to_save)
|
|
||||||
self.script_state = saved_data
|
|
||||||
end
|
|
||||||
|
|
||||||
function createAll()
|
|
||||||
s_color = {0.5, 0.5, 0.5, 95}
|
|
||||||
|
|
||||||
if light_mode then
|
|
||||||
f_color = {1,1,1,95}
|
|
||||||
else
|
|
||||||
f_color = {0,0,0,100}
|
|
||||||
end
|
|
||||||
|
|
||||||
self.createButton({
|
self.createButton({
|
||||||
click_function="printStats",
|
click_function = "handleStatTrackerClick",
|
||||||
function_owner=self,
|
tooltip = "Left-Click: Print stats\nRight-Click: Reset stats",
|
||||||
position={0,0.05,0},
|
height = 1250,
|
||||||
height=600,
|
width = 1250,
|
||||||
width=1000,
|
color = { 0, 0, 0, 0 }
|
||||||
alignment = 3,
|
})
|
||||||
tooltip = "Left Click to print stats. Right Click to reset them.",
|
|
||||||
scale={x=1.5, y=1.5, z=1.5},
|
|
||||||
font_size=600,
|
|
||||||
font_color=f_color,
|
|
||||||
color={0,0,0,0}
|
|
||||||
})
|
|
||||||
|
|
||||||
if light_mode then
|
|
||||||
lightButtonText = "[ Set dark ]"
|
|
||||||
else
|
|
||||||
lightButtonText = "[ Set light ]"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function removeAll()
|
|
||||||
self.removeInput(0)
|
|
||||||
self.removeInput(1)
|
|
||||||
self.removeButton(0)
|
|
||||||
self.removeButton(1)
|
|
||||||
self.removeButton(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function reloadAll()
|
|
||||||
removeAll()
|
|
||||||
createAll()
|
|
||||||
updateSave()
|
|
||||||
end
|
|
||||||
|
|
||||||
function swap_fcolor(_obj, _color, alt_click)
|
|
||||||
light_mode = not light_mode
|
|
||||||
reloadAll()
|
|
||||||
end
|
|
||||||
|
|
||||||
function swap_align(_obj, _color, alt_click)
|
|
||||||
center_mode = not center_mode
|
|
||||||
reloadAll()
|
|
||||||
end
|
|
||||||
|
|
||||||
function editName(_obj, _string, value)
|
|
||||||
self.setName(value)
|
|
||||||
setTooltips()
|
|
||||||
end
|
|
||||||
|
|
||||||
function setTooltips()
|
|
||||||
self.editInput({
|
|
||||||
index = 0,
|
|
||||||
value = self.getName(),
|
|
||||||
tooltip = "Left click to show stats. Right click to reset them."
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function keepSample(_obj, _string, value)
|
|
||||||
reloadAll()
|
|
||||||
end
|
|
||||||
|
|
||||||
function onDestroy()
|
|
||||||
if timerID and type(timerID) == 'object' then
|
|
||||||
Timer.destroy(timerID)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -6,10 +6,10 @@ ENCOUNTER_DECK_POS = {-3.93, 1, 5.76}
|
|||||||
ENCOUNTER_DECK_DISCARD_POSITION = {-3.85, 1, 10.38}
|
ENCOUNTER_DECK_DISCARD_POSITION = {-3.85, 1, 10.38}
|
||||||
|
|
||||||
-- GUID of data helper
|
-- GUID of data helper
|
||||||
tokenDataId = "708279"
|
DATA_HELPER_GUID = "708279"
|
||||||
|
|
||||||
-- GUIDs that will not be interactable (e.g. parts of the table)
|
-- GUIDs that will not be interactable (e.g. parts of the table)
|
||||||
NOT_INTERACTABLE = {
|
local NOT_INTERACTABLE = {
|
||||||
"6161b4",
|
"6161b4",
|
||||||
"721ba2",
|
"721ba2",
|
||||||
"9f334f",
|
"9f334f",
|
||||||
@ -22,6 +22,9 @@ NOT_INTERACTABLE = {
|
|||||||
"7bff34"
|
"7bff34"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local chaosTokens = {}
|
||||||
|
local chaosTokensLastMat = nil
|
||||||
|
local IS_RESHUFFLING = false
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- data for tokens
|
-- data for tokens
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
@ -60,7 +63,7 @@ IMAGE_TOKEN_MAP = {
|
|||||||
-- data for chaos token stat tracker
|
-- data for chaos token stat tracker
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
maxSquid = 0
|
local maxSquid = 0
|
||||||
|
|
||||||
MAT_GUID_TO_COLOUR = {
|
MAT_GUID_TO_COLOUR = {
|
||||||
["8b081b"] = "White",
|
["8b081b"] = "White",
|
||||||
@ -69,14 +72,14 @@ MAT_GUID_TO_COLOUR = {
|
|||||||
["0840d5"] = "Red"
|
["0840d5"] = "Red"
|
||||||
}
|
}
|
||||||
|
|
||||||
PLAYER_PULLS = {
|
local personalStats = {
|
||||||
["8b081b"] = {},
|
["8b081b"] = {},
|
||||||
["bd0ff4"] = {},
|
["bd0ff4"] = {},
|
||||||
["383d8b"] = {},
|
["383d8b"] = {},
|
||||||
["0840d5"] = {}
|
["0840d5"] = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
PULLS = {
|
local overallStats = {
|
||||||
-- cultist
|
-- cultist
|
||||||
["https://i.imgur.com/VzhJJaH.png"] = 0,
|
["https://i.imgur.com/VzhJJaH.png"] = 0,
|
||||||
-- skull
|
-- skull
|
||||||
@ -164,7 +167,7 @@ function actualEncounterCardDraw(card, params)
|
|||||||
local alwaysFaceUp = params[3]
|
local alwaysFaceUp = params[3]
|
||||||
local faceUpRotation = 0
|
local faceUpRotation = 0
|
||||||
if not alwaysFaceUp then
|
if not alwaysFaceUp then
|
||||||
if getObjectFromGUID(tokenDataId).call('checkHiddenCard', card.getName()) then
|
if getObjectFromGUID(DATA_HELPER_GUID).call('checkHiddenCard', card.getName()) then
|
||||||
faceUpRotation = 180
|
faceUpRotation = 180
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -172,7 +175,6 @@ function actualEncounterCardDraw(card, params)
|
|||||||
card.setRotationSmooth({0, rotation.y, faceUpRotation}, false, false)
|
card.setRotationSmooth({0, rotation.y, faceUpRotation}, false, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
IS_RESHUFFLING = false
|
|
||||||
function reshuffleEncounterDeck(params)
|
function reshuffleEncounterDeck(params)
|
||||||
-- finishes moving the deck back and draws a card
|
-- finishes moving the deck back and draws a card
|
||||||
local function move(deck)
|
local function move(deck)
|
||||||
@ -223,15 +225,13 @@ function findChaosBag()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CHAOS_TOKENS = {}
|
function returnChaosTokens()
|
||||||
function putBackChaosTokens()
|
for _, token in pairs(chaosTokens) do
|
||||||
for _, token in pairs(CHAOS_TOKENS) do
|
|
||||||
if token ~= nil then chaosbag.putObject(token) end
|
if token ~= nil then chaosbag.putObject(token) end
|
||||||
end
|
end
|
||||||
CHAOS_TOKENS = {}
|
chaosTokens = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
CHAOS_TOKENS_LAST_MAT = nil
|
|
||||||
function drawChaostoken(params)
|
function drawChaostoken(params)
|
||||||
findChaosBag()
|
findChaosBag()
|
||||||
|
|
||||||
@ -240,31 +240,30 @@ function drawChaostoken(params)
|
|||||||
local isRightClick = params[3]
|
local isRightClick = params[3]
|
||||||
|
|
||||||
-- return token(s) on other playmat first
|
-- return token(s) on other playmat first
|
||||||
if CHAOS_TOKENS_LAST_MAT ~= nil and CHAOS_TOKENS_LAST_MAT ~= mat and #CHAOS_TOKENS ~= 0 then
|
if chaosTokensLastMat ~= nil and chaosTokensLastMat ~= mat and #chaosTokens ~= 0 then
|
||||||
putBackChaosTokens()
|
returnChaosTokens()
|
||||||
CHAOS_TOKENS_LAST_MAT = nil
|
chaosTokensLastMat = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
CHAOS_TOKENS_LAST_MAT = mat
|
chaosTokensLastMat = mat
|
||||||
-- if we have left clicked and have no tokens OR if we have right clicked
|
-- if we have left clicked and have no tokens OR if we have right clicked
|
||||||
if isRightClick or #CHAOS_TOKENS == 0 then
|
if isRightClick or #chaosTokens == 0 then
|
||||||
if #chaosbag.getObjects() == 0 then return end
|
if #chaosbag.getObjects() == 0 then return end
|
||||||
chaosbag.shuffle()
|
chaosbag.shuffle()
|
||||||
|
|
||||||
-- add the token to the list, compute new position based on list length
|
-- add the token to the list, compute new position based on list length
|
||||||
-- callback is needed for stat tracking
|
tokenOffset[1] = tokenOffset[1] + (0.17 * #chaosTokens)
|
||||||
tokenOffset[1] = tokenOffset[1] + (0.17 * #CHAOS_TOKENS)
|
|
||||||
local token = chaosbag.takeObject({
|
local token = chaosbag.takeObject({
|
||||||
index = 0,
|
index = 0,
|
||||||
position = mat.positionToWorld(tokenOffset),
|
position = mat.positionToWorld(tokenOffset),
|
||||||
rotation = mat.getRotation(),
|
rotation = mat.getRotation(),
|
||||||
callback_function = function(obj) take_callback(obj, mat) end
|
callback_function = function(obj) trackChaosToken(obj, mat.getGUID()) end
|
||||||
})
|
})
|
||||||
CHAOS_TOKENS[#CHAOS_TOKENS + 1] = token
|
chaosTokens[#chaosTokens + 1] = token
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
putBackChaosTokens()
|
returnChaosTokens()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -273,23 +272,28 @@ end
|
|||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
function spawnToken(params)
|
function spawnToken(params)
|
||||||
local position = params[1]
|
local position = params[1]
|
||||||
local tokenType = params[2]
|
local tokenType = params[2]
|
||||||
local rotation = params[3] or {0, 270, 0}
|
local rotation = params[3] or {0, 270, 0}
|
||||||
local tokenData = TOKEN_DATA[tokenType]
|
local tokenData = TOKEN_DATA[tokenType]
|
||||||
if tokenData == nil then error("no token data found for '" .. tokenType .. "'") end
|
|
||||||
|
if tokenData == nil then
|
||||||
|
error("no token data found for '" .. tokenType .. "'")
|
||||||
|
end
|
||||||
|
|
||||||
local token = spawnObject({
|
local token = spawnObject({
|
||||||
type = 'Custom_Token',
|
type = 'Custom_Token',
|
||||||
position = position,
|
position = position,
|
||||||
rotation = rotation
|
rotation = rotation
|
||||||
})
|
})
|
||||||
|
|
||||||
token.setCustomObject({
|
token.setCustomObject({
|
||||||
image = tokenData['image'],
|
image = tokenData['image'],
|
||||||
thickness = 0.3,
|
thickness = 0.3,
|
||||||
merge_distance = 5,
|
merge_distance = 5,
|
||||||
stackable = true
|
stackable = true
|
||||||
})
|
})
|
||||||
|
|
||||||
token.use_snap_points = false
|
token.use_snap_points = false
|
||||||
token.scale(tokenData['scale'])
|
token.scale(tokenData['scale'])
|
||||||
return token
|
return token
|
||||||
@ -299,53 +303,64 @@ end
|
|||||||
-- chaos token stat tracker
|
-- chaos token stat tracker
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
function take_callback(object_spawned, mat)
|
function trackChaosToken(token, matGUID)
|
||||||
local player = mat.getGUID()
|
local image = token.getCustomObject().image
|
||||||
local image = object_spawned.getCustomObject().image
|
overallStats[image] = (overallStats[image] or 0) + 1
|
||||||
PULLS[image] = (PULLS[image] or 0) + 1
|
personalStats[matGUID][image] = (personalStats[matGUID][image] or 0) + 1
|
||||||
PLAYER_PULLS[player][image] = (PLAYER_PULLS[player][image] or 0) + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function printOrResetStats(_, _, isRightClick)
|
function handleStatTrackerClick(_, _, isRightClick)
|
||||||
if isRightClick then
|
if isRightClick then
|
||||||
for key, _ in pairs(PULLS) do
|
resetChaosTokenStats()
|
||||||
PULLS[key] = 0
|
|
||||||
end
|
|
||||||
for playerKey, _ in pairs(PLAYER_PULLS) do
|
|
||||||
for key, value in pairs(PULLS) do
|
|
||||||
PLAYER_PULLS[playerKey][key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local squidKing = "Nobody"
|
printChaosTokenStats()
|
||||||
printToAll("Overall Game stats")
|
|
||||||
printToAll("------------------------------")
|
|
||||||
printNonZeroTokenPairs(PULLS)
|
|
||||||
printToAll("Individual Stats")
|
|
||||||
printToAll("------------------------------")
|
|
||||||
for playerMatGuid, _ in pairs(PLAYER_PULLS) do
|
|
||||||
local playerColour = MAT_GUID_TO_COLOUR[playerMatGuid]
|
|
||||||
local playerSquidCount = PLAYER_PULLS[playerMatGuid]["https://i.imgur.com/lns4fhz.png"] or 0
|
|
||||||
local playerName = playerColour
|
|
||||||
if Player[playerColour].seated then
|
|
||||||
playerName = Player[playerColour].steam_name
|
|
||||||
end
|
|
||||||
|
|
||||||
printToAll(playerName .. " Stats", playerColour)
|
|
||||||
printNonZeroTokenPairs(PLAYER_PULLS[playerMatGuid])
|
|
||||||
|
|
||||||
if playerSquidCount > maxSquid then
|
|
||||||
squidKing = playerName
|
|
||||||
maxSquid = playerSquidCount
|
|
||||||
end
|
|
||||||
end
|
|
||||||
printToAll(squidKing .. " is an auto-fail magnet.", {255, 0, 0})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function resetChaosTokenStats()
|
||||||
|
for key, _ in pairs(overallStats) do
|
||||||
|
overallStats[key] = 0
|
||||||
|
end
|
||||||
|
for playerKey, _ in pairs(personalStats) do
|
||||||
|
for key, value in pairs(overallStats) do
|
||||||
|
personalStats[playerKey][key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function printChaosTokenStats()
|
||||||
|
local squidKing = "Nobody"
|
||||||
|
printToAll("")
|
||||||
|
printToAll("Overall Stats")
|
||||||
|
printToAll("------------------------------")
|
||||||
|
printNonZeroTokenPairs(overallStats)
|
||||||
|
printToAll("")
|
||||||
|
printToAll("Individual Stats")
|
||||||
|
printToAll("------------------------------")
|
||||||
|
for matGUID, _ in pairs(personalStats) do
|
||||||
|
local playerColour = MAT_GUID_TO_COLOUR[matGUID]
|
||||||
|
local playerSquidCount = personalStats[matGUID]["https://i.imgur.com/lns4fhz.png"] or 0
|
||||||
|
local playerName = playerColour
|
||||||
|
if Player[playerColour].seated then
|
||||||
|
playerName = Player[playerColour].steam_name
|
||||||
|
end
|
||||||
|
|
||||||
|
printToAll(playerName .. " Stats", playerColour)
|
||||||
|
printNonZeroTokenPairs(personalStats[matGUID])
|
||||||
|
|
||||||
|
if playerSquidCount > maxSquid then
|
||||||
|
squidKing = playerName
|
||||||
|
maxSquid = playerSquidCount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
printToAll(squidKing .. " is an auto-fail magnet.", {255, 0, 0})
|
||||||
|
end
|
||||||
|
|
||||||
function printNonZeroTokenPairs(theTable)
|
function printNonZeroTokenPairs(theTable)
|
||||||
for key, value in pairs(theTable) do
|
for key, value in pairs(theTable) do
|
||||||
if value ~= 0 then printToAll(IMAGE_TOKEN_MAP[key] .. ': ' .. tostring(value)) end
|
if value ~= 0 then
|
||||||
|
printToAll(IMAGE_TOKEN_MAP[key] .. ': ' .. tostring(value))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -455,7 +470,7 @@ function fillContainer(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function getDataValue(storage, key)
|
function getDataValue(storage, key)
|
||||||
local data = getObjectFromGUID(tokenDataId).getTable(storage)
|
local data = getObjectFromGUID(DATA_HELPER_GUID).getTable(storage)
|
||||||
if data ~= nil then
|
if data ~= nil then
|
||||||
local value = data[key]
|
local value = data[key]
|
||||||
if value ~= nil then
|
if value ~= nil then
|
||||||
@ -476,7 +491,7 @@ function getDataValue(storage, key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function spawnChaosToken(id, pos)
|
function spawnChaosToken(id, pos)
|
||||||
local url = getImageUrl(id)
|
local url = getChaosTokenImageURL(id)
|
||||||
if url ~= '' then
|
if url ~= '' then
|
||||||
local obj = spawnObject({
|
local obj = spawnObject({
|
||||||
type = 'Custom_Tile',
|
type = 'Custom_Tile',
|
||||||
@ -501,7 +516,7 @@ function getTokenName(params)
|
|||||||
return name
|
return name
|
||||||
end
|
end
|
||||||
|
|
||||||
function getImageUrl(id)
|
function getChaosTokenImageURL(id)
|
||||||
if id == 'p1' then return 'https://i.imgur.com/uIx8jbY.png' end
|
if id == 'p1' then return 'https://i.imgur.com/uIx8jbY.png' end
|
||||||
if id == '0' then return 'https://i.imgur.com/btEtVfd.png' end
|
if id == '0' then return 'https://i.imgur.com/btEtVfd.png' end
|
||||||
if id == 'm1' then return 'https://i.imgur.com/w3XbrCC.png' end
|
if id == 'm1' then return 'https://i.imgur.com/w3XbrCC.png' end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user