Skip to content

RPG R5: levels, character sheets and campaigns - #74

Merged
luoxin9510 merged 5 commits into
mainfrom
rpg-r5-progression
Nov 10, 2026
Merged

luoxin9510 merged 5 commits into
mainfrom
rpg-r5-progression

Conversation

@luoxin9510

Copy link
Copy Markdown
Owner

RPG R5 (docs/rpg-engine-prd.md §4.4, §4.6): levels, perks and campaigns through character sheets.

Levels

  • levels: { resource: xp, at: [0, 4, 10] } generates VAR level, next_level_at() (0 at the top), level_up_ready() and level_up() (returns whether it went up).
  • hud().level drives a level row on the status bar, with a mark when a level can be taken; the web page shows the same.
  • Perks are ordinary items without a slot. They don't use slot: perk, because a slot holds only one item.

Character sheets and campaigns

  • A line tagged #sheet writes the character being played as a note in the game's sheets: folder (relative to the game's folder, default 角色/Characters). It writes only when the line first appears after a choice; back, load and replay never write. The command "Save character sheet" and api.saveSheet() do the same.
  • The note's frontmatter is a characters entry: skills, items, equipped, counts, level, resources, statuses. Writing again replaces the frontmatter and adds a section to the body, so the note becomes the campaign's record.
  • The next adventure writes characters: { from: ../角色 }; resolveCharacters reads the sheets, and the folder and its notes are compile dependencies.
  • Characters written in game.md can set the same new fields.
  • Pure parts live in src/game/sheet.ts (sheetOf, sheetName, sheetNote, characterFromNote). The note itself is written in main.ts.
  • New problems: levelsResource, levelsOrder, characterLevel, characterResource, characterStatus, charactersFolder.

Acceptance (tutorial 10.5, to be added to the vault)

A hero plays two adventures with a camp in between, all three on a small shared pack. Level, perk, equipment, herbs and a wound carry over through 角色/阿岚.md. All three pass check-ink --all --novelty in zh and en.

Still to do: the Obsidian check and writing the example into the vault. The plugin has to be built into the vault from outside the sandbox first.

Tests: 596 pass; lint is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_015vdVgYTb9jm7MRdePSgs8B

luoxin9510 and others added 3 commits November 10, 2026 21:01
levels: { resource, at } generates VAR level, next_level_at(), level_up_ready()
and level_up(); hud().level, shown on the panel's status (with a mark when a
level can be taken) and the web page. Perks are ordinary items.

A character can carry level, resources and statuses (loaded by
pick_character). The character being played is a sheet (src/game/sheet.ts:
sheetOf, sheetName, sheetNote): a line tagged #sheet after a choice, the
command save-sheet or api.saveSheet() writes it into the game's sheets
folder, frontmatter replaced and the epilogue added to the body. The next
adventure reads them with characters: { from: folder } (resolveCharacters,
the folder and notes are dependencies; problem charactersFolder).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015vdVgYTb9jm7MRdePSgs8B
A character can say what it wears (equipped:); a sheet writes it, so the
next adventure starts with the same weapon rather than the first carried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015vdVgYTb9jm7MRdePSgs8B
Comment thread src/main.ts Outdated
private sheetAfterMove(): void {
const session = this.runs.session;
if (!session || !this.runs.game) return;
const made = session.choicesMade.length, seen = this.sheetSeen.get(session) ?? made;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: seen defaults to made the first time a session is seen, so made <= seen holds and that first choice is never examined. A #sheet line on the first choice after a session starts (or restarts) writes nothing, and any later one depends on this map being updated at the right moments. Default seen to 0 for a new session. On replay or resume, also make sure old choices don't re-trigger a write: the afterResume path or back followed by a new choice can leave made <= seen and skip a real new choice. Add a test for this; tests/campaign.test.ts only covers the pure parts.

Comment thread src/main.ts Outdated
new Notice(T().templateBadFolder(engine.config.sheets ?? ""));
return { path: null };
}
const path = normalizePath(`${folder}/${sheetName(sheet, engine.language || getLanguage())}.md`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name comes from the character's name in the current play language. Playing the same hero in zh and then en writes two notes with the same id:, and the next adventure's characters.from will then read duplicate characters. Name the file by the id, or look up the existing sheet by id. Also, modify replaces the whole frontmatter, which drops any fields the player added by hand. Merge into the existing frontmatter instead. Minor: folder.startsWith("..") also rejects a folder like ..notes; compare against ../ or .. exactly.

@claude

claude Bot commented Nov 10, 2026

Copy link
Copy Markdown

Review summary: I would not merge as is.

  • Bug: sheetAfterMove in src/main.ts never looks at the first choice of a session, so a #sheet line there writes nothing (inline comment). The back and resume cases look fragile too, and the main.ts wiring has no test.
  • Sheet files: a sheet is named after the localized character name, so playing in both languages writes duplicate ids. An update also replaces the whole frontmatter, which drops fields the player added (inline comment).
  • Nit: the new levelInk doc comment sits between the existing records doc comment and its function in inkgen.ts, so the records comment now sits above the wrong function.

The levels, config validation, sheet, i18n and web-export parts look consistent, and the pure parts are tested.

🤖 Generated with Claude Code

…dy doc comments

Review fixes: the #sheet check compared choice counts per session and missed a
#sheet right after a session began or a run was picked up again. The
controller now calls RunHost.afterChoose with the paragraphs of each choice
the player takes (never on back, replay, load or a language switch). The
doc comments of recordInk and liveJournal had been separated from them by
inserted functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015vdVgYTb9jm7MRdePSgs8B
Comment thread src/main.ts
new Notice(T().sheetNoCharacter);
return { path: null };
}
const folder = joinPath(`${folderOf(root)}${engine.config.sheets ?? T().sheetsFolder}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sheets folder is not checked against the compile dependencies. JournalNotes.create refuses a path inside a dependency folder; this doesn't. If a game reads characters: { from: <folder> } and also writes its sheet to that folder, which is the camp-between-adventures case, saving the sheet changes a dependency. That triggers a recompile with a new character list in the middle of the run (an "update" in player mode, otherwise a replay), and the player is thrown out of the ending they just reached. Please either refuse or defer the write when the target is a dependency, as the journal does, or add a test showing it is safe.

@claude

claude Bot commented Nov 10, 2026

Copy link
Copy Markdown

Review: I would not merge as is, only because of the inline comment. I did not run the test suite or lint.

  • Bug (plausible): saveSheet can write into a folder the story depends on (characters.from). The write then causes a recompile mid-run. The live journal guards against this; the sheet does not.
  • Rule checks: The changes I read follow CLAUDE.md: new text goes through T() in both languages, src/game/sheet.ts is pure and has tests, and I saw no Node APIs. stringifyYaml is part of the Obsidian API, so please confirm it exists at the minAppVersion in manifest.json (1.13.0, per the changelog).
  • Minor: saveSheet reads the old note, then modifies it with no queue. Two quick saves could drop one epilogue. The file name depends on the current UI language, so switching language mid-campaign would start a second sheet for the same character.

🤖 Generated with Claude Code

…s own write

Review follow-ups: two saves in a row could lose an epilogue (now queued with
the run's writes); a sheet is found by its frontmatter id, so a language
switch does not start a second one; a game that reads the folder it writes
its sheet into (a camp) no longer recompiles from that write mid-run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015vdVgYTb9jm7MRdePSgs8B
@luoxin9510

Copy link
Copy Markdown
Owner Author

Addressed in 4669418:

  • Writing into a dependency folder: the generated presets live in _engine.ink, which a sheet write does not change, so the run itself replays the same. The write did trigger a recompile (a new version, the player-mode update banner). Change events for a file the panel wrote are now ignored for 3 s. The engine-stale warning that follows is intended: the next play needs regenerated presets.
  • stringifyYaml is long-standing Obsidian API, available at 1.13.0.
  • Two quick saves: the state is read at once and the write is queued with the run's other writes (runs.enqueue).
  • File name and language: the character's sheet is found by its frontmatter id first; a new file is named only when none exists.

Comment thread src/main.ts
}
const existing = this.app.vault.getAbstractFileByPath(path);
const oldBody = existing instanceof TFile ? splitNote(await this.app.vault.read(existing), parseYaml).body : "";
const text = sheetNote(stringifyYaml(sheet), oldBody, epilogue, storyName(root, this.app.vault.getName()), stamp(new Date()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sheetNote replaces the whole frontmatter with stringifyYaml(sheet). Anything the player added to a sheet by hand is lost on the next save: extra fields, comments, a localized name written differently, and a playable: false that sheetOf only carries when it's already in config. The body is kept, the frontmatter is not. Consider merging the old frontmatter under the new sheet fields, or say in the docs that the frontmatter is generated.

Comment thread src/main.ts
// A line tagged #sheet among the text a choice produced writes the character sheet, that line as the epilogue.
afterChoose: (paragraphs) => {
const line = paragraphs.find((p) => p.tags.some((t) => t.trim() === "sheet"));
if (line) void this.saveSheet(line.text);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each choice that shows a #sheet line appends a new ## title · date section. Back, then choosing the same ending again, or reaching the ending twice (a replay-by-choosing loop in the same session), adds duplicate epilogues, and the earlier file write is not undone. Not data loss, but the campaign record can get duplicate sections. Consider skipping the append when the last section's epilogue text is identical.

@claude

claude Bot commented Nov 10, 2026

Copy link
Copy Markdown

Review: no blocking bugs found in the new code. Checked sheet.ts, resolveCharacters, the level ink, saveSheet/writeSheet and the controller hook. Rule checks: no Node APIs in src/, the new strings have both zh and en, the sheet code is pure and has tests (tests/campaign.test.ts). I did not run the test suite, lint or a build, and did not run the plugin in Obsidian. Two minor inline notes: the frontmatter is overwritten on every save, and a repeated #sheet line appends duplicate epilogue sections. I would merge as is; the two notes are optional follow-ups.

@luoxin9510
luoxin9510 merged commit c3b55fa into main Nov 10, 2026
2 checks passed
@luoxin9510
luoxin9510 deleted the rpg-r5-progression branch November 10, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant