From 6b7eba56a52c8f25866754f0ef4010a6459421f3 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 12 Nov 2022 13:51:43 +0100 Subject: [PATCH] changes from code review --- src/core/AgendaDeck.ttslua | 8 +++----- src/core/DoomInPlayCounter.ttslua | 31 +++++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/core/AgendaDeck.ttslua b/src/core/AgendaDeck.ttslua index 0b284bcc..910be946 100644 --- a/src/core/AgendaDeck.ttslua +++ b/src/core/AgendaDeck.ttslua @@ -18,7 +18,7 @@ function onLoad(saved_data) self.createButton({ label = tostring(val), - click_function = "add_subtract", + click_function = "addOrSubtract", function_owner = self, position = { 0, 0.06, 0 }, height = 800, @@ -48,8 +48,8 @@ end function setToZero() updateVal(0) end -function add_subtract(_obj, _color, alt_click) - new_value = math.min(math.max(val + (alt_click and -1 or 1), 0), 99) +function addOrSubtract(_, _, alt_click) + local new_value = math.min(math.max(val + (alt_click and -1 or 1), 0), 99) if val ~= new_value then updateVal(new_value) end end @@ -58,5 +58,3 @@ function updateVal(number) self.editButton({ index = 0, label = tostring(val) }) printToAll("Doom on agenda set to: " .. val) end - -function updateSave() end diff --git a/src/core/DoomInPlayCounter.ttslua b/src/core/DoomInPlayCounter.ttslua index 475f7458..7260e959 100644 --- a/src/core/DoomInPlayCounter.ttslua +++ b/src/core/DoomInPlayCounter.ttslua @@ -7,22 +7,21 @@ information = { } -- common parameters -local CAST_PARAMETERS = {} -CAST_PARAMETERS.direction = { 0, 1, 0 } -CAST_PARAMETERS.type = 3 -CAST_PARAMETERS.max_distance = 0 +local castParameters = {} +castParameters.direction = { 0, 1, 0 } +castParameters.type = 3 +castParameters.max_distance = 0 -local ypos = 1.6 local zone = getObjectFromGUID("a2f932") local doom_url = "https://i.imgur.com/EoL7yaZ.png" local IGNORE_TAG = "DoomCounter_ignore" -- playermats 1 to 4 local originAndSize = { - { origin = { -55, ypos, 16.5 }, size = { 12, 1, 25 } }, - { origin = { -55, ypos, -16.5 }, size = { 12, 1, 25 } }, - { origin = { -25, ypos, 27 }, size = { 25, 1, 12 } }, - { origin = { -25, ypos, -27 }, size = { 25, 1, 12 } } + { origin = { -55, 1.6, 16.5 }, size = { 12, 1, 25 } }, + { origin = { -55, 1.6, -16.5 }, size = { 12, 1, 25 } }, + { origin = { -25, 1.6, 27 }, size = { 25, 1, 12 } }, + { origin = { -25, 1.6, -27 }, size = { 25, 1, 12 } } } -- create button, context menu and start loop @@ -43,8 +42,8 @@ function onLoad() -- context menu self.addContextMenuItem("More Information", moreInformation) self.addContextMenuItem("Remove Doom", function() - removeDoom = true Wait.stop(loopID) + removeDoom = true countDoom() Wait.time(function() removeDoom = false @@ -75,21 +74,21 @@ function search(num) local val = 0 if num == 5 then for _, obj in ipairs(zone.getObjects()) do - val = val + getResult(obj) + val = val + isDoom(obj) end else - CAST_PARAMETERS.origin = originAndSize[num].origin - CAST_PARAMETERS.size = originAndSize[num].size + castParameters.origin = originAndSize[num].origin + castParameters.size = originAndSize[num].size - for _, obj in ipairs(Physics.cast(CAST_PARAMETERS)) do - val = val + getResult(obj.hit_object) + for _, obj in ipairs(Physics.cast(castParameters)) do + val = val + isDoom(obj.hit_object) end end return val end -- checks an object for the doom image and gets quantity (for stacks) -function getResult(obj) +function isDoom(obj) if (obj.is_face_down and obj.getCustomObject().image_bottom == doom_url) or (obj.name == "Custom_Token" and obj.getCustomObject().image == doom_url) then if not obj.hasTag(IGNORE_TAG) then