v10 migration, ongoing WIP

This commit is contained in:
sladecraven 2022-05-03 09:01:10 +02:00
parent 4538439c02
commit a3fb328b7d
11 changed files with 60 additions and 65 deletions

View File

@ -48,7 +48,7 @@ export class RdDActorEntiteSheet extends ActorSheet {
limited: this.object.limited, limited: this.object.limited,
options: this.options, options: this.options,
owner: this.document.isOwner, owner: this.document.isOwner,
itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i.data))), itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))),
}; };
formData.options.isGM = game.user.isGM; formData.options.isGM = game.user.isGM;

View File

@ -53,7 +53,7 @@ export class RdDActorSheet extends ActorSheet {
limited: this.object.limited, limited: this.object.limited,
options: this.options, options: this.options,
owner: this.document.isOwner, owner: this.document.isOwner,
itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i.data))), itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))),
}; };
console.log("ACTOR DATA:", formData) console.log("ACTOR DATA:", formData)
@ -79,11 +79,12 @@ export class RdDActorSheet extends ActorSheet {
}; };
formData.competences.forEach(item => { formData.competences.forEach(item => {
item.visible = this.options.cherchercompetence console.log('Comp', item)
item.isVisible = this.options.cherchercompetence
? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence) ? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence)
: (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item)); : (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item));
RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value); RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value)
}); })
Object.values(formData.data.carac).forEach(c => { Object.values(formData.data.carac).forEach(c => {
RdDCarac.levelUp(c); RdDCarac.levelUp(c);
@ -386,9 +387,9 @@ export class RdDActorSheet extends ActorSheet {
this.actor.updateCarac(caracName, parseInt(event.target.value)); this.actor.updateCarac(caracName, parseInt(event.target.value));
}); });
html.find('.carac-xp').change(async event => { html.find('.carac-xp').change(async event => {
let caracName = event.currentTarget.name.replace(".xp", "").replace("data.carac.", ""); let caracName = event.currentTarget.name.replace(".xp", "").replace("system.carac.", "")
//console.log("Value changed :", event, caracName); //console.log("Value changed :", event, caracName)
this.actor.updateCaracXP(caracName, parseInt(event.target.value)); this.actor.updateCaracXP(caracName, parseInt(event.target.value))
}); });
// On competence change // On competence change
html.find('.competence-value').change(async event => { html.find('.competence-value').change(async event => {

View File

@ -845,6 +845,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async updateCarac(caracName, caracValue) { async updateCarac(caracName, caracValue) {
console.log("Carac change", caracName)
if (caracName == "force") { if (caracName == "force") {
if (Number(caracValue) > this.getTaille() + 4) { if (Number(caracValue) > this.getTaille() + 4) {
ui.notifications.warn("Votre FORCE doit être au maximum de TAILLE+4"); ui.notifications.warn("Votre FORCE doit être au maximum de TAILLE+4");
@ -951,11 +952,11 @@ export class RdDActor extends Actor {
if (competence) { if (competence) {
const update = { _id: competence.id } const update = { _id: competence.id }
if (fieldName == "niveau") if (fieldName == "niveau")
update['data.niveau'] = compValue; update['system.niveau'] = compValue;
else if (fieldName == "dommages") else if (fieldName == "dommages")
update['data.dommages'] = compValue; update['system.dommages'] = compValue;
else else
update['data.carac_value'] = compValue; update['system.carac_value'] = compValue;
await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity
} }
} }

View File

@ -32,6 +32,7 @@ export class ChatUtility {
} }
} }
/* -------------------------------------------- */
static onNotifyUser(data) { static onNotifyUser(data) {
if (game.user.id == data.userId) { if (game.user.id == data.userId) {
switch (data.level) { switch (data.level) {
@ -46,28 +47,15 @@ export class ChatUtility {
static onRemoveMessages(data) { static onRemoveMessages(data) {
if (Misc.isUniqueConnectedGM()) { if (Misc.isUniqueConnectedGM()) {
if (data.part) { if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); const toDelete = game.messages.filter(it => it.content.includes(data.part))
toDelete.forEach(it => it.delete()); toDelete.forEach(it => it.delete())
} }
if (data.messageId) { if (data.messageId) {
game.messages.get(data.messageId)?.delete(); game.messages.get(data.messageId)?.delete()
}
}
}
static onRemoveMessages(data) {
if (Misc.isUniqueConnectedGM()) {
if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part));
toDelete.forEach(it => it.delete());
}
if (data.messageId) {
game.messages.get(data.messageId)?.delete();
} }
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static removeMessages(data) { static removeMessages(data) {
if (Misc.isUniqueConnectedGM()) { if (Misc.isUniqueConnectedGM()) {
ChatUtility.onRemoveMessages(data); ChatUtility.onRemoveMessages(data);
@ -90,7 +78,7 @@ export class ChatUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async createChatWithRollMode(name, chatOptions) { static async createChatWithRollMode(name, chatOptions) {
return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -141,7 +129,7 @@ export class ChatUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getUsers(filter) { static getUsers(filter) {
return Misc.getUsers().filter(filter).map(user => user.data._id); return Misc.getUsers().filter(filter).map(user => user.id)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -162,17 +150,20 @@ export class ChatUtility {
} }
} }
/* -------------------------------------------- */
static async setMessageData(chatMessage, key, data) { static async setMessageData(chatMessage, key, data) {
if (data) { if (data) {
await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data)); await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data));
} }
} }
/* -------------------------------------------- */
static getMessageData(chatMessage, key) { static getMessageData(chatMessage, key) {
const json = chatMessage.getFlag(SYSTEM_RDD, key); const json = chatMessage.getFlag(SYSTEM_RDD, key);
return json ? JSON.parse(json) : undefined; return json ? JSON.parse(json) : undefined;
} }
/* -------------------------------------------- */
static getChatMessage(event) { static getChatMessage(event) {
const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id'); const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id');
return game.messages.get(chatMessageId); return game.messages.get(chatMessageId);

View File

@ -20,8 +20,9 @@ const nomCategorieParade = {
export class RdDItemArme extends Item { export class RdDItemArme extends Item {
static isArme(itemData) { static isArme(itemData) {
itemData = Misc.data(itemData); console.log("ARM", itemData)
return (itemData.type == 'competencecreature' && itemData.data.iscombat) || itemData.type == 'arme'; //itemData = Misc.data(itemData)
return (itemData.type == 'competencecreature' && itemData.system.iscombat) || itemData.type == 'arme';
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -35,12 +36,14 @@ export class RdDItemArme extends Item {
return RdDItemArme.mainsNues(); return RdDItemArme.mainsNues();
} }
/* -------------------------------------------- */
static computeNiveauArmes(armes, competences) { static computeNiveauArmes(armes, competences) {
for (const arme of armes) { for (const arme of armes) {
arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences) arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences)
} }
} }
/* -------------------------------------------- */
static niveauCompetenceArme(arme, competences) { static niveauCompetenceArme(arme, competences) {
const compArme = competences.find(it => it.name == arme.system.competence); const compArme = competences.find(it => it.name == arme.system.competence);
return compArme?.system.niveau ?? -8; return compArme?.system.niveau ?? -8;

View File

@ -133,12 +133,12 @@ export class RdDItemCompetence extends Item {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeXP(competence) { static computeXP(competence) {
const itemData = Misc.data(competence); console.log("Competence", competence)
const factor = itemData.name.includes('Thanatos') ? 2 : 1; // Thanatos compte double ! const factor = competence.name.includes('Thanatos') ? 2 : 1 // Thanatos compte double !
const xpNiveau = RdDItemCompetence.computeDeltaXP(itemData.data.base, itemData.data.niveau ?? itemData.data.base); const xpNiveau = RdDItemCompetence.computeDeltaXP(competence.system.base, competence.system.niveau ?? competence.system.base)
const xp = itemData.data.xp ?? 0; const xp = competence.system.xp ?? 0
const xpSort = itemData.data.xp_sort ?? 0; const xpSort = competence.system.xp_sort ?? 0
return factor * (xpNiveau + xp) + xpSort; return factor * (xpNiveau + xp) + xpSort
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -227,8 +227,8 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
get template() { get template() {
let type = this.object.data.type; let type = this.object.type
return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`; return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -239,7 +239,7 @@ export class RdDUtility {
if (b.name.includes("Extérieur")) return 1; if (b.name.includes("Extérieur")) return 1;
return a.name.localeCompare(b.name); return a.name.localeCompare(b.name);
} }
if (a.data.categorie.startsWith("melee") && b.data.categorie.startsWith("melee")) { if (a.system.categorie.startsWith("melee") && b.system.categorie.startsWith("melee")) {
if (a.name.includes("Corps")) return -1; if (a.name.includes("Corps")) return -1;
if (b.name.includes("Corps")) return 1; if (b.name.includes("Corps")) return 1;
if (a.name.includes("Dague")) return -1; if (a.name.includes("Dague")) return -1;
@ -414,38 +414,37 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildArbreDeConteneurs(conteneurs, objets) { static buildArbreDeConteneurs(conteneurs, objets) {
let objetVersConteneur = {}; let objetVersConteneur = {}
// Attribution des objets aux conteneurs // Attribution des objets aux conteneurs
for (let conteneur of conteneurs) { for (let conteneur of conteneurs) {
conteneur.subItems = []; conteneur.subItems = []
for (let id of conteneur.data.contenu ?? []) { for (let id of conteneur.system.contenu ?? []) {
let objet = objets.find(objet => (id == objet._id)); let objet = objets.find(objet => (id == objet._id))
if (objet) { if (objet) {
objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template
objetVersConteneur[id] = conteneur._id; objetVersConteneur[id] = conteneur._id
conteneur.subItems.push(objet); conteneur.subItems.push(objet)
} }
} }
} }
for (let conteneur of conteneurs) { for (let conteneur of conteneurs) {
conteneur.data.encTotal = RdDUtility.calculEncContenu(conteneur, objets); conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets)
} }
return objetVersConteneur; return objetVersConteneur
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static calculEncContenu(conteneur, objets) { static calculEncContenu(conteneur, objets) {
const itemData = Misc.data(conteneur); const contenuDatas = (conteneur.system.contenu ?? []).filter(id => id != undefined)
const contenuDatas = (itemData.data.contenu ?? []).filter(id => id != undefined) .map(id => objets.find(it => (id == it._id)) )
.map(id => Misc.data(objets.find(it => (id == it._id)))) .filter(it => it)
.filter(it => it); let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1)
let enc = Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); for (let subContenu of contenuDatas) {
for (let itemData of contenuDatas) { if (subContenu.type == 'conteneur') {
if (itemData.type == 'conteneur') { enc += RdDUtility.calculEncContenu(subContenu, objets)
enc += RdDUtility.calculEncContenu(itemData, objets);
} }
else { else {
enc += Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); enc += Number(subContenu.system.encombrement ?? 0) * Number(subContenu.system.quantite ?? 1)
} }
} }
return enc; return enc;

View File

@ -103,11 +103,11 @@
<span class="competence-label">{{comp.name}}</span> <span class="competence-label">{{comp.name}}</span>
</a> </a>
<input class="competence-value creature-carac" type="text" compname="{{comp.name}}" <input class="competence-value creature-carac" type="text" compname="{{comp.name}}"
value="{{comp.data.carac_value}}" data-dtype="number" /> value="{{comp.system.carac_value}}" data-dtype="number" />
<input class="competence-value creature-niveau" type="text" compname="{{comp.name}}" <input class="competence-value creature-niveau" type="text" compname="{{comp.name}}"
value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" /> value="{{numberFormat comp.system.niveau decimals=0 sign=true}}" data-dtype="number" />
<input class="competence-value creature-dommages" type="text" compname="{{comp.name}}" <input class="competence-value creature-dommages" type="text" compname="{{comp.name}}"
value="{{numberFormat comp.data.dommages decimals=0 sign=true}}" data-dtype="number" /> value="{{numberFormat comp.system.dommages decimals=0 sign=true}}" data-dtype="number" />
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>

View File

@ -99,11 +99,11 @@
<img class="sheet-competence-img" src="{{comp.img}}" /> <img class="sheet-competence-img" src="{{comp.img}}" />
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
<input class="competence-value creature-carac" type="text" compname="{{comp.name}}" <input class="competence-value creature-carac" type="text" compname="{{comp.name}}"
value="{{comp.data.carac_value}}" data-dtype="number" /> value="{{comp.system.carac_value}}" data-dtype="number" />
<input class="competence-value creature-niveau" type="text" compname="{{comp.name}}" <input class="competence-value creature-niveau" type="text" compname="{{comp.name}}"
value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" /> value="{{numberFormat comp.system.niveau decimals=0 sign=true}}" data-dtype="number" />
<input class="competence-value creature-dommages" type="text" compname="{{comp.name}}" <input class="competence-value creature-dommages" type="text" compname="{{comp.name}}"
value="{{numberFormat comp.data.dommages decimals=0 sign=true}}" data-dtype="number" /> value="{{numberFormat comp.system.dommages decimals=0 sign=true}}" data-dtype="number" />
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>

View File

@ -1,4 +1,4 @@
{{#if visible}} {{#if isVisible}}
<li class="item flexrow list-item {{#if data.isLevelUp}}xp-level-up tooltip{{/if}}" data-item-id="{{_id}}"> <li class="item flexrow list-item {{#if data.isLevelUp}}xp-level-up tooltip{{/if}}" data-item-id="{{_id}}">
<a class="competence-label" name="{{name}}"> <a class="competence-label" name="{{name}}">
<img class="sheet-competence-img" src="{{img}}"/> <img class="sheet-competence-img" src="{{img}}"/>
@ -13,7 +13,7 @@
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{name}}" name="comp-value-{{name}}" <input class="competence-value" type="text" compname="{{name}}" name="comp-value-{{name}}"
value="{{numberFormat data.niveau decimals=0 sign=true}}" data-dtype="number" value="{{numberFormat system.niveau decimals=0 sign=true}}" data-dtype="number"
{{#unless @root.options.editCaracComp}}disabled{{/unless}} /> {{#unless @root.options.editCaracComp}}disabled{{/unless}} />
<span class="competence-xp tooltip"> <span class="competence-xp tooltip">