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 851fc36 + 3e14c4e commit 1b49b87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
14 changes: 11 additions & 3 deletions src/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1185,15 +1185,23 @@ function entities.minimumSize(room, layer, entity)
end

function entities.maximumSize(room, layer, entity)
return entities.getHandlerValue(entity, room, "minimumSize", math.huge, math.huge)
return entities.getHandlerValue(entity, room, "maximumSize", math.huge, math.huge)
end

function entities.warnBelowSize(room, layer, entity)
return entities.getHandlerValue(entity, room, "warnBelowSize", 8, 8)
local minimumWidth, minimumHeight = entities.minimumSize(room, layer, entity)
local fallbackWidth = math.max(minimumWidth, 8)
local fallbackHeight = math.max(minimumHeight, 8)

return entities.getHandlerValue(entity, room, "warnBelowSize", fallbackWidth, fallbackHeight)
end

function entities.warnAboveSize(room, layer, entity)
return entities.getHandlerValue(entity, room, "warnAbove", math.huge, math.huge)
local maximumWidth, maximumHeight = entities.maximumSize(room, layer, entity)
local fallbackWidth = math.min(maximumWidth, math.huge)
local fallbackHeight = math.min(maximumHeight, math.huge)

return entities.getHandlerValue(entity, room, "warnAbove", fallbackWidth, fallbackHeight)
end

function entities.nodeLimits(room, layer, entity)
Expand Down
34 changes: 20 additions & 14 deletions src/tools/placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ local function getPlacementOffset()
return getGridPosition(placementCurrentX, placementCurrentY)
end

local function updatePlacementDrawable()
local function updatePlacementDrawable(layer)
layer = layer or tool.layer

local room = state.getSelectedRoom()

if room and placementTemplate then
local target = placementTemplate.item._name or placementTemplate.item.texture
local drawable = placementUtils.getDrawable(tool.layer, target, room, placementTemplate.item)
local drawable = placementUtils.getDrawable(layer, target, room, placementTemplate.item)

placementTemplate.drawable = drawable
end
Expand Down Expand Up @@ -308,12 +310,14 @@ local placementUpdaters = {
line = updateLinePlacement
}

local function updatePlacementNodes()
local function updatePlacementNodes(layer)
layer = layer or tool.layer

local room = state.room

local item = placementTemplate.item
local placementType = getCurrentPlacementType()
local minimumNodes, maximumNodes = placementUtils.nodeLimits(room, tool.layer, item)
local minimumNodes, maximumNodes = placementUtils.nodeLimits(room, layer, item)

if minimumNodes > 0 then
-- Set up empty nodes table if needed
Expand Down Expand Up @@ -373,24 +377,26 @@ local function updatePlacement(force)
end
end

local function setPlacement(placement, sendEvent)
local function setPlacement(placement, sendEvent, layer)
layer = layer or tool.layer

placementTemplate = {
item = utils.deepcopy(placement.itemTemplate),
placement = placement,
}

updatePlacementNodes()
updatePlacementDrawable()
updatePlacementNodes(layer)
updatePlacementDrawable(layer)

if sendEvent ~= false then
toolUtils.sendMaterialEvent(tool, tool.layer, placement.name)
toolUtils.sendMaterialEvent(tool, layer, placement.name)
end
end

local function selectPlacement(name, index, sendEvent)
local function selectPlacement(name, index, sendEvent, layer)
for i, placement in ipairs(placementsAvailable) do
if i == index or placement.displayName == name or placement.name == name then
setPlacement(placement, sendEvent)
setPlacement(placement, sendEvent, layer)

return true
end
Expand Down Expand Up @@ -457,23 +463,23 @@ local function updatePlacements(layer, sendEvent)
local useFallback = not persistenceMaterial

if persistenceMaterial then
useFallback = not selectPlacement(persistenceMaterial, nil, sendEvent)
useFallback = not selectPlacement(persistenceMaterial, nil, sendEvent, layer)
end

if useFallback then
selectPlacement(nil, 1, sendEvent)
selectPlacement(nil, 1, sendEvent, layer)
end
end

function tool.setLayer(layer)
local sameLayer = layer == tool.layer

tool.layer = layer

if state.map and (not sameLayer or not placementsAvailable) then
updatePlacements(layer, false)
end

tool.layer = layer

toolUtils.sendLayerEvent(tool, layer)

return false
Expand Down

0 comments on commit 1b49b87

Please sign in to comment.