traits+debut combat

This commit is contained in:
rwanoux
2024-11-18 16:17:30 +01:00
parent de7cfca093
commit c0432d1efb
29 changed files with 1561 additions and 3691 deletions
+8 -5
View File
@@ -11,11 +11,11 @@ export class VermineItem extends Item {
// preparation methods overridden (such as prepareBaseData()).
super.prepareData();
}
prepareBaseData(){
prepareBaseData() {
const actorType = (this.actor !== null) ? this.actor.type : 'character';
switch (this.type){
case 'ability':
switch (this.type) {
case 'ability':
if (this.system.type == "") {
// console.log('je suis une capacité, avec pour sous-type', this.system.type, actorType);
this.system.type = actorType;
@@ -34,9 +34,9 @@ export class VermineItem extends Item {
* Prepare a data object which is passed to any Roll formulas which are created related to this Item
* @private
*/
getRollData() {
getRollData() {
// If present, return the actor's roll data.
if ( !this.actor ) return null;
if (!this.actor) return null;
const rollData = this.actor.getRollData();
// Grab the item's system data as well.
rollData.item = foundry.utils.deepClone(this.system);
@@ -50,6 +50,9 @@ export class VermineItem extends Item {
* @private
*/
async roll() {
if (this.type == "weapon") {
this.rollWeapon()
}
const item = this;
// Initialize chat data.
+9 -31
View File
@@ -57,7 +57,6 @@ export class VermineActorSheet extends ActorSheet {
/** @override */
activateListeners(html) {
super.activateListeners(html);
html.find('.min-max-edit').click(this._onMinMaxEdit.bind(this))
// Render the item sheet for viewing/editing prior to the editable check.
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
@@ -79,7 +78,9 @@ export class VermineActorSheet extends ActorSheet {
item.delete();
li.slideUp(200, () => this.render(false));
});
html.find(".item-roll").click(ev => {
this._onRollItem(ev)
})
// Active Effect management
html.find(".effect-control").click(ev => onManageActiveEffect(ev, this.actor));
@@ -103,6 +104,12 @@ export class VermineActorSheet extends ActorSheet {
})
}
async _onRollItem(ev) {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("itemId"));
item.roll();
}
_onClickRadioHexa(ev) {
let input = ev.currentTarget;
console.log(input.value, input.name);
@@ -123,35 +130,6 @@ export class VermineActorSheet extends ActorSheet {
}
async _onMinMaxEdit(event) {
event.preventDefault();
let propPath = event.currentTarget.dataset.prop;
let propName = propPath.split('.').slice(-1).pop()
let data = {
actorName: this.actor.name,
propName: propName
}
let html = await renderTemplate('systems/vermine2047/templates/dialogs/min-max-edit.hbs', data);
let ui = new Dialog({
title: "edit : " + propName,
content: html,
buttons: {
roll: {
label: "ok",
callback: (html) => { }
},
cancel: {
label: game.i18n.localize('Close'),
callback: () => { }
}
}
}
);
ui.render(true)
}
async _onItemCreate(event) {
event.preventDefault();
+1
View File
@@ -66,6 +66,7 @@ export class VermineItemSheet extends ItemSheet {
html.find('.traits-selector').click(ev => {
this.openTraitSelector(ev)
})
}
async _onClickDamage(ev) {
+23 -9
View File
@@ -149,27 +149,37 @@ export class TraitSelector extends Application {
async activateListeners(html) {
super.activateListeners(html);
this.validateTraits(html);
html.find('input').click(ev => {
html.find('input').change(ev => {
this.onChangeInput(ev)
})
}
async validateTraits(html) {
let checks = html.find("input.trait-selector");
for (let ch of checks) {
if (this.targetItem.system.traits[ch.dataset.trait]) {
ch.checked = true
let val = html.find("input.trait-value");
for (let inp of [...checks, val]) {
if (this.targetItem.system.traits[inp.dataset.trait]) {
if (inp.type == "checkbox") {
inp.checked = true
}
if (inp.type == "value") {
inp.value = this.targetItem.system.traits[inp.dataset.trait].value
}
}
}
}
async onChangeInput(ev) {
let el = ev.currentTarget;
if (el.classList.contains('trait-selector')) {
let traitKey = el.dataset.trait; // Récupère la clé du trait à partir de l'attribut data-trait
let traits = this.targetItem.system.traits || {}; // Récupère les traits actuels, ou un objet vide si aucun trait n'est défini
let traitKey = el.dataset.trait; // Récupère la clé du trait à partir de l'attribut data-trait
let traitValue = parseInt(el.value) || null
let traits = this.targetItem.system.traits || {}; // Récupère les traits actuels, ou un objet vide si aucun trait n'est défini
console.log(traitKey, traitValue, traits)
if (el.classList.contains('trait-selector')) {
if (!traits[traitKey]) {
// Si la case est cochée, ajoute le trait
await this.targetItem.update({ [`system.traits.${traitKey}`]: this.traits[traitKey] });
@@ -178,8 +188,12 @@ export class TraitSelector extends Application {
await this.targetItem.update({ [`system.traits.${traitKey}`]: null });
}
}
else if (el.classList.contains('trait-value')) {
if (traitValue) {
console.log(el.value)
// Logique pour les valeurs des traits si nécessaire
el.closest("label").querySelector('.trait-selector').checked = true;
} else {
el.closest("label").querySelector('.trait-selector').checked = false;
}
}
}
+6
View File
@@ -246,3 +246,9 @@ VERMINE.traits = {
},
// etc...etc...
}
VERMINE.damageTypes = [
"choc",
"lame",
"feu",
"balle"
]
+2
View File
@@ -51,7 +51,9 @@ export default class RollDialog extends Dialog {
}) {
// Retrieve the actor data based on the actorId
data.actor = await game.actors.get(data.actorId);
console.log(data.actor)
data.availableSpecialties = data.actor.items.filter(it => it.type == "specialty");
console.log(data.availableSpecialties)
data.availableItems = data.actor.items.filter(it => it.type == "item");
data.config = CONFIG.VERMINE;
// Define options for the dialog
+14 -15
View File
@@ -326,7 +326,7 @@ export class VermineCombat extends Combat {
}
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
// console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
@@ -428,20 +428,7 @@ export class VermineCombatTracker extends CombatTracker {
return "systems/vermine2047/templates/combat-tracker.hbs";
}
async getData(options) {
const context = await super.getData(options);
if (!context.hasCombat) {
return context;
}
for (let [i, combatant] of context.combat.turns.entries()) {
context.turns[i].hasActed = combatant.getFlag("world", "hasActed");
context.turns[i].isPlayer = combatant.actor.type == "player";
context.turns[i].isNpc = combatant.actor.type == "npc";
}
return context;
}
/* -------------------------------------------- */
get template() {
@@ -466,14 +453,26 @@ export class VermineCombatTracker extends CombatTracker {
activateListeners(html) {
super.activateListeners(html);
html.find("[data-attitude]").click(this._setStatut.bind(this));
html.find("[data-control='rollInitiative']").click(this.rollVermineInitiative.bind(this))
}
async rollVermineInitiative(ev) {
ev.preventDefault();
ev.stopPropagation();
const btn = ev.currentTarget;
const li = btn.closest(".combatant");
const combat = this.viewed;
const combatant = combat.combatants.get(li.dataset.combatantId);
console.log(combatant)
}
/**
* @description Use to put an attitude to an actor
* @param {*} event
*/
async _setStatut(event) {
event.preventDefault();
event.stopPropagation();