diff --git a/src/main.mjs b/src/main.mjs index d08884f6..b7cf9caa 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -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!") diff --git a/src/module/Actors/dsa-actor.mjs b/src/module/Actors/dsa-actor.mjs deleted file mode 100644 index da6bcce9..00000000 --- a/src/module/Actors/dsa-actor.mjs +++ /dev/null @@ -1,3 +0,0 @@ -export class DsaActor extends Actor { - -} \ No newline at end of file diff --git a/src/module/data/base-item.mjs b/src/module/data/base-item.mjs new file mode 100644 index 00000000..f0c7f60f --- /dev/null +++ b/src/module/data/base-item.mjs @@ -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; + } + +} \ No newline at end of file diff --git a/src/module/character/character.mjs b/src/module/data/character.mjs similarity index 94% rename from src/module/character/character.mjs rename to src/module/data/character.mjs index 0c5f9c01..802f43ed 100644 --- a/src/module/character/character.mjs +++ b/src/module/data/character.mjs @@ -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 { diff --git a/src/module/Items/skill.mjs b/src/module/data/skill.mjs similarity index 68% rename from src/module/Items/skill.mjs rename to src/module/data/skill.mjs index 161aef91..5056e80a 100644 --- a/src/module/Items/skill.mjs +++ b/src/module/data/skill.mjs @@ -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() { } + } \ No newline at end of file diff --git a/src/module/Items/spell.mjs b/src/module/data/spell.mjs similarity index 85% rename from src/module/Items/spell.mjs rename to src/module/data/spell.mjs index a2ae8de0..7a2628b4 100644 --- a/src/module/Items/spell.mjs +++ b/src/module/data/spell.mjs @@ -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() { } + } \ No newline at end of file diff --git a/src/module/documents/character.mjs b/src/module/documents/character.mjs new file mode 100644 index 00000000..a46baa97 --- /dev/null +++ b/src/module/documents/character.mjs @@ -0,0 +1,9 @@ +export class Character extends Item { + /** + * Augment the basic Item data model with additional dynamic data. + */ + prepareData() { + super.prepareData(); + } + +} \ No newline at end of file diff --git a/src/module/documents/skill.mjs b/src/module/documents/skill.mjs new file mode 100644 index 00000000..ead10ed7 --- /dev/null +++ b/src/module/documents/skill.mjs @@ -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(); + } + +} \ No newline at end of file diff --git a/src/module/documents/spell.mjs b/src/module/documents/spell.mjs new file mode 100644 index 00000000..f382a84c --- /dev/null +++ b/src/module/documents/spell.mjs @@ -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(); + } + +} \ No newline at end of file diff --git a/src/module/Items/skillSheet.mjs b/src/module/sheets/skillSheet.mjs similarity index 96% rename from src/module/Items/skillSheet.mjs rename to src/module/sheets/skillSheet.mjs index 563da5b9..59d17497 100644 --- a/src/module/Items/skillSheet.mjs +++ b/src/module/sheets/skillSheet.mjs @@ -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, { diff --git a/src/module/Items/spellSheet.mjs b/src/module/sheets/spellSheet.mjs similarity index 95% rename from src/module/Items/spellSheet.mjs rename to src/module/sheets/spellSheet.mjs index 9b93553d..e6f30cf5 100644 --- a/src/module/Items/spellSheet.mjs +++ b/src/module/sheets/spellSheet.mjs @@ -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, { diff --git a/src/system.json b/src/system.json index a7c60663..1013f8c7 100644 --- a/src/system.json +++ b/src/system.json @@ -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" ]