From 0aa14883726e9eb866ac05390351382a03365112 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 18:11:51 +0300 Subject: [PATCH] Fix multi-tile buildings for shrinking --- src/js/core/rectangle.js | 2 +- src/js/game/modes/puzzle_edit.js | 6 ++++-- src/js/game/systems/zone.js | 7 ++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/js/core/rectangle.js b/src/js/core/rectangle.js index f17825ca..7ff57203 100644 --- a/src/js/core/rectangle.js +++ b/src/js/core/rectangle.js @@ -72,7 +72,7 @@ export class Rectangle { /** * Returns if this rectangle is equal to the other while taking an epsilon into account * @param {Rectangle} other - * @param {number} epsilon + * @param {number} [epsilon] */ equalsEpsilon(other, epsilon) { return ( diff --git a/src/js/game/modes/puzzle_edit.js b/src/js/game/modes/puzzle_edit.js index ab5d6cf6..d5d91e2b 100644 --- a/src/js/game/modes/puzzle_edit.js +++ b/src/js/game/modes/puzzle_edit.js @@ -68,9 +68,11 @@ export class PuzzleEditGameMode extends PuzzleGameMode { const newZone = this.createCenteredRectangle(this.zoneWidth + w, this.zoneHeight + h); const entities = this.root.entityMgr.entities; + // @fixme find a better way to check this for (const entity of entities) { - const point = entity.components.StaticMapEntity.origin; - if (!newZone.containsPoint(point.x, point.y)) { + const staticComp = entity.components.StaticMapEntity; + const union = newZone.getUnion(staticComp.getTileSpaceBounds()); + if (!union.equalsEpsilon(newZone)) { return; } } diff --git a/src/js/game/systems/zone.js b/src/js/game/systems/zone.js index 2dc36849..c7c24408 100644 --- a/src/js/game/systems/zone.js +++ b/src/js/game/systems/zone.js @@ -49,17 +49,14 @@ export class ZoneSystem extends GameSystem { transformed.y += tile.y; } - let withinAnyZone = false; for (const zone of zones) { const intersection = zone.getIntersection(transformed); if (intersection && intersection.w * intersection.h === transformed.w * transformed.h) { - withinAnyZone = true; + return; } } - if (!withinAnyZone) { - return STOP_PROPAGATION; - } + return STOP_PROPAGATION; } /**