mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-07-26 18:36:23 +09:00
Add AABB.size (#445)
This commit is contained in:
@@ -28,8 +28,8 @@ commands.lawnmower = Commands.new("lawnmower", { "exp-commands_lawnmower.descrip
|
|||||||
SelectArea:on_selection(function(event)
|
SelectArea:on_selection(function(event)
|
||||||
local player = assert(game.get_player(event.player_index))
|
local player = assert(game.get_player(event.player_index))
|
||||||
local area = AABB.expand(event.area)
|
local area = AABB.expand(event.area)
|
||||||
|
local area_size = AABB.size(area)
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
|
|
||||||
|
|
||||||
if area_size > 1000 then
|
if area_size > 1000 then
|
||||||
player.print({ "exp-commands_lawnmower.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
player.print({ "exp-commands_lawnmower.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ commands.clear_blueprints = Commands.new("clear-blueprints", { "exp-commands_sur
|
|||||||
SelectArea:on_selection(function(event)
|
SelectArea:on_selection(function(event)
|
||||||
local player = assert(game.get_player(event.player_index))
|
local player = assert(game.get_player(event.player_index))
|
||||||
local area = AABB.expand(event.area)
|
local area = AABB.expand(event.area)
|
||||||
|
local area_size = AABB.size(area)
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
|
|
||||||
|
|
||||||
if area_size > 1000 then
|
if area_size > 1000 then
|
||||||
player.print({ "exp-commands_surface.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
player.print({ "exp-commands_surface.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ commands.waterfill = Commands.new("waterfill", { "exp-commands_waterfill.descrip
|
|||||||
--- When an area is selected to be converted to water
|
--- When an area is selected to be converted to water
|
||||||
SelectArea:on_selection(function(event)
|
SelectArea:on_selection(function(event)
|
||||||
local area = AABB.expand(event.area)
|
local area = AABB.expand(event.area)
|
||||||
|
local area_size = AABB.size(area)
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
|
|
||||||
@@ -51,8 +52,6 @@ SelectArea:on_selection(function(event)
|
|||||||
end
|
end
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
|
|
||||||
|
|
||||||
if area_size > 1000 then
|
if area_size > 1000 then
|
||||||
player.print({ "exp-commands_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
player.print({ "exp-commands_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ function AABB.valid(aabb)
|
|||||||
return aabb.left_top.x < aabb.right_bottom.x and aabb.left_top.y < aabb.right_bottom.y
|
return aabb.left_top.x < aabb.right_bottom.x and aabb.left_top.y < aabb.right_bottom.y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the size of the area contained within an AABB
|
||||||
|
--- @param aabb BoundingBox
|
||||||
|
--- @return number
|
||||||
|
function AABB.size(aabb)
|
||||||
|
return (aabb.right_bottom.x - aabb.left_top.x) * (aabb.right_bottom.y - aabb.left_top.y)
|
||||||
|
end
|
||||||
|
|
||||||
--- Clone an area, allows for safe mutation of an input value
|
--- Clone an area, allows for safe mutation of an input value
|
||||||
--- @param aabb BoundingBox
|
--- @param aabb BoundingBox
|
||||||
--- @return BoundingBox
|
--- @return BoundingBox
|
||||||
|
|||||||
Reference in New Issue
Block a user