@vttforge/cli 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +21 -23
  3. package/dist/bin.mjs +1 -1
  4. package/dist/index.d.mts +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/dist/{src-CWhUNM__.mjs → src-BrNh991M.mjs} +90 -4
  7. package/dist/src-BrNh991M.mjs.map +1 -0
  8. package/package.json +3 -3
  9. package/templates/module-js/README.md +46 -22
  10. package/templates/module-js/lang/en.json +19 -1
  11. package/templates/module-js/module.json +7 -2
  12. package/templates/module-js/scripts/constants.mjs +12 -0
  13. package/templates/module-js/scripts/data/note-data.mjs +18 -0
  14. package/templates/module-js/scripts/enricher.mjs +56 -0
  15. package/templates/module-js/scripts/main.mjs +75 -53
  16. package/templates/module-js/scripts/sheets/note-sheet.mjs +69 -0
  17. package/templates/module-js/styles/main.css +70 -9
  18. package/templates/module-js/templates/item/note-sheet.hbs +34 -0
  19. package/templates/module-ts/README.md +51 -22
  20. package/templates/module-ts/lang/en.json +19 -1
  21. package/templates/module-ts/module.json +7 -2
  22. package/templates/module-ts/scripts/constants.ts +12 -0
  23. package/templates/module-ts/scripts/data/note-data.ts +19 -0
  24. package/templates/module-ts/scripts/enricher.ts +52 -0
  25. package/templates/module-ts/scripts/main.ts +73 -55
  26. package/templates/module-ts/scripts/sheets/note-sheet.ts +76 -0
  27. package/templates/module-ts/styles/main.css +70 -9
  28. package/templates/module-ts/templates/item/note-sheet.hbs +34 -0
  29. package/templates/module-ts/tsconfig.json +8 -2
  30. package/templates/system-js/README.md +45 -27
  31. package/templates/system-js/scripts/data/character-data.mjs +65 -59
  32. package/templates/system-js/scripts/data/gear-data.mjs +31 -31
  33. package/templates/system-js/scripts/main.mjs +38 -21
  34. package/templates/system-js/scripts/sheets/character-sheet.mjs +49 -50
  35. package/templates/system-js/scripts/sheets/gear-sheet.mjs +14 -12
  36. package/templates/system-js/templates/actor/character-sheet.hbs +1 -1
  37. package/templates/system-ts/README.md +45 -27
  38. package/templates/system-ts/scripts/data/character-data.ts +80 -64
  39. package/templates/system-ts/scripts/data/gear-data.ts +35 -31
  40. package/templates/system-ts/scripts/main.ts +38 -21
  41. package/templates/system-ts/scripts/sheets/character-sheet.ts +99 -98
  42. package/templates/system-ts/scripts/sheets/gear-sheet.ts +26 -20
  43. package/templates/system-ts/templates/actor/character-sheet.hbs +1 -1
  44. package/templates/system-ts/tsconfig.json +1 -0
  45. package/dist/src-CWhUNM__.mjs.map +0 -1
@@ -1,4 +1,11 @@
1
1
  {
2
+ "TYPES": {
3
+ "Item": {
4
+ "{{ID}}": {
5
+ "note": "Note"
6
+ }
7
+ }
8
+ },
2
9
  "{{LOCALE_PREFIX}}": {
3
10
  "Settings": {
4
11
  "showWelcome": {
@@ -6,6 +13,17 @@
6
13
  "hint": "Display a one-shot toast when {{TITLE}} loads in a world."
7
14
  }
8
15
  },
9
- "Welcome": "{{TITLE}} loaded — try `game.modules.get(\"{{ID}}\").api.greet(\"GM\")` in the console."
16
+ "Welcome": "{{TITLE}} loaded — create a Note from the Items sidebar, or try `game.modules.get(\"{{ID}}\").api.createNote(\"Hello\")` in the console.",
17
+ "Sheet": {
18
+ "NamePlaceholder": "Name",
19
+ "Note": {
20
+ "title": "Note"
21
+ }
22
+ },
23
+ "Note": {
24
+ "NewName": "New Note",
25
+ "Pinned": "Pinned",
26
+ "ReferenceHint": "Paste this in any text field to link here."
27
+ }
10
28
  }
11
29
  }
@@ -11,10 +11,15 @@
11
11
  "esmodules": ["main.mjs"],
12
12
  "styles": [{ "src": "styles/main.css" }],
13
13
  "languages": [{ "lang": "en", "name": "English", "path": "lang/en.json" }],
14
+ "documentTypes": {
15
+ "Item": {
16
+ "note": { "htmlFields": ["body"] }
17
+ }
18
+ },
14
19
  "flags": {
15
20
  "hotReload": {
16
- "extensions": ["css", "json"],
17
- "paths": ["styles", "lang"]
21
+ "extensions": ["css", "hbs", "json"],
22
+ "paths": ["styles", "templates", "lang"]
18
23
  }
19
24
  }
20
25
  }
@@ -0,0 +1,12 @@
1
+ import { moduleSubType } from '@vttforge/core';
2
+
3
+ export const MODULE_ID = '{{ID}}';
4
+
5
+ /**
6
+ * The key Foundry files the `note` sub-type under: `{{ID}}.note`.
7
+ *
8
+ * A module's sub-types are namespaced by Foundry. Use this constant wherever
9
+ * the type is named — `item.type === NOTE_TYPE`, `types: [NOTE_TYPE]` — and
10
+ * the prefix cannot be forgotten.
11
+ */
12
+ export const NOTE_TYPE = moduleSubType(MODULE_ID, 'note');
@@ -0,0 +1,18 @@
1
+ /**
2
+ * NoteData — the `note` Item sub-type this module adds to any system.
3
+ *
4
+ * The schema is a function handed to the factory. It has to be a function
5
+ * because `fields()` reads a Foundry global that does not exist when this
6
+ * module is first evaluated.
7
+ */
8
+ import { BaseTypeDataModel, fields } from '@vttforge/core';
9
+
10
+ const defineNoteSchema = () => {
11
+ const f = fields();
12
+ return {
13
+ body: new f.HTMLField(),
14
+ pinned: new f.BooleanField({ required: true, nullable: false, initial: false }),
15
+ };
16
+ };
17
+
18
+ export class NoteData extends BaseTypeDataModel(defineNoteSchema) {}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * `@Note[id]` — a link to a note from any enriched text field.
3
+ *
4
+ * Declared as data and handed to `registerModule({ enrichers })`, which
5
+ * registers it as `{{ID}}.note`. The pattern carries the `g` flag because
6
+ * enrichment runs it through `matchAll`, and `onRender` binds the click
7
+ * where the markup is declared rather than in a separate hook.
8
+ */
9
+ import { NOTE_TYPE } from './constants.mjs';
10
+
11
+ /**
12
+ * @param {string} id
13
+ * @returns {any}
14
+ */
15
+ function findNote(id) {
16
+ const item = game.items.get(id);
17
+ return item?.type === NOTE_TYPE ? item : undefined;
18
+ }
19
+
20
+ /** @type {import('@vttforge/core').EnricherRegistration} */
21
+ export const noteEnricher = {
22
+ id: 'note',
23
+ pattern: /@Note\[([^\]]+)\]/g,
24
+
25
+ /** @param {RegExpMatchArray} match */
26
+ enricher(match) {
27
+ const id = match[1];
28
+ const note = id === undefined ? undefined : findNote(id);
29
+ // Leave the text alone when the note is gone: a dead link is worse than
30
+ // the raw reference, which at least says what was meant.
31
+ if (note === undefined) return null;
32
+
33
+ const link = document.createElement('a');
34
+ link.className = '{{ID}}-note-link';
35
+ link.dataset.noteId = id;
36
+ link.draggable = false;
37
+ const icon = document.createElement('i');
38
+ icon.className = 'fa-solid fa-note-sticky';
39
+ link.append(icon, note.name);
40
+ return link;
41
+ },
42
+
43
+ /** @param {HTMLElement} element */
44
+ onRender(element) {
45
+ const links = /** @type {NodeListOf<HTMLElement>} */ (
46
+ element.querySelectorAll('a.{{ID}}-note-link')
47
+ );
48
+ for (const link of links) {
49
+ link.addEventListener('click', (event) => {
50
+ event.preventDefault();
51
+ const { noteId } = link.dataset;
52
+ if (noteId) findNote(noteId)?.sheet.render(true);
53
+ });
54
+ }
55
+ },
56
+ };
@@ -1,65 +1,87 @@
1
1
  /**
2
2
  * {{TITLE}} — entry point.
3
3
  *
4
- * Demonstrates the typical Foundry module lifecycle:
5
- *
6
- * - `Hooks.once("init")` — register settings (here via `SystemConfig` from
7
- * `@vttforge/core` for typed access) and expose the public API on
8
- * `game.modules.get(MODULE_ID).api`.
9
- * - `Hooks.once("ready")` — surface a one-shot notification if the user
10
- * opted in via settings.
11
- * - `Hooks.on("renderActorSheetV2", ...)` — example hook listener that
12
- * tags any actor sheet with a discreet `.{{ID}}-badge` so you can verify
13
- * the module is actually attached without hunting through devtools.
4
+ * One `registerModule` call replaces the `Hooks.once("init", ...)` block most
5
+ * modules copy from each other: the sub-type, its sheet, the enricher, the
6
+ * settings, and the public API.
14
7
  */
15
- import { SystemConfig } from '@vttforge/core';
8
+ import { registerModule, SystemConfig, VttfError } from '@vttforge/core';
9
+ import { MODULE_ID, NOTE_TYPE } from './constants.mjs';
10
+ import { NoteData } from './data/note-data.mjs';
11
+ import { noteEnricher } from './enricher.mjs';
12
+ import { NoteSheet } from './sheets/note-sheet.mjs';
16
13
 
17
- const MODULE_ID = '{{ID}}';
18
14
  const settings = new SystemConfig(MODULE_ID);
19
15
 
20
- Hooks.once('init', () => {
21
- settings.register('showWelcome', {
22
- name: '{{LOCALE_PREFIX}}.Settings.showWelcome.name',
23
- hint: '{{LOCALE_PREFIX}}.Settings.showWelcome.hint',
24
- scope: 'client',
25
- config: true,
26
- type: Boolean,
27
- default: true,
28
- });
16
+ /** What `game.modules.get("{{ID}}").api` offers other modules and macros. */
17
+ const api = {
18
+ /** The prefixed type key, for `item.type === api.noteType` checks. */
19
+ noteType: NOTE_TYPE,
20
+ /**
21
+ * @param {string} name
22
+ * @param {string} [body]
23
+ */
24
+ createNote(name, body = '') {
25
+ return CONFIG.Item.documentClass.create(
26
+ { name, type: NOTE_TYPE, system: { body } },
27
+ { renderSheet: true },
28
+ );
29
+ },
30
+ };
29
31
 
30
- const api = {
31
- greet(name) {
32
- return `Hello, ${name}!`;
33
- },
34
- getSetting(key) {
35
- return settings.get(key);
36
- },
37
- };
32
+ try {
33
+ registerModule({
34
+ id: MODULE_ID,
38
35
 
39
- const moduleHandle = game.modules.get(MODULE_ID);
40
- if (moduleHandle) {
41
- moduleHandle.api = api;
42
- }
43
- });
36
+ // Registered as `{{ID}}.note` — the prefix is added for you, and the
37
+ // manifest declares the same key under `documentTypes.Item`.
38
+ itemDataModels: { note: NoteData },
44
39
 
45
- Hooks.once('ready', () => {
46
- const shouldWelcome = settings.get('showWelcome');
47
- if (shouldWelcome) {
48
- ui.notifications?.info(game.i18n.localize('{{LOCALE_PREFIX}}.Welcome'));
49
- }
50
- });
40
+ // Declared here rather than with `Items.registerSheet`. Foundry keys a
41
+ // sheet by `${scope}.${class name}` and saves that key on every document
42
+ // using it; a bundler renames classes between builds, and the saved key
43
+ // then names a sheet that no longer exists. The `id` is written down, so
44
+ // the key does not move. Pick it once and keep it.
45
+ sheets: [
46
+ {
47
+ id: 'note',
48
+ document: 'Item',
49
+ sheet: NoteSheet,
50
+ types: [NOTE_TYPE],
51
+ makeDefault: true,
52
+ label: '{{LOCALE_PREFIX}}.Sheet.Note.title',
53
+ },
54
+ ],
55
+
56
+ enrichers: [noteEnricher],
51
57
 
52
- Hooks.on('renderActorSheetV2', (_app, element) => {
53
- // Decorative: tag the rendered sheet so it's obvious the module is
54
- // active. Remove or replace with real behaviour once you start shipping
55
- // module features.
56
- const header = element.querySelector('.window-header .window-title');
57
- if (header && !header.querySelector(`.{{ID}}-badge`)) {
58
- const badge = document.createElement('span');
59
- badge.className = '{{ID}}-badge';
60
- // Double-quoted because `vttforge init` rejects `"` and `\` in the
61
- // title — apostrophes in titles like "Daisy's Module" stay intact.
62
- badge.textContent = "{{TITLE}}";
63
- header.appendChild(badge);
58
+ // Runs first inside `init` — the usual home for the module API, so it is
59
+ // there before anything that might hook `init` after us asks for it.
60
+ onBeforeInit: () => {
61
+ const handle = game.modules.get(MODULE_ID);
62
+ if (handle) handle.api = api;
63
+ },
64
+
65
+ onAfterInit: () => {
66
+ settings.register('showWelcome', {
67
+ name: '{{LOCALE_PREFIX}}.Settings.showWelcome.name',
68
+ hint: '{{LOCALE_PREFIX}}.Settings.showWelcome.hint',
69
+ scope: 'client',
70
+ config: true,
71
+ type: Boolean,
72
+ default: true,
73
+ });
74
+ },
75
+
76
+ onReady: () => {
77
+ if (settings.get('showWelcome')) {
78
+ ui.notifications?.info(game.i18n.localize('{{LOCALE_PREFIX}}.Welcome'));
79
+ }
80
+ },
81
+ });
82
+ } catch (err) {
83
+ if (err instanceof VttfError) {
84
+ console.error(`[${err.code}] ${err.message} — see ${err.docsUrl}`);
64
85
  }
65
- });
86
+ throw err;
87
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * NoteSheet — the `note` Item sheet on `BaseItemSheet()`.
3
+ *
4
+ * One part, no tabs, one action. The smallest sheet a module can ship.
5
+ */
6
+ import { BaseItemSheet } from '@vttforge/core';
7
+ import { MODULE_ID } from '../constants.mjs';
8
+
9
+ export class NoteSheet extends BaseItemSheet() {
10
+ /** @override */
11
+ static DEFAULT_OPTIONS = foundry.utils.mergeObject(
12
+ super.DEFAULT_OPTIONS,
13
+ {
14
+ id: '{{ID}}-note',
15
+ classes: ['{{ID}}', 'sheet', 'item', 'note'],
16
+ window: {
17
+ title: '{{LOCALE_PREFIX}}.Sheet.Note.title',
18
+ icon: 'fa-solid fa-note-sticky',
19
+ },
20
+ position: { width: 480, height: 480 },
21
+ actions: {
22
+ togglePinned: NoteSheet._onTogglePinned,
23
+ },
24
+ },
25
+ { inplace: false },
26
+ );
27
+
28
+ static PARTS = {
29
+ sheet: { template: `modules/${MODULE_ID}/templates/item/note-sheet.hbs` },
30
+ };
31
+
32
+ /**
33
+ * The item this sheet is for. One place to read `this.document` from, so
34
+ * the rest of the sheet says `this.item` and means it.
35
+ * @returns {any}
36
+ */
37
+ get item() {
38
+ return this.document;
39
+ }
40
+
41
+ /**
42
+ * @override
43
+ * @param {Record<string, unknown>} options
44
+ * @returns {Promise<Record<string, unknown>>}
45
+ */
46
+ async _prepareContext(options) {
47
+ const context = await super._prepareContext(options);
48
+ const { item } = this;
49
+ context.item = item;
50
+ context.system = item.system;
51
+ context.isEditable = this.isEditable;
52
+ context.reference = `@Note[${item.id}]`;
53
+ context.enrichedBody = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
54
+ item.system.body,
55
+ { relativeTo: item, secrets: item.isOwner },
56
+ );
57
+ return context;
58
+ }
59
+
60
+ /**
61
+ * @this {NoteSheet} ApplicationV2 declares action handlers static but calls
62
+ * them with `this` bound to the sheet instance.
63
+ */
64
+ static async _onTogglePinned() {
65
+ // biome-ignore lint/complexity/noThisInStatic: ApplicationV2 binds `this` to the sheet instance at call time
66
+ const { item } = this;
67
+ await item.update({ 'system.pinned': !item.system.pinned });
68
+ }
69
+ }
@@ -1,16 +1,77 @@
1
1
  /**
2
2
  * {{TITLE}} stylesheet.
3
3
  *
4
- * Scope all rules under the `.{{ID}}` namespace so they don't leak into
5
- * other modules or the host system's sheets. Foundry's CSS cascade is
6
- * already layered, but namespacing makes intent explicit.
4
+ * Every rule is scoped under `.{{ID}}` so nothing leaks into the host system's
5
+ * sheets. Colours come from Foundry's own variables so the sheet follows the
6
+ * light and dark themes.
7
7
  */
8
- .{{ID}}-badge {
9
- display: inline-flex;
8
+ .{{ID}}.sheet .sheet-header {
9
+ display: flex;
10
10
  align-items: center;
11
- gap: 0.4em;
12
- padding: 0.15em 0.5em;
11
+ gap: 0.5rem;
12
+ margin-bottom: 0.5rem;
13
+ }
14
+
15
+ .{{ID}}.sheet .sheet-header .portrait {
16
+ width: 48px;
17
+ height: 48px;
18
+ object-fit: cover;
19
+ border: 1px solid var(--color-border-dark, #7a7971);
13
20
  border-radius: 4px;
14
- background: rgba(0, 0, 0, 0.08);
15
- font-size: 0.8em;
21
+ cursor: pointer;
22
+ }
23
+
24
+ .{{ID}}.sheet .sheet-header input[name="name"] {
25
+ flex: 1;
26
+ font-size: var(--font-size-20, 1.25rem);
27
+ }
28
+
29
+ .{{ID}}.sheet .sheet-header .pin {
30
+ flex: 0 0 auto;
31
+ width: 2rem;
32
+ height: 2rem;
33
+ opacity: 0.5;
34
+ }
35
+
36
+ .{{ID}}.sheet .sheet-header .pin.active {
37
+ opacity: 1;
38
+ color: var(--color-warm-2, #c9593f);
39
+ }
40
+
41
+ .{{ID}}.sheet .sheet-body {
42
+ display: flex;
43
+ flex-direction: column;
44
+ gap: 0.5rem;
45
+ height: 100%;
46
+ }
47
+
48
+ .{{ID}}.sheet prose-mirror,
49
+ .{{ID}}.sheet .body-readonly {
50
+ flex: 1;
51
+ min-height: 12rem;
52
+ }
53
+
54
+ .{{ID}}.sheet .reference {
55
+ display: flex;
56
+ align-items: baseline;
57
+ gap: 0.5rem;
58
+ color: var(--color-text-secondary, #4b4a44);
59
+ font-size: var(--font-size-12, 0.75rem);
60
+ }
61
+
62
+ /* Rendered by the `note` enricher wherever `@Note[id]` appears. */
63
+ a.{{ID}}-note-link {
64
+ display: inline-flex;
65
+ align-items: center;
66
+ gap: 0.25em;
67
+ padding: 0 0.35em;
68
+ border: 1px dotted var(--color-border-dark, #7a7971);
69
+ border-radius: 3px;
70
+ background: var(--color-bg-tertiary, rgba(0, 0, 0, 0.06));
71
+ text-decoration: none;
72
+ }
73
+
74
+ a.{{ID}}-note-link:hover {
75
+ border-style: solid;
76
+ text-shadow: none;
16
77
  }
@@ -0,0 +1,34 @@
1
+ {{!-- Note sheet — one part, no tabs. --}}
2
+ <form autocomplete="off">
3
+
4
+ <header class="sheet-header">
5
+ <img class="portrait" src="{{item.img}}" alt="{{item.name}}" data-edit="img" />
6
+ <input type="text" name="name" value="{{item.name}}"
7
+ placeholder="{{localize '{{LOCALE_PREFIX}}.Sheet.NamePlaceholder'}}" />
8
+ <button type="button" class="pin {{#if system.pinned}}active{{/if}}"
9
+ data-action="togglePinned"
10
+ title="{{localize '{{LOCALE_PREFIX}}.Note.Pinned'}}">
11
+ <i class="fa-solid fa-thumbtack"></i>
12
+ </button>
13
+ </header>
14
+
15
+ <section class="sheet-body">
16
+ {{#if isEditable}}
17
+ <prose-mirror name="system.body"
18
+ button="true"
19
+ editable="{{isEditable}}"
20
+ toggled="false"
21
+ value="{{system.body}}">
22
+ {{{enrichedBody}}}
23
+ </prose-mirror>
24
+ {{else}}
25
+ <div class="body-readonly">{{{enrichedBody}}}</div>
26
+ {{/if}}
27
+
28
+ <footer class="reference">
29
+ <code>{{reference}}</code>
30
+ <small>{{localize '{{LOCALE_PREFIX}}.Note.ReferenceHint'}}</small>
31
+ </footer>
32
+ </section>
33
+
34
+ </form>
@@ -2,56 +2,85 @@
2
2
 
3
3
  {{DESCRIPTION}}
4
4
 
5
- A Foundry VTT module built on [VTTForge](https://github.com/vttforge/vttforge) — uses `SystemConfig` from `@vttforge/core` for typed settings, ships an example hook listener, and exposes a small public API on `game.modules.get("{{ID}}").api`.
6
-
7
- > **Note** — VTTForge is currently in pre-release and not yet published to npm. Dependencies in `package.json` will resolve once VTTForge ships its first public release.
5
+ A Foundry VTT v13+ module built on [VTTForge](https://vttforge.dev). It adds a
6
+ `note` Item type to whatever system the world runs, a sheet for it, and an
7
+ `@Note[id]` enricher that links to one from any text field.
8
8
 
9
9
  ## Quick start
10
10
 
11
11
  ```bash
12
12
  pnpm install
13
- pnpm dev # vite build --watch + auto-symlinks dist/ into Foundry's Data
14
- pnpm build # one-shot build + emits {{ID}}-<version>.zip for foundryvtt.com
13
+ pnpm dev # build, link dist/ into Foundry's data dir, watch
14
+ pnpm build # dist/ plus {{ID}}-<version>.zip
15
15
  ```
16
16
 
17
- `pnpm dev` (`vttforge dev` under the hood) auto-detects your Foundry user-data
18
- directory on the first run, prompts you to confirm it, and saves the choice to
19
- `.vttforge/config.json` for next time. Override with `--data-dir <path>` or set
20
- `FOUNDRY_DATA_DIR` in your environment.
17
+ `pnpm dev` asks where Foundry keeps its data on the first run and remembers
18
+ the answer in `.vttforge/config.json`. Override with `--foundry-data <path>`
19
+ or `FOUNDRY_DATA_DIR`. If Foundry runs in a container it cannot follow the
20
+ symlink, and the command prints the compose mount to use instead.
21
+
22
+ Save a template and the open sheet redraws in place; save a stylesheet and the
23
+ CSS swaps. Enable **VTTForge Dev** in the world once; `pnpm dev` links it in.
21
24
 
22
- Run Foundry with `--hotReload` to pick up changes without refreshing the page.
23
- Then enable **{{TITLE}}** in any world.
25
+ Then enable **{{TITLE}}** in a world and create a Note from the Items sidebar.
24
26
 
25
27
  ## What's inside
26
28
 
27
29
  | Path | Purpose |
28
30
  |---|---|
29
- | `module.json` | Manifest |
30
- | `scripts/main.ts` | Entry point — settings registration, hook listeners, public API |
31
- | `styles/main.css` | Stylesheet, scoped under `.{{ID}}` |
32
- | `lang/en.json` | Localization strings |
31
+ | `module.json` | Manifest. Declares the `note` sub-type under `documentTypes` and the hot-reload paths |
32
+ | `scripts/main.ts` | One `registerModule` call: data model, sheet, enricher, settings, API |
33
+ | `scripts/constants.ts` | `MODULE_ID` and `NOTE_TYPE`, the prefixed key Foundry files the sub-type under |
34
+ | `scripts/data/note-data.ts` | The data model. The schema is a function handed to `BaseTypeDataModel`, which is what makes `this.body` a `string` |
35
+ | `scripts/sheets/note-sheet.ts` | The sheet, on `BaseItemSheet` |
36
+ | `scripts/enricher.ts` | `@Note[id]` → a link that opens the note |
37
+ | `templates/` | Handlebars, using v13's own elements (`<prose-mirror>`, `data-action`) |
38
+ | `styles/main.css` | Scoped under `.{{ID}}`, colours from Foundry's variables |
39
+ | `lang/en.json` | Strings, under the `{{LOCALE_PREFIX}}` prefix, plus the `TYPES.Item` label |
40
+
41
+ ## Three things worth knowing before you edit
42
+
43
+ **A module's sub-types are namespaced.** You register `note`; Foundry files it
44
+ as `{{ID}}.note`, and so must the manifest. `registerModule` adds the prefix,
45
+ and `NOTE_TYPE` in `constants.ts` is the one place it is spelled out.
46
+
47
+ **Sheets are registered by id, not by class name.** `registerModule({ sheets })`
48
+ pins each sheet under `{{ID}}.<id>`. Foundry saves that key on every item
49
+ whose owner picked the sheet, and derives it from the class name unless told
50
+ otherwise, and a bundler renames classes between builds. Keep the ids.
51
+
52
+ **`this.document` is `unknown` on the sheet bases.** Which document a sheet is
53
+ for is yours to know. The sheet narrows it once in a getter (`item`) and
54
+ everything below reads typed.
33
55
 
34
56
  ## Public API
35
57
 
36
- The module exposes its API on `game.modules.get("{{ID}}").api`:
37
-
38
58
  ```ts
39
59
  const api = game.modules.get("{{ID}}").api;
40
- api.greet("world"); // returns "Hello, world!"
41
- api.getSetting("showWelcome"); // returns the current value
60
+ await api.createNote("Session 3", "<p>The party reached the gate.</p>");
61
+ api.noteType; // "{{ID}}.note"
42
62
  ```
43
63
 
44
- Extend `scripts/main.ts` to add real methods — the example exists to show the registration pattern.
64
+ ## Checks
45
65
 
46
- ## Releasing to Foundry
66
+ ```bash
67
+ pnpm typecheck # tsc against the real @vttforge/core types
68
+ npx vttforge audit # manifest + source against the v13 list of quiet breakages
69
+ ```
70
+
71
+ ## Releasing
47
72
 
48
- Tag-push triggers `.github/workflows/release.yml` to build, zip, and attach `{{ID}}-<version>.zip` + `dist/module.json` to a GitHub Release. Point Foundry at the `latest/download/module.json` URL.
73
+ Push a tag and `.github/workflows/release.yml` builds, zips, and attaches
74
+ `{{ID}}-<version>.zip` plus `module.json` to a GitHub Release:
49
75
 
50
76
  ```bash
51
77
  git tag v0.1.0
52
78
  git push --tags
53
79
  ```
54
80
 
81
+ Point Foundry, and foundryvtt.com, at the release's
82
+ `latest/download/module.json`, so installs auto-update on every tag.
83
+
55
84
  ## License
56
85
 
57
86
  {{LICENSE}} © {{YEAR}} {{AUTHOR}}
@@ -1,4 +1,11 @@
1
1
  {
2
+ "TYPES": {
3
+ "Item": {
4
+ "{{ID}}": {
5
+ "note": "Note"
6
+ }
7
+ }
8
+ },
2
9
  "{{LOCALE_PREFIX}}": {
3
10
  "Settings": {
4
11
  "showWelcome": {
@@ -6,6 +13,17 @@
6
13
  "hint": "Display a one-shot toast when {{TITLE}} loads in a world."
7
14
  }
8
15
  },
9
- "Welcome": "{{TITLE}} loaded — try `game.modules.get(\"{{ID}}\").api.greet(\"GM\")` in the console."
16
+ "Welcome": "{{TITLE}} loaded — create a Note from the Items sidebar, or try `game.modules.get(\"{{ID}}\").api.createNote(\"Hello\")` in the console.",
17
+ "Sheet": {
18
+ "NamePlaceholder": "Name",
19
+ "Note": {
20
+ "title": "Note"
21
+ }
22
+ },
23
+ "Note": {
24
+ "NewName": "New Note",
25
+ "Pinned": "Pinned",
26
+ "ReferenceHint": "Paste this in any text field to link here."
27
+ }
10
28
  }
11
29
  }
@@ -11,10 +11,15 @@
11
11
  "esmodules": ["main.mjs"],
12
12
  "styles": [{ "src": "styles/main.css" }],
13
13
  "languages": [{ "lang": "en", "name": "English", "path": "lang/en.json" }],
14
+ "documentTypes": {
15
+ "Item": {
16
+ "note": { "htmlFields": ["body"] }
17
+ }
18
+ },
14
19
  "flags": {
15
20
  "hotReload": {
16
- "extensions": ["css", "json"],
17
- "paths": ["styles", "lang"]
21
+ "extensions": ["css", "hbs", "json"],
22
+ "paths": ["styles", "templates", "lang"]
18
23
  }
19
24
  }
20
25
  }
@@ -0,0 +1,12 @@
1
+ import { moduleSubType } from '@vttforge/core';
2
+
3
+ export const MODULE_ID = '{{ID}}';
4
+
5
+ /**
6
+ * The key Foundry files the `note` sub-type under: `{{ID}}.note`.
7
+ *
8
+ * A module's sub-types are namespaced by Foundry. Use this constant wherever
9
+ * the type is named — `item.type === NOTE_TYPE`, `types: [NOTE_TYPE]` — and
10
+ * the prefix cannot be forgotten.
11
+ */
12
+ export const NOTE_TYPE = moduleSubType(MODULE_ID, 'note');
@@ -0,0 +1,19 @@
1
+ /**
2
+ * NoteData — the `note` Item sub-type this module adds to any system.
3
+ *
4
+ * The schema is a function handed to the factory. It has to be a function
5
+ * because `fields()` reads a Foundry global that does not exist when this
6
+ * module is first evaluated, and handing it to `BaseTypeDataModel(...)` is
7
+ * what types `this.body` and `this.pinned` on the instance.
8
+ */
9
+ import { BaseTypeDataModel, fields } from '@vttforge/core';
10
+
11
+ const defineNoteSchema = () => {
12
+ const f = fields();
13
+ return {
14
+ body: new f.HTMLField(),
15
+ pinned: new f.BooleanField({ required: true, nullable: false, initial: false }),
16
+ };
17
+ };
18
+
19
+ export class NoteData extends BaseTypeDataModel(defineNoteSchema) {}