mirror of https://github.com/dirtbags/moth.git
Refer to server docs for Puzzle fields
This commit is contained in:
parent
47671b9a12
commit
8ff91e79ec
|
@ -37,23 +37,45 @@ type PuzzleDebug struct {
|
||||||
Summary string
|
Summary string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Puzzle contains everything about a puzzle that a client would see.
|
// Puzzle contains everything about a puzzle that a client will see.
|
||||||
type Puzzle struct {
|
type Puzzle struct {
|
||||||
Debug PuzzleDebug
|
// Debug contains debugging information, omitted in mothballs
|
||||||
Authors []string
|
Debug PuzzleDebug
|
||||||
Attachments []string
|
|
||||||
Scripts []string
|
// Authors names all authors of this puzzle
|
||||||
Body string
|
Authors []string
|
||||||
|
|
||||||
|
// Attachments is a list of filenames used by this puzzle
|
||||||
|
Attachments []string
|
||||||
|
|
||||||
|
// Scripts is a list of EMCAScript files needed by the client for this puzzle
|
||||||
|
Scripts []string
|
||||||
|
|
||||||
|
// Body is the HTML rendering of this puzzle
|
||||||
|
Body string
|
||||||
|
|
||||||
|
// AnswerPattern contains the pattern (regular expression?) used to match valid answers
|
||||||
AnswerPattern string
|
AnswerPattern string
|
||||||
AnswerHashes []string
|
|
||||||
Objective string
|
// AnswerHashes contains hashes of all answers for this puzzle
|
||||||
KSAs []string
|
AnswerHashes []string
|
||||||
Success struct {
|
|
||||||
|
// Objective is the learning objective for this puzzle
|
||||||
|
Objective string
|
||||||
|
|
||||||
|
// KSAs lists all KSAs achieved upon successfull completion of this puzzle
|
||||||
|
KSAs []string
|
||||||
|
|
||||||
|
// Success lists the criteria for successfully understanding this puzzle
|
||||||
|
Success struct {
|
||||||
|
// Acceptable describes the minimum work required to be considered successfully understanding this puzzle's concepts
|
||||||
Acceptable string
|
Acceptable string
|
||||||
Mastery string
|
|
||||||
|
// Mastery describes the work required to be considered mastering this puzzle's conceptss
|
||||||
|
Mastery string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Answers will be empty in a mothball
|
// Answers lists all acceptable answers, omitted in mothballs
|
||||||
Answers []string
|
Answers []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,14 @@ class Award {
|
||||||
* A puzzle.
|
* A puzzle.
|
||||||
*
|
*
|
||||||
* A new Puzzle only knows its category and point value.
|
* A new Puzzle only knows its category and point value.
|
||||||
* If you want to populate it with meta-information, you must call Get().
|
* If you want to populate it with meta-information, you must call Populate().
|
||||||
|
*
|
||||||
|
* Parameters created by Populate are described in the server source code:
|
||||||
|
* {@link https://pkg.go.dev/github.com/dirtbags/moth/v4/pkg/transpile#Puzzle}
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class Puzzle {
|
class Puzzle {
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {Server} server
|
* @param {Server} server
|
||||||
* @param {String} category
|
* @param {String} category
|
||||||
* @param {Number} points
|
* @param {Number} points
|
||||||
|
@ -44,71 +47,22 @@ class Puzzle {
|
||||||
* @type {Server}
|
* @type {Server}
|
||||||
*/
|
*/
|
||||||
this.server = server
|
this.server = server
|
||||||
/** Category this puzzle belongs to
|
|
||||||
* @type {String}
|
|
||||||
*/
|
|
||||||
this.Category = category
|
|
||||||
/** Point value of this puzzle
|
|
||||||
* @type {Number}
|
|
||||||
*/
|
|
||||||
this.Points = points
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Error returned trying to fetch this puzzle */
|
/** Category this puzzle belongs to */
|
||||||
Error = {
|
this.Category = String(category)
|
||||||
/** Status code provided by server */
|
|
||||||
Status: 0,
|
/** Point value of this puzzle */
|
||||||
/** Status text provided by server */
|
this.Points = Number(points)
|
||||||
StatusText: "",
|
|
||||||
/** Full text of server error */
|
/** Error returned trying to fetch this puzzle */
|
||||||
Body: "",
|
this.Error = {
|
||||||
}
|
/** Status code provided by server */
|
||||||
/** Hashes of answers
|
Status: 0,
|
||||||
* @type {String[]}
|
/** Status text provided by server */
|
||||||
*/
|
StatusText: "",
|
||||||
AnswerHashes = []
|
/** Full text of server error */
|
||||||
/** Pattern that answer should match
|
Body: "",
|
||||||
* @type {String[]}
|
}
|
||||||
*/
|
|
||||||
AnswerPattern = ""
|
|
||||||
/** Accepted answers
|
|
||||||
* @type {String[]}
|
|
||||||
*/
|
|
||||||
Answers = []
|
|
||||||
/** Other files attached to this puzzles
|
|
||||||
* @type {String[]}
|
|
||||||
*/
|
|
||||||
Attachments = []
|
|
||||||
/** This puzzle's authors
|
|
||||||
* @type {String[]}
|
|
||||||
*/
|
|
||||||
Authors = []
|
|
||||||
/** HTML body of this puzzle */
|
|
||||||
Body = ""
|
|
||||||
/** Debugging information */
|
|
||||||
Debug = {
|
|
||||||
Errors: [],
|
|
||||||
Hints: [],
|
|
||||||
Log: [],
|
|
||||||
Notes: "",
|
|
||||||
Summary: "",
|
|
||||||
}
|
|
||||||
/** KSAs met by solving this puzzle
|
|
||||||
* @type {String[]}
|
|
||||||
*/
|
|
||||||
KSAs = []
|
|
||||||
/** Learning objective for this puzzle */
|
|
||||||
Objective = ""
|
|
||||||
/** ECMAScript scripts needed for this puzzle
|
|
||||||
* @type {String[]}
|
|
||||||
*/
|
|
||||||
Scripts = []
|
|
||||||
/** Criteria for succeeding at this puzzle */
|
|
||||||
Success = {
|
|
||||||
/** Acceptable Minimum criteria for success */
|
|
||||||
Minimum: "",
|
|
||||||
/** Criteria for demonstrating mastery of this puzzle */
|
|
||||||
Mastery: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,19 +20,15 @@ async function init() {
|
||||||
let state = await server.GetState()
|
let state = await server.GetState()
|
||||||
|
|
||||||
doing("Retrieving all puzzles")
|
doing("Retrieving all puzzles")
|
||||||
let puzzles = state.Puzzles()
|
|
||||||
for (let p of puzzles) {
|
|
||||||
await p.Populate().catch(x => {})
|
|
||||||
}
|
|
||||||
|
|
||||||
doing("Filling table")
|
|
||||||
let puzzlerowTemplate = document.querySelector("template#puzzlerow")
|
let puzzlerowTemplate = document.querySelector("template#puzzlerow")
|
||||||
for (let tbody of document.querySelectorAll("tbody")) {
|
let puzzles = state.Puzzles()
|
||||||
for (let puzzle of puzzles) {
|
for (let puzzle of puzzles) {
|
||||||
|
await puzzle.Populate().catch(x => {})
|
||||||
|
for (let tbody of document.querySelectorAll("tbody")) {
|
||||||
let row = puzzlerowTemplate.content.cloneNode(true)
|
let row = puzzlerowTemplate.content.cloneNode(true)
|
||||||
row.querySelector(".category").textContent = puzzle.Category
|
row.querySelector(".category").textContent = puzzle.Category
|
||||||
row.querySelector(".points").textContent = puzzle.Points
|
row.querySelector(".points").textContent = puzzle.Points
|
||||||
row.querySelector(".ksas").textContent = puzzle.KSAs.join(" ")
|
row.querySelector(".ksas").textContent = (puzzle.KSAs || []).join(" ")
|
||||||
row.querySelector(".error").textContent = puzzle.Error.Body
|
row.querySelector(".error").textContent = puzzle.Error.Body
|
||||||
tbody.appendChild(row)
|
tbody.appendChild(row)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue