diff --git a/src/module/data/deity.mjs b/src/module/data/deity.mjs new file mode 100644 index 00000000..64d1dfc8 --- /dev/null +++ b/src/module/data/deity.mjs @@ -0,0 +1,35 @@ +import BaseItem from "./baseItem.mjs"; +import {Liturgy} from "../documents/liturgy.mjs"; + +const { + ArrayField, + NumberField, + StringField, + HTMLField, + SchemaField, + DocumentIdField, +} = foundry.data.fields; + +export class DeityDataModel extends BaseItem { + + static defineSchema() { + return { + alias: new ArrayField(new StringField()), + description: new HTMLField(), + miracleMinus: new ArrayField(new StringField()), + miraclePlus: new ArrayField(new StringField()), + karmicEnergy: new NumberField({integer: true}), + liturgies: new SchemaField({ + rank0: new ArrayField(new StringField()), + rank1: new ArrayField(new StringField()), + rank2: new ArrayField(new StringField()), + rank3: new ArrayField(new StringField()), + rank4: new ArrayField(new StringField()), + rank5: new ArrayField(new StringField()), + rank6: new ArrayField(new StringField()), + rank7: new ArrayField(new StringField()), + rank8: new ArrayField(new StringField()), + }), + } + } +} \ No newline at end of file diff --git a/src/module/documents/deity.mjs b/src/module/documents/deity.mjs new file mode 100644 index 00000000..ed5bb394 --- /dev/null +++ b/src/module/documents/deity.mjs @@ -0,0 +1,9 @@ +export class Deity extends Item { + /** + * Augment the basic Item data model with additional dynamic data. + */ + prepareData() { + super.prepareData(); + } + +} diff --git a/src/module/setup/config.mjs b/src/module/setup/config.mjs index d2e9c7e7..53a2dfd8 100644 --- a/src/module/setup/config.mjs +++ b/src/module/setup/config.mjs @@ -19,6 +19,7 @@ import {BattleDialog} from "../dialog/battleDialog.mjs"; import {Talent} from "../data/talent.mjs"; import {Character} from "../documents/character.mjs"; import {currency} from "../handlebar-helpers/currency.mjs"; +import {DeityDataModel} from "../data/deity.mjs"; function initGlobalAccess() { @@ -59,6 +60,7 @@ function initDataModels(config) { Profession: ProfessionDataModel, Spezies: SpeciesDataModel, Kultur: CultureDataModel, + Deity: DeityDataModel, } } diff --git a/src/module/setup/sheets.mjs b/src/module/setup/sheets.mjs index 9fee2f1b..51fe9bec 100644 --- a/src/module/setup/sheets.mjs +++ b/src/module/setup/sheets.mjs @@ -12,6 +12,7 @@ import {CultureSheet} from "../sheets/cultureSheet.mjs"; import {SpeciesSheet} from "../sheets/SpeciesSheet.mjs"; import {ProfessionSheet} from "../sheets/professionSheet.mjs"; import {MerchantSheet} from "../sheets/merchantSheet.mjs"; +import {DeitySheet} from "../sheets/deitySheet.mjs"; function setUpActorSheets(registry) { @@ -88,6 +89,11 @@ function setUpItemSheets(registry) { makeDefault: true, }) + registry.registerSheet('dsa41.deity', DeitySheet, { + types: ['Deity'], + makeDefault: true, + }) + } export { diff --git a/src/module/sheets/deitySheet.mjs b/src/module/sheets/deitySheet.mjs new file mode 100644 index 00000000..d002f736 --- /dev/null +++ b/src/module/sheets/deitySheet.mjs @@ -0,0 +1,228 @@ +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +export class DeitySheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 520, height: 848}, + classes: ['dsa41', 'sheet', 'item', 'deity'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: DeitySheet.#onSubmitForm + }, + window: { + resizable: true, + }, + actions: { + editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage, + openLiturgy: DeitySheet.#openLiturgySheet, + removeLiturgy: DeitySheet.#removeLiturgy, + } + } + + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/deity-sheet.hbs` + }, + } + + /** + * Handle form submission + * @this {SpeciesSheet} + * @param {SubmitEvent} event + * @param {HTMLFormElement} form + * @param {FormDataExtended} formData + */ + static async #onSubmitForm(event, form, formData) { + event.preventDefault() + + formData.object["system.miraclePlus"] = formData.object.miraclePlus.split(",") + formData.object["system.miracleMinus"] = formData.object.miracleMinus.split(",") + + delete formData.object.miraclePlus + delete formData.object.miracleMinus + + await this.document.update(formData.object) // Note: formData.object + } + + static async #openLiturgySheet(event, target) { + const {rank, liturgyId} = target.dataset + if (liturgyId && rank) { + this.document.system.liturgies["rank" + rank].find(p => p._id === liturgyId)?.sheet.render(true, {editable: false}) + } + } + + static async #removeLiturgy(event, target) { + const {rank, liturgyId} = target.dataset + if (liturgyId && rank) { + const idx = this.document.system.liturgies["rank" + rank].findIndex(p => p._id === liturgyId) + this.document.system.liturgies["rank" + rank].splice(idx, 1) + const thisUpdateObject = {} + thisUpdateObject["system.liturgies.rank" + rank] = this.document.system.liturgies + this.document.update(thisUpdateObject) + this.render({parts: ["form"]}) + } + } + + _configureRenderOptions(options) { + super._configureRenderOptions(options) + + if (options.window) { + options.window.title = this.document.name + } + + return options + } + + /** @override */ + async _prepareContext(options) { + + // const context = await super._prepareContext(options) + context.system = this.document.system + + context.name = this.document.name + context.img = this.document.img + context.description = this.document.description + + context.liturgies = { + rank0: [], + rank1: [], + rank2: [], + rank3: [], + rank4: [], + rank5: [], + rank6: [], + rank7: [], + rank8: [], + } + + context.miraclePlus = this.document.system.miraclePlus?.join(",") + context.miracleMinus = this.document.system.miracleMinus?.join(",") + + this.document.system.liturgies.rank0.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank0.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank1.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank1.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank2.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank2.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank3.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank3.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank4.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank4.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank5.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank5.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank6.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank6.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank7.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank7.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + this.document.system.liturgies.rank8.forEach(liturgyUuid => { + fromUuid(liturgyUuid).then(liturgy => { + context.liturgies.rank8.push({ + id: liturgy._id, + name: liturgy.name, + }) + }) + }) + + return context + } + + + async _canDragDrop() { + return true + } + + _onRender(context, options) { + new foundry.applications.ux.DragDrop.implementation({ + dropSelector: ".liturgy-drops", + permissions: { + drop: this._canDragDrop.bind(this) + }, + callbacks: { + drop: this._onDrop.bind(this) + } + }).bind(this.element); + } + + async _onDrop(event, target) { + const data = TextEditor.implementation.getDragEventData(event); + const documentClass = foundry.utils.getDocumentClass(data.type) + if (documentClass) { + const document = await documentClass.fromDropData(data); + + if (document.type === "Liturgy") { + // process and drop it rightly + const {rank} = event.target.dataset + if (rank) { + let rankData = this.document.system.liturgies["rank" + rank] + rankData.push(document.uuid) + const updateData = {} + updateData["system.liturgies.rank" + rank] = rankData + this.document.update(updateData) + this.render({parts: ["form"]}) + } + + } + } + } + +} \ No newline at end of file diff --git a/src/style/organisms/_deity-sheet.scss b/src/style/organisms/_deity-sheet.scss new file mode 100644 index 00000000..3e6214ac --- /dev/null +++ b/src/style/organisms/_deity-sheet.scss @@ -0,0 +1,73 @@ +.dsa41.item.deity { + + .deity { + + .head { + display: grid; + grid-template-columns: 52px 1fr 80px; + height: 52px; + gap: 8px; + + img { + width: 52px; + height: 52px; + } + + margin-bottom: 8px; + } + + fieldset { + padding: 8px 0; + } + + .miracles { + + display: flex; + gap: 8px; + + } + + table { + + tr th:first-child { + width: 64px; + } + + div.liturgy { + border: 1px solid #333; + background-color: darkgrey; + box-shadow: 1px 1px 1px black; + height: 24px; + display: inline-block; + position: relative; + padding-left: 4px; + padding-right: 24px; + + span { + line-height: 24px; + height: 24px; + vertical-align: middle; + + } + + button.mini { + border: unset; + background: unset; + width: 24px; + height: 24px; + padding: unset; + margin: unset; + text-align: center; + position: absolute; + right: 0; + top: -2px; + } + + + } + + } + + } + +} \ No newline at end of file diff --git a/src/style/styles.scss b/src/style/styles.scss index 6c95fc74..e78462f6 100644 --- a/src/style/styles.scss +++ b/src/style/styles.scss @@ -34,4 +34,5 @@ @use "organisms/resting-dialog"; @use "organisms/battle-dialog"; @use "organisms/liturgy-sheet"; -@use "organisms/dialog"; \ No newline at end of file +@use "organisms/dialog"; +@use "organisms/deity-sheet"; \ No newline at end of file diff --git a/src/system.json b/src/system.json index 9c5adae7..fd2be8a8 100644 --- a/src/system.json +++ b/src/system.json @@ -308,6 +308,7 @@ }, "Blessing": {}, "Liturgy": {}, + "Deity": {}, "Spell": { "stringFields": [ "name", diff --git a/src/templates/item/deity-sheet.hbs b/src/templates/item/deity-sheet.hbs new file mode 100644 index 00000000..a84e4020 --- /dev/null +++ b/src/templates/item/deity-sheet.hbs @@ -0,0 +1,165 @@ +
+
+ + + + +
+
+ + + {{{description}}} + +
+
+ Mirakel +
+
+
+
+
+
+ Liturgien + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
GradLiturgien
0 + {{#each liturgies.rank0}} +
+ {{this.name}} + +
+ {{/each}} +
I + {{#each liturgies.rank1}} +
+ {{this.name}} + +
+ {{/each}} +
II + {{#each liturgies.rank2}} +
+ {{this.name}} + +
+ {{/each}} +
III + {{#each liturgies.rank3}} +
+ {{this.name}} + +
+ {{/each}} +
IV + {{#each liturgies.rank4}} +
+ {{this.name}} + +
+ {{/each}} +
V + {{#each liturgies.rank5}} +
+ {{this.name}} + +
+ {{/each}} +
VI + {{#each liturgies.rank6}} +
+ {{this.name}} + +
+ {{/each}} +
VII + {{#each liturgies.rank7}} +
+ {{this.name}} + +
+ {{/each}} +
VIII + {{#each liturgies.rank8}} +
+ {{this.name}} + +
+ {{/each}} +
+
+
\ No newline at end of file