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

Puzzle mode, part 4

This commit is contained in:
tobspr 2021-04-30 17:36:23 +02:00
parent 4c3846f55e
commit 569921b51a
5 changed files with 71 additions and 3 deletions

View File

@ -30,6 +30,7 @@ export class MetaGoalAcceptorBuilding extends MetaBuilding {
{
pos: new Vector(0, 0),
directions: [enumDirection.bottom],
filter: "shape",
},
],
})

View File

@ -2,11 +2,13 @@ import { globalConfig, THIRDPARTY_URLS } from "../../../core/config";
import { createLogger } from "../../../core/logging";
import { DialogWithForm } from "../../../core/modal_dialog_elements";
import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms";
import { STOP_PROPAGATION } from "../../../core/signal";
import { fillInLinkIntoTranslation, makeDiv } from "../../../core/utils";
import { PuzzleSerializer } from "../../../savegame/puzzle_serializer";
import { T } from "../../../translations";
import { ConstantSignalComponent } from "../../components/constant_signal";
import { GoalAcceptorComponent } from "../../components/goal_acceptor";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { ShapeItem } from "../../items/shape_item";
import { ShapeDefinition } from "../../shape_definition";
import { BaseHUDPart } from "../base_hud_part";
@ -163,5 +165,13 @@ export class HUDPuzzleReview extends BaseHUDPart {
return T.puzzleMenu.validation.goalAcceptorRateNotMet;
}
}
// Check if all buildings are within the area
const entities = this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent);
for (const entity of entities) {
if (this.root.systemMgr.systems.zone.prePlacementCheck(entity) === STOP_PROPAGATION) {
return T.puzzleMenu.validation.buildingOutOfBounds;
}
}
}
}

View File

@ -8,6 +8,8 @@ import { globalConfig } from "../../core/config";
import { STOP_PROPAGATION } from "../../core/signal";
import { GameSystem } from "../game_system";
import { THEME } from "../theme";
import { Entity } from "../entity";
import { Vector } from "../../core/vector";
export class ZoneSystem extends GameSystem {
/** @param {GameRoot} root */
@ -21,6 +23,12 @@ export class ZoneSystem extends GameSystem {
});
}
/**
*
* @param {Entity} entity
* @param {Vector | undefined} tile
* @returns
*/
prePlacementCheck(entity, tile = null) {
const staticComp = entity.components.StaticMapEntity;
@ -36,10 +44,15 @@ export class ZoneSystem extends GameSystem {
}
const transformed = staticComp.getTileSpaceBounds();
if (tile) {
transformed.x += tile.x;
transformed.y += tile.y;
}
let withinAnyZone = false;
for (const zone of zones) {
if (zone.expandedInAllDirections(-1).containsRect(transformed)) {
const intersection = zone.getIntersection(transformed);
if (intersection && intersection.w * intersection.h === transformed.w * transformed.h) {
withinAnyZone = true;
}
}

View File

@ -1,3 +1,6 @@
import { enumConstantSignalType } from "../game/components/constant_signal";
import { StaticMapEntityComponent } from "../game/components/static_map_entity";
import { ShapeItem } from "../game/items/shape_item";
import { GameRoot } from "../game/root";
export class PuzzleSerializer {
@ -10,9 +13,47 @@ export class PuzzleSerializer {
generateDumpFromGameRoot(root, sanityChecks = true) {
console.log("serializing", root);
let buildings = [];
for (const entity of root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity;
const signalComp = entity.components.ConstantSignal;
if (signalComp) {
assert(signalComp.type === enumConstantSignalType.wireless, "not a wireless signal");
assert(signalComp.signal.getItemType() === "shape", "not a shape signal");
buildings.push({
type: "emitter",
item: /** @type {ShapeItem} */ (signalComp.signal).definition.getHash(),
pos: {
x: staticComp.origin.x,
y: staticComp.origin.y,
r: staticComp.rotation,
},
});
continue;
}
const goalComp = entity.components.GoalAcceptor;
if (goalComp) {
assert(goalComp.item, "goals is missing item");
assert(goalComp.item.getItemType() === "shape", "goal is not an item");
buildings.push({
type: "goal",
item: /** @type {ShapeItem} */ (goalComp.item).definition.getHash(),
pos: {
x: staticComp.origin.x,
y: staticComp.origin.y,
r: staticComp.rotation,
},
});
continue;
}
}
return {
type: "puzzle",
contents: "foo",
buildings,
bounds: root.gameMode.getBuildableZones()[0],
};
}
}

View File

@ -142,6 +142,9 @@ puzzleMenu:
One or more Goal Acceptors have not yet assigned an item. Deliver a shape to them to set a goal.
goalAcceptorRateNotMet: >-
One or more Goal Acceptors are not getting enough items. Make sure that the indicators are green for all acceptors.
buildingOutOfBounds: >-
One ore more buildings are outside of the buildable area. Either increase the area or remove them.
dialogs:
buttons:
ok: OK