From 2027b6ff50e3634fb1473b473d472b5c9e0c1e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Fri, 30 Apr 2021 17:12:39 +0300 Subject: [PATCH] Disallow shrinking zone if there are buildings --- src/js/game/game_mode.js | 2 +- src/js/game/hud/parts/mode_settings.js | 2 +- src/js/game/modes/puzzle_edit.js | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/js/game/game_mode.js b/src/js/game/game_mode.js index bf7e0d97..ae2fc140 100644 --- a/src/js/game/game_mode.js +++ b/src/js/game/game_mode.js @@ -142,7 +142,7 @@ export class GameMode extends BasicSerializableObject { * @param {number} w * @param {number} h */ - expandZone(w = 0, h = 0) { + adjustZone(w = 0, h = 0) { abstract; return; } diff --git a/src/js/game/hud/parts/mode_settings.js b/src/js/game/hud/parts/mode_settings.js index 48e4defe..094a806e 100644 --- a/src/js/game/hud/parts/mode_settings.js +++ b/src/js/game/hud/parts/mode_settings.js @@ -48,7 +48,7 @@ export class HUDModeSettings extends BaseHUDPart { } modifyZone(width, height) { - this.root.gameMode.expandZone(width, height); + this.root.gameMode.adjustZone(width, height); this.updateZoneValues(); } diff --git a/src/js/game/modes/puzzle_edit.js b/src/js/game/modes/puzzle_edit.js index 5c90a0a7..ab5d6cf6 100644 --- a/src/js/game/modes/puzzle_edit.js +++ b/src/js/game/modes/puzzle_edit.js @@ -55,16 +55,28 @@ export class PuzzleEditGameMode extends PuzzleGameMode { ]; } - expandZone(w = 0, h = 0) { - if (this.zoneWidth + w > 0) { - this.zoneWidth += w; + adjustZone(w = 0, h = 0) { + // @todo notify user when zone cannot be shrunk + if (this.zoneWidth + w <= 0) { + return; } - if (this.zoneHeight + h > 0) { - this.zoneHeight += h; + if (this.zoneHeight + h <= 0) { + return; } - this.zone = this.createCenteredRectangle(this.zoneWidth, this.zoneHeight); + const newZone = this.createCenteredRectangle(this.zoneWidth + w, this.zoneHeight + h); + const entities = this.root.entityMgr.entities; + + for (const entity of entities) { + const point = entity.components.StaticMapEntity.origin; + if (!newZone.containsPoint(point.x, point.y)) { + return; + } + } + + this.zoneWidth = newZone.w; + this.zoneHeight = newZone.h; } getIsEditor() {