-
Notifications
You must be signed in to change notification settings - Fork 0
feat(rules,backend,web): narrative identity — epithet, appearance, traits, backstory #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { For } from "solid-js"; | ||
| import type { NarrativeForm } from "../lib/narrative.ts"; | ||
| import { MonoLabel, TextInput } from "./ui.tsx"; | ||
|
|
||
| // maxLength mirrors the rules-layer schema caps so writes can't be rejected | ||
| // for length (appearanceSchema / narrativeSchema in @riftforge/rules). | ||
| const APPEARANCE_FIELDS = [ | ||
| ["height", "HEIGHT", 40], | ||
| ["weight", "WEIGHT", 40], | ||
| ["age", "AGE", 40], | ||
| ["eyes", "EYES", 80], | ||
| ["origin", "ORIGIN", 120], | ||
| ["disposition", "DISPOSITION", 120], | ||
| ] as const satisfies readonly (readonly [keyof NarrativeForm, string, number])[]; | ||
|
|
||
| /** 12 traits × 60 chars + separators — the schema's worst legal case. */ | ||
| const TRAITS_INPUT_MAX = 12 * 60 + 11 * 2; | ||
|
|
||
| /** | ||
| * The player-authored identity fields — shared by the wizard's identity step | ||
| * and the dossier's edit panel. All optional: story, not mechanics. | ||
| */ | ||
| export function NarrativeFields(props: { | ||
| form: NarrativeForm; | ||
| onChange: <K extends keyof NarrativeForm>(field: K, value: string) => void; | ||
| }) { | ||
| return ( | ||
| <div class="space-y-3"> | ||
| <label class="block space-y-1"> | ||
| <MonoLabel>EPITHET — one line under the name</MonoLabel> | ||
| <TextInput | ||
| class="w-full" | ||
| maxLength={200} | ||
| placeholder='"The ley lines whisper, and she whispers back."' | ||
| value={props.form.epithet} | ||
| onInput={(e) => props.onChange("epithet", e.currentTarget.value)} | ||
| /> | ||
| </label> | ||
| <div class="grid grid-cols-2 gap-2 md:grid-cols-3"> | ||
| <For each={APPEARANCE_FIELDS}> | ||
| {([field, label, max]) => ( | ||
| <label class="block space-y-1"> | ||
| <MonoLabel>{label}</MonoLabel> | ||
| <TextInput | ||
| class="w-full" | ||
| maxLength={max} | ||
| value={props.form[field]} | ||
| onInput={(e) => props.onChange(field, e.currentTarget.value)} | ||
| /> | ||
| </label> | ||
| )} | ||
| </For> | ||
| </div> | ||
| <label class="block space-y-1"> | ||
| <MonoLabel>TRAITS — comma-separated, up to 12 (60 chars each)</MonoLabel> | ||
| <TextInput | ||
| class="w-full" | ||
| maxLength={TRAITS_INPUT_MAX} | ||
| placeholder="Magic Zone survivor, Coalition watchlist, D-Bee sympathizer" | ||
| value={props.form.traits} | ||
| onInput={(e) => props.onChange("traits", e.currentTarget.value)} | ||
| /> | ||
| </label> | ||
| <label class="block space-y-1"> | ||
| <MonoLabel>BACKSTORY — your words, the machine won't touch them</MonoLabel> | ||
| <textarea | ||
| rows={6} | ||
| maxLength={20_000} | ||
| class="notch-8 w-full border border-line bg-noir px-3 py-2 font-narrative text-[14px] text-fg placeholder:text-dead focus:border-amber" | ||
| placeholder="She walked out of the Magic Zone on her fourteenth birthday…" | ||
| value={props.form.backstory} | ||
| onInput={(e) => props.onChange("backstory", e.currentTarget.value)} | ||
| /> | ||
| </label> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { Narrative } from "@riftforge/rules"; | ||
|
|
||
| /** Raw form strings for the narrative fields (wizard + dossier editor). */ | ||
| export interface NarrativeForm { | ||
| epithet: string; | ||
| height: string; | ||
| weight: string; | ||
| age: string; | ||
| eyes: string; | ||
| origin: string; | ||
| disposition: string; | ||
| /** Comma-separated in the form; split into chips on save. */ | ||
| traits: string; | ||
| backstory: string; | ||
| } | ||
|
|
||
| export const emptyNarrativeForm: NarrativeForm = { | ||
| epithet: "", | ||
| height: "", | ||
| weight: "", | ||
| age: "", | ||
| eyes: "", | ||
| origin: "", | ||
| disposition: "", | ||
| traits: "", | ||
| backstory: "", | ||
| }; | ||
|
|
||
| const opt = (value: string): string | undefined => { | ||
| const trimmed = value.trim(); | ||
| return trimmed === "" ? undefined : trimmed; | ||
| }; | ||
|
|
||
| /** Form strings -> a Narrative, or undefined when every field is blank. */ | ||
| export function toNarrative(form: NarrativeForm): Narrative | undefined { | ||
| const appearance = { | ||
| height: opt(form.height), | ||
| weight: opt(form.weight), | ||
| age: opt(form.age), | ||
| eyes: opt(form.eyes), | ||
| origin: opt(form.origin), | ||
| disposition: opt(form.disposition), | ||
| }; | ||
| const hasAppearance = Object.values(appearance).some((v) => v !== undefined); | ||
| const traits = form.traits | ||
| .split(",") | ||
|
StreamDemon marked this conversation as resolved.
|
||
| .map((t) => t.trim()) | ||
| .filter((t) => t.length > 0); | ||
| const narrative: Narrative = { | ||
| ...(opt(form.epithet) !== undefined ? { epithet: opt(form.epithet) } : {}), | ||
| ...(hasAppearance ? { appearance } : {}), | ||
| ...(traits.length > 0 ? { traits } : {}), | ||
| ...(opt(form.backstory) !== undefined ? { backstory: opt(form.backstory) } : {}), | ||
| }; | ||
| return Object.keys(narrative).length > 0 ? narrative : undefined; | ||
| } | ||
|
|
||
| /** A stored Narrative -> form strings (for the dossier editor). */ | ||
| export function fromNarrative(narrative: Narrative | undefined): NarrativeForm { | ||
| return { | ||
| epithet: narrative?.epithet ?? "", | ||
| height: narrative?.appearance?.height ?? "", | ||
| weight: narrative?.appearance?.weight ?? "", | ||
| age: narrative?.appearance?.age ?? "", | ||
| eyes: narrative?.appearance?.eyes ?? "", | ||
| origin: narrative?.appearance?.origin ?? "", | ||
| disposition: narrative?.appearance?.disposition ?? "", | ||
| traits: narrative?.traits?.join(", ") ?? "", | ||
| backstory: narrative?.backstory ?? "", | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.