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