mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-06 09:34:05 +00:00
Minor puzzle control refactoring
This commit is contained in:
parent
285dd3840d
commit
db355da09e
@ -1,5 +1,3 @@
|
||||
/* typehints:start */
|
||||
/* typehints:end */
|
||||
import { globalConfig } from "../../../core/config";
|
||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||
import { createLogger } from "../../../core/logging";
|
||||
@ -50,7 +48,7 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
|
||||
</div>
|
||||
|
||||
<div class="buildingsButton">
|
||||
<button class="styledButton clearBuildings">${T.ingame.puzzleEditorSettings.clearBuildings}</button>
|
||||
<button class="styledButton resetPuzzle">${T.ingame.puzzleEditorSettings.resetPuzzle}</button>
|
||||
</div>
|
||||
|
||||
</div>`
|
||||
@ -62,7 +60,7 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
|
||||
bind(".zoneHeight .plus", () => this.modifyZone(0, 1));
|
||||
bind("button.trim", this.trim);
|
||||
bind("button.clearItems", this.clearItems);
|
||||
bind("button.clearBuildings", this.clearBuildings);
|
||||
bind("button.resetPuzzle", this.resetPuzzle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,9 +68,14 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
|
||||
this.root.logic.clearAllBeltsAndItems();
|
||||
}
|
||||
|
||||
clearBuildings() {
|
||||
resetPuzzle() {
|
||||
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const goalComp = entity.components.GoalAcceptor;
|
||||
|
||||
if (goalComp) {
|
||||
goalComp.clear();
|
||||
}
|
||||
|
||||
if (
|
||||
[MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding]
|
||||
|
@ -1,10 +1,6 @@
|
||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||
import { createLogger } from "../../../core/logging";
|
||||
import { makeDiv } from "../../../core/utils";
|
||||
import { T } from "../../../translations";
|
||||
import { MetaBlockBuilding } from "../../buildings/block";
|
||||
import { MetaConstantProducerBuilding } from "../../buildings/constant_producer";
|
||||
import { MetaGoalAcceptorBuilding } from "../../buildings/goal_acceptor";
|
||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
|
||||
@ -23,13 +19,13 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
|
||||
["section"],
|
||||
`
|
||||
<button class="styledButton clearItems">${T.ingame.puzzleEditorSettings.clearItems}</button>
|
||||
<button class="styledButton clearBuildings">${T.ingame.puzzleEditorSettings.resetPuzzle}</button>
|
||||
<button class="styledButton resetPuzzle">${T.ingame.puzzleEditorSettings.resetPuzzle}</button>
|
||||
|
||||
`
|
||||
);
|
||||
|
||||
bind("button.clearItems", this.clearItems);
|
||||
bind("button.clearBuildings", this.clearBuildings);
|
||||
bind("button.resetPuzzle", this.resetPuzzle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,20 +33,19 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
|
||||
this.root.logic.clearAllBeltsAndItems();
|
||||
}
|
||||
|
||||
clearBuildings() {
|
||||
resetPuzzle() {
|
||||
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const goalComp = entity.components.GoalAcceptor;
|
||||
|
||||
if (
|
||||
[MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding]
|
||||
.map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id)
|
||||
.includes(staticComp.getMetaBuilding().id)
|
||||
) {
|
||||
continue;
|
||||
if (goalComp) {
|
||||
goalComp.clear();
|
||||
}
|
||||
|
||||
this.root.map.removeStaticEntity(entity);
|
||||
this.root.entityMgr.destroyEntity(entity);
|
||||
if (staticComp.getMetaBuilding().getIsRemovable(this.root)) {
|
||||
this.root.map.removeStaticEntity(entity);
|
||||
this.root.entityMgr.destroyEntity(entity);
|
||||
}
|
||||
}
|
||||
this.root.entityMgr.processDestroyList();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user