army sheet : added ability to drop a actor for commander & warlord, and some fixes

This commit is contained in:
Vlyan
2021-12-02 10:09:47 +01:00
parent 1b1dbbdb2d
commit c265e741b9
12 changed files with 261 additions and 70 deletions

View File

@@ -14,10 +14,77 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
width: 600,
height: 800,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "army" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
});
}
constructor(options = {}) {
super(options);
this._initialize();
}
/**
* Initialize once
* @private
*/
_initialize() {
const data = this.object.data.data;
// update linked actor datas
if (data.commander_actor_id) {
const commander = game.actors.get(data.commander_actor_id);
if (commander) {
this._updateLinkedActorData("commander", commander);
} else {
this._removeLinkedActorData("commander");
}
}
if (data.warlord_actor_id) {
const warlord = game.actors.get(data.warlord_actor_id);
if (warlord) {
this._updateLinkedActorData("warlord", warlord);
} else {
this._removeLinkedActorData("warlord");
}
}
}
/**
* Create drag-and-drop workflow handlers for this Application
* @return An array of DragDrop handlers
*/
_createDragDropHandlers() {
return [
new DragDrop({
dropSelector: ".warlord",
callbacks: { drop: this._onDropActors.bind(this, "warlord") },
}),
new DragDrop({
dropSelector: ".commander",
callbacks: { drop: this._onDropActors.bind(this, "commander") },
}),
new DragDrop({
dropSelector: null,
callbacks: { drop: this._onDrop.bind(this) },
}),
];
}
/**
* 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 (warlod/commander)
html.find(".actor-remove-control").on("click", this._removeLinkedActor.bind(this));
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData(options);
@@ -48,7 +115,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
}
/**
* Handle dropped data on the Actor sheet
* Handle dropped Item data on the Actor sheet (cohort, fortification)
* @param {DragEvent} event
*/
async _onDrop(event) {
@@ -57,10 +124,12 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
return;
}
// Check item type and subtype
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || item.documentName !== "Item" || !["army_cohort", "army_fortification"].includes(item.data.type)) {
console.warn("L5R5E | Wrong type", item?.data?.type, item);
// actor dual trigger...
if (item?.documentName !== "Actor") {
console.warn("L5R5E | Wrong item type", item?.data?.type, item);
}
return;
}
@@ -72,7 +141,101 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
let itemData = item.data.toObject(true);
// Finally create the embed
// Finally, create the embed
return this.actor.createEmbeddedDocuments("Item", [itemData]);
}
/**
* Handle dropped Actor data on the Actor sheet
* @param {string} type warlord|commander|item
* @param {DragEvent} event
*/
async _onDropActors(type, 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(type, droppedActor);
}
/**
* Remove the linked actor (commander/warlord)
* @param {Event} event
* @return {Promise<void>}
* @private
*/
async _removeLinkedActor(event) {
event.preventDefault();
event.stopPropagation();
const id = $(event.currentTarget).data("actor-id");
const type = $(event.currentTarget).data("type");
if (!id || !type) {
return;
}
return this._removeLinkedActorData(type);
}
/**
* Update actor datas for this army sheet
* @param {string} type commander|warlord
* @param {ActorL5r5e} actor actor object
* @return {Promise<abstract.Document>}
* @private
*/
async _updateLinkedActorData(type, actor) {
if (!actor || actor.documentName !== "Actor" || !["character", "npc"].includes(actor.data?.type)) {
console.warn("L5R5E | Wrong actor type", actor?.data?.type, actor);
return;
}
const actorData = {};
switch (type) {
case "commander":
actorData.commander = actor.data.name;
actorData.commander_actor_id = actor.data._id;
actorData.commander_standing = {
honor: actor.data.data.social.honor,
glory: actor.data.data.social.glory,
status: actor.data.data.social.status,
};
break;
case "warlord":
actorData.warlord = actor.data.name;
actorData.warlord_actor_id = actor.data._id;
break;
default:
console.warn("L5R5E | Unknown type", type);
return;
}
return this.actor.update({ data: actorData });
}
/**
* Clean ActorId for army sheet
* @param {string} type commander|warlord
* @return {Promise<abstract.Document>}
* @private
*/
async _removeLinkedActorData(type) {
const actorData = {};
switch (type) {
case "commander":
actorData.commander_actor_id = null;
break;
case "warlord":
actorData.warlord_actor_id = null;
break;
default:
console.warn("L5R5E | Unknown type", type);
return;
}
return this.actor.update({ data: actorData });
}
}

View File

@@ -144,8 +144,8 @@ export class GmMonitor extends FormApplication {
return;
}
// Open sheet
html.find(`.actor-sheet-control`).on("click", this._openActorSheet.bind(this));
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html);
// Delete
html.find(`.actor-remove-control`).on("click", this._removeActor.bind(this));
@@ -222,24 +222,6 @@ export class GmMonitor extends FormApplication {
);
}
/**
* Open the Sheet for this actor
* @param {Event} event
* @return {Promise<void>}
* @private
*/
async _openActorSheet(event) {
event.preventDefault();
event.stopPropagation();
const id = $(event.currentTarget).data("actor-id");
if (!id) {
return;
}
this.object.actors.find((e) => e.id === id)?.sheet?.render(true);
}
/**
* Remove the link to a property for the current item
* @param {Event} event

View File

@@ -70,7 +70,7 @@ export class HelpersL5r5e {
* @return {Promise<null>}
*/
static async getDragnDropTargetObject(event) {
const json = event.dataTransfer.getData("text/plain");
const json = event.dataTransfer?.getData("text/plain");
if (!json) {
return null;
}
@@ -427,6 +427,18 @@ export class HelpersL5r5e {
}
return await item.renderTextTemplate();
});
// Open actor sheet
html.find(".open-sheet-actor-id").on("click", (event) => {
event.preventDefault();
event.stopPropagation();
const id = $(event.currentTarget).data("actor-id");
if (!id) {
return;
}
game.actors.get(id)?.sheet?.render(true);
});
}
/**

File diff suppressed because one or more lines are too long

View File

@@ -20,6 +20,7 @@
li {
flex: 25%;
display: inline-grid;
position: relative;
strong {
color: $l5r5e-label;
text-align: center;
@@ -36,9 +37,9 @@
content: "";
width: 2rem;
height: 2rem;
position: relative;
right: calc(50% - 5.5rem);
top: calc(50% - 2.83rem);
position: absolute;
right: calc(50% - 0.9rem);
top: calc(50% - 0.2rem);
background: transparent url("../assets/icons/circle.svg") no-repeat 0 0;
background-size: contain;
opacity: 0.25;
@@ -94,6 +95,9 @@
textarea {
height: calc(100% - 22px);
}
.actor-remove-control {
font-size: 12px;
}
}
}
.standing {
@@ -158,5 +162,12 @@
}
}
}
&.others {
flex-direction: column;
.editor-content {
min-height: 8rem;
max-height: 14rem;
}
}
}
}

View File

@@ -145,6 +145,7 @@
},
"army": {
"warlord": "",
"warlord_actor_id": null,
"allies_backers": "",
"purpose_mustering": "",
"battle_readiness": {
@@ -158,6 +159,7 @@
}
},
"commander": "",
"commander_actor_id": null,
"commander_abilities": "",
"army_abilities": "",
"commander_standing": {

View File

@@ -8,19 +8,19 @@
<ul>
<li>
<strong>{{localize 'l5r5e.army.battle_readiness.casualties'}}</strong>
<input name="data.battle_readiness.casualties_strength.value" type="text" value="{{data.data.battle_readiness.casualties_strength.value}}" />
<input name="data.battle_readiness.casualties_strength.value" type="number" value="{{data.data.battle_readiness.casualties_strength.value}}" />
</li>
<li>
<strong>{{localize 'l5r5e.army.battle_readiness.strength'}}</strong>
<input name="data.battle_readiness.casualties_strength.max" type="text" value="{{data.data.battle_readiness.casualties_strength.max}}" />
<input name="data.battle_readiness.casualties_strength.max" type="number" value="{{data.data.battle_readiness.casualties_strength.max}}" />
</li>
<li>
<strong>{{localize 'l5r5e.army.battle_readiness.panic'}}</strong>
<input name="data.battle_readiness.panic_discipline.value" type="text" value="{{data.data.battle_readiness.panic_discipline.value}}" />
<input name="data.battle_readiness.panic_discipline.value" type="number" value="{{data.data.battle_readiness.panic_discipline.value}}" />
</li>
<li>
<strong>{{localize 'l5r5e.army.battle_readiness.discipline'}}</strong>
<input name="data.battle_readiness.panic_discipline.max" type="text" value="{{data.data.battle_readiness.panic_discipline.max}}" />
<input name="data.battle_readiness.panic_discipline.max" type="number" value="{{data.data.battle_readiness.panic_discipline.max}}" />
</li>
</ul>
</div>

View File

@@ -2,7 +2,14 @@
<fieldset>
<p>
<strong>{{localize 'l5r5e.army.warlord'}}</strong>
<input name="data.warlord" type="text" value="{{data.data.warlord}}" />
</p>
<p>
{{#if data.data.warlord_actor_id}}
<span data-actor-id="{{actor.id}}" data-type="warlord" class="actor-remove-control pointer" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></span>
<a data-actor-id="{{data.data.warlord_actor_id}}" class="open-sheet-actor-id">{{data.data.warlord}}</a>
{{else}}
<input name="data.warlord" type="text" value="{{data.data.warlord}}" />
{{/if}}
</p>
<p>
<strong>{{localize 'l5r5e.army.allies_backers'}}</strong>
@@ -18,21 +25,26 @@
<fieldset>
<label>
<strong>{{localize 'l5r5e.army.commander'}}</strong>
<input name="data.commander" type="text" value="{{data.data.commander}}" />
</label>
{{#if data.data.commander_actor_id}}
<span data-actor-id="{{actor.id}}" data-type="commander" class="actor-remove-control pointer" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></span>
<a data-actor-id="{{data.data.commander_actor_id}}" class="open-sheet-actor-id">{{data.data.commander}}</a>
{{else}}
<input name="data.commander" type="text" value="{{data.data.commander}}" />
{{/if}}
<div class="standing">
<ul>
<li>
<strong>{{localize 'l5r5e.social.honor'}}</strong>
<input name="data.commander_standing.honor" type="text" value="{{data.data.commander_standing.honor}}" />
<input name="data.commander_standing.honor" type="number" value="{{data.data.commander_standing.honor}}" />
</li>
<li>
<strong>{{localize 'l5r5e.social.glory'}}</strong>
<input name="data.commander_standing.glory" type="text" value="{{data.data.commander_standing.glory}}" />
<input name="data.commander_standing.glory" type="number" value="{{data.data.commander_standing.glory}}" />
</li>
<li>
<strong>{{localize 'l5r5e.social.status'}}</strong>
<input name="data.commander_standing.status" type="text" value="{{data.data.commander_standing.status}}" />
<input name="data.commander_standing.status" type="number" value="{{data.data.commander_standing.status}}" />
</li>
</ul>
</div>

View File

@@ -1,25 +1,23 @@
<div>
{{!-- Supplies and Logistics --}}
<fieldset class="supplies_logistics">
<legend class="text-block-header">{{localize 'l5r5e.army.supplies_logistics'}}</legend>
{{editor content=data.data.supplies_logistics target="data.supplies_logistics" button=true editable=options.editable}}
</fieldset>
{{!-- Supplies and Logistics --}}
<fieldset class="supplies_logistics">
<legend class="text-block-header">{{localize 'l5r5e.army.supplies_logistics'}}</legend>
{{editor content=data.data.supplies_logistics target="data.supplies_logistics" button=true editable=options.editable}}
</fieldset>
{{!-- Past Battles --}}
<fieldset class="past_battles">
<legend class="text-block-header">{{localize 'l5r5e.army.past_battles'}}</legend>
{{editor content=data.data.past_battles target="data.past_battles" button=true editable=options.editable}}
</fieldset>
{{!-- Past Battles --}}
<fieldset class="past_battles">
<legend class="text-block-header">{{localize 'l5r5e.army.past_battles'}}</legend>
{{editor content=data.data.past_battles target="data.past_battles" button=true editable=options.editable}}
</fieldset>
{{!-- Description (public) --}}
<fieldset class="description">
<legend class="text-block-header">{{localize 'l5r5e.description'}}</legend>
{{editor content=data.data.description target="data.description" button=true editable=options.editable}}
</fieldset>
{{!-- Description (public) --}}
<fieldset class="description">
<legend class="text-block-header">{{localize 'l5r5e.description'}}</legend>
{{editor content=data.data.description target="data.description" button=true editable=options.editable}}
</fieldset>
{{!-- Notes (private) --}}
<fieldset class="note">
<legend class="text-block-header">{{localize 'l5r5e.notes'}}</legend>
{{editor content=data.data.notes target="data.notes" button=true editable=options.editable}}
</fieldset>
</div>
{{!-- Notes (private) --}}
<fieldset class="note">
<legend class="text-block-header">{{localize 'l5r5e.notes'}}</legend>
{{editor content=data.data.notes target="data.notes" button=true editable=options.editable}}
</fieldset>

View File

@@ -23,7 +23,7 @@
<tr>
<td><img class="profile actor-profile" title="{{actor.name}}" src="{{actor.img}}"></td>
<td>
<a data-actor-id="{{actor.id}}" class="actor-sheet-control">{{actor.name}}</a>
<a data-actor-id="{{actor.id}}" class="open-sheet-actor-id">{{actor.name}}</a>
{{#if actor.data.data.attitude}}<p>({{actor.data.data.attitude}})</p>{{/if}}
</td>
<td><i data-type="text" data-text="<h2>{{localize 'l5r5e.conflict.stance'}} ({{localizeRing actor.data.data.stance}})</h2>{{localizeStanceTip actor.data.data.stance}}" class="i_{{actor.data.data.stance}} actor-infos-control"></i></td>
@@ -92,8 +92,14 @@
{{#each data.actors as |actor|}}
<tr>
<td><img class="profile actor-profile" title="{{actor.name}}" src="{{actor.img}}"></td>
<td><a data-actor-id="{{actor.id}}" class="actor-sheet-control">{{actor.name}}</a></td>
<td>{{actor.data.data.warlord}}</td>
<td><a data-actor-id="{{actor.id}}" class="open-sheet-actor-id">{{actor.name}}</a></td>
<td>
{{#if actor.data.data.warlord_actor_id}}
<a data-actor-id="{{actor.data.data.warlord_actor_id}}" class="open-sheet-actor-id">{{actor.data.data.warlord}}</a>
{{else}}
{{actor.data.data.warlord}}
{{/if}}
</td>
<td>
<span class="{{#ifCond actor.data.data.battle_readiness.casualties_strength.value '>' actor.data.data.battle_readiness.casualties_strength.max}}badvalue{{/ifCond}}">{{actor.data.data.battle_readiness.casualties_strength.value}}</span>
/ {{actor.data.data.battle_readiness.casualties_strength.max}}
@@ -103,7 +109,12 @@
/ {{actor.data.data.battle_readiness.panic_discipline.max}}
</td>
<td>
{{actor.data.data.commander}}<br>
{{#if actor.data.data.commander_actor_id}}
<a data-actor-id="{{actor.data.data.commander_actor_id}}" class="open-sheet-actor-id">{{actor.data.data.commander}}</a>
{{else}}
{{actor.data.data.commander}}
{{/if}}
<br>
<span class="{{#ifCond actor.data.data.commander_standing.honor '>' 64}}goodvalue{{/ifCond}}{{#ifCond actor.data.data.commander_standing.honor '<' 30}}badvalue{{/ifCond}}">{{actor.data.data.commander_standing.honor}}</span>
/ <span class="{{#ifCond actor.data.data.commander_standing.glory '>' 64}}goodvalue{{/ifCond}}{{#ifCond actor.data.data.commander_standing.glory '<' 20}}badvalue{{/ifCond}}">{{actor.data.data.commander_standing.glory}}</span>
/ {{actor.data.data.commander_standing.status}}

View File

@@ -9,15 +9,15 @@
<article class="attributes" data-group="primary" data-tab="description">
<label class="attribute army-cohort-types">
{{localize 'l5r5e.army.cohort.leader'}}
<input class="select-on-focus" type="number" name="data.leader" value="{{data.data.leader}}" data-dtype="Number"/>
<input class="select-on-focus" type="text" name="data.leader" value="{{data.data.leader}}" data-dtype="String"/>
</label>
<label class="attribute army-cohort-types">
{{localize 'l5r5e.equipment'}}
<input class="select-on-focus" type="number" name="data.equipment" value="{{data.data.equipment}}" data-dtype="Number"/>
<input class="select-on-focus" type="text" name="data.equipment" value="{{data.data.equipment}}" data-dtype="String"/>
</label>
<label class="attribute army-cohort-types">
{{localize 'l5r5e.army.cohort.abilities'}}
<input class="select-on-focus" type="number" name="data.abilities" value="{{data.data.abilities}}" data-dtype="Number"/>
<input class="select-on-focus" type="text" name="data.abilities" value="{{data.data.abilities}}" data-dtype="String"/>
</label>
{{!-- battle readiness --}}

View File

@@ -8,10 +8,10 @@
<li><strong>{{localize 'l5r5e.equipment'}}</strong> : {{data.data.equipment}}</li>
<li><strong>{{localize 'l5r5e.army.cohort.abilities'}}</strong> : {{data.data.abilities}}</li>
{{!-- battle readiness --}}
<li><strong>{{localize 'l5r5e.army.battle_readiness.strength'}}</strong> : {{data.data.battle_readiness.casualties_strength.max}}</li>
<li><strong>{{localize 'l5r5e.army.battle_readiness.casualties'}}</strong> : {{data.data.battle_readiness.casualties_strength.value}}</li>
<li><strong>{{localize 'l5r5e.army.battle_readiness.discipline'}}</strong> : {{data.data.battle_readiness.panic_discipline.max}}</li>
<li><strong>{{localize 'l5r5e.army.battle_readiness.strength'}}</strong> : {{data.data.battle_readiness.casualties_strength.max}}</li>
<li><strong>{{localize 'l5r5e.army.battle_readiness.panic'}}</strong> : {{data.data.battle_readiness.panic_discipline.value}}</li>
<li><strong>{{localize 'l5r5e.army.battle_readiness.discipline'}}</strong> : {{data.data.battle_readiness.panic_discipline.max}}</li>
</ul>
{{!--item-infos--}}
<p><strong>{{localize 'l5r5e.description'}}</strong> : {{{data.data.description}}}</p>