changes from code review

This commit is contained in:
Chr1Z93 2022-11-12 13:51:43 +01:00
parent d22c4d5806
commit 6b7eba56a5
2 changed files with 18 additions and 21 deletions

View File

@ -18,7 +18,7 @@ function onLoad(saved_data)
self.createButton({ self.createButton({
label = tostring(val), label = tostring(val),
click_function = "add_subtract", click_function = "addOrSubtract",
function_owner = self, function_owner = self,
position = { 0, 0.06, 0 }, position = { 0, 0.06, 0 },
height = 800, height = 800,
@ -48,8 +48,8 @@ end
function setToZero() updateVal(0) end function setToZero() updateVal(0) end
function add_subtract(_obj, _color, alt_click) function addOrSubtract(_, _, alt_click)
new_value = math.min(math.max(val + (alt_click and -1 or 1), 0), 99) 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 if val ~= new_value then updateVal(new_value) end
end end
@ -58,5 +58,3 @@ function updateVal(number)
self.editButton({ index = 0, label = tostring(val) }) self.editButton({ index = 0, label = tostring(val) })
printToAll("Doom on agenda set to: " .. val) printToAll("Doom on agenda set to: " .. val)
end end
function updateSave() end

View File

@ -7,22 +7,21 @@ information = {
} }
-- common parameters -- common parameters
local CAST_PARAMETERS = {} local castParameters = {}
CAST_PARAMETERS.direction = { 0, 1, 0 } castParameters.direction = { 0, 1, 0 }
CAST_PARAMETERS.type = 3 castParameters.type = 3
CAST_PARAMETERS.max_distance = 0 castParameters.max_distance = 0
local ypos = 1.6
local zone = getObjectFromGUID("a2f932") local zone = getObjectFromGUID("a2f932")
local doom_url = "https://i.imgur.com/EoL7yaZ.png" local doom_url = "https://i.imgur.com/EoL7yaZ.png"
local IGNORE_TAG = "DoomCounter_ignore" local IGNORE_TAG = "DoomCounter_ignore"
-- playermats 1 to 4 -- playermats 1 to 4
local originAndSize = { local originAndSize = {
{ origin = { -55, ypos, 16.5 }, size = { 12, 1, 25 } }, { origin = { -55, 1.6, 16.5 }, size = { 12, 1, 25 } },
{ origin = { -55, ypos, -16.5 }, size = { 12, 1, 25 } }, { origin = { -55, 1.6, -16.5 }, size = { 12, 1, 25 } },
{ origin = { -25, ypos, 27 }, size = { 25, 1, 12 } }, { origin = { -25, 1.6, 27 }, size = { 25, 1, 12 } },
{ origin = { -25, ypos, -27 }, size = { 25, 1, 12 } } { origin = { -25, 1.6, -27 }, size = { 25, 1, 12 } }
} }
-- create button, context menu and start loop -- create button, context menu and start loop
@ -43,8 +42,8 @@ function onLoad()
-- context menu -- context menu
self.addContextMenuItem("More Information", moreInformation) self.addContextMenuItem("More Information", moreInformation)
self.addContextMenuItem("Remove Doom", function() self.addContextMenuItem("Remove Doom", function()
removeDoom = true
Wait.stop(loopID) Wait.stop(loopID)
removeDoom = true
countDoom() countDoom()
Wait.time(function() Wait.time(function()
removeDoom = false removeDoom = false
@ -75,21 +74,21 @@ function search(num)
local val = 0 local val = 0
if num == 5 then if num == 5 then
for _, obj in ipairs(zone.getObjects()) do for _, obj in ipairs(zone.getObjects()) do
val = val + getResult(obj) val = val + isDoom(obj)
end end
else else
CAST_PARAMETERS.origin = originAndSize[num].origin castParameters.origin = originAndSize[num].origin
CAST_PARAMETERS.size = originAndSize[num].size castParameters.size = originAndSize[num].size
for _, obj in ipairs(Physics.cast(CAST_PARAMETERS)) do for _, obj in ipairs(Physics.cast(castParameters)) do
val = val + getResult(obj.hit_object) val = val + isDoom(obj.hit_object)
end end
end end
return val return val
end end
-- checks an object for the doom image and gets quantity (for stacks) -- 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 if (obj.is_face_down and obj.getCustomObject().image_bottom == doom_url) or
(obj.name == "Custom_Token" and obj.getCustomObject().image == doom_url) then (obj.name == "Custom_Token" and obj.getCustomObject().image == doom_url) then
if not obj.hasTag(IGNORE_TAG) then if not obj.hasTag(IGNORE_TAG) then