From 68522582fd99d10dd9cc474264c829c372ce3ac3 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:56:53 +0200 Subject: [PATCH] add basic actor sheet --- src/ActorSheet.html | 67 +++++++++++++++++++++++++++++ src/Assets/d20.svg | 15 +++++++ src/main.css | 62 +++++++++++++++++++++++++++ src/main.mjs | 100 ++++++++++++++++++++++++++++++-------------- template.json | 16 +++---- 5 files changed, 218 insertions(+), 42 deletions(-) create mode 100644 src/ActorSheet.html create mode 100644 src/Assets/d20.svg diff --git a/src/ActorSheet.html b/src/ActorSheet.html new file mode 100644 index 0000000..8df08e4 --- /dev/null +++ b/src/ActorSheet.html @@ -0,0 +1,67 @@ +{{#*inline "editable-text"}} +
+ {{#if @root.editable}} + + {{else}} +
{{value}}
+ {{/if}} + + {{#if placeholder}} +
{{placeholder}}
+ {{/if}} +
+{{/inline}} + +{{#*inline "die-type"}} +
{{type}}
+{{/inline}} + +{{#*inline "die-value"}} +
+
{{type}}
+
{{lookup @root.actor.system.computed type}}
+
+{{/inline}} + +
+
+ {{>editable-text name="name" value=actor.name placeholder="Name"}} + {{>editable-text name="system.race" value=actor.system.race placeholder="Rasse"}} + {{>editable-text name="system.cultuee" value=actor.system.culture placeholder="Kultur"}} + {{>editable-text name="system.profession" value=actor.system.profession placeholder="Profession"}} +
+
+ + {{#each actor.system.attributes}} + {{>die-value type=@key}} + {{/each}} +
+
+ + + + {{#each actor.system.attributes}} + + {{/each}} + + + + {{#each actor.system.attributes}} + + {{/each}} + + + + {{#each actor.system.attributes}} + + {{/each}} + + + + {{#each actor.system.attributes}} + + {{/each}} + +
{{@key}}
Startwert{{>editable-text name=(concat "system.attributes." @key ".initial") value=(lookup this "initial")}}
Steigerungen{{>editable-text name=(concat "system.attributes." @key ".advancement") value=(lookup this "advancement")}}
Modifikatoren{{>editable-text name=(concat "system.attributes." @key ".modifier") value=(lookup this "modifier")}}
+
+
\ No newline at end of file diff --git a/src/Assets/d20.svg b/src/Assets/d20.svg new file mode 100644 index 0000000..bf4af44 --- /dev/null +++ b/src/Assets/d20.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/main.css b/src/main.css index fe1bc29..d9f6f00 100644 --- a/src/main.css +++ b/src/main.css @@ -1,3 +1,65 @@ +.row { + display: flex; + flex-direction: row; +} + +.col { + display: flex; + flex-direction: column; +} + +.wrap { + flex-wrap: wrap; +} + +.center { + text-align: center; +} + + +.placeholder { + font-size: 0.8em; + border-top: 1px solid; +} + +.editable-text { + flex: 1; + padding: 0px 3px; +} + +.editable-text input { + border: none; +} + + +.character-image { + width: 115px; + height: 115px; +} + +.die { + width: 48px; + height: 48px; + line-height: 48px; + + background-color: #000; + mask-image: url("../src/Assets/d20.svg"); + mask-size: contain; + + text-align: center; + color: #fff; +} + +.die-MU { background-color: #b22319; } +.die-KL { background-color: #8158a3; } +.die-IN { background-color: #388834; } +.die-CH { background-color: #0c0c0c; } +.die-FF { background-color: #d4b366; } +.die-GE { background-color: #678ec3; } +.die-KO { background-color: #a3a3a3; } +.die-KK { background-color: #d5a877; } + + .item-sheet header { display: flex; flex-flow: row wrap; diff --git a/src/main.mjs b/src/main.mjs index 3aca58d..bf99013 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -1,43 +1,79 @@ -function init() { +Hooks.once("init", function() { console.log("INIT"); + CONFIG.Actor.dataModels.Player = DSA41_CharacterData; + + //DocumentSheetConfig.unregisterSheet(Actor, "core", ActorSheet); + DocumentSheetConfig.registerSheet(Actor, "dsa41", DSA41_ActorSheet, { + makeDefault: true, + types: [ + "Player", + ] + }); + //DocumentSheetConfig.unregisterSheet(Item, "core", ItemSheet); DocumentSheetConfig.registerSheet(Item, "dsa41", DSA41_ItemSheet, { - makeDefault: true, - types: [ - "Generic Item", - "Melee Weapon", - "Ranged Weapon", - "Armor", - "Shield", - ] + makeDefault: true, + types: [ + "Generic Item", + "Melee Weapon", + "Ranged Weapon", + "Armor", + "Shield", + ] + }); +}); + +const { SchemaField, NumberField, StringField } = foundry.data.fields; + +class AttributeField extends foundry.data.fields.SchemaField { + constructor() { + return super({ + initial: new NumberField({ integer: true, initial: 8, min: 8, max: 14, }), + advancement: new NumberField({ integer: true, initial: 0, min: 0, max: 4, }), + modifier: new NumberField({ integer: true, initial: 0, min: 0, }), + }); + } +} + +class DSA41_CharacterData extends foundry.abstract.TypeDataModel { + static defineSchema() { + return { + race: new StringField(), + culture: new StringField(), + profession: new StringField(), + + attributes: new SchemaField({ + MU: new AttributeField(), + KL: new AttributeField(), + IN: new AttributeField(), + CH: new AttributeField(), + FF: new AttributeField(), + GE: new AttributeField(), + KO: new AttributeField(), + KK: new AttributeField(), + }), } - ); + } + + prepareDerivedData() { + super.prepareDerivedData(); + this.computed = {}; + + for (const [attribute, values] of Object.entries(this.attributes)) { + this.computed[attribute] = Object.values(values).reduce((a, b) => a + b, 0); + } + } +} + +class DSA41_ActorSheet extends ActorSheet { + get template() { + return "systems/dsa-4th-edition/src/ActorSheet.html"; + } } class DSA41_ItemSheet extends ItemSheet { get template() { - return "systems/dsa-4th-edition/src/ItemSheets/" + this.item.type + ".html" + return "systems/dsa-4th-edition/src/ItemSheets/" + this.item.type + ".html"; } - - - getData() { - const data = super.getData(); - console.log(data); - return data; - } - } - -function ready() { - console.log("READY"); -} - -function setup() { - console.log("SETUP"); - //Item.create({"name": "TestItem4", "type": "spell", "system": {"price": "15"}}); -} - -Hooks.once("init", init); -Hooks.once("ready", ready); -Hooks.once("setup", setup); diff --git a/template.json b/template.json index 3c61cfc..d7168fb 100644 --- a/template.json +++ b/template.json @@ -1,20 +1,16 @@ { + "Actor": { + "types": [ + "Player" + ] + }, "Item": { - "templates": { - - }, "types": [ "Generic Item", "Melee Weapon", "Ranged Weapon", "Armor", "Shield" - ], - "weapon": { - "templates": [] - }, - "spell": { - "templates": [] - } + ] } } \ No newline at end of file