│ DataModels │ │ - Reorganize DataModels into src/module/models/ (one .mjs per type) │ - Create AppV2 actor/item sheets (HandlebarsApplicationMixin)…
4.1 KiB
Copilot Instructions for foundryvtt-mgt2
Project Overview
This is a Foundry VTT game system implementing Mongoose Publishing Traveller 2nd Edition (MGT2). It runs entirely in the browser within the FoundryVTT platform — there is no Node.js runtime or backend server to develop against.
The distributed entry point is mgt2.bundle.js (pre-bundled from src/). CSS is compiled from src/sass/ to styles/mgt2.min.css. No build tooling (package.json, webpack, etc.) is committed to the repo, so bundling is done externally.
Architecture
Entry Point & Initialization
src/module/core.js is the main module. It runs in the FoundryVTT init hook and:
- Registers all Actor/Item document classes
- Registers all TypeDataModel schemas (
datamodels.js) - Registers sheets (actor and item)
- Preloads Handlebars templates
Document Classes
| Class | File | Purpose |
|---|---|---|
TravellerActor |
actors/actor.js |
Extends Actor; delegates character logic to ActorCharacter |
ActorCharacter |
actors/character.js |
Static methods for character-specific actor logic |
TravellerItem |
item.js |
Extends Item |
MGT2Combatant |
actors/actor.js |
Extends Combatant |
Sheets
TravellerActorSheet(actors/character-sheet.js) — character sheet. Usestemplates/actors/actor-sheet.html.getData()returnscontext.data(not the full context).TravellerItemSheet(item-sheet.js) — item sheet. Template is dynamically resolved astemplates/items/{item.type}-sheet.html.VehiculeSheet(actors/vehicule-sheet.js) — vehicle actor sheet.
Data Models
All schemas are TypeDataModels defined in src/module/datamodels.js. Actor types: character, vehicule. Item types: contact, career, disease, item, equipment, talent, armor, weapon, computer, container, species.
The CharacterData model uses a helper createCharacteristicField() for the 12 characteristics (strength, dexterity, endurance, intellect, education, social, morale, luck, sanity, charm, psionic, other). Each characteristic has .value, .max, and .dm fields.
Config Constants
src/module/config.js exports MGT2 — a set of frozen objects mapping internal keys to i18n strings (e.g., MGT2.Difficulty.Average). Accessible at runtime via CONFIG.MGT2.
Templates
Handlebars templates live in templates/. Paths always use the FoundryVTT-relative prefix systems/mgt2/templates/.... Partial templates (used across sheets) live in templates/items/parts/.
Styles & Theming
SASS source is in src/sass/. The active theme is a CSS class applied to every sheet element — e.g. ["mgt2", game.settings.get("mgt2", "theme"), "sheet", ...]. Available themes: black-and-red, mwamba, blue.
Localization
All user-facing strings go through game.i18n.localize(). Keys follow the pattern MGT2.Section.Key. String definitions are in lang/en.json and lang/fr.json.
Chat Cards
ChatHelper (chatHelper.js) hooks into renderChatMessage to attach button listeners. Chat card templates are in templates/chat/.
Key Conventions
getData()returnscontext.data— the character sheet'sgetData()callssuper.getData()then returnscontext.data, notcontextitself. Keep this pattern for character sheet overrides.- Actor logic delegation —
TravellerActoris thin; type-specific logic lives in static methods onActorCharacter. Follow this pattern for new actor types. - Settings keys — always namespaced as
game.settings.get("mgt2", "settingName"). Settings are registered insettings.js. vehiculespelling — the actor type and related files use the French spellingvehicule(notvehicle). Do not rename.- Template paths — always use the full FoundryVTT path
systems/mgt2/templates/...in JS; never relative paths. - i18n keys in config —
config.jsstores i18n key strings (not translated text). Actual translation happens at render time viagame.i18n.localize(). lifeis the primary token attribute — configured insystem.jsonasprimaryTokenAttribute: "life".