Merge branch 'master' into dev_gennpc

# Conflicts:
#	system/styles/l5r5e.css
This commit is contained in:
Vlyan
2021-12-19 16:21:30 +01:00
84 changed files with 3183 additions and 226 deletions

View File

@@ -13,11 +13,110 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
template: CONFIG.l5r5e.paths.templates + "actors/army-sheet.html",
width: 600,
height: 800,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "cohort" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "army" }],
});
}
/** @override */
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) },
}),
];
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
* @param {object} options TinyMCE initialization options passed to TextEditor.create
* @param {string} initialContent Initial text content for the editor area.
* @override
*/
activateEditor(name, options = {}, initialContent = "") {
if (["data.army_abilities", "data.supplies_logistics", "data.past_battles"].includes(name) && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
}
/**
* This method is called upon form submission after form data is validated
* @param event {Event} The initial triggering submission event
* @param formData {Object} The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
["data.army_abilities", "data.supplies_logistics", "data.past_battles"].forEach((name) => {
if (!formData[name]) {
return;
}
formData[name] = game.l5r5e.HelpersL5r5e.convertSymbols(formData[name], true);
});
return super._updateObject(event, formData);
}
/**
* 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 (warlord/commander)
html.find(".actor-remove-control").on("click", this._removeLinkedActor.bind(this));
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData(options);
@@ -48,7 +147,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 +156,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);
// actor dual trigger...
if (item?.documentName !== "Actor") {
console.warn("L5R5E | Characters items are not allowed", item?.data?.type, item);
}
return;
}
@@ -72,7 +173,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

@@ -198,6 +198,11 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
// Item subtype specific
switch (itemData.type) {
case "army_cohort":
case "army_fortification":
console.warn("L5R5E | Army items are not allowed", item?.data?.type, item);
return;
case "advancement":
// Specific advancements, remove 1 to selected ring/skill
await this.actor.addBonus(item);

View File

@@ -87,13 +87,12 @@ export class BaseSheetL5r5e extends ActorSheet {
* @override
*/
async _updateObject(event, formData) {
if (formData["data.notes"]) {
formData["data.notes"] = game.l5r5e.HelpersL5r5e.convertSymbols(formData["data.notes"], true);
}
if (formData["data.description"]) {
formData["data.description"] = game.l5r5e.HelpersL5r5e.convertSymbols(formData["data.description"], true);
}
["data.notes", "data.description"].forEach((name) => {
if (!formData[name]) {
return;
}
formData[name] = game.l5r5e.HelpersL5r5e.convertSymbols(formData[name], true);
});
return super._updateObject(event, formData);
}

View File

@@ -7,6 +7,7 @@ export class GmMonitor extends FormApplication {
* Settings
*/
object = {
view: "characters", // characters|armies
actors: [],
};
@@ -30,6 +31,33 @@ export class GmMonitor extends FormApplication {
});
}
/**
* Add the Switch View button on top of sheet
* @override
*/
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
// Send To Chat
buttons.unshift({
label: game.i18n.localize("l5r5e.gm_monitor.switch_view"),
class: "switch-view",
icon: "fas fa-users",
onclick: () =>
game.l5r5e.HelpersL5r5e.debounce(
"SwitchView-" + this.object.id,
() => {
this.object.view = this.object.view === "armies" ? "characters" : "armies";
this.render(false);
},
1000,
true
)(),
});
return buttons;
}
/**
* Constructor
* @param {ApplicationOptions} options
@@ -72,9 +100,7 @@ export class GmMonitor extends FormApplication {
return a.name.localeCompare(b.name);
});
this.object = {
actors,
};
this.object.actors = actors;
}
/**
@@ -97,7 +123,12 @@ export class GmMonitor extends FormApplication {
getData(options = null) {
return {
...super.getData(options),
data: this.object,
data: {
...this.object,
actors: this.object.actors.filter((e) =>
this.object.view === "armies" ? e.type === "army" : e.type !== "army"
),
},
};
}
@@ -113,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));
@@ -140,11 +171,11 @@ export class GmMonitor extends FormApplication {
switch (type) {
case "armors":
return await this._getTooltipArmors(actor);
return this._getTooltipArmors(actor);
case "weapons":
return await this._getTooltipWeapons(actor);
return this._getTooltipWeapons(actor);
case "global":
return await this._getTooltipGlobal(actor);
return actor.type === "army" ? this._getTooltipArmiesGlobal(actor) : this._getTooltipGlobal(actor);
}
});
}
@@ -173,12 +204,6 @@ export class GmMonitor extends FormApplication {
return;
}
// No armies allowed !
if (actor.data.type === "army") {
console.log(`L5R5E | Armies are not supported !`);
return;
}
this.object.actors.push(actor);
return this._saveActorsIds();
@@ -197,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
@@ -236,7 +243,7 @@ export class GmMonitor extends FormApplication {
}
/**
* Get tooltips informations for this actor
* Get tooltips informations for this character
* @param {BaseSheetL5r5e} actor
* @return {string}
* @private
@@ -263,6 +270,21 @@ export class GmMonitor extends FormApplication {
});
}
/**
* Get tooltips informations for this army
* @param {BaseSheetL5r5e} actor
* @return {string}
* @private
*/
async _getTooltipArmiesGlobal(actor) {
const actorData = (await actor.sheet?.getData()) || actor.data;
// *** Template ***
return renderTemplate(`${CONFIG.l5r5e.paths.templates}gm/monitor-tooltips/global-armies.html`, {
actorData: actorData.data,
});
}
/**
* Get weapons informations for this actor
* @param {BaseSheetL5r5e} actor

View File

@@ -80,16 +80,16 @@ export const RegisterHandlebars = function () {
result = a !== b;
break;
case "<":
result = a < b;
result = +a < +b;
break;
case "<=":
result = a <= b;
result = +a <= +b;
break;
case ">":
result = a > b;
result = +a > +b;
break;
case ">=":
result = a >= b;
result = +a >= +b;
break;
case "&&":
result = a && b;

View File

@@ -70,12 +70,10 @@ export class HelpersL5r5e {
* @return {Promise<null>}
*/
static async getDragnDropTargetObject(event) {
const json = event.dataTransfer.getData("text/plain");
if (!json) {
return null;
}
const data = JSON.parse(json);
if (!data) {
let data;
try {
data = JSON.parse(event.dataTransfer?.getData("text/plain"));
} catch (err) {
return null;
}
return await HelpersL5r5e.getObjectGameOrPack(data);
@@ -419,6 +417,21 @@ export class HelpersL5r5e {
}
});
// Ability to drag n drop an actor
html.find(".dragndrop-actor-id").on("dragstart", (event) => {
const actorId = $(event.currentTarget).data("actor-id");
if (!actorId) {
return;
}
event.originalEvent.dataTransfer.setData(
"text/plain",
JSON.stringify({
type: "Actor",
id: actorId,
})
);
});
// Item detail tooltips
this.popupManager(html.find(".l5r5e-tooltip"), async (event) => {
const item = await HelpersL5r5e.getEmbedItemByEvent(event, actor);
@@ -427,6 +440,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);
});
}
/**
@@ -656,12 +681,11 @@ export class HelpersL5r5e {
console.log(`L5R5E | Pack not found[${pack}]`);
return;
}
if (!comp.indexed) {
await comp.getDocuments();
}
await comp.getDocuments();
const table = await comp.getName(tableName);
if (!table) {
console.log(`L5R5E | Table not found[${tableName}]`);
console.log(`L5R5E | Table not found[${tableName}]`, comp, table);
return;
}
return await table.drawMany(retrieve, opt);

View File

@@ -4,16 +4,12 @@ export default class HooksL5r5e {
* Do anything after initialization but before ready
*/
static setup() {
// Embed Babele compendiums
// Enable embed Babele compendiums only if custom compendium is not found or disabled
if (
typeof Babele !== "undefined" &&
Babele.get().modules.every((module) => module.lang !== "fr" || module.module !== "l5r5e-custom-compendiums")
Babele.get().modules.every((module) => module.module !== "l5r5e-custom-compendiums")
) {
Babele.get().register({
module: "../systems/l5r5e", // babele only accept modules, so... well :D
lang: "fr",
dir: "babele/fr-fr",
});
Babele.get().setSystemTranslationsDir("babele"); // Since Babele v2.0.4
}
}

View File

@@ -10,8 +10,132 @@ 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();
}
}
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
* @param {object} options TinyMCE initialization options passed to TextEditor.create
* @param {string} initialContent Initial text content for the editor area.
* @override
*/
activateEditor(name, options = {}, initialContent = "") {
if (name === "data.abilities" && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
}
/**
* This method is called upon form submission after form data is validated
* @param event {Event} The initial triggering submission event
* @param formData {Object} The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
if (formData["data.abilities"]) {
formData["data.abilities"] = game.l5r5e.HelpersL5r5e.convertSymbols(formData["data.abilities"], true);
}
return super._updateObject(event, formData);
}
/**
* 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,
},
});
}
}

View File

@@ -29,6 +29,7 @@ export const PreloadTemplates = async function () {
`${tpl}actors/npc/skill.html`,
`${tpl}actors/npc/techniques.html`,
// *** Actors : Army ***
`${tpl}actors/army/army.html`,
`${tpl}actors/army/cohort.html`,
`${tpl}actors/army/fortification.html`,
`${tpl}actors/army/others.html`,