From 95d2417683e7b665511968b324ff0059ab09fecc Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Fri, 7 May 2021 13:52:05 +0100 Subject: [PATCH] heavily improved validation and prevented autocompletion --- src/js/game/hud/parts/puzzle_editor_review.js | 31 ++++++++++++++----- translations/base-en.yaml | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/js/game/hud/parts/puzzle_editor_review.js b/src/js/game/hud/parts/puzzle_editor_review.js index f36b4ae4..b297c21f 100644 --- a/src/js/game/hud/parts/puzzle_editor_review.js +++ b/src/js/game/hud/parts/puzzle_editor_review.js @@ -49,23 +49,26 @@ export class HUDPuzzleEditorReview extends BaseHUDPart { // Manually simulate ticks this.root.logic.clearAllBeltsAndItems(); - const ticks = + const maxTicks = this.root.gameMode.getFixedTickrate() * globalConfig.puzzleValidationDurationSeconds; const deltaMs = this.root.dynamicTickrate.deltaMs; - logger.log("Simulating", ticks, "ticks, start=", this.root.time.now().toFixed(1)); + logger.log("Simulating up to", maxTicks, "ticks, start=", this.root.time.now().toFixed(1)); const now = performance.now(); - for (let i = 0; i < ticks; ++i) { - if (i % Math.round((ticks - 1) / 10) === 0) { - console.log("Ticking", Math.round((i / ticks) * 100) + "%"); - } - // Perform logic ticks + let simulatedTicks = 0; + for (let i = 0; i < maxTicks; ++i) { + // Perform logic tick this.root.time.performTicks(deltaMs, this.root.gameState.core.boundInternalTick); + simulatedTicks++; + if (!this.validatePuzzle()) { + break; + } } + const duration = performance.now() - now; logger.log( "Simulated", - ticks, + simulatedTicks, "ticks, end=", this.root.time.now().toFixed(1), "duration=", @@ -73,7 +76,19 @@ export class HUDPuzzleEditorReview extends BaseHUDPart { "ms" ); + console.log("duration: " + duration); closeLoading(); + + //if it took so little ticks that it must have autocompeted + if (simulatedTicks < 300) { + this.root.hud.parts.dialogs.showWarning( + T.puzzleMenu.validation.title, + T.puzzleMenu.validation.autoComplete + ); + return; + } + + //if we reached maximum ticks and the puzzle still isn't completed const validationError = this.validatePuzzle(); if (validationError) { this.root.hud.parts.dialogs.showWarning(T.puzzleMenu.validation.title, validationError); diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 565cf377..3a9bc9e7 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -151,6 +151,8 @@ puzzleMenu: One or more Goal Acceptors are not getting enough items. Make sure that the indicators are green for all acceptors. buildingOutOfBounds: >- One or more buildings are outside of the buildable area. Either increase the area or remove them. + autoComplete: >- + Your puzzle autocompletes itself! Please make sure your constant producers are not directly delivering to your goal acceptors. dialogs: buttons: