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:
parent
4c3846f55e
commit
569921b51a
@ -30,6 +30,7 @@ export class MetaGoalAcceptorBuilding extends MetaBuilding {
|
|||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: [enumDirection.bottom],
|
||||||
|
filter: "shape",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -2,11 +2,13 @@ import { globalConfig, THIRDPARTY_URLS } from "../../../core/config";
|
|||||||
import { createLogger } from "../../../core/logging";
|
import { createLogger } from "../../../core/logging";
|
||||||
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
||||||
import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms";
|
import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms";
|
||||||
|
import { STOP_PROPAGATION } from "../../../core/signal";
|
||||||
import { fillInLinkIntoTranslation, makeDiv } from "../../../core/utils";
|
import { fillInLinkIntoTranslation, makeDiv } from "../../../core/utils";
|
||||||
import { PuzzleSerializer } from "../../../savegame/puzzle_serializer";
|
import { PuzzleSerializer } from "../../../savegame/puzzle_serializer";
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
import { ConstantSignalComponent } from "../../components/constant_signal";
|
import { ConstantSignalComponent } from "../../components/constant_signal";
|
||||||
import { GoalAcceptorComponent } from "../../components/goal_acceptor";
|
import { GoalAcceptorComponent } from "../../components/goal_acceptor";
|
||||||
|
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||||
import { ShapeItem } from "../../items/shape_item";
|
import { ShapeItem } from "../../items/shape_item";
|
||||||
import { ShapeDefinition } from "../../shape_definition";
|
import { ShapeDefinition } from "../../shape_definition";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
@ -163,5 +165,13 @@ export class HUDPuzzleReview extends BaseHUDPart {
|
|||||||
return T.puzzleMenu.validation.goalAcceptorRateNotMet;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import { globalConfig } from "../../core/config";
|
|||||||
import { STOP_PROPAGATION } from "../../core/signal";
|
import { STOP_PROPAGATION } from "../../core/signal";
|
||||||
import { GameSystem } from "../game_system";
|
import { GameSystem } from "../game_system";
|
||||||
import { THEME } from "../theme";
|
import { THEME } from "../theme";
|
||||||
|
import { Entity } from "../entity";
|
||||||
|
import { Vector } from "../../core/vector";
|
||||||
|
|
||||||
export class ZoneSystem extends GameSystem {
|
export class ZoneSystem extends GameSystem {
|
||||||
/** @param {GameRoot} root */
|
/** @param {GameRoot} root */
|
||||||
@ -21,6 +23,12 @@ export class ZoneSystem extends GameSystem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Entity} entity
|
||||||
|
* @param {Vector | undefined} tile
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
prePlacementCheck(entity, tile = null) {
|
prePlacementCheck(entity, tile = null) {
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
|
||||||
@ -36,10 +44,15 @@ export class ZoneSystem extends GameSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const transformed = staticComp.getTileSpaceBounds();
|
const transformed = staticComp.getTileSpaceBounds();
|
||||||
|
if (tile) {
|
||||||
|
transformed.x += tile.x;
|
||||||
|
transformed.y += tile.y;
|
||||||
|
}
|
||||||
|
|
||||||
let withinAnyZone = false;
|
let withinAnyZone = false;
|
||||||
for (const zone of zones) {
|
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;
|
withinAnyZone = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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";
|
import { GameRoot } from "../game/root";
|
||||||
|
|
||||||
export class PuzzleSerializer {
|
export class PuzzleSerializer {
|
||||||
@ -10,9 +13,47 @@ export class PuzzleSerializer {
|
|||||||
generateDumpFromGameRoot(root, sanityChecks = true) {
|
generateDumpFromGameRoot(root, sanityChecks = true) {
|
||||||
console.log("serializing", root);
|
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 {
|
return {
|
||||||
type: "puzzle",
|
buildings,
|
||||||
contents: "foo",
|
bounds: root.gameMode.getBuildableZones()[0],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
One or more Goal Acceptors have not yet assigned an item. Deliver a shape to them to set a goal.
|
||||||
goalAcceptorRateNotMet: >-
|
goalAcceptorRateNotMet: >-
|
||||||
One or more Goal Acceptors are not getting enough items. Make sure that the indicators are green for all acceptors.
|
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:
|
dialogs:
|
||||||
buttons:
|
buttons:
|
||||||
ok: OK
|
ok: OK
|
||||||
|
Loading…
Reference in New Issue
Block a user