Army sheet : added ability to drag n drop a cohort on a map
Cohort sheet : added ability to drag n drop an actor and some css
This commit is contained in:
@@ -17,6 +17,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this._initialize();
|
||||
@@ -81,7 +82,9 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the linked Actor (warlod/commander)
|
||||
html.find(".entity-link").on("dragstart", this._onDragEntityLink.bind(this));
|
||||
|
||||
// Delete the linked Actor (warlord/commander)
|
||||
html.find(".actor-remove-control").on("click", this._removeLinkedActor.bind(this));
|
||||
}
|
||||
|
||||
@@ -114,6 +117,24 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback actions which occur at the beginning of a drag start workflow.
|
||||
* @param {DragEvent} event The originating DragEvent
|
||||
*/
|
||||
_onDragEntityLink(event) {
|
||||
const actorId = $(event.currentTarget).data("actor-id");
|
||||
if (!actorId) {
|
||||
return;
|
||||
}
|
||||
event.originalEvent.dataTransfer.setData(
|
||||
"text/plain",
|
||||
JSON.stringify({
|
||||
type: "Actor",
|
||||
id: actorId,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dropped Item data on the Actor sheet (cohort, fortification)
|
||||
* @param {DragEvent} event
|
||||
|
||||
@@ -10,8 +10,104 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
|
||||
classes: ["l5r5e", "sheet", "army-cohort"],
|
||||
template: CONFIG.l5r5e.paths.templates + "items/army-cohort/army-cohort-sheet.html",
|
||||
width: 520,
|
||||
height: 480,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
|
||||
height: 520,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "infos" }],
|
||||
dragDrop: [{ dragSelector: ".item", dropSelector: null }],
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this._initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize once
|
||||
* @private
|
||||
*/
|
||||
_initialize() {
|
||||
const data = this.object.data.data;
|
||||
|
||||
// update linked actor datas
|
||||
if (data.leader_actor_id) {
|
||||
const actor = game.actors.get(data.leader_actor_id);
|
||||
if (actor) {
|
||||
this._updateLinkedActorData(actor);
|
||||
} else {
|
||||
this._removeLinkedActor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to events from the sheet.
|
||||
* @param {jQuery} html HTML content of the sheet.
|
||||
*/
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.isEditable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the linked Actor
|
||||
html.find(".actor-remove-control").on("click", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const id = $(event.currentTarget).data("actor-id");
|
||||
if (id) {
|
||||
this._removeLinkedActor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dropped Item data on the Actor sheet (cohort, fortification)
|
||||
* @param {DragEvent} event
|
||||
*/
|
||||
async _onDrop(event) {
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.isEditable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const droppedActor = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
return this._updateLinkedActorData(droppedActor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update actor datas for this army sheet
|
||||
* @param {ActorL5r5e} actor actor object
|
||||
* @return {Promise<abstract.Document>}
|
||||
* @private
|
||||
*/
|
||||
async _updateLinkedActorData(actor) {
|
||||
if (!actor || actor.documentName !== "Actor" || !["character", "npc"].includes(actor.data?.type)) {
|
||||
console.warn("L5R5E | Wrong actor type", actor?.data?.type, actor);
|
||||
return;
|
||||
}
|
||||
|
||||
return this.object.update({
|
||||
img: actor.data.img,
|
||||
data: {
|
||||
leader: actor.data.name,
|
||||
leader_actor_id: actor.data._id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the linked actor (commander/warlord)
|
||||
* @return {Promise<void>}
|
||||
* @private
|
||||
*/
|
||||
async _removeLinkedActor() {
|
||||
return this.object.update({
|
||||
data: {
|
||||
leader_actor_id: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user