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

added clear buildings button to both game modes

This commit is contained in:
Sense101 2021-06-23 22:59:16 +01:00
parent 1046d1d354
commit 6b60206865
4 changed files with 69 additions and 7 deletions

View File

@ -57,6 +57,15 @@
} }
} }
} }
> .buildingsButton {
display: grid;
align-items: center;
@include S(margin-top, 4px);
> button {
@include SuperSmallText;
}
}
} }
} }
} }

View File

@ -13,7 +13,7 @@
> .section { > .section {
display: grid; display: grid;
@include S(grid-gap, 10px); @include S(grid-gap, 5px);
grid-auto-flow: row; grid-auto-flow: row;
> button { > button {

View File

@ -9,6 +9,8 @@ import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { StaticMapEntityComponent } from "../../components/static_map_entity"; import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { BaseHUDPart } from "../base_hud_part"; import { BaseHUDPart } from "../base_hud_part";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { MetaBlockBuilding } from "../../buildings/block";
const logger = createLogger("puzzle-editor"); const logger = createLogger("puzzle-editor");
@ -43,8 +45,13 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
<div class="buttonBar"> <div class="buttonBar">
<button class="styledButton trim">${T.ingame.puzzleEditorSettings.trimZone}</button> <button class="styledButton trim">${T.ingame.puzzleEditorSettings.trimZone}</button>
<button class="styledButton clear">${T.ingame.puzzleEditorSettings.clearItems}</button> <button class="styledButton clear items">${T.ingame.puzzleEditorSettings.clearItems}</button>
</div> </div>
<div class="buildingsButton">
<button class="styledButton clear buildings">clear buildings</button>
</div>
</div>` </div>`
); );
@ -53,14 +60,35 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
bind(".zoneHeight .minus", () => this.modifyZone(0, -1)); bind(".zoneHeight .minus", () => this.modifyZone(0, -1));
bind(".zoneHeight .plus", () => this.modifyZone(0, 1)); bind(".zoneHeight .plus", () => this.modifyZone(0, 1));
bind("button.trim", this.trim); bind("button.trim", this.trim);
bind("button.clear", this.clear); bind("button.items", this.clearItems);
bind("button.buildings", this.clearBuildings);
} }
} }
clear() { clearItems() {
this.root.logic.clearAllBeltsAndItems(); this.root.logic.clearAllBeltsAndItems();
} }
clearBuildings() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity;
const signalComp = entity.components.ConstantSignal;
const goalComp = entity.components.GoalAcceptor;
if (
signalComp ||
goalComp ||
staticComp.getMetaBuilding().id === gMetaBuildingRegistry.findByClass(MetaBlockBuilding).id
) {
continue;
}
this.root.map.removeStaticEntity(entity);
this.root.entityMgr.destroyEntity(entity);
}
this.root.entityMgr.processDestroyList();
}
trim() { trim() {
// Now, find the center // Now, find the center
const buildings = this.root.entityMgr.entities.slice(); const buildings = this.root.entityMgr.entities.slice();

View File

@ -1,6 +1,9 @@
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { createLogger } from "../../../core/logging"; import { createLogger } from "../../../core/logging";
import { makeDiv } from "../../../core/utils"; import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { MetaBlockBuilding } from "../../buildings/block";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { BaseHUDPart } from "../base_hud_part"; import { BaseHUDPart } from "../base_hud_part";
const logger = createLogger("puzzle-play"); const logger = createLogger("puzzle-play");
@ -17,19 +20,41 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
null, null,
["section"], ["section"],
` `
<button class="styledButton clear">${T.ingame.puzzleEditorSettings.clearItems}</button> <button class="styledButton clear items">${T.ingame.puzzleEditorSettings.clearItems}</button>
<button class="styledButton clear buildings">Clear Buildings</button>
` `
); );
bind("button.clear", this.clear); bind("button.items", this.clearItems);
bind("button.buildings", this.clearBuildings);
} }
} }
clear() { clearItems() {
this.root.logic.clearAllBeltsAndItems(); this.root.logic.clearAllBeltsAndItems();
} }
clearBuildings() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity;
const signalComp = entity.components.ConstantSignal;
const goalComp = entity.components.GoalAcceptor;
if (
signalComp ||
goalComp ||
staticComp.getMetaBuilding().id === gMetaBuildingRegistry.findByClass(MetaBlockBuilding).id
) {
continue;
}
this.root.map.removeStaticEntity(entity);
this.root.entityMgr.destroyEntity(entity);
}
this.root.entityMgr.processDestroyList();
}
initialize() { initialize() {
this.visible = true; this.visible = true;
} }