Repository navigation
RPG R5: levels, character sheets and campaigns - #74
Conversation
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
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
| 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; |
There was a problem hiding this comment.
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.
| new Notice(T().templateBadFolder(engine.config.sheets ?? "")); | ||
| return { path: null }; | ||
| } | ||
| const path = normalizePath(`${folder}/${sheetName(sheet, engine.language || getLanguage())}.md`); |
There was a problem hiding this comment.
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.
|
Review summary: I would not merge as is.
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
| new Notice(T().sheetNoCharacter); | ||
| return { path: null }; | ||
| } | ||
| const folder = joinPath(`${folderOf(root)}${engine.config.sheets ?? T().sheetsFolder}`); |
There was a problem hiding this comment.
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.
|
Review: I would not merge as is, only because of the inline comment. I did not run the test suite or lint.
🤖 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
|
Addressed in 4669418:
|
| } | ||
| 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())); |
There was a problem hiding this comment.
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.
| // 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); |
There was a problem hiding this comment.
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.
|
Review: no blocking bugs found in the new code. Checked |
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] }generatesVAR level,next_level_at()(0 at the top),level_up_ready()andlevel_up()(returns whether it went up).hud().leveldrives a level row on the status bar, with a mark when a level can be taken; the web page shows the same.slot: perk, because a slot holds only one item.Character sheets and campaigns
#sheetwrites the character being played as a note in the game'ssheets: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" andapi.saveSheet()do the same.charactersentry: 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.characters: { from: ../角色 };resolveCharactersreads the sheets, and the folder and its notes are compile dependencies.game.mdcan set the same new fields.src/game/sheet.ts(sheetOf,sheetName,sheetNote,characterFromNote). The note itself is written inmain.ts.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 passcheck-ink --all --noveltyin 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