refactoring module structure

pull/14/head
macniel 2025-09-27 11:41:25 +02:00
parent db1b60fb19
commit ea436f3e4a
12 changed files with 95 additions and 34 deletions

View File

@ -1,14 +1,14 @@
import { PlayerCharacterDataModel } from "./module/character/character.mjs";
import { DsaActor } from "./module/Actors/dsa-actor.mjs";
import { Skill } from "./module/Items/skill.mjs"
import { SkillSheet } from "./module/Items/skillSheet.mjs";
import { Spell } from "./module/Items/spell.mjs";
import { SpellSheet } from "./module/Items/spellSheet.mjs";
import { SkillSheet } from "./module/sheets/skillSheet.mjs";
import { SpellSheet } from "./module/sheets/spellSheet.mjs";
import { SkillDataModel } from "./module/data/skill.mjs";
import { SpellDataModel } from "./module/data/spell.mjs";
import { Character } from "./module/documents/character.mjs";
Hooks.once("init", () => {
// Configure custom Document implementations.
CONFIG.Actor.documentClass = DsaActor;
CONFIG.Actor.documentClass = Character;
// Configure System Data Models.
CONFIG.Actor.dataModels = {
@ -16,8 +16,8 @@ Hooks.once("init", () => {
};
CONFIG.Item.dataModels = {
skills: Skill,
spells: Spell
skill: SkillDataModel,
spell: SpellDataModel
}
console.log("DSA 4.1 is ready for development!")

View File

@ -1,3 +0,0 @@
export class DsaActor extends Actor {
}

View File

@ -0,0 +1,21 @@
export default class BaseItem extends foundry.abstract.TypeDataModel {
/** @inheritDoc */
async importFromCompendium(pack, id, updateData={}, options={}) {
console.log(`called ${pack} ${id} `);
const created = await super.importFromCompendium(pack, id, updateData, options);
const item = await pack.getDocument(id);
const contents = await item.system.contents;
if ( contents ) {
const fromOptions = foundry.utils.mergeObject({ clearSort: false }, options);
const toCreate = await BaseItem.createWithContents(contents, {
container: created, keepId: options.keepId, transformAll: item => this.fromCompendium(item, fromOptions)
});
await BaseItem.createDocuments(toCreate, {fromCompendium: true, keepId: true});
}
return created;
}
}

View File

@ -1,11 +1,11 @@
import { Skill } from "../Items/skill.mjs";
import { Spell } from "../Items/spell.mjs";
import { Skill } from "./Items/skill.mjs";
import { Spell } from "./Items/spell.mjs";
const {
SchemaField, NumberField, StringField, ArrayField, BooleanField, EmbeddedCollectionField,
} = foundry.data.fields;
export class PlayerCharacterDataModel extends Actor {
export class PlayerCharacterDataModel extends foundry.abstract.TypeDataModel {
static defineSchema() {
return {

View File

@ -1,6 +1,8 @@
import BaseItem from "./base-item.mjs";
const { BooleanField, ArrayField, NumberField, SchemaField, StringField, HTMLField } = foundry.data.fields;
export class Skill extends Item {
export class SkillDataModel extends BaseItem {
static defineSchema() {
return {
@ -8,12 +10,12 @@ export class Skill extends Item {
gruppe: new StringField({ required: true }),
probe: new ArrayField(new StringField(), { exact: 3 }), // References one of the eight attributes by name
voraussetzung: new SchemaField({
talent: new StringField({ model: Skill }),
wert: new NumberField(),
talent: new StringField({ model: SkillDataModel }),
wert: new NumberField({}),
}), // Required skills at a given level
talent: new HTMLField(),
behinderung: new NumberField(), // BE-X
komplexität: new NumberField(), // In case of languages
talent: new HTMLField({ required: true }),
behinderung: new NumberField({ required: false}), // BE-X
komplexität: new NumberField({ required: false }), // In case of languages
}
}
/**
@ -33,4 +35,5 @@ export class Skill extends Item {
* @private
*/
async roll() { }
}

View File

@ -1,17 +1,20 @@
import BaseItem from "./base-item.mjs";
const { BooleanField, NumberField, SchemaField, ArrayField, StringField, HTMLField } = foundry.data.fields;
export class Spell extends Item {
export class SpellDataModel extends BaseItem {
static defineSchema() {
return {
seite: new NumberField(),
name: new StringField({ required: true }),
probe: new ArrayField({ required: true, exact: 3 }),
probe: new ArrayField( new StringField(), { required: true, exact: 3 }),
probeMod: new StringField(),
technik: new StringField(),
zauberdauer: new StringField(),
wirkung: new StringField(),
kosten: new StringField(),
zielobjekt: new StringField(),
reichweite: new StringField({ required: true }),
wirkungsdauer: new StringField({ required: true }),
modifikationen: new StringField({ required: true }),
@ -42,4 +45,5 @@ export class Spell extends Item {
* @private
*/
async roll() { }
}

View File

@ -0,0 +1,9 @@
export class Character extends Item {
/**
* Augment the basic Item data model with additional dynamic data.
*/
prepareData() {
super.prepareData();
}
}

View File

@ -0,0 +1,11 @@
import { BaseItem } from "./base-item.mjs";
export class Skill extends BaseItem {
/**
* Augment the basic Item data model with additional dynamic data.
*/
prepareData() {
super.prepareData();
}
}

View File

@ -0,0 +1,11 @@
import { BaseItem } from "./base-item.mjs";
export class Spell extends BaseItem {
/**
* Augment the basic Item data model with additional dynamic data.
*/
prepareData() {
super.prepareData();
}
}

View File

@ -1,4 +1,4 @@
export class SkillSheet extends ItemSheet {
export class SkillSheet extends foundry.appv1.sheets.ItemSheet {
/**@override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {

View File

@ -1,4 +1,4 @@
export class SpellSheet extends ItemSheet {
export class SpellSheet extends foundry.appv1.sheets.ItemSheet {
/**@override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {

View File

@ -26,7 +26,7 @@
],
"packs": [
{
"name": "Skill",
"name": "skills",
"label": "Basistalente",
"system": "DSA_4-1",
"type": "Item",
@ -34,7 +34,7 @@
"private": false
},
{
"name": "Spells",
"name": "spells",
"label": "Basiszauber",
"system": "DSA_4-1",
"type": "Item",
@ -60,7 +60,7 @@
"color": "#801020",
"sorting": "m",
"packs": [
"Spells"
"spells"
]
}
],
@ -79,18 +79,19 @@
"Skill": {
"stringFields": [
"name",
"gruppe",
"probe",
"voraussetzung"
"gruppe"
],
"arrayFields": [
"probe"
],
"numberFields": [
"handicapValue",
"complexity"
"behinderung",
"komplexität"
],
"htmlFields": [
"text"
"talent"
],
"foreignDocumentField": [
"schemaFields": [
"voraussetzung"
]
},
@ -102,6 +103,7 @@
"zauberdauer",
"wirkung",
"kosten",
"zielobjekt",
"reichweite",
"wirkungsdauer",
"modifikationen",
@ -115,6 +117,9 @@
"numberFields": [
"seite"
],
"schemaFields": [
"varianten"
],
"arrayFields": [
"probe"
]