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

Allow completing puzzles

This commit is contained in:
tobspr 2021-04-30 21:18:40 +02:00
parent 31811f20b7
commit 272508ff87

View File

@ -11,11 +11,15 @@ export class GoalAcceptorSystem extends GameSystemWithFilter {
/** @param {GameRoot} root */
constructor(root) {
super(root, [GoalAcceptorComponent]);
this.puzzleCompleted = false;
}
update() {
const now = this.root.time.now();
let allAccepted = true;
for (let i = 0; i < this.allEntities.length; ++i) {
const entity = this.allEntities[i];
const goalComp = entity.components.GoalAcceptor;
@ -25,6 +29,20 @@ export class GoalAcceptorSystem extends GameSystemWithFilter {
d =>
now - d.time < globalConfig.goalAcceptorMinimumDurationSeconds && d.item === goalComp.item
);
if (goalComp.deliveryHistory.length < goalComp.getRequiredDeliveryHistorySize()) {
allAccepted = false;
}
}
if (
!this.puzzleCompleted &&
this.root.gameInitialized &&
allAccepted &&
!this.root.gameMode.getIsEditor()
) {
this.root.hud.parts.dialogs.showInfo("Puzzle completed", "Congrats!");
this.puzzleCompleted = true;
}
}