Scroll To Bottom Mystery Master Build PHP Puzzle Parts Member

build-puzzle-parts

This metawork article explains how I build the PHP files for each part of a puzzle. For puzzles that have been solved by the Mystery Master application, there is additional information about the puzzle itself, and about solving the puzzle. If you are a member, there are several links along the bottom of a puzzle page. Here is a brief description of each link.

These pages are in subfolders under the help folder: The analysis folder, the puzzle folder (before the puzzle was solved), and the solved folder (after the puzzle was solved). The pages in each folder have the same name as the puzzle. Note: These folders are not "listable" - you need to click a link on the puzzle page.

The JavaScript module build-puzzle-parts.mjs builds the puzzle part files for one or all puzzles, before and/or after a puzzle is solved. The main folder is metawork/parts, with subfolders puzzle and solved. Some of the following subfolders contain files that show up as links at the bottom of a puzzle page.

The Viewer object (aka viewer) sets the nodeFlag according to it's environment (server or browser). If the viewer is running on the server (node mode), it calls on the Filer module in respect to the build options to create the files. Below is pseudocode for each participating viewer event.

constructor if (okAllPuzzles) { init variables; okAutorun = true; call doNextPuzzle; }
doNextPuzzle ++puzzleNum; load puzzle by name; call setPuzzle;
setPuzzle if (okSavePuzzle) saves puzzle parts under "puzzle" folder; if (okAutorun) solve puzzle;
saySolution if (okSaveSolved) saves puzzle parts under "solved" folder; if (okAllPuzzles) solver.quitFlag = true;
sayPause if (okAllPuzzles and caller is sayStopped) call doNextPuzzle;

TODO write SQL UPDATE statements to one of two files so that a database table can be updated. Below is the source code.

/* jshint esversion: 6 */
// 1. Change cwd: cd /projects/mysterymaster.com/metawork/js/server
// 2. Run script: node build-puzzle-parts.mjs

import { getPuzzle } from "./Filer.js";
import { Viewer }    from "../viewer/Viewer.js";

const okAllPuzzles = false; // Load all puzzles or just one?
const okSavePuzzle = true;  // Save parts to puzzle folder?
const okSaveSolved = true;  // Save parts to solved folder?

// Name of puzzle to load if okAllPuzzles is false.
const puzzleName = "ADayAtTheZoo";

// Builds puzzle part files for one or all puzzles.
const viewer = new Viewer(okAllPuzzles, okSavePuzzle, okSaveSolved);
if (!okAllPuzzles) {
    const puzzle = getPuzzle(viewer.solver, puzzleName);
    viewer.setPuzzle(puzzle);
    viewer.doWork();
}