@vttforge/cli 0.5.2 → 0.5.3
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.
- package/CHANGELOG.md +16 -0
- package/README.md +21 -23
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-CWhUNM__.mjs → src-KI6RBaTd.mjs} +90 -4
- package/dist/src-KI6RBaTd.mjs.map +1 -0
- package/package.json +1 -1
- package/templates/module-js/README.md +46 -22
- package/templates/module-js/lang/en.json +19 -1
- package/templates/module-js/module.json +7 -2
- package/templates/module-js/scripts/constants.mjs +12 -0
- package/templates/module-js/scripts/data/note-data.mjs +18 -0
- package/templates/module-js/scripts/enricher.mjs +56 -0
- package/templates/module-js/scripts/main.mjs +75 -53
- package/templates/module-js/scripts/sheets/note-sheet.mjs +69 -0
- package/templates/module-js/styles/main.css +70 -9
- package/templates/module-js/templates/item/note-sheet.hbs +34 -0
- package/templates/module-ts/README.md +51 -22
- package/templates/module-ts/lang/en.json +19 -1
- package/templates/module-ts/module.json +7 -2
- package/templates/module-ts/scripts/constants.ts +12 -0
- package/templates/module-ts/scripts/data/note-data.ts +19 -0
- package/templates/module-ts/scripts/enricher.ts +52 -0
- package/templates/module-ts/scripts/main.ts +73 -55
- package/templates/module-ts/scripts/sheets/note-sheet.ts +76 -0
- package/templates/module-ts/styles/main.css +70 -9
- package/templates/module-ts/templates/item/note-sheet.hbs +34 -0
- package/templates/module-ts/tsconfig.json +8 -2
- package/templates/system-js/README.md +45 -27
- package/templates/system-js/scripts/data/character-data.mjs +65 -59
- package/templates/system-js/scripts/data/gear-data.mjs +31 -31
- package/templates/system-js/scripts/main.mjs +38 -21
- package/templates/system-js/scripts/sheets/character-sheet.mjs +49 -50
- package/templates/system-js/scripts/sheets/gear-sheet.mjs +14 -12
- package/templates/system-js/templates/actor/character-sheet.hbs +1 -1
- package/templates/system-ts/README.md +45 -27
- package/templates/system-ts/scripts/data/character-data.ts +80 -64
- package/templates/system-ts/scripts/data/gear-data.ts +35 -31
- package/templates/system-ts/scripts/main.ts +38 -21
- package/templates/system-ts/scripts/sheets/character-sheet.ts +99 -98
- package/templates/system-ts/scripts/sheets/gear-sheet.ts +26 -20
- package/templates/system-ts/templates/actor/character-sheet.hbs +1 -1
- package/templates/system-ts/tsconfig.json +1 -0
- package/dist/src-CWhUNM__.mjs.map +0 -1
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GearData —
|
|
2
|
+
* GearData — the `gear` Item type.
|
|
3
3
|
*
|
|
4
|
-
* `kind`
|
|
5
|
-
* `
|
|
6
|
-
* muted.
|
|
4
|
+
* `kind` drives the inventory pill on the character sheet: `equipped` and
|
|
5
|
+
* `valued` render with the accent pill, `stowed` renders muted.
|
|
7
6
|
*/
|
|
8
7
|
import { BaseTypeDataModel, fields } from '@vttforge/core';
|
|
9
8
|
|
|
10
|
-
const GEAR_KINDS = /** @type {const} */ (['equipped', 'valued', 'stowed']);
|
|
9
|
+
export const GEAR_KINDS = /** @type {const} */ (['equipped', 'valued', 'stowed']);
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
const defineGearSchema = () => {
|
|
12
|
+
const f = fields();
|
|
13
|
+
return {
|
|
14
|
+
quantity: new f.NumberField({
|
|
15
|
+
required: true,
|
|
16
|
+
nullable: false,
|
|
17
|
+
integer: true,
|
|
18
|
+
min: 0,
|
|
19
|
+
initial: 1,
|
|
20
|
+
}),
|
|
21
|
+
weight: new f.NumberField({
|
|
22
|
+
required: true,
|
|
23
|
+
nullable: false,
|
|
24
|
+
min: 0,
|
|
25
|
+
initial: 0,
|
|
26
|
+
}),
|
|
27
|
+
kind: new f.StringField({
|
|
28
|
+
required: true,
|
|
29
|
+
nullable: false,
|
|
30
|
+
choices: GEAR_KINDS,
|
|
31
|
+
initial: 'stowed',
|
|
32
|
+
}),
|
|
33
|
+
description: new f.HTMLField(),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export class GearData extends BaseTypeDataModel(defineGearSchema) {}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* {{TITLE}} — entry point.
|
|
3
3
|
*
|
|
4
|
-
* `registerSystem`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* registration, settings, and the `Hooks.once("ready", ...)` migration
|
|
8
|
-
* gate are all wired by one call.
|
|
4
|
+
* One `registerSystem` call replaces the `Hooks.once("init", ...)` block most
|
|
5
|
+
* systems copy from each other: data models, initiative, sheets, settings,
|
|
6
|
+
* and the `ready`-time migration gate.
|
|
9
7
|
*/
|
|
10
8
|
import { registerSystem, SystemConfig, VttfError } from '@vttforge/core';
|
|
11
9
|
import { CharacterData } from './data/character-data.mjs';
|
|
@@ -26,6 +24,39 @@ try {
|
|
|
26
24
|
combat: {
|
|
27
25
|
initiative: { formula: '1d20 + @abilities.dex.mod', decimals: 2 },
|
|
28
26
|
},
|
|
27
|
+
|
|
28
|
+
// The core sheets have to go before ours can be the default. This runs
|
|
29
|
+
// before the `sheets` below are registered.
|
|
30
|
+
onBeforeInit: () => {
|
|
31
|
+
const { Actors, Items } = foundry.documents.collections;
|
|
32
|
+
Actors.unregisterSheet('core', foundry.applications.sheets.ActorSheetV2);
|
|
33
|
+
Items.unregisterSheet('core', foundry.applications.sheets.ItemSheetV2);
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Declared here rather than with `Actors.registerSheet`. Foundry keys a
|
|
37
|
+
// sheet by `${scope}.${class name}` and saves that key on every document
|
|
38
|
+
// using it; a bundler renames classes between builds, and the saved key
|
|
39
|
+
// then names a sheet that no longer exists. The `id` is written down, so
|
|
40
|
+
// the key does not move. Pick it once and keep it.
|
|
41
|
+
sheets: [
|
|
42
|
+
{
|
|
43
|
+
id: 'character',
|
|
44
|
+
document: 'Actor',
|
|
45
|
+
sheet: CharacterSheet,
|
|
46
|
+
types: ['character'],
|
|
47
|
+
makeDefault: true,
|
|
48
|
+
label: '{{LOCALE_PREFIX}}.Sheet.Character.title',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'gear',
|
|
52
|
+
document: 'Item',
|
|
53
|
+
sheet: GearSheet,
|
|
54
|
+
types: ['gear'],
|
|
55
|
+
makeDefault: true,
|
|
56
|
+
label: '{{LOCALE_PREFIX}}.Sheet.Gear.title',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
|
|
29
60
|
onAfterInit: () => {
|
|
30
61
|
settings.register('showTutorial', {
|
|
31
62
|
name: '{{LOCALE_PREFIX}}.Settings.showTutorial.name',
|
|
@@ -36,24 +67,10 @@ try {
|
|
|
36
67
|
default: true,
|
|
37
68
|
});
|
|
38
69
|
|
|
39
|
-
//
|
|
40
|
-
// to read and write the version flag.
|
|
70
|
+
// The schemaVersion setting `migrations.run()` reads and writes.
|
|
41
71
|
migrations.register();
|
|
42
|
-
|
|
43
|
-
const { Actors, Items } = foundry.documents.collections;
|
|
44
|
-
Actors.unregisterSheet('core', foundry.applications.sheets.ActorSheetV2);
|
|
45
|
-
Actors.registerSheet(SYSTEM_ID, CharacterSheet, {
|
|
46
|
-
types: ['character'],
|
|
47
|
-
makeDefault: true,
|
|
48
|
-
label: '{{LOCALE_PREFIX}}.Sheet.Character.title',
|
|
49
|
-
});
|
|
50
|
-
Items.unregisterSheet('core', foundry.applications.sheets.ItemSheetV2);
|
|
51
|
-
Items.registerSheet(SYSTEM_ID, GearSheet, {
|
|
52
|
-
types: ['gear'],
|
|
53
|
-
makeDefault: true,
|
|
54
|
-
label: '{{LOCALE_PREFIX}}.Sheet.Gear.title',
|
|
55
|
-
});
|
|
56
72
|
},
|
|
73
|
+
|
|
57
74
|
onReady: async () => {
|
|
58
75
|
if (!game.user?.isGM) return;
|
|
59
76
|
try {
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CharacterSheet — tabbed character sheet
|
|
3
|
-
* `@vttforge/core`. Demonstrates the full boilerplate-elimination surface:
|
|
2
|
+
* CharacterSheet — tabbed character sheet on `BaseActorSheet()`.
|
|
4
3
|
*
|
|
5
|
-
* - `static TABS` — `context.tabs.<group>`
|
|
6
|
-
*
|
|
7
|
-
* - `
|
|
8
|
-
*
|
|
9
|
-
* - Typed `onDropItem(item, event)` — pre-resolves UUIDs, rejects
|
|
10
|
-
* non-`gear` items with a notification, lets `gear` flow through to
|
|
11
|
-
* Foundry's default `_onDropItem` by returning `undefined`.
|
|
4
|
+
* - `static TABS` — `context.tabs.<group>` is filled in for you.
|
|
5
|
+
* - `static DRAG_DROP` — drag-drop wired on render, gated on `isEditable`.
|
|
6
|
+
* - `onDropItem(item, event)` — the item arrives resolved, not as a UUID.
|
|
7
|
+
* Return `false` to refuse, `undefined` to hand the drop back to Foundry.
|
|
12
8
|
*/
|
|
13
9
|
import { BaseActorSheet } from '@vttforge/core';
|
|
14
10
|
|
|
15
11
|
const SYSTEM_ID = '{{ID}}';
|
|
16
12
|
|
|
13
|
+
const ABILITY_LABELS = {
|
|
14
|
+
str: '{{LOCALE_PREFIX}}.Ability.str',
|
|
15
|
+
dex: '{{LOCALE_PREFIX}}.Ability.dex',
|
|
16
|
+
con: '{{LOCALE_PREFIX}}.Ability.con',
|
|
17
|
+
int: '{{LOCALE_PREFIX}}.Ability.int',
|
|
18
|
+
wis: '{{LOCALE_PREFIX}}.Ability.wis',
|
|
19
|
+
cha: '{{LOCALE_PREFIX}}.Ability.cha',
|
|
20
|
+
};
|
|
21
|
+
|
|
17
22
|
export class CharacterSheet extends BaseActorSheet() {
|
|
18
23
|
static DEFAULT_OPTIONS = foundry.utils.mergeObject(
|
|
19
24
|
super.DEFAULT_OPTIONS,
|
|
@@ -35,9 +40,7 @@ export class CharacterSheet extends BaseActorSheet() {
|
|
|
35
40
|
);
|
|
36
41
|
|
|
37
42
|
static PARTS = {
|
|
38
|
-
sheet: {
|
|
39
|
-
template: `systems/${SYSTEM_ID}/templates/actor/character-sheet.hbs`,
|
|
40
|
-
},
|
|
43
|
+
sheet: { template: `systems/${SYSTEM_ID}/templates/actor/character-sheet.hbs` },
|
|
41
44
|
};
|
|
42
45
|
|
|
43
46
|
static TABS = {
|
|
@@ -72,34 +75,31 @@ export class CharacterSheet extends BaseActorSheet() {
|
|
|
72
75
|
},
|
|
73
76
|
};
|
|
74
77
|
|
|
75
|
-
static DRAG_DROP = [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
static DRAG_DROP = [{ dragSelector: '.sh-item[draggable=true]', dropSelector: '.sh-body' }];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The actor this sheet is for. One place to read `this.document` from, so
|
|
82
|
+
* the rest of the sheet says `this.actor` and means it.
|
|
83
|
+
* @returns {any}
|
|
84
|
+
*/
|
|
85
|
+
get actor() {
|
|
86
|
+
return this.document;
|
|
87
|
+
}
|
|
81
88
|
|
|
82
89
|
/** @override */
|
|
83
90
|
async _prepareContext(options) {
|
|
84
91
|
const context = await super._prepareContext(options);
|
|
85
|
-
const actor = this
|
|
86
|
-
const system = actor
|
|
87
|
-
|
|
88
|
-
str: '{{LOCALE_PREFIX}}.Ability.str',
|
|
89
|
-
dex: '{{LOCALE_PREFIX}}.Ability.dex',
|
|
90
|
-
con: '{{LOCALE_PREFIX}}.Ability.con',
|
|
91
|
-
int: '{{LOCALE_PREFIX}}.Ability.int',
|
|
92
|
-
wis: '{{LOCALE_PREFIX}}.Ability.wis',
|
|
93
|
-
cha: '{{LOCALE_PREFIX}}.Ability.cha',
|
|
94
|
-
};
|
|
92
|
+
const { actor } = this;
|
|
93
|
+
const { system } = actor;
|
|
94
|
+
|
|
95
95
|
context.actor = actor;
|
|
96
96
|
context.system = system;
|
|
97
97
|
context.isEditable = this.isEditable;
|
|
98
|
-
context.abilities = Object.entries(system.abilities
|
|
98
|
+
context.abilities = Object.entries(system.abilities).map(([key, ability]) => ({
|
|
99
99
|
key,
|
|
100
|
-
label: game.i18n.localize(
|
|
101
|
-
value:
|
|
102
|
-
mod:
|
|
100
|
+
label: game.i18n.localize(ABILITY_LABELS[key] ?? key),
|
|
101
|
+
value: ability.value,
|
|
102
|
+
mod: ability.mod,
|
|
103
103
|
}));
|
|
104
104
|
context.gear = actor.items
|
|
105
105
|
.filter((item) => item.type === 'gear')
|
|
@@ -107,19 +107,19 @@ export class CharacterSheet extends BaseActorSheet() {
|
|
|
107
107
|
id: item.id,
|
|
108
108
|
name: item.name,
|
|
109
109
|
img: item.img,
|
|
110
|
-
kind: item.system
|
|
111
|
-
quantity: item.system
|
|
112
|
-
weight: item.system
|
|
113
|
-
description: item.system
|
|
110
|
+
kind: item.system.kind,
|
|
111
|
+
quantity: item.system.quantity,
|
|
112
|
+
weight: item.system.weight,
|
|
113
|
+
description: item.system.description,
|
|
114
114
|
}));
|
|
115
115
|
context.enrichedBiography = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
|
116
|
-
system.biography
|
|
116
|
+
system.biography,
|
|
117
117
|
{ relativeTo: actor, secrets: actor.isOwner },
|
|
118
118
|
);
|
|
119
119
|
return context;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
/**
|
|
122
|
+
/** Only gear belongs in this inventory. Anything else is refused with a reason. */
|
|
123
123
|
async onDropItem(item, _event) {
|
|
124
124
|
if (item?.type !== 'gear') {
|
|
125
125
|
ui.notifications?.warn(
|
|
@@ -130,11 +130,14 @@ export class CharacterSheet extends BaseActorSheet() {
|
|
|
130
130
|
return undefined;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
// ApplicationV2 declares action handlers static and calls them with `this`
|
|
134
|
+
// bound to the sheet instance.
|
|
135
|
+
|
|
133
136
|
static async _onRollAbility(_event, target) {
|
|
134
|
-
const key = target
|
|
137
|
+
const key = target.dataset.ability;
|
|
135
138
|
if (!key) return;
|
|
136
|
-
const actor = this
|
|
137
|
-
const mod = actor.system.abilities
|
|
139
|
+
const { actor } = this;
|
|
140
|
+
const mod = actor.system.abilities[key]?.mod ?? 0;
|
|
138
141
|
const roll = new Roll(`1d20 + ${mod}`, actor.getRollData());
|
|
139
142
|
await roll.evaluate();
|
|
140
143
|
await roll.toMessage({
|
|
@@ -145,20 +148,16 @@ export class CharacterSheet extends BaseActorSheet() {
|
|
|
145
148
|
});
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
static async _onCreateGear(
|
|
149
|
-
|
|
150
|
-
const parent = this.document;
|
|
151
|
-
await cls.create(
|
|
151
|
+
static async _onCreateGear() {
|
|
152
|
+
await CONFIG.Item.documentClass.create(
|
|
152
153
|
{ name: game.i18n.localize('{{LOCALE_PREFIX}}.Sheet.NewGearName'), type: 'gear' },
|
|
153
|
-
{ parent, renderSheet: true },
|
|
154
|
+
{ parent: this.actor, renderSheet: true },
|
|
154
155
|
);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
static async _onDeleteItem(_event, target) {
|
|
158
|
-
const
|
|
159
|
-
const id = row?.dataset?.itemId;
|
|
159
|
+
const id = target.closest('[data-item-id]')?.dataset.itemId;
|
|
160
160
|
if (!id) return;
|
|
161
|
-
|
|
162
|
-
await item?.delete();
|
|
161
|
+
await this.actor.items.get(id)?.delete();
|
|
163
162
|
}
|
|
164
163
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* GearSheet —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* GearSheet — the `gear` Item sheet on `BaseItemSheet()`.
|
|
3
|
+
*
|
|
4
|
+
* Single part, one tab group, no drag-drop: the smallest useful sheet.
|
|
5
5
|
*/
|
|
6
6
|
import { BaseItemSheet } from '@vttforge/core';
|
|
7
7
|
|
|
@@ -23,9 +23,7 @@ export class GearSheet extends BaseItemSheet() {
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
static PARTS = {
|
|
26
|
-
sheet: {
|
|
27
|
-
template: `systems/${SYSTEM_ID}/templates/item/gear-sheet.hbs`,
|
|
28
|
-
},
|
|
26
|
+
sheet: { template: `systems/${SYSTEM_ID}/templates/item/gear-sheet.hbs` },
|
|
29
27
|
};
|
|
30
28
|
|
|
31
29
|
static TABS = {
|
|
@@ -48,18 +46,22 @@ export class GearSheet extends BaseItemSheet() {
|
|
|
48
46
|
},
|
|
49
47
|
};
|
|
50
48
|
|
|
49
|
+
/** @returns {any} */
|
|
50
|
+
get item() {
|
|
51
|
+
return this.document;
|
|
52
|
+
}
|
|
53
|
+
|
|
51
54
|
/** @override */
|
|
52
55
|
async _prepareContext(options) {
|
|
53
56
|
const context = await super._prepareContext(options);
|
|
54
|
-
const item = this
|
|
57
|
+
const { item } = this;
|
|
55
58
|
context.item = item;
|
|
56
59
|
context.system = item.system;
|
|
57
60
|
context.isEditable = this.isEditable;
|
|
58
|
-
context.enrichedDescription =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
61
|
+
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
|
62
|
+
item.system.description,
|
|
63
|
+
{ relativeTo: item, secrets: item.isOwner },
|
|
64
|
+
);
|
|
63
65
|
return context;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
<div class="sh-abil">
|
|
77
77
|
<div class="lbl" title="{{ability.label}}">{{ability.key}}</div>
|
|
78
78
|
<input class="val" type="number"
|
|
79
|
-
name="system.abilities.{{ability.key}}"
|
|
79
|
+
name="system.abilities.{{ability.key}}.value"
|
|
80
80
|
value="{{ability.value}}" min="1" max="30" />
|
|
81
81
|
<button type="button" class="mod sh-abil-roll"
|
|
82
82
|
data-action="rollAbility" data-ability="{{ability.key}}"
|
|
@@ -2,55 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
{{DESCRIPTION}}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
A Foundry VTT v13+ system built on [VTTForge](https://vttforge.dev): typed
|
|
6
|
+
data models, sheet bases that already know their tabs and drops, a migration
|
|
7
|
+
runner, and a build that produces what foundryvtt.com expects.
|
|
8
8
|
|
|
9
9
|
## Quick start
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
pnpm install
|
|
13
|
-
pnpm dev #
|
|
14
|
-
pnpm build #
|
|
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`
|
|
18
|
-
|
|
19
|
-
`.
|
|
20
|
-
|
|
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
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
swaps CSS / Handlebars / JSON on the fly.
|
|
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.
|
|
25
24
|
|
|
26
|
-
Then
|
|
25
|
+
Then create a world on **{{TITLE}}** and open a character.
|
|
27
26
|
|
|
28
27
|
## What's inside
|
|
29
28
|
|
|
30
29
|
| Path | Purpose |
|
|
31
30
|
|---|---|
|
|
32
|
-
| `system.json` | Manifest
|
|
33
|
-
| `template.json` |
|
|
34
|
-
| `scripts/main.ts` |
|
|
35
|
-
| `scripts/data/*.ts` |
|
|
36
|
-
| `scripts/sheets/*.ts` |
|
|
37
|
-
| `scripts/migrations.ts` | `createMigrationRunner
|
|
38
|
-
| `templates/` | Handlebars
|
|
39
|
-
| `styles/main.css` |
|
|
40
|
-
| `lang/en.json` |
|
|
31
|
+
| `system.json` | Manifest — types, `htmlFields`, hot-reload paths, migration flags |
|
|
32
|
+
| `template.json` | The type names Foundry expects to see declared |
|
|
33
|
+
| `scripts/main.ts` | One `registerSystem` call: models, sheets, initiative, settings, migrations |
|
|
34
|
+
| `scripts/data/*.ts` | Data models. The schema is a function handed to `BaseTypeDataModel`, which is what makes `this.level` a `number` |
|
|
35
|
+
| `scripts/sheets/*.ts` | Sheets on `BaseActorSheet` / `BaseItemSheet` — `static TABS`, `static DRAG_DROP`, typed `onDropItem` |
|
|
36
|
+
| `scripts/migrations.ts` | `createMigrationRunner` — versioned, idempotent, GM-gated |
|
|
37
|
+
| `templates/` | Handlebars, using v13's own elements (`<prose-mirror>`, `data-action`) |
|
|
38
|
+
| `styles/main.css` | Imports `@vttforge/styles` and scopes your rules under `.{{ID}}` |
|
|
39
|
+
| `lang/en.json` | Strings, under the `{{LOCALE_PREFIX}}` prefix |
|
|
40
|
+
|
|
41
|
+
## Two things worth knowing before you edit
|
|
42
|
+
|
|
43
|
+
**Sheets are registered by id, not by class name.** `registerSystem({ sheets })`
|
|
44
|
+
pins each sheet under `{{ID}}.<id>`. Foundry saves that key on every actor
|
|
45
|
+
whose owner picked the sheet, and derives it from the class name unless told
|
|
46
|
+
otherwise — which a bundler renames between builds. Keep the ids; renaming one
|
|
47
|
+
loses the sheet choice on every document already using it.
|
|
48
|
+
|
|
49
|
+
**`this.document` is `unknown` on the sheet bases.** Which document a sheet is
|
|
50
|
+
for is yours to know. Each sheet here narrows it once in a getter (`actor`,
|
|
51
|
+
`item`) and everything below reads typed.
|
|
52
|
+
|
|
53
|
+
## Checks
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
```bash
|
|
56
|
+
pnpm typecheck # tsc against the real @vttforge/core types
|
|
57
|
+
npx vttforge audit # manifest + source against the v13 list of quiet breakages
|
|
58
|
+
```
|
|
43
59
|
|
|
44
|
-
|
|
60
|
+
## Releasing
|
|
61
|
+
|
|
62
|
+
Push a tag and `.github/workflows/release.yml` builds, zips, and attaches
|
|
63
|
+
`{{ID}}-<version>.zip` plus `system.json` to a GitHub Release:
|
|
45
64
|
|
|
46
65
|
```bash
|
|
47
66
|
git tag v0.1.0
|
|
48
67
|
git push --tags
|
|
49
68
|
```
|
|
50
69
|
|
|
51
|
-
Foundry
|
|
52
|
-
|
|
53
|
-
For foundryvtt.com submissions, submit the same manifest URL pattern.
|
|
70
|
+
Point Foundry — and foundryvtt.com — at the release's
|
|
71
|
+
`latest/download/system.json`, so installs auto-update on every tag.
|
|
54
72
|
|
|
55
73
|
## License
|
|
56
74
|
|
|
@@ -1,81 +1,97 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CharacterData —
|
|
2
|
+
* CharacterData — the `character` Actor type.
|
|
3
3
|
*
|
|
4
|
-
* Quick stats are HP / AC / SPD / INIT
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `prepareBaseData` initialises fields that Active Effects need to mutate
|
|
9
|
-
* (base max HP before any AE bonus); `prepareDerivedData` then computes
|
|
10
|
-
* the AE-aware values (modifiers, percentages, totals). Never write to the
|
|
11
|
-
* database in either hook — they're purely in-memory derivations.
|
|
4
|
+
* Quick stats are HP / AC / SPD / INIT; abilities are the six classic scores.
|
|
5
|
+
* Derived state (modifiers, max HP, armour class, initiative) is computed in
|
|
6
|
+
* memory in `prepareDerivedData`. Never write to the database from there.
|
|
12
7
|
*/
|
|
13
8
|
import { BaseTypeDataModel, fields } from '@vttforge/core';
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The schema, as a function handed to the factory.
|
|
12
|
+
*
|
|
13
|
+
* Both this and a `static defineSchema()` on the class work at runtime. Only
|
|
14
|
+
* this form is typed: pass it in and `this.level` is a `number` inside
|
|
15
|
+
* `prepareDerivedData`, while the no-argument form leaves every field unknown.
|
|
16
|
+
*
|
|
17
|
+
* It has to be a function rather than an object because `fields()` reads a
|
|
18
|
+
* Foundry global that does not exist when this module is first evaluated.
|
|
19
|
+
*/
|
|
20
|
+
const defineCharacterSchema = () => {
|
|
21
|
+
const f = fields();
|
|
22
|
+
|
|
23
|
+
// One ability. `value` is stored and is what the sheet's input writes to
|
|
24
|
+
// (`name="system.abilities.str.value"`). `mod` is derived on every data
|
|
25
|
+
// preparation and lives in the schema only so it has a typed home — see
|
|
26
|
+
// the note on `armorClass` below for the alternative.
|
|
27
|
+
const score = () =>
|
|
28
|
+
new f.SchemaField({
|
|
29
|
+
value: new f.NumberField({
|
|
23
30
|
required: true,
|
|
24
31
|
nullable: false,
|
|
25
32
|
integer: true,
|
|
26
33
|
min: 1,
|
|
27
34
|
max: 30,
|
|
28
35
|
initial: 10,
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
level: new f.NumberField({
|
|
32
|
-
required: true,
|
|
33
|
-
nullable: false,
|
|
34
|
-
integer: true,
|
|
35
|
-
min: 1,
|
|
36
|
-
max: 20,
|
|
37
|
-
initial: 1,
|
|
38
|
-
}),
|
|
39
|
-
speed: new f.NumberField({
|
|
40
|
-
required: true,
|
|
41
|
-
nullable: false,
|
|
42
|
-
integer: true,
|
|
43
|
-
min: 0,
|
|
44
|
-
initial: 30,
|
|
45
|
-
}),
|
|
46
|
-
abilities: new f.SchemaField({
|
|
47
|
-
str: score(),
|
|
48
|
-
dex: score(),
|
|
49
|
-
con: score(),
|
|
50
|
-
int: score(),
|
|
51
|
-
wis: score(),
|
|
52
|
-
cha: score(),
|
|
53
|
-
}),
|
|
54
|
-
health: new f.SchemaField({
|
|
55
|
-
value: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 10 }),
|
|
56
|
-
max: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 10 }),
|
|
57
|
-
}),
|
|
58
|
-
power: new f.SchemaField({
|
|
59
|
-
value: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 5 }),
|
|
60
|
-
max: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 5 }),
|
|
61
36
|
}),
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
}
|
|
37
|
+
mod: new f.NumberField({ required: true, nullable: false, integer: true, initial: 0 }),
|
|
38
|
+
});
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
40
|
+
return {
|
|
41
|
+
level: new f.NumberField({
|
|
42
|
+
required: true,
|
|
43
|
+
nullable: false,
|
|
44
|
+
integer: true,
|
|
45
|
+
min: 1,
|
|
46
|
+
max: 20,
|
|
47
|
+
initial: 1,
|
|
48
|
+
}),
|
|
49
|
+
speed: new f.NumberField({
|
|
50
|
+
required: true,
|
|
51
|
+
nullable: false,
|
|
52
|
+
integer: true,
|
|
53
|
+
min: 0,
|
|
54
|
+
initial: 30,
|
|
55
|
+
}),
|
|
56
|
+
abilities: new f.SchemaField({
|
|
57
|
+
str: score(),
|
|
58
|
+
dex: score(),
|
|
59
|
+
con: score(),
|
|
60
|
+
int: score(),
|
|
61
|
+
wis: score(),
|
|
62
|
+
cha: score(),
|
|
63
|
+
}),
|
|
64
|
+
health: new f.SchemaField({
|
|
65
|
+
value: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 10 }),
|
|
66
|
+
max: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 10 }),
|
|
67
|
+
}),
|
|
68
|
+
power: new f.SchemaField({
|
|
69
|
+
value: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 5 }),
|
|
70
|
+
max: new f.NumberField({ required: true, nullable: false, integer: true, min: 0, initial: 5 }),
|
|
71
|
+
}),
|
|
72
|
+
biography: new f.HTMLField(),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
export class CharacterData extends BaseTypeDataModel(defineCharacterSchema) {
|
|
77
|
+
/**
|
|
78
|
+
* Derived, so declared rather than put in the schema. `declare` tells
|
|
79
|
+
* TypeScript the property exists after `prepareDerivedData` without
|
|
80
|
+
* emitting a class field that would shadow what Foundry prepares.
|
|
81
|
+
*/
|
|
82
|
+
declare armorClass: number;
|
|
83
|
+
declare initiative: number;
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
override prepareDerivedData(): void {
|
|
86
|
+
for (const ability of Object.values(this.abilities)) {
|
|
87
|
+
ability.mod = Math.floor((ability.value - 10) / 2);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.health.max = 10 + this.level + this.abilities.con.mod;
|
|
91
|
+
this.armorClass = 10 + this.abilities.dex.mod;
|
|
92
|
+
this.initiative = this.abilities.dex.mod;
|
|
80
93
|
}
|
|
81
94
|
}
|
|
95
|
+
|
|
96
|
+
/** The shape of `actor.system` for a character, derived from the schema. */
|
|
97
|
+
export type CharacterSystem = CharacterData['$inferData'];
|