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,
options: this.options,
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;

View File

@ -53,7 +53,7 @@ export class RdDActorSheet extends ActorSheet {
limited: this.object.limited,
options: this.options,
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)
@ -79,11 +79,12 @@ export class RdDActorSheet extends ActorSheet {
};
formData.competences.forEach(item => {
item.visible = this.options.cherchercompetence
console.log('Comp', item)
item.isVisible = this.options.cherchercompetence
? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence)
: (!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 => {
RdDCarac.levelUp(c);
@ -386,9 +387,9 @@ export class RdDActorSheet extends ActorSheet {
this.actor.updateCarac(caracName, parseInt(event.target.value));
});
html.find('.carac-xp').change(async event => {
let caracName = event.currentTarget.name.replace(".xp", "").replace("data.carac.", "");
//console.log("Value changed :", event, caracName);
this.actor.updateCaracXP(caracName, parseInt(event.target.value));
let caracName = event.currentTarget.name.replace(".xp", "").replace("system.carac.", "")
//console.log("Value changed :", event, caracName)
this.actor.updateCaracXP(caracName, parseInt(event.target.value))
});
// On competence change
html.find('.competence-value').change(async event => {

View File

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

View File

@ -32,6 +32,7 @@ export class ChatUtility {
}
}
/* -------------------------------------------- */
static onNotifyUser(data) {
if (game.user.id == data.userId) {
switch (data.level) {
@ -46,28 +47,15 @@ export class ChatUtility {
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());
const toDelete = game.messages.filter(it => it.content.includes(data.part))
toDelete.forEach(it => it.delete())
}
if (data.messageId) {
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();
game.messages.get(data.messageId)?.delete()
}
}
}
/* -------------------------------------------- */
static removeMessages(data) {
if (Misc.isUniqueConnectedGM()) {
ChatUtility.onRemoveMessages(data);
@ -90,7 +78,7 @@ export class ChatUtility {
/* -------------------------------------------- */
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) {
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) {
if (data) {
await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data));
}
}
/* -------------------------------------------- */
static getMessageData(chatMessage, key) {
const json = chatMessage.getFlag(SYSTEM_RDD, key);
return json ? JSON.parse(json) : undefined;
}
/* -------------------------------------------- */
static getChatMessage(event) {
const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id');
return game.messages.get(chatMessageId);

View File

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

View File

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

View File

@ -227,8 +227,8 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */
get template() {
let type = this.object.data.type;
return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`;
let type = this.object.type
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;
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 (b.name.includes("Corps")) return 1;
if (a.name.includes("Dague")) return -1;
@ -414,38 +414,37 @@ export class RdDUtility {
/* -------------------------------------------- */
static buildArbreDeConteneurs(conteneurs, objets) {
let objetVersConteneur = {};
let objetVersConteneur = {}
// Attribution des objets aux conteneurs
for (let conteneur of conteneurs) {
conteneur.subItems = [];
for (let id of conteneur.data.contenu ?? []) {
let objet = objets.find(objet => (id == objet._id));
conteneur.subItems = []
for (let id of conteneur.system.contenu ?? []) {
let objet = objets.find(objet => (id == objet._id))
if (objet) {
objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template
objetVersConteneur[id] = conteneur._id;
conteneur.subItems.push(objet);
objetVersConteneur[id] = conteneur._id
conteneur.subItems.push(objet)
}
}
}
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) {
const itemData = Misc.data(conteneur);
const contenuDatas = (itemData.data.contenu ?? []).filter(id => id != undefined)
.map(id => Misc.data(objets.find(it => (id == it._id))))
.filter(it => it);
let enc = Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1);
for (let itemData of contenuDatas) {
if (itemData.type == 'conteneur') {
enc += RdDUtility.calculEncContenu(itemData, objets);
const contenuDatas = (conteneur.system.contenu ?? []).filter(id => id != undefined)
.map(id => objets.find(it => (id == it._id)) )
.filter(it => it)
let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1)
for (let subContenu of contenuDatas) {
if (subContenu.type == 'conteneur') {
enc += RdDUtility.calculEncContenu(subContenu, objets)
}
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;

View File

@ -103,11 +103,11 @@
<span class="competence-label">{{comp.name}}</span>
</a>
<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}}"
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}}"
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">
<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>

View File

@ -99,11 +99,11 @@
<img class="sheet-competence-img" src="{{comp.img}}" />
<span class="competence-label"><a>{{comp.name}}</a></span>
<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}}"
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}}"
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">
<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>

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}}">
<a class="competence-label" name="{{name}}">
<img class="sheet-competence-img" src="{{img}}"/>
@ -13,7 +13,7 @@
{{/if}}
<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}} />
<span class="competence-xp tooltip">