Compare commits
2 Commits
21479ce082
...
b6814c9f74
| Author | SHA1 | Date |
|---|---|---|
|
|
b6814c9f74 | |
|
|
e47deaf938 |
|
|
@ -14,7 +14,8 @@ async function preloadHandlebarsTemplates() {
|
|||
'systems/DSA_4-1/templates/ui/partial-rollable-button.hbs',
|
||||
'systems/DSA_4-1/templates/ui/partial-attribute-button.hbs',
|
||||
'systems/DSA_4-1/templates/ui/partial-talent-editable.hbs',
|
||||
'systems/DSA_4-1/templates/ui/partial-die.hbs'
|
||||
'systems/DSA_4-1/templates/ui/partial-die.hbs',
|
||||
'systems/DSA_4-1/templates/ui/partial-advantage-button.hbs'
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,110 +34,4 @@ export class Character extends Actor {
|
|||
console.log(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
static onDroppedData(character, characterSheet, uuid) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
async addSkillFromCompendiumByNameToActor(talentName, actor) {
|
||||
const compendiumOfSkills = game.packs.get('DSA_4-1.talente-brw');
|
||||
const talentId = compendiumOfSkills.index.find( skill => skill.name === talentName)
|
||||
let talentObject = {}
|
||||
const talent = await compendiumOfSkills.getDocument(talentId);
|
||||
try {
|
||||
const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [talent]))[0]
|
||||
if (embeddedDocument.type === "Skill") {
|
||||
if (talent) {
|
||||
talentObject = {
|
||||
taw: 0,
|
||||
talent: embeddedDocument.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${talentName} not found in items`, error)
|
||||
}
|
||||
await actor.update({system: { talente: talentObject, ...actor.system.talente}})
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds base skills according to the BRW to the given actor
|
||||
* @param actor
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async #createBaseSkills(actor) {
|
||||
const talentsByName = [
|
||||
"Athletik", "Klettern", "Körperbeherrschung", "Schleichen", "Schwimmen", "Selbstbeherrschung", "Sich Verstecken", "Singen", "Sinnenschärfe", "Tanzen", "Zechen",
|
||||
"Menschenkenntnis", "Überreden",
|
||||
"Fährtensuchen", "Orientierung", "Wildnisleben",
|
||||
"Götter/Kulte", "Rechnen", "Sagen/Legenden",
|
||||
"Heilkunde: Wunden", "Holzbearbeitung", "Kochen", "Lederverarbeitung", "Malen/Zeichnen", "Schneidern"
|
||||
]
|
||||
|
||||
const talente = []
|
||||
|
||||
talentsByName.forEach(talentName => {
|
||||
|
||||
this.addSkillFromCompendiumByNameToActor(
|
||||
talentName,
|
||||
)
|
||||
})
|
||||
|
||||
await actor.update({system: { talente: talente}})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes of the given actor to their default values
|
||||
* @param actor
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async #setBaseAttributes(actor) {
|
||||
const startEigenschaften = {
|
||||
"mu": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"kl": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"in": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"ch": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"ff": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"ge": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"ko": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
},
|
||||
"kk": {
|
||||
start: 10,
|
||||
aktuell: 10,
|
||||
mod: 0
|
||||
}
|
||||
}
|
||||
|
||||
await actor.update({system: {attribute: startEigenschaften}})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,25 +80,20 @@ export class CharacterSheet extends ActorSheet {
|
|||
}
|
||||
|
||||
#addAdvantagesToContext(context) {
|
||||
const actorAdvantages = {}
|
||||
context.advantages = [];
|
||||
const actorData = context.data;
|
||||
Object.values(actorData.items).forEach( (item) => {
|
||||
if (item.type === "Advantage") {
|
||||
actorAdvantages[item._id] = item;
|
||||
context.advantages.push({
|
||||
id: item._id,
|
||||
name: item.name,
|
||||
value: item.system.value,
|
||||
options: item.system.auswahl,
|
||||
description: item.system.description,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
if ( context.system.vornachteile.length >= 0) {
|
||||
context.system.vornachteile.forEach( ( { vornachteil }, index) => {
|
||||
context.vornachteile.push(
|
||||
{
|
||||
name: vornachteil.name,
|
||||
value: vornachteil.value,
|
||||
auswahl: vornachteil.auswahl,
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#addAttributesToContext(context) {
|
||||
|
|
@ -193,18 +188,6 @@ export class CharacterSheet extends ActorSheet {
|
|||
}
|
||||
}
|
||||
|
||||
_onDropDocument(event, item) {
|
||||
console.log(item)
|
||||
|
||||
}
|
||||
|
||||
_onDragStart(event) {
|
||||
super._onDragStart(event);
|
||||
const src = event.target
|
||||
console.log(event)
|
||||
event.dataTransfer.setData("plain/text", src.dataset.name);
|
||||
}
|
||||
|
||||
_evaluateRoll(rolledDice, { taw, lowerThreshold = 1, upperThreshold = 20, countToMeisterlich = 3, countToPatzer = 3, werte = [] } ) {
|
||||
let tap = taw;
|
||||
let meisterlichCounter = 0;
|
||||
|
|
@ -262,8 +245,7 @@ export class CharacterSheet extends ActorSheet {
|
|||
}
|
||||
}
|
||||
|
||||
_onOpenSkill(documentId) {
|
||||
console.log(this.object.items.get(documentId).sheet);
|
||||
openEmbeddedDocument(documentId) {
|
||||
this.object.items.get(documentId).sheet.render(true)
|
||||
}
|
||||
|
||||
|
|
@ -315,7 +297,12 @@ export class CharacterSheet extends ActorSheet {
|
|||
});
|
||||
|
||||
html.on('click', '.talent .name', (evt) => {
|
||||
this._onOpenSkill(evt.target.dataset.id);
|
||||
this.openEmbeddedDocument(evt.target.dataset.id);
|
||||
evt.stopPropagation();
|
||||
})
|
||||
|
||||
html.on('click', '.advantage .name', (evt) => {
|
||||
this.openEmbeddedDocument(evt.target.dataset.id);
|
||||
evt.stopPropagation();
|
||||
})
|
||||
|
||||
|
|
@ -342,7 +329,6 @@ export class CharacterSheet extends ActorSheet {
|
|||
}
|
||||
]);
|
||||
|
||||
|
||||
let handler = ev => this._onDragStart(ev);
|
||||
// Find all items on the character sheet.
|
||||
html.find('.talent.rollable').each((i, li) => {
|
||||
|
|
@ -362,6 +348,15 @@ export class CharacterSheet extends ActorSheet {
|
|||
}
|
||||
}
|
||||
|
||||
#handleDroppedAdvantage(actor, advantage) {
|
||||
const array = Array.from(actor.items);
|
||||
for ( let i = 0; i < array.length; i++ ) {
|
||||
if (array[i].name === advantage.name) { // TODO: adjust for uniqueness
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getElementByName(collection, id) {
|
||||
const array = Array.from(collection);
|
||||
for (const element of array) {
|
||||
|
|
@ -383,6 +378,8 @@ export class CharacterSheet extends ActorSheet {
|
|||
switch (type) {
|
||||
case "Skill":
|
||||
return characterSheet.#handleDroppedSkill(actor, document); // on false cancel this whole operation
|
||||
case "Advantage":
|
||||
return characterSheet.#handleDroppedAdvantage(actor, document);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export async function importCharacter(actorId, file) {
|
|||
let dom = domParser.parseFromString(xmlString, 'application/xml')
|
||||
|
||||
let rawJson = getJsonFromXML(dom)
|
||||
let characterJson = mapRawJson(rawJson)
|
||||
let characterJson = mapRawJson(actor, rawJson)
|
||||
|
||||
actor.update(characterJson)
|
||||
}
|
||||
|
|
@ -70,6 +70,22 @@ function getJsonFromXML(dom) {
|
|||
return jsonResult;
|
||||
}
|
||||
|
||||
async function addSkillFromCompendiumByNameToActor(talentName, taw, actor) {
|
||||
const compendiumOfSkills = game.packs.get('DSA_4-1.talente-brw');
|
||||
const talentId = compendiumOfSkills.index.find( skill => skill.name === talentName)
|
||||
if (talentId) {
|
||||
|
||||
const talent = await compendiumOfSkills.getDocument(talentId._id);
|
||||
|
||||
try {
|
||||
const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [talent]))[0]
|
||||
embeddedDocument.update({system: {taw: taw}});
|
||||
} catch (error) {
|
||||
console.error(`${talentName} not found in items`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the text content of a file
|
||||
* @param file the file with the desired content
|
||||
|
|
@ -101,20 +117,11 @@ function calculateBirthdate(json) {
|
|||
return `${day}. ${month} ${year} BF`
|
||||
}
|
||||
|
||||
function mapSkills(rawJson) {
|
||||
let talents = []
|
||||
function mapSkills(actor, held) {
|
||||
for (let talent in held.talentliste.talent) {
|
||||
talent = held.talentliste.talent[talent]
|
||||
let talentItem = game.items.getName(talent.name)
|
||||
if (talentItem) {
|
||||
let talentJson = {
|
||||
talent: talentItem,
|
||||
taw: talent.value,
|
||||
addSkillFromCompendiumByNameToActor(talent.name, talent.value, actor)
|
||||
}
|
||||
talents.push(talentJson)
|
||||
}
|
||||
}
|
||||
return talents
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,7 +129,7 @@ function mapSkills(rawJson) {
|
|||
* @param rawJson the json parsed from the Helden-Software XML
|
||||
* @returns {{}} a json representation of the character
|
||||
*/
|
||||
function mapRawJson(rawJson) {
|
||||
function mapRawJson(actor, rawJson) {
|
||||
let json = {}
|
||||
let held = rawJson.helden.held;
|
||||
json.name = held.name
|
||||
|
|
@ -265,7 +272,7 @@ function mapRawJson(rawJson) {
|
|||
json.sonderfertigkeiten = specialAbilities
|
||||
json.liturgien = liturgies
|
||||
|
||||
json.talente = mapSkills(rawJson)
|
||||
mapSkills(actor, held)
|
||||
let spells = []
|
||||
/*for (let spell in held.zauberliste.zauber) {
|
||||
spell = held.zauberliste.zauber[spell]
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@
|
|||
</div>
|
||||
<div class="tab attributes" data-group="primary" data-tab="attributes">
|
||||
<ul>
|
||||
{{#each items}}
|
||||
<li>{{this.name}}</li>
|
||||
{{#each this.advantages}}
|
||||
<li>{{> "systems/DSA_4-1/templates/ui/partial-advantage-button.hbs" this}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
{{!-- Sheet Body --}}
|
||||
<section class="sheet-body" style="flex: 1">
|
||||
<div class="tab json" data-group="primary" data-tab="json">
|
||||
<pre style="overflow: auto">{{json}}</pre>
|
||||
<pre style="overflow: auto; white-space: normal; position: relative; top: 8px; bottom: 8px; left: 8px; right: 8px">{{json}}</pre>
|
||||
</div>
|
||||
</section>
|
||||
</form>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div class="advantage">
|
||||
<span class="name" data-id="{{this.id}}">{{this.name}}</span>
|
||||
</div>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<div class="block rollable {{this.type}} {{this.gruppe}}" data-id="{{this.id}}" data-taw="{{this.taw}}'data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}" data-eigenschaft3="{{this.eigenschaft3}}" data-taw="{{this.taw}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}" data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
|
||||
<div class="block rollable {{this.type}} {{this.gruppe}}" data-id="{{this.id}}" data-taw="{{this.taw}}" data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}" data-eigenschaft3="{{this.eigenschaft3}}" data-taw="{{this.taw}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}" data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
|
||||
|
||||
<div class="die">
|
||||
{{> 'systems/DSA_4-1/templates/ui/partial-die.hbs' }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue