mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
completed flow for building locking
This commit is contained in:
parent
61a21d6719
commit
cd2ed178c7
@ -1,6 +1,7 @@
|
||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||
import { STOP_PROPAGATION } from "../../../core/signal";
|
||||
import { makeDiv, safeModulo } from "../../../core/utils";
|
||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||
import { MetaBuilding } from "../../meta_building";
|
||||
import { GameRoot } from "../../root";
|
||||
@ -35,7 +36,8 @@ export class HUDBaseToolbar extends BaseHUDPart {
|
||||
* selected: boolean,
|
||||
* element: HTMLElement,
|
||||
* index: number
|
||||
* puzzleLocked: boolean,
|
||||
* puzzleLocked: boolean;
|
||||
* class: typeof MetaBuilding,
|
||||
* }>} */
|
||||
this.buildingHandles = {};
|
||||
}
|
||||
@ -106,7 +108,7 @@ export class HUDBaseToolbar extends BaseHUDPart {
|
||||
);
|
||||
itemContainer.setAttribute("data-icon", "building_icons/" + metaBuilding.getId() + ".png");
|
||||
itemContainer.setAttribute("data-id", metaBuilding.getId());
|
||||
binding.add(() => this.selectBuildingForPlacement(metaBuilding));
|
||||
binding.add(() => this.togglePuzzleLock(metaBuilding));
|
||||
|
||||
this.trackClicks(itemContainer, () => this.selectBuildingForPlacement(metaBuilding), {
|
||||
clickSound: null,
|
||||
@ -121,12 +123,13 @@ export class HUDBaseToolbar extends BaseHUDPart {
|
||||
});
|
||||
|
||||
this.buildingHandles[metaBuilding.id] = {
|
||||
metaBuilding,
|
||||
metaBuilding: metaBuilding,
|
||||
element: itemContainer,
|
||||
unlocked: false,
|
||||
selected: false,
|
||||
index: i,
|
||||
puzzleLocked: false,
|
||||
class: allBuildings[i],
|
||||
};
|
||||
}
|
||||
|
||||
@ -154,7 +157,7 @@ export class HUDBaseToolbar extends BaseHUDPart {
|
||||
let recomputeSecondaryToolbarVisibility = false;
|
||||
for (const buildingId in this.buildingHandles) {
|
||||
const handle = this.buildingHandles[buildingId];
|
||||
const newStatus = handle.metaBuilding.getIsUnlocked(this.root);
|
||||
const newStatus = !handle.puzzleLocked && handle.metaBuilding.getIsUnlocked(this.root);
|
||||
if (handle.unlocked !== newStatus) {
|
||||
handle.unlocked = newStatus;
|
||||
handle.element.classList.toggle("unlocked", newStatus);
|
||||
@ -271,8 +274,24 @@ export class HUDBaseToolbar extends BaseHUDPart {
|
||||
return STOP_PROPAGATION;
|
||||
}
|
||||
|
||||
const entityManager = this.root.entityMgr;
|
||||
for (const entity of entityManager.getAllWithComponent(StaticMapEntityComponent)) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
if (staticComp.getMetaBuilding().id === metaBuilding.id) {
|
||||
this.root.map.removeStaticEntity(entity);
|
||||
entityManager.destroyEntity(entity);
|
||||
}
|
||||
}
|
||||
entityManager.processDestroyList();
|
||||
|
||||
const currentMetaBuilding = this.root.hud.parts.buildingPlacer.currentMetaBuilding;
|
||||
if (currentMetaBuilding.get() == metaBuilding) {
|
||||
currentMetaBuilding.set(null);
|
||||
}
|
||||
|
||||
const handle = this.buildingHandles[metaBuilding.getId()];
|
||||
handle.puzzleLocked = !handle.puzzleLocked;
|
||||
handle.element.classList.toggle("unlocked", handle.puzzleLocked);
|
||||
|
||||
this.root.soundProxy.playUiClick();
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import { createLogger } from "../../core/logging";
|
||||
import { HUDPuzzleCompleteNotification } from "../hud/parts/puzzle_complete_notification";
|
||||
import { HUDPuzzlePlaySettings } from "../hud/parts/puzzle_play_settings";
|
||||
import { MetaBlockBuilding } from "../buildings/block";
|
||||
import { gMetaBuildingRegistry } from "../../core/global_registries";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
|
||||
const logger = createLogger("puzzle-play");
|
||||
|
@ -36,6 +36,7 @@ export class ClientAPI {
|
||||
if (G_IS_DEV) {
|
||||
return "http://localhost:15001";
|
||||
}
|
||||
return "https://api-staging.shapez.io";
|
||||
if (window.location.host === "beta.shapez.io") {
|
||||
return "https://api-staging.shapez.io";
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { StaticMapEntityComponent } from "../game/components/static_map_entity";
|
||||
import { ShapeItem } from "../game/items/shape_item";
|
||||
import { Vector } from "../core/vector";
|
||||
import { MetaConstantProducerBuilding } from "../game/buildings/constant_producer";
|
||||
import { defaultBuildingVariant } from "../game/meta_building";
|
||||
import { defaultBuildingVariant, MetaBuilding } from "../game/meta_building";
|
||||
import { gMetaBuildingRegistry } from "../core/global_registries";
|
||||
import { MetaGoalAcceptorBuilding } from "../game/buildings/goal_acceptor";
|
||||
import { createLogger } from "../core/logging";
|
||||
@ -82,6 +82,18 @@ export class PuzzleSerializer {
|
||||
|
||||
const mode = /** @type {PuzzleGameMode} */ (root.gameMode);
|
||||
|
||||
const handles = root.hud.parts.buildingsToolbar.buildingHandles;
|
||||
const ids = gMetaBuildingRegistry.getAllIds();
|
||||
|
||||
/** @type {Array<typeof MetaBuilding>} */
|
||||
let excludedBuildings = [];
|
||||
for (let i = 0; i < ids.length; ++i) {
|
||||
const handle = handles[ids[i]];
|
||||
if (handle && handle.puzzleLocked) {
|
||||
excludedBuildings.push(handle.class);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
version: 1,
|
||||
buildings,
|
||||
@ -90,7 +102,7 @@ export class PuzzleSerializer {
|
||||
h: mode.zoneHeight,
|
||||
},
|
||||
//read from the toolbar when making a puzzle
|
||||
excludedBuildings: [MetaBlockBuilding],
|
||||
excludedBuildings,
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user