Skip to content

Commit

Permalink
Merge branch 'master' into ui-olympUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruor committed Mar 27, 2024
2 parents 1b49b87 + 8a58ecb commit b8f8db2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,8 @@ function entities.getHandler(entity)
end

-- All extra arguments considered default value
-- Specifically for functions that need both entity and room
-- Will unpack returned tables, do not use for functions that actually want table returns
function entities.getHandlerValue(entity, room, key, ...)
local handler = entities.getHandler(entity)

Expand Down Expand Up @@ -1209,7 +1211,13 @@ function entities.nodeLimits(room, layer, entity)
end

function entities.nodeLineRenderType(layer, entity)
return entities.getHandlerValue(entity, nil, "nodeLineRenderType", false)
local handler = entities.getHandler(entity)

if handler and handler.nodeLineRenderType then
return utils.callIfFunction(handler.nodeLineRenderType, entity)
end

return false
end

function entities.nodeLineRenderOffset(layer, entity, node, nodeIndex)
Expand All @@ -1224,7 +1232,13 @@ function entities.nodeLineRenderOffset(layer, entity, node, nodeIndex)
end

function entities.nodeVisibility(layer, entity)
return entities.getHandlerValue(entity, nil, "nodeVisibility", "selected")
local handler = entities.getHandler(entity)

if handler and handler.nodeVisibility then
return utils.callIfFunction(handler.nodeVisibility, entity)
end

return "selected"
end

function entities.ignoredFields(layer, entity)
Expand Down
25 changes: 22 additions & 3 deletions src/triggers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ function triggers.getHandler(trigger)
end

-- All extra arguments considered default value
-- Specifically for functions that need both entity and room
-- Will unpack returned tables, do not use for functions that actually want table returns
function triggers.getHandlerValue(trigger, room, key, ...)
local handler = triggers.getHandler(trigger)

Expand Down Expand Up @@ -676,11 +678,23 @@ function triggers.nodeLimits(room, layer, trigger)
end

function triggers.nodeLineRenderType(layer, trigger)
return triggers.getHandlerValue(trigger, nil, "nodeLineRenderType", "line")
local handler = triggers.getHandler(trigger)

if handler and handler.nodeLineRenderType then
return utils.callIfFunction(handler.nodeLineRenderType, trigger)
end

return "line"
end

function triggers.nodeVisibility(layer, trigger)
return triggers.getHandlerValue(trigger, nil, "nodeVisibility", "selected")
local handler = triggers.getHandler(trigger)

if handler and handler.nodeVisibility then
return utils.callIfFunction(handler.nodeVisibility, trigger)
end

return "selected"
end

function triggers.ignoredFields(layer, trigger)
Expand All @@ -707,8 +721,13 @@ end

function triggers.fieldOrder(layer, trigger)
local defaultFieldOrder = {"x", "y", "width", "height"}
local handler = triggers.getHandler(trigger)

if handler and handler.fieldOrder then
return utils.callIfFunction(handler.fieldOrder, trigger)
end

return triggers.getHandlerValue(trigger, nil, "fieldOrder", defaultFieldOrder)
return defaultFieldOrder
end

function triggers.fieldInformation(layer, trigger)
Expand Down

0 comments on commit b8f8db2

Please sign in to comment.