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

cleaned up the clear buildings button code and renamed it to reset puzzle in all modes

This commit is contained in:
Sense101 2021-06-25 12:46:53 +01:00
parent 2e4bbdac58
commit 6e5b46ea5e
8 changed files with 49 additions and 28 deletions

View File

@ -22,6 +22,14 @@ export class MetaBlockBuilding extends MetaBuilding {
return root.gameMode.getIsEditor(); return root.gameMode.getIsEditor();
} }
/**
* @param {import("../../savegame/savegame_serializer").GameRoot} root
* @returns {boolean}
*/
getIsPuzzleRemovable(root) {
return false;
}
/** /**
* Creates the entity at the given location * Creates the entity at the given location
* @param {Entity} entity * @param {Entity} entity

View File

@ -26,6 +26,14 @@ export class MetaConstantProducerBuilding extends MetaBuilding {
return root.gameMode.getIsEditor(); return root.gameMode.getIsEditor();
} }
/**
* @param {import("../../savegame/savegame_serializer").GameRoot} root
* @returns {boolean}
*/
getIsPuzzleRemovable(root) {
return false;
}
/** /**
* Creates the entity at the given location * Creates the entity at the given location
* @param {Entity} entity * @param {Entity} entity

View File

@ -26,6 +26,14 @@ export class MetaGoalAcceptorBuilding extends MetaBuilding {
return root.gameMode.getIsEditor(); return root.gameMode.getIsEditor();
} }
/**
* @param {import("../../savegame/savegame_serializer").GameRoot} root
* @returns {boolean}
*/
getIsPuzzleRemovable(root) {
return false;
}
/** /**
* Creates the entity at the given location * Creates the entity at the given location
* @param {Entity} entity * @param {Entity} entity

View File

@ -1,6 +1,5 @@
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { DrawParameters } from "../../../core/draw_parameters"; import { DrawParameters } from "../../../core/draw_parameters";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { createLogger } from "../../../core/logging"; import { createLogger } from "../../../core/logging";
import { STOP_PROPAGATION } from "../../../core/signal"; import { STOP_PROPAGATION } from "../../../core/signal";
import { formatBigNumberFull } from "../../../core/utils"; import { formatBigNumberFull } from "../../../core/utils";
@ -8,8 +7,6 @@ import { Vector } from "../../../core/vector";
import { ACHIEVEMENTS } from "../../../platform/achievement_provider"; import { ACHIEVEMENTS } from "../../../platform/achievement_provider";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { Blueprint } from "../../blueprint"; import { Blueprint } from "../../blueprint";
import { MetaBlockBuilding } from "../../buildings/block";
import { MetaConstantProducerBuilding } from "../../buildings/constant_producer";
import { enumMouseButton } from "../../camera"; import { enumMouseButton } from "../../camera";
import { Component } from "../../component"; import { Component } from "../../component";
import { Entity } from "../../entity"; import { Entity } from "../../entity";

View File

@ -1,14 +1,10 @@
/* typehints:start */ /* typehints:start */
/* typehints:end */ /* typehints:end */
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { createLogger } from "../../../core/logging"; import { createLogger } from "../../../core/logging";
import { Rectangle } from "../../../core/rectangle"; import { Rectangle } from "../../../core/rectangle";
import { makeDiv } from "../../../core/utils"; import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; 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 { StaticMapEntityComponent } from "../../components/static_map_entity";
import { PuzzleGameMode } from "../../modes/puzzle"; import { PuzzleGameMode } from "../../modes/puzzle";
import { BaseHUDPart } from "../base_hud_part"; import { BaseHUDPart } from "../base_hud_part";
@ -50,7 +46,7 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
</div> </div>
<div class="buildingsButton"> <div class="buildingsButton">
<button class="styledButton clearBuildings">${T.ingame.puzzleEditorSettings.clearBuildings}</button> <button class="styledButton resetPuzzle">${T.ingame.puzzleEditorSettings.resetPuzzle}</button>
</div> </div>
</div>` </div>`
@ -62,7 +58,7 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
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.clearItems", this.clearItems); bind("button.clearItems", this.clearItems);
bind("button.clearBuildings", this.clearBuildings); bind("button.resetPuzzle", this.resetPuzzle);
} }
} }
@ -70,15 +66,15 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
this.root.logic.clearAllBeltsAndItems(); this.root.logic.clearAllBeltsAndItems();
} }
clearBuildings() { resetPuzzle() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) { for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const goalComp = entity.components.GoalAcceptor;
if ( if (!staticComp.getMetaBuilding().getIsPuzzleRemovable(this.root)) {
[MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding] if (goalComp) {
.map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id) goalComp.clear();
.includes(staticComp.getMetaBuilding().id) }
) {
continue; continue;
} }

View File

@ -1,10 +1,6 @@
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 { MetaConstantProducerBuilding } from "../../buildings/constant_producer";
import { MetaGoalAcceptorBuilding } from "../../buildings/goal_acceptor";
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";
@ -23,13 +19,13 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
["section"], ["section"],
` `
<button class="styledButton clearItems">${T.ingame.puzzleEditorSettings.clearItems}</button> <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.clearItems", this.clearItems);
bind("button.clearBuildings", this.clearBuildings); bind("button.resetPuzzle", this.resetPuzzle);
} }
} }
@ -37,15 +33,15 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
this.root.logic.clearAllBeltsAndItems(); this.root.logic.clearAllBeltsAndItems();
} }
clearBuildings() { resetPuzzle() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) { for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const goalComp = entity.components.GoalAcceptor;
if ( if (!staticComp.getMetaBuilding().getIsPuzzleRemovable(this.root)) {
[MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding] if (goalComp) {
.map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id) goalComp.clear();
.includes(staticComp.getMetaBuilding().id) }
) {
continue; continue;
} }

View File

@ -115,6 +115,15 @@ export class MetaBuilding {
return true; return true;
} }
/**
* Returns whether this building is removable in puzzle mode
* @param {GameRoot} root
* @returns {boolean}
*/
getIsPuzzleRemovable(root) {
return true;
}
/** /**
* Returns the placement sound * Returns the placement sound
* @returns {string} * @returns {string}

View File

@ -632,7 +632,6 @@ ingame:
zoneHeight: Height zoneHeight: Height
trimZone: Trim trimZone: Trim
clearItems: Clear Items clearItems: Clear Items
clearBuildings: Clear Buildings
resetPuzzle: Reset Puzzle resetPuzzle: Reset Puzzle
share: Share share: Share
report: Report report: Report