resolving comments (part 1)

This commit is contained in:
Chr1Z93 2022-12-19 14:39:32 +01:00
parent 7a60c318ca
commit 43789fdaa7
4 changed files with 26 additions and 33 deletions

View File

@ -1,11 +1,3 @@
-- Chaos Bag Manager
-- made by: Chr1Z
-- description: for easier managing of the chaos bag (adding / removing tokens)
information = {
version = "1.5",
last_updated = "24.11.2022"
}
local TOKEN_URL = {
ElderSign = "https://i.imgur.com/nEmqjmj.png",
plusOne = "https://i.imgur.com/uIx8jbY.png",
@ -61,7 +53,7 @@ buttonParameters.width = 300
buttonParameters.height = 300
local UPDATING = false
local tokenarranger
local tokenArranger
local name
local tokens = {}
@ -87,11 +79,10 @@ function onLoad()
self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White")
printToAll("Chaos Bag Manager v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("last updated: " .. information["last_updated"], "White")
printToAll("Chaos Bag Manager by Chr1Z", "Orange")
end)
tokenarranger = getObjectFromGUID("022907")
tokenArranger = getObjectFromGUID("022907")
end
-- get chaos bag from scripting zone and description
@ -182,11 +173,11 @@ function spawnCallback(obj)
end
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

View File

@ -93,21 +93,24 @@ function onLoad(save_state)
end)
-- send object reference to bless/curse manager
Wait.time(function()
getObjectFromGUID("5933fb").setVar("tokenArranger", self)
end, 1)
Wait.time(function() getObjectFromGUID("5933fb").setVar("tokenArranger", self) end, 1)
end
function onDestroy()
deleteCopiedTokens()
-- remove object reference from bless/curse manager
getObjectFromGUID("5933fb").setVar("tokenArranger", nil)
end
function onPickUp()
deleteCopiedTokens()
end
-- helper functions to carry index
function attachIndex(click_function, index)
local fn_name = click_function .. index
_G[fn_name] = function(obj, player_color, alt_click)
_G[click_function](obj, player_color, alt_click, index)
_G[fn_name] = function(obj, player_color, isRightClick)
_G[click_function](obj, player_color, isRightClick, index)
end
return fn_name
end
@ -121,21 +124,18 @@ function attachIndex2(input_function, index)
end
-- click_function for buttons on chaos tokens
function tokenClick(obj, player_color, alt_click, index)
function tokenClick(_, _, isRightClick, index)
if not updating then
updating = true
if alt_click then
TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] = TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] - 1
else
TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] = TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] + 1
end
local change = tonumber(isRightClick and "-1" or "1")
TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] = TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] + change
self.editInput({ index = index - 1, value = TOKEN_PRECEDENCE[TOKEN_NAMES[index]][1] })
layout()
end
end
-- input_function for input_boxes
function tokenInput(obj, player_color, input, selected, index)
function tokenInput(_, _, input, selected, index)
if selected == false and not updating then
updating = true
local num = tonumber(input)
@ -181,10 +181,14 @@ function getChaosBag()
return chaosbag
end
-- deletes previously placed tokens
function deleteCopiedTokens()
for _, token in ipairs(getObjectsWithTag("to_be_deleted")) do token.destruct() end
end
-- main function (delete old tokens, clone chaos bag content, sort it and position it)
function layout(_, _, isRightClick)
-- delete previously pulled out tokens
for _, token in ipairs(getObjectsWithTag("to_be_deleted")) do token.destruct() end
deleteCopiedTokens()
-- stop here if right-clicked
if isRightClick then return end
@ -205,12 +209,11 @@ function layout(_, _, isRightClick)
end
-- wait until all tokens have finished spawning
Wait.condition(function() do_position() end,
function() return #chaos_bag_objects == #getObjectsWithTag("to_be_deleted") end)
Wait.condition(function() placeTokens() end, function() return #chaos_bag_objects == #getObjectsWithTag("to_be_deleted") end)
end
-- position tokens sorted by value
function do_position()
function placeTokens()
local data = {}
-- create table with tokens

View File

@ -854,7 +854,6 @@ function applyOptionPanelChange(id, state)
-- option: Show chaos bag manager
elseif id == "showChaosBagManager" then
spawnOrRemoveHelper(state, "Chaos Bag Manager", {-67.8, 1.4, -49.5})
end
end

View File

@ -174,7 +174,7 @@ end
function doReset(color)
-- delete previously pulled out tokens by the token arranger
if tokenArranger then
for _, token in ipairs("to_be_deleted") do token.destruct() end
tokenArranger.call("deleteCopiedTokens")
end
playerColor = color