better integration of Token Arranger
This commit is contained in:
parent
4b9265dccb
commit
92522dcd63
@ -3,12 +3,12 @@
|
|||||||
-- original by: Whimsical
|
-- original by: Whimsical
|
||||||
-- description: displays the content of the chaos bag
|
-- description: displays the content of the chaos bag
|
||||||
information = {
|
information = {
|
||||||
version = "1.6",
|
version = "1.7",
|
||||||
last_updated = "10.10.2022"
|
last_updated = "13.11.2022"
|
||||||
}
|
}
|
||||||
|
|
||||||
-- names of tokens in order
|
-- names of tokens in order
|
||||||
token_names = {
|
local token_names = {
|
||||||
"Elder Sign",
|
"Elder Sign",
|
||||||
"Skull",
|
"Skull",
|
||||||
"Cultist",
|
"Cultist",
|
||||||
@ -21,36 +21,9 @@ token_names = {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
-- common parameters
|
-- token modifiers for sorting (and order for same modifier)
|
||||||
local BUTTON_PARAMETERS = {}
|
-- order starts at 2 because there is a "+1" token
|
||||||
BUTTON_PARAMETERS.function_owner = self
|
local token_precedence = {
|
||||||
BUTTON_PARAMETERS.label = ""
|
|
||||||
BUTTON_PARAMETERS.tooltip = "Add / Remove"
|
|
||||||
BUTTON_PARAMETERS.color = { 0, 0, 0, 0 }
|
|
||||||
BUTTON_PARAMETERS.width = 325
|
|
||||||
BUTTON_PARAMETERS.height = 325
|
|
||||||
|
|
||||||
local INPUT_PARAMETERS = {}
|
|
||||||
INPUT_PARAMETERS.function_owner = self
|
|
||||||
INPUT_PARAMETERS.font_size = 100
|
|
||||||
INPUT_PARAMETERS.width = 250
|
|
||||||
INPUT_PARAMETERS.height = INPUT_PARAMETERS.font_size + 23
|
|
||||||
INPUT_PARAMETERS.alignment = 3
|
|
||||||
INPUT_PARAMETERS.validation = 2
|
|
||||||
INPUT_PARAMETERS.tab = 2
|
|
||||||
|
|
||||||
-- tag for cloned tokens
|
|
||||||
TO_DELETE_TAG = "to_be_deleted"
|
|
||||||
|
|
||||||
function onSave() return JSON.encode(token_precedence) end
|
|
||||||
|
|
||||||
function onload(save_state)
|
|
||||||
if save_state ~= nil then
|
|
||||||
token_precedence = JSON.decode(save_state)
|
|
||||||
else
|
|
||||||
-- token modifiers for sorting (and order for same modifier)
|
|
||||||
-- order starts at 2 because there is a "+1" token
|
|
||||||
token_precedence = {
|
|
||||||
["Elder Sign"] = { 100, 2 },
|
["Elder Sign"] = { 100, 2 },
|
||||||
["Skull"] = { -1, 3 },
|
["Skull"] = { -1, 3 },
|
||||||
["Cultist"] = { -2, 4 },
|
["Cultist"] = { -2, 4 },
|
||||||
@ -61,45 +34,69 @@ function onload(save_state)
|
|||||||
["Curse"] = { -101, 9 },
|
["Curse"] = { -101, 9 },
|
||||||
["Frost"] = { -99, 10 },
|
["Frost"] = { -99, 10 },
|
||||||
[""] = { 0, 11 }
|
[""] = { 0, 11 }
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
updating = false
|
-- common parameters
|
||||||
|
local buttonParameters = {}
|
||||||
|
buttonParameters.function_owner = self
|
||||||
|
buttonParameters.label = ""
|
||||||
|
buttonParameters.tooltip = "Add / Remove"
|
||||||
|
buttonParameters.color = { 0, 0, 0, 0 }
|
||||||
|
buttonParameters.width = 325
|
||||||
|
buttonParameters.height = 325
|
||||||
|
|
||||||
|
local inputParameters = {}
|
||||||
|
inputParameters.function_owner = self
|
||||||
|
inputParameters.font_size = 100
|
||||||
|
inputParameters.width = 250
|
||||||
|
inputParameters.height = inputParameters.font_size + 23
|
||||||
|
inputParameters.alignment = 3
|
||||||
|
inputParameters.validation = 2
|
||||||
|
inputParameters.tab = 2
|
||||||
|
|
||||||
|
-- tag for cloned tokens
|
||||||
|
TO_DELETE_TAG = "to_be_deleted"
|
||||||
|
|
||||||
|
updating = false
|
||||||
|
|
||||||
|
function onSave() return JSON.encode(token_precedence) end
|
||||||
|
|
||||||
|
function onLoad(save_state)
|
||||||
|
if save_state ~= nil then
|
||||||
|
token_precedence = JSON.decode(save_state)
|
||||||
|
end
|
||||||
|
|
||||||
-- create UI
|
-- create UI
|
||||||
local offset = 0.725
|
local offset = 0.725
|
||||||
local pos = {
|
local pos = { x = { -1.067, 0.377 }, z = -2.175 }
|
||||||
x = { -1.067, 0.377 },
|
|
||||||
z = -2.175
|
|
||||||
}
|
|
||||||
|
|
||||||
-- button and inputs index 1-10
|
-- button and inputs index 1-10
|
||||||
for i = 1, 10 do
|
for i = 1, 10 do
|
||||||
if i < 6 then
|
if i < 6 then
|
||||||
BUTTON_PARAMETERS.position = { pos.x[1], 0, pos.z + i * offset }
|
buttonParameters.position = { pos.x[1], 0, pos.z + i * offset }
|
||||||
INPUT_PARAMETERS.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
|
inputParameters.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
|
||||||
else
|
else
|
||||||
BUTTON_PARAMETERS.position = { pos.x[2], 0, pos.z + (i - 5) * offset }
|
buttonParameters.position = { pos.x[2], 0, pos.z + (i - 5) * offset }
|
||||||
INPUT_PARAMETERS.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset }
|
inputParameters.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset }
|
||||||
end
|
end
|
||||||
|
|
||||||
BUTTON_PARAMETERS.click_function = attachIndex("tokenClick", i)
|
buttonParameters.click_function = attachIndex("tokenClick", i)
|
||||||
INPUT_PARAMETERS.input_function = attachIndex2("tokenInput", i)
|
inputParameters.input_function = attachIndex2("tokenInput", i)
|
||||||
INPUT_PARAMETERS.value = token_precedence[token_names[i]][1]
|
inputParameters.value = token_precedence[token_names[i]][1]
|
||||||
|
|
||||||
self.createButton(BUTTON_PARAMETERS)
|
self.createButton(buttonParameters)
|
||||||
self.createInput(INPUT_PARAMETERS)
|
self.createInput(inputParameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- index 11: "Update / Hide" button
|
-- index 11: "Update / Hide" button
|
||||||
BUTTON_PARAMETERS.label = "Update / Hide"
|
buttonParameters.label = "Update / Hide"
|
||||||
BUTTON_PARAMETERS.click_function = "layout"
|
buttonParameters.click_function = "layout"
|
||||||
BUTTON_PARAMETERS.tooltip = "Left-Click: Update!\nRight-Click: Hide Tokens!"
|
buttonParameters.tooltip = "Left-Click: Update!\nRight-Click: Hide Tokens!"
|
||||||
BUTTON_PARAMETERS.position = { 0.725, 0.1, 2.025 }
|
buttonParameters.position = { 0.725, 0.1, 2.025 }
|
||||||
BUTTON_PARAMETERS.color = { 1, 1, 1 }
|
buttonParameters.color = { 1, 1, 1 }
|
||||||
BUTTON_PARAMETERS.width = 675
|
buttonParameters.width = 675
|
||||||
BUTTON_PARAMETERS.height = 175
|
buttonParameters.height = 175
|
||||||
self.createButton(BUTTON_PARAMETERS)
|
self.createButton(buttonParameters)
|
||||||
|
|
||||||
self.addContextMenuItem("More Information", function()
|
self.addContextMenuItem("More Information", function()
|
||||||
printToAll("------------------------------", "White")
|
printToAll("------------------------------", "White")
|
||||||
@ -107,6 +104,16 @@ function onload(save_state)
|
|||||||
printToAll("last updated: " .. information["last_updated"], "White")
|
printToAll("last updated: " .. information["last_updated"], "White")
|
||||||
printToAll("original concept by Whimsical", "White")
|
printToAll("original concept by Whimsical", "White")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- send object reference to bless/curse manager
|
||||||
|
Wait.time(function()
|
||||||
|
getObjectFromGUID("5933fb").setVar("tokenArranger", self)
|
||||||
|
end, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function onDestroy()
|
||||||
|
-- remove object reference from bless/curse manager
|
||||||
|
getObjectFromGUID("5933fb").setVar("tokenArranger", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- helper functions to carry index
|
-- helper functions to carry index
|
||||||
@ -221,7 +228,7 @@ function do_position()
|
|||||||
|
|
||||||
-- create table with tokens
|
-- create table with tokens
|
||||||
for i, token in ipairs(getObjectsWithTag(TO_DELETE_TAG)) do
|
for i, token in ipairs(getObjectsWithTag(TO_DELETE_TAG)) do
|
||||||
local name = token.getName()
|
local name = token.getName() or ""
|
||||||
local value = tonumber(name)
|
local value = tonumber(name)
|
||||||
local precedence = token_precedence[name]
|
local precedence = token_precedence[name]
|
||||||
|
|
||||||
|
@ -19,23 +19,24 @@ buttonParamaters.color = { 0, 0, 0, 0 }
|
|||||||
buttonParamaters.width = 700
|
buttonParamaters.width = 700
|
||||||
buttonParamaters.height = 700
|
buttonParamaters.height = 700
|
||||||
|
|
||||||
local tokenarranger = getObjectFromGUID("022907")
|
local altState = false
|
||||||
local MODE = { [false] = "Add / Remove", [true] = "Take / Return" }
|
local MODE = { [false] = "Add / Remove", [true] = "Take / Return" }
|
||||||
local BUTTON_COLOR = { [false] = { 0.4, 0.4, 0.4 }, [true] = { 0.9, 0.9, 0.9 } }
|
local BUTTON_COLOR = { [false] = { 0.4, 0.4, 0.4 }, [true] = { 0.9, 0.9, 0.9 } }
|
||||||
local FONT_COLOR = { [false] = { 1, 1, 1 }, [true] = { 0, 0, 0 } }
|
local FONT_COLOR = { [false] = { 1, 1, 1 }, [true] = { 0, 0, 0 } }
|
||||||
local whitespace = " "
|
local whitespace = " "
|
||||||
|
|
||||||
|
-- variable will be set by outside call
|
||||||
|
tokenArranger = nil
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- creating buttons and menus + initializing tables
|
-- creating buttons and menus + initializing tables
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
function onSave() return JSON.encode(TOGGLE) end
|
function onSave() return JSON.encode(altState) end
|
||||||
|
|
||||||
function onLoad(saved_state)
|
function onLoad(saved_state)
|
||||||
if saved_state ~= nil then
|
if saved_state ~= nil then
|
||||||
TOGGLE = JSON.decode(saved_state)
|
altState = JSON.decode(saved_state)
|
||||||
else
|
|
||||||
TOGGLE = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- index: 0 - bless
|
-- index: 0 - bless
|
||||||
@ -82,12 +83,6 @@ function onLoad(saved_state)
|
|||||||
tokensTaken = { Bless = {}, Curse = {} }
|
tokensTaken = { Bless = {}, Curse = {} }
|
||||||
sealedTokens = {}
|
sealedTokens = {}
|
||||||
Wait.time(initializeState, 1)
|
Wait.time(initializeState, 1)
|
||||||
|
|
||||||
-- feedback for token arranger
|
|
||||||
if tokenarranger then
|
|
||||||
print("Bless/Curse Manager will update the Token Arranger automatically.")
|
|
||||||
print("If you remove the Token Arranger, save and reload before continuing.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function initializeState()
|
function initializeState()
|
||||||
@ -117,8 +112,14 @@ function initializeState()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Bless Tokens " .. getTokenCount("Bless"))
|
broadcastCount("Curse")
|
||||||
print("Curse Tokens " .. getTokenCount("Curse"))
|
broadcastCount("Bless")
|
||||||
|
end
|
||||||
|
|
||||||
|
function broadcastCount(token)
|
||||||
|
local count = getTokenCount(token)
|
||||||
|
if count == "(0/0)" then return end
|
||||||
|
broadcastToAll(token .. " Tokens " .. count, "White")
|
||||||
end
|
end
|
||||||
|
|
||||||
function printStatus(color)
|
function printStatus(color)
|
||||||
@ -172,8 +173,8 @@ end
|
|||||||
-- context menu function 2
|
-- context menu function 2
|
||||||
function doReset(color)
|
function doReset(color)
|
||||||
-- delete previously pulled out tokens by the token arranger
|
-- delete previously pulled out tokens by the token arranger
|
||||||
if tokenarranger then
|
if tokenArranger then
|
||||||
for _, token in ipairs(getObjectsWithTag(tokenarranger.getVar("TO_DELETE_TAG"))) do
|
for _, token in ipairs(getObjectsWithTag(tokenArranger.getVar("TO_DELETE_TAG"))) do
|
||||||
token.destruct()
|
token.destruct()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -203,15 +204,15 @@ end
|
|||||||
|
|
||||||
-- click function 3
|
-- click function 3
|
||||||
function enableAlt()
|
function enableAlt()
|
||||||
if TOGGLE then return end
|
if altState then return end
|
||||||
TOGGLE = not TOGGLE
|
altState = not altState
|
||||||
updateButtons()
|
updateButtons()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- click function 4
|
-- click function 4
|
||||||
function enableDefault()
|
function enableDefault()
|
||||||
if not TOGGLE then return end
|
if not altState then return end
|
||||||
TOGGLE = not TOGGLE
|
altState = not altState
|
||||||
updateButtons()
|
updateButtons()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -222,33 +223,33 @@ end
|
|||||||
function updateButtons()
|
function updateButtons()
|
||||||
self.editButton({
|
self.editButton({
|
||||||
index = 0,
|
index = 0,
|
||||||
tooltip = MODE[TOGGLE] .. " Bless"
|
tooltip = MODE[altState] .. " Bless"
|
||||||
})
|
})
|
||||||
|
|
||||||
self.editButton({
|
self.editButton({
|
||||||
index = 1,
|
index = 1,
|
||||||
tooltip = MODE[TOGGLE] .. " Curse"
|
tooltip = MODE[altState] .. " Curse"
|
||||||
})
|
})
|
||||||
|
|
||||||
self.editButton({
|
self.editButton({
|
||||||
index = 2,
|
index = 2,
|
||||||
label = whitespace .. MODE[true] .. (TOGGLE and " ✓" or whitespace) .. " ",
|
label = whitespace .. MODE[true] .. (altState and " ✓" or whitespace) .. " ",
|
||||||
color = BUTTON_COLOR[not TOGGLE],
|
color = BUTTON_COLOR[not altState],
|
||||||
font_color = FONT_COLOR[not TOGGLE]
|
font_color = FONT_COLOR[not altState]
|
||||||
})
|
})
|
||||||
|
|
||||||
self.editButton({
|
self.editButton({
|
||||||
index = 3,
|
index = 3,
|
||||||
label = whitespace .. MODE[false] .. (TOGGLE and whitespace or " ✓") .. " ",
|
label = whitespace .. MODE[false] .. (altState and whitespace or " ✓") .. " ",
|
||||||
color = BUTTON_COLOR[TOGGLE],
|
color = BUTTON_COLOR[altState],
|
||||||
font_color = FONT_COLOR[TOGGLE]
|
font_color = FONT_COLOR[altState]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- function that is called by click_functions 1+2 and calls the other functions
|
-- function that is called by click_functions 1+2 and calls the other functions
|
||||||
function callFunctions(token, isRightClick)
|
function callFunctions(token, isRightClick)
|
||||||
local success
|
local success
|
||||||
if not TOGGLE then
|
if not altState then
|
||||||
if isRightClick then
|
if isRightClick then
|
||||||
success = takeToken(token, true)
|
success = takeToken(token, true)
|
||||||
else
|
else
|
||||||
@ -266,11 +267,11 @@ end
|
|||||||
|
|
||||||
UPDATING = false
|
UPDATING = false
|
||||||
function updateTokenArranger()
|
function updateTokenArranger()
|
||||||
if tokenarranger and not UPDATING then
|
if tokenArranger and not UPDATING then
|
||||||
UPDATING = true
|
UPDATING = true
|
||||||
Wait.time(function()
|
Wait.time(function()
|
||||||
UPDATING = false
|
UPDATING = false
|
||||||
tokenarranger.call("layout")
|
tokenArranger.call("layout")
|
||||||
end, 1.5)
|
end, 1.5)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -352,8 +353,8 @@ function takeToken(type, remove)
|
|||||||
printToColor("No " .. type .. " tokens in the chaos bag.", playerColor)
|
printToColor("No " .. type .. " tokens in the chaos bag.", playerColor)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local pos = self.getPosition() + Vector(-2, 0, 2.5)
|
local pos = self.getPosition() + Vector(2.25, 0, 0.85)
|
||||||
if type == "Curse" then pos[3] = pos[3] - 5 end
|
if type == "Curse" then pos[3] = pos[3] - 1.7 end
|
||||||
chaosbag.takeObject({
|
chaosbag.takeObject({
|
||||||
guid = table.remove(tokens),
|
guid = table.remove(tokens),
|
||||||
position = pos,
|
position = pos,
|
||||||
@ -426,7 +427,7 @@ function addMenuOptions(playerColor, hoveredObject)
|
|||||||
sealedTokens[hoveredObject.getGUID()] = {}
|
sealedTokens[hoveredObject.getGUID()] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function sealToken(type, color, enemy)
|
function sealToken(type, playerColor, enemy)
|
||||||
local chaosbag = getChaosBag()
|
local chaosbag = getChaosBag()
|
||||||
if chaosbag == nil then return end
|
if chaosbag == nil then return end
|
||||||
local pos = enemy.getPosition()
|
local pos = enemy.getPosition()
|
||||||
@ -441,17 +442,17 @@ function sealToken(type, color, enemy)
|
|||||||
Wait.frames(function()
|
Wait.frames(function()
|
||||||
table.insert(sealedTokens[enemy.getGUID()], obj)
|
table.insert(sealedTokens[enemy.getGUID()], obj)
|
||||||
table.insert(tokensTaken[type], obj.getGUID())
|
table.insert(tokensTaken[type], obj.getGUID())
|
||||||
printToColor("Sealing " .. type .. " token " .. getTokenCount(type), color)
|
printToColor("Sealing " .. type .. " token " .. getTokenCount(type), playerColor)
|
||||||
end, 1)
|
end, 1)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
printToColor(type .. " token not found in bag", color)
|
printToColor(type .. " token not found in bag", playerColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function releaseToken(type, color, enemy)
|
function releaseToken(type, playerColor, enemy)
|
||||||
local chaosbag = getChaosBag()
|
local chaosbag = getChaosBag()
|
||||||
if chaosbag == nil then return end
|
if chaosbag == nil then return end
|
||||||
local tokens = sealedTokens[enemy.getGUID()]
|
local tokens = sealedTokens[enemy.getGUID()]
|
||||||
@ -465,11 +466,11 @@ function releaseToken(type, color, enemy)
|
|||||||
if v == guid then
|
if v == guid then
|
||||||
table.remove(tokensTaken[type], j)
|
table.remove(tokensTaken[type], j)
|
||||||
table.remove(tokens, i)
|
table.remove(tokens, i)
|
||||||
printToColor("Releasing " .. type .. " token" .. getTokenCount(type), color)
|
printToColor("Releasing " .. type .. " token" .. getTokenCount(type), playerColor)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
printToColor(type .. " token not sealed on " .. enemy.getName(), color)
|
printToColor(type .. " token not sealed on " .. enemy.getName(), playerColor)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user