From 6a6860b5da14841d30a77a3bc97ff509dcad4259 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 3 Jan 2024 14:28:50 -0700 Subject: [PATCH] Allow arbitrary metadata on puzzles --- CHANGELOG.md | 7 ++++++- pkg/transpile/puzzle.go | 10 +++++++--- theme/moth.mjs | 10 ++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca958ae..ad9040f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Answer hashes are now the first 4 characters of the hex-encoded SHA1 digest - Reworked the built-in theme -- [moth.mjs](theme/moth.mjs) is now the standard MOTH library for ECMAScript - Devel mode no longer accepts an empty team ID - messages.html moved into theme + +### Added +- [moth.mjs](theme/moth.mjs) is now the standard MOTH library for ECMAScript - Exported state now includes "Enabled" boolean +- New `Extra` field on puzzles will allow addition of arbitrary fields to be attached to puzzles. + PNNL's SCTR Osprey will use this to standardize fields for their custom theme, + but it can be generally used for anything. ## [v4.4.11] - 2023-04-11 ### Changed diff --git a/pkg/transpile/puzzle.go b/pkg/transpile/puzzle.go index 23d8a90..700d8fa 100644 --- a/pkg/transpile/puzzle.go +++ b/pkg/transpile/puzzle.go @@ -60,6 +60,13 @@ type Puzzle struct { // AnswerHashes contains hashes of all answers for this puzzle AnswerHashes []string + // Answers lists all acceptable answers, omitted in mothballs + Answers []string + + // Extra is send unchanged to the client. + // Eventually, Objective, KSAs, and Success will move into Extra. + Extra map[string]any + // Objective is the learning objective for this puzzle Objective string @@ -74,9 +81,6 @@ type Puzzle struct { // Mastery describes the work required to be considered mastering this puzzle's conceptss Mastery string } - - // Answers lists all acceptable answers, omitted in mothballs - Answers []string } func (puzzle *Puzzle) computeAnswerHashes() { diff --git a/theme/moth.mjs b/theme/moth.mjs index 4e2854d..937e745 100644 --- a/theme/moth.mjs +++ b/theme/moth.mjs @@ -178,11 +178,17 @@ class Puzzle { this.Answers ||= [] this.Attachments ||= [] this.Authors ||= [] + this.Scripts ||= [] + this.Debug ||= {} this.Debug.Errors ||= [] this.Debug.Hints ||= [] this.Debug.Log ||= [] - this.KSAs ||= [] - this.Scripts ||= [] + this.Extra ||= {} + + // Be ready to handle a future revision to the Puzzle structure + this.Objective ||= this.Extra.Objective + this.KSAs ||= this.Extra.KSAs || [] + this.Success ||= this.Extra.Success || {} } /**