English
Generate twenty quests from a table
You have a list, programs to install or habits to keep, and you want one quest per row without writing twenty blocks by hand.
Solution
Add the SDK to your project as in Check a file from a Node script, then save this script as generate-quests.mjs:
generate-quests.mjs
js
// Writes one quest per row of a table into a quest file, checks it, and saves it only if it passes.
// Usage: node generate-quests.mjs my-pack/tools.json
import { writeFileSync } from "node:fs";
import { formatProblem, validate } from "@altasystem/sdk";
// One row per program: its command, then its name in English and in French.
const TABLE = [
["git", "Git", "Git"], ["node", "Node.js", "Node.js"], ["python3", "Python", "Python"], ["jq", "jq", "jq"],
["rg", "ripgrep", "ripgrep"], ["fd", "fd", "fd"], ["ffmpeg", "FFmpeg", "FFmpeg"], ["gh", "GitHub CLI", "la CLI GitHub"],
["tmux", "tmux", "tmux"], ["htop", "htop", "htop"], ["wget", "wget", "wget"], ["tree", "tree", "tree"],
["bat", "bat", "bat"], ["fzf", "fzf", "fzf"], ["sqlite3", "SQLite", "SQLite"], ["pandoc", "Pandoc", "Pandoc"],
["yt-dlp", "yt-dlp", "yt-dlp"], ["imagemagick", "ImageMagick", "ImageMagick"], ["uv", "uv", "uv"], ["deno", "Deno", "Deno"],
];
const quest = ([bin, en, fr]) => ({
id: `tool-${bin}`,
uid: `core.my-pack.tool-${bin}`,
act: 1,
giver: "operator",
title: { en: `Have ${en} at hand`, fr: `Avoir ${fr} sous la main` },
reward: { xp: 20 },
steps: [{
id: "installed",
kind: "check",
title: { en: `${en} is installed`, fr: `${fr} est installé` },
check: { type: "bin", name: bin },
}],
});
const file = process.argv[2] ?? "my-pack/tools.json";
const doc = { schema: "alta.quests/0.3", branch: "core", quests: TABLE.map(quest) };
const result = validate(doc);
for (const p of result.problems) console.log(formatProblem(p, file));
if (result.ok) {
writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
console.log(`wrote ${doc.quests.length} quests to ${file}`);
} else process.exitCode = 1;examples/recipes/sdk/generate-quests.mjs
Run it next to your pack, then check the pack:
Terminal
sh
node generate-quests.mjs my-pack/tools.json
alta lint my-packOutput
text
wrote 20 quests to my-pack/tools.json
ok my-pack/quests.json (quests)
ok my-pack/tools.json (quests)
2 checked, 0 errors, 0 warningsHow it works
Each row becomes a quest with one check step: a bin check completes it as soon as the program is installed, so the player never clicks "I did it". The script checks the whole document with validate before writing it, so a typo in the table (two rows with the same command, a program name with a capital letter) stops the script instead of producing a broken file. alta lint then checks the new file with the rest of your pack.
Variants
- Let the game install it. Make the step an
actionthat runspkg.install; its program must be in that executor's closed list. See Executors. - From a spreadsheet. Export it as CSV and build
TABLEfrom the lines of the file. - Builders.
actionStepandhumanStepof the SDK build valid steps that do something;stepProblemschecks steps alone.