Working on 0.8.x - Character sheets related
This commit is contained in:
@@ -64,7 +64,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
Object.keys(out).forEach((tech) => {
|
||||
if (
|
||||
out[tech].length < 1 &&
|
||||
!sheetData.data.techniques[tech] &&
|
||||
!sheetData.data.data.techniques[tech] &&
|
||||
!CONFIG.l5r5e.techniques_school.includes(tech)
|
||||
) {
|
||||
delete out[tech];
|
||||
@@ -72,11 +72,11 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
});
|
||||
|
||||
// Manage school add button
|
||||
sheetData.data.techniques["school_ability"] = out["school_ability"].length === 0;
|
||||
sheetData.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
|
||||
sheetData.data.data.techniques["school_ability"] = out["school_ability"].length === 0;
|
||||
sheetData.data.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
|
||||
|
||||
// Always display "school_ability", but display "mastery_ability" only if rank >= 5
|
||||
if (sheetData.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
|
||||
if (sheetData.data.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
|
||||
delete out["mastery_ability"];
|
||||
}
|
||||
return out;
|
||||
@@ -155,7 +155,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
if (
|
||||
!item ||
|
||||
item.entity !== "Item" ||
|
||||
item.documentName !== "Item" ||
|
||||
!["item", "armor", "weapon", "technique", "peculiarity", "advancement"].includes(item.data.type)
|
||||
) {
|
||||
return;
|
||||
@@ -221,7 +221,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
if (allowed === false) {
|
||||
return;
|
||||
}
|
||||
return this._onDropItem(event, item);
|
||||
return this._onDropItemCreate(item.toJSON());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,12 +321,14 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
peculiarity: "l5r5e.peculiarities.title_new",
|
||||
advancement: "l5r5e.advancements.title_new",
|
||||
};
|
||||
const created = await this.actor.createEmbeddedEntity("OwnedItem", {
|
||||
name: game.i18n.localize(titles[type]),
|
||||
type: type,
|
||||
img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`,
|
||||
});
|
||||
const item = this.actor.getOwnedItem(created._id);
|
||||
const created = await this.actor.createEmbeddedDocuments("Item", [
|
||||
{
|
||||
name: game.i18n.localize(titles[type]),
|
||||
type: type,
|
||||
img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`,
|
||||
},
|
||||
]);
|
||||
const item = this.actor.items.get(created[0].id);
|
||||
|
||||
// assign current school rank to the new adv/tech
|
||||
if (this.actor.data.data.identity?.school_rank && ["advancement", "technique"].includes(item.data.type)) {
|
||||
@@ -347,7 +349,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
const techType = $(event.currentTarget).data("tech-type");
|
||||
if ([...CONFIG.l5r5e.techniques, ...CONFIG.l5r5e.techniques_school].includes(techType)) {
|
||||
item.data.data.technique_type = techType;
|
||||
item.data.img = `${CONFIG.l5r5e.paths.assets}/icons/techs/${techType}.svg`;
|
||||
item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techType}.svg`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -366,7 +368,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
event.stopPropagation();
|
||||
|
||||
const itemId = $(event.currentTarget).data("item-id");
|
||||
const item = this.actor.getOwnedItem(itemId);
|
||||
const item = this.actor.items.get(itemId);
|
||||
item.sheet.render(true);
|
||||
}
|
||||
|
||||
@@ -382,7 +384,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
const itemId = $(event.currentTarget).data("item-id");
|
||||
|
||||
// Remove 1 qty if possible
|
||||
const tmpItem = this.actor.getOwnedItem(itemId);
|
||||
const tmpItem = this.actor.items.get(itemId);
|
||||
if (tmpItem && tmpItem.data.data.quantity > 1 && this._modifyQuantity(tmpItem._id, -1)) {
|
||||
return;
|
||||
}
|
||||
@@ -411,8 +413,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
data: diffObject(this.actor.data.data, actor),
|
||||
});
|
||||
}
|
||||
|
||||
return this.actor.deleteOwnedItem(itemId);
|
||||
return this.actor.deleteEmbeddedDocuments("Item", [itemId]);
|
||||
};
|
||||
|
||||
// Holing Ctrl = without confirm
|
||||
@@ -433,7 +434,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
*/
|
||||
_switchSubItemCurriculum(event) {
|
||||
const itemId = $(event.currentTarget).data("item-id");
|
||||
const item = this.actor.getOwnedItem(itemId);
|
||||
const item = this.actor.items.get(itemId);
|
||||
if (item.type !== "item") {
|
||||
item.update({
|
||||
data: {
|
||||
@@ -448,7 +449,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
* @private
|
||||
*/
|
||||
_modifyQuantity(itemId, add) {
|
||||
const tmpItem = this.actor.getOwnedItem(itemId);
|
||||
const tmpItem = this.actor.items.get(itemId);
|
||||
if (tmpItem) {
|
||||
tmpItem.data.data.quantity = Math.max(1, tmpItem.data.data.quantity + add);
|
||||
tmpItem.update({
|
||||
@@ -476,7 +477,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
}
|
||||
|
||||
const itemId = $(event.currentTarget).data("item-id");
|
||||
const tmpItem = this.actor.getOwnedItem(itemId);
|
||||
const tmpItem = this.actor.items.get(itemId);
|
||||
if (!tmpItem || tmpItem.data.data[type] === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -498,7 +499,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
* @private
|
||||
*/
|
||||
_getWeaponSkillId(weaponId) {
|
||||
const item = this.actor.getOwnedItem(weaponId);
|
||||
const item = this.actor.items.get(weaponId);
|
||||
if (!!item && item.type === "weapon") {
|
||||
return item.data.data.skill;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,13 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
|
||||
this.actor.data.data.identity.school_rank = Math.max(1, this.actor.data.data.identity.school_rank);
|
||||
|
||||
// Split Money
|
||||
sheetData.data.money = this._zeniToMoney(this.actor.data.data.zeni);
|
||||
sheetData.data.data.money = this._zeniToMoney(this.actor.data.data.zeni);
|
||||
|
||||
// split advancements list by rank, and calculate xp spent
|
||||
this._prepareAdvancement(sheetData);
|
||||
sheetData.data.xp_saved = Math.floor(parseInt(sheetData.data.xp_total) - parseInt(sheetData.data.xp_spent));
|
||||
sheetData.data.data.xp_saved = Math.floor(
|
||||
parseInt(sheetData.data.data.xp_total) - parseInt(sheetData.data.data.xp_spent)
|
||||
);
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
@@ -100,14 +102,14 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
|
||||
*/
|
||||
_prepareAdvancement(sheetData) {
|
||||
const adv = [];
|
||||
sheetData.data.xp_spent = 0;
|
||||
sheetData.data.data.xp_spent = 0;
|
||||
sheetData.items.forEach((item) => {
|
||||
if (!["peculiarity", "technique", "advancement"].includes(item.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let xp = parseInt(item.data.xp_used) || 0;
|
||||
sheetData.data.xp_spent = parseInt(sheetData.data.xp_spent) + xp;
|
||||
sheetData.data.data.xp_spent = parseInt(sheetData.data.data.xp_spent) + xp;
|
||||
|
||||
// if not in curriculum, xp spent /2 for this item
|
||||
if (!item.data.in_curriculum && xp > 0) {
|
||||
@@ -126,7 +128,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
|
||||
adv[rank].list.push(item);
|
||||
adv[rank].spent = adv[rank].spent + xp;
|
||||
});
|
||||
sheetData.advancementsListByRank = adv;
|
||||
sheetData.data.advancementsListByRank = adv;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ export class NpcSheetL5r5e extends BaseSheetL5r5e {
|
||||
getData() {
|
||||
const sheetData = super.getData();
|
||||
|
||||
sheetData.data.types = NpcSheetL5r5e.types.map((e) => ({
|
||||
sheetData.data.data.types = NpcSheetL5r5e.types.map((e) => ({
|
||||
id: e,
|
||||
label: game.i18n.localize("l5r5e.character_types." + e),
|
||||
}));
|
||||
|
||||
@@ -51,7 +51,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
* Define a unique and dynamic element ID for the rendered ActorSheet application
|
||||
*/
|
||||
get id() {
|
||||
return `l5r5e-twenty-questions-dialog-${this.actor._id}`;
|
||||
return `l5r5e-twenty-questions-dialog-${this.actor.id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
if (!this.actor) {
|
||||
return;
|
||||
}
|
||||
this._initialize(game.actors.get(this.actor._id));
|
||||
this._initialize(game.actors.get(this.actor.id));
|
||||
await this._constructCache();
|
||||
this.render(false);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
try {
|
||||
// Get item
|
||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
if (item.entity !== "Item" || !item) {
|
||||
if (item.documentName !== "Item" || !item) {
|
||||
console.warn("forbidden item for this drop zone", type, item.data.type);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ export class TwentyQuestions {
|
||||
shuji: false,
|
||||
maho: false,
|
||||
ninjutsu: false,
|
||||
link: false,
|
||||
specificity: false,
|
||||
},
|
||||
techniques: [],
|
||||
school_ability: [],
|
||||
@@ -285,8 +287,8 @@ export class TwentyQuestions {
|
||||
});
|
||||
|
||||
// Clear and add items to actor
|
||||
const deleteIds = actor.data.items.map((e) => e._id);
|
||||
await actor.deleteEmbeddedEntity("OwnedItem", deleteIds);
|
||||
const deleteIds = actor.data.items.map((e) => e.id);
|
||||
await actor.deleteEmbeddedDocuments("Item", deleteIds);
|
||||
|
||||
// Add items in 20Q to actor
|
||||
for (const types of Object.values(itemsCache)) {
|
||||
@@ -298,7 +300,7 @@ export class TwentyQuestions {
|
||||
if (itemData.data?.xp_spent) {
|
||||
itemData.data.xp_spent = 0;
|
||||
}
|
||||
await actor.createEmbeddedEntity("OwnedItem", itemData);
|
||||
await actor.createEmbeddedDocuments("Item", [itemData]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export class HelpersL5r5e {
|
||||
|
||||
// Named pack
|
||||
if (pack) {
|
||||
const data = await game.packs.get(pack).getEntity(id);
|
||||
const data = await game.packs.get(pack).getDocument(id);
|
||||
if (data) {
|
||||
return HelpersL5r5e.createItemFromCompendium(data);
|
||||
}
|
||||
@@ -107,13 +107,13 @@ export class HelpersL5r5e {
|
||||
|
||||
// Unknown pack object, iterate all packs
|
||||
for (const comp of game.packs) {
|
||||
// TODO Bug with babele if "comp.getEntity(id)" return null...
|
||||
const babeleFix = (await comp.getIndex()).some((e) => e._id === id);
|
||||
// TODO Bug with babele if "comp.getDocument(id)" return null...
|
||||
const babeleFix = (await comp.getIndex()).some((e) => e.id === id);
|
||||
if (!babeleFix) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const data = await comp.getEntity(id);
|
||||
const data = await comp.getDocument(id);
|
||||
if (data) {
|
||||
return HelpersL5r5e.createItemFromCompendium(data);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ export class HelpersL5r5e {
|
||||
item = await ItemL5r5e.create(data, { temporary: true });
|
||||
|
||||
// reinject compendium id (required for properties)
|
||||
item.data._id = data._id;
|
||||
item.data.id = data.id;
|
||||
} else {
|
||||
// Quick object
|
||||
item = new ItemL5r5e(data);
|
||||
@@ -158,7 +158,7 @@ export class HelpersL5r5e {
|
||||
item.data.data.properties.map(async (property) => {
|
||||
const gameProp = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack(property.id, "Item");
|
||||
if (gameProp) {
|
||||
return { id: gameProp._id, name: gameProp.name };
|
||||
return { id: gameProp.id, name: gameProp.name };
|
||||
}
|
||||
return property;
|
||||
})
|
||||
|
||||
@@ -147,18 +147,20 @@ export default class HooksL5r5e {
|
||||
static async renderCompendium(app, html, data) {
|
||||
// templates "item" : add Rarity
|
||||
// Techniques / Peculiarities : add Ring / Rank
|
||||
if (app.entity === "Item") {
|
||||
const content = await app.getContent();
|
||||
content.forEach((item) => {
|
||||
if (["weapon", "armor", "item", "peculiarity", "technique", "peculiarity"].includes(item.type)) {
|
||||
html.find(`[data-entry-id="${item._id}"]`).append(
|
||||
if (app.collection.documentName === "Item") {
|
||||
const content = await app.collection.getDocuments();
|
||||
content.forEach((document) => {
|
||||
if (["weapon", "armor", "item", "peculiarity", "technique", "peculiarity"].includes(document.type)) {
|
||||
html.find(`[data-document-id="${document.id}"]`).append(
|
||||
`<i` +
|
||||
(item.data.data.ring ? ` class="i_${item.data.data.ring}"` : ``) +
|
||||
(document.data.data.ring ? ` class="i_${document.data.data.ring}"` : ``) +
|
||||
`>` +
|
||||
(item.data.data.rarity
|
||||
? `${game.i18n.localize("l5r5e.rarity")} ${item.data.data.rarity}`
|
||||
(document.data.data.rarity
|
||||
? `${game.i18n.localize("l5r5e.rarity")} ${document.data.data.rarity}`
|
||||
: "") +
|
||||
(document.data.data.rank
|
||||
? game.i18n.localize("l5r5e.rank") + " " + document.data.data.rank
|
||||
: "") +
|
||||
(item.data.data.rank ? game.i18n.localize("l5r5e.rank") + " " + item.data.data.rank : "") +
|
||||
`</i>`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,16 +35,16 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
async _prepareProperties(sheetData) {
|
||||
sheetData.data.propertiesList = [];
|
||||
|
||||
if (Array.isArray(sheetData.data.properties)) {
|
||||
if (Array.isArray(sheetData.data.data.properties)) {
|
||||
const props = [];
|
||||
for (const property of sheetData.data.properties) {
|
||||
for (const property of sheetData.data.data.properties) {
|
||||
const gameProp = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack(property.id, "Item");
|
||||
if (gameProp) {
|
||||
sheetData.data.propertiesList.push(gameProp);
|
||||
props.push({ id: gameProp._id, name: gameProp.name });
|
||||
props.push({ id: gameProp.id, name: gameProp.name });
|
||||
}
|
||||
}
|
||||
sheetData.data.properties = props;
|
||||
sheetData.data.data.properties = props;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
|
||||
// Check item type and subtype
|
||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
if (!item || item.entity !== "Item" || item.data.type !== "property" || this.item.type === "property") {
|
||||
if (!item || item.documentName !== "Item" || item.data.type !== "property" || this.item.type === "property") {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,19 +148,19 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
* @private
|
||||
*/
|
||||
_addProperty(item) {
|
||||
if (!Array.isArray(this.entity.data.data.properties)) {
|
||||
this.entity.data.data.properties = [];
|
||||
if (!Array.isArray(this.document.data.data.properties)) {
|
||||
this.document.data.data.properties = [];
|
||||
}
|
||||
|
||||
if (this.entity.data.data.properties.findIndex((p) => p.id === item.id) !== -1) {
|
||||
if (this.document.data.data.properties.findIndex((p) => p.id === item.id) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.entity.data.data.properties.push({ id: item.id, name: item.name });
|
||||
this.document.data.data.properties.push({ id: item.id, name: item.name });
|
||||
|
||||
this.entity.update({
|
||||
this.document.update({
|
||||
data: {
|
||||
properties: this.entity.data.data.properties,
|
||||
properties: this.document.data.data.properties,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -173,21 +173,21 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (!Array.isArray(this.entity.data.data.properties)) {
|
||||
if (!Array.isArray(this.document.data.data.properties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const id = $(event.currentTarget).parents(".property").data("propertyId");
|
||||
const tmpProps = this.entity.data.data.properties.find((p) => p.id === id);
|
||||
const tmpProps = this.document.data.data.properties.find((p) => p.id === id);
|
||||
if (!tmpProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
const callback = async () => {
|
||||
this.entity.data.data.properties = this.entity.data.data.properties.filter((p) => p.id !== id);
|
||||
this.entity.update({
|
||||
this.document.data.data.properties = this.document.data.data.properties.filter((p) => p.id !== id);
|
||||
this.document.update({
|
||||
data: {
|
||||
properties: this.entity.data.data.properties,
|
||||
properties: this.document.data.data.properties,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -14,5 +14,11 @@ export class PropertySheetL5r5e extends ItemSheetL5r5e {
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
|
||||
});
|
||||
}
|
||||
// TODO certain propriétés en annule d'autres : aiguisé <-> abimé. voir comment faire.
|
||||
// TODO Some properties cancel others :
|
||||
// Concealable and Cumbersome
|
||||
// Ceremonial and Mundane
|
||||
// Damaged and Durable
|
||||
// Resplendent and Subtle
|
||||
// Subtle and Wargear
|
||||
// Sacred and Unholy
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ Hooks.once("init", async () => {
|
||||
CONFIG.l5r5e = L5R5E;
|
||||
|
||||
// Assign custom classes and constants here
|
||||
CONFIG.Combat.entityClass = CombatL5r5e;
|
||||
CONFIG.Actor.entityClass = ActorL5r5e;
|
||||
CONFIG.Combat.documentClass = CombatL5r5e;
|
||||
CONFIG.Actor.documentClass = ActorL5r5e;
|
||||
CONFIG.Actor.sheetClasses = CharacterSheetL5r5e;
|
||||
CONFIG.Item.entityClass = ItemL5r5e;
|
||||
CONFIG.JournalEntry.entityClass = JournalL5r5e;
|
||||
CONFIG.Item.documentClass = ItemL5r5e;
|
||||
CONFIG.JournalEntry.documentClass = JournalL5r5e;
|
||||
CONFIG.JournalEntry.sheetClass = BaseJournalSheetL5r5e;
|
||||
|
||||
// Define custom Roll class
|
||||
|
||||
Reference in New Issue
Block a user