diff --git a/src/entities.lua b/src/entities.lua index 14c8a9f5..b4c50080 100644 --- a/src/entities.lua +++ b/src/entities.lua @@ -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) diff --git a/src/tools/placement.lua b/src/tools/placement.lua index 4d7776bb..2bec66c4 100644 --- a/src/tools/placement.lua +++ b/src/tools/placement.lua @@ -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 @@ -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 @@ -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 @@ -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