actor picker 1

This commit is contained in:
François-Xavier Guillois
2023-09-01 19:59:44 +02:00
parent 918b7c0b0c
commit e11525564a
13 changed files with 136 additions and 20 deletions
+77 -1
View File
@@ -22,7 +22,6 @@ export class TotemPicker extends Application {
getData() {
// Send data to the template
return {
config: CONFIG.VERMINE,
/*anarchy: this.gmAnarchy.getAnarchy(),
@@ -49,3 +48,80 @@ export class TotemPicker extends Application {
// console.log(formData.exampleInput);
}*/
}
export class ActorPicker extends Application {
constructor(linkEl, actor) {
super();
this.linkEl = linkEl;
this.actor = actor;
}
/* -------------------------------------------- */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id:"ACTOR_PICKER",
title:game.i18n.localize("VERMINE.actor_picker"),
template:'systems/vermine2047/templates/applications/choose-actor.hbs',
popOut:true,
resizable:true,
height:"600",
width:"600"
});
}
getData() {
// Send data to the template
const npcs = game.actors.filter(a => a.type == "npc");
const characters = game.actors.filter(a => a.type == "character");
const encounters = game.actors.filter(a => a.type == "npc" || a.type == 'character');
const type = $(this.linkEl).data('type');
let actorsList = [];
if (type == 'members'){
actorsList = characters;
} else if (type == 'relations'){
actorsList = npc;
} else {
actorsList = encounters;
}
return {
config: CONFIG.VERMINE,
actorsList: actorsList
}
}
activateListeners(html) {
super.activateListeners(html);
html.find('.actor').click(event => {
const actorId = $(event.target).parent('div').data('id');
let actorsList = [];
const type = $(this.linkEl).data('type');
if (type == 'members'){
actorsList = this.actor.system.members;
} else if (type == 'encounters'){
actorsList = this.actor.system.encounters;
}
if (!Array.isArray(actorsList)){
actorsList = [];
}
console.log(actorsList, type, this.actor.system.encounters, this.actor.system.members);
actorsList.push(actorId);
if (type == 'members'){
actorsList = this.actor.system.members;
this.actor.update({ 'system.members': actorsList });
} else if (type == 'encounters'){
this.actor.update({ 'system.encounters': actorsList });
}
console.log(actorsList);
});
}
}