1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Disallow shrinking zone if there are buildings

This commit is contained in:
Даниїл Григор'єв 2021-04-30 17:12:39 +03:00
parent 640d1065f0
commit 2027b6ff50
No known key found for this signature in database
GPG Key ID: B890DF16341D8C1D
3 changed files with 20 additions and 8 deletions

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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() {