Skip to content

Commit

Permalink
Merge pull request #225 from anthonyronda/fix/item-summary-show-descr…
Browse files Browse the repository at this point in the history
…iption-v10

fix: item summaries and show item to chat
  • Loading branch information
anthonyronda authored Sep 6, 2022
2 parents d586349 + 03c7c50 commit 555bdd9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 36 deletions.
62 changes: 37 additions & 25 deletions src/module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,55 @@ export class OseItem extends Item {
super.prepareData();
}

prepareDerivedData() {
const actorData = this?.system || this?.data?.data; //v9-compatibility
actorData.autoTags = this.getAutoTagList();
actorData.manualTags = actorData.tags;
async prepareDerivedData() {
const itemData = this?.system || this?.data?.data; //v9-compatibility
itemData.autoTags = this.getAutoTagList();
itemData.manualTags = itemData.tags;

// Rich text description
if (isNewerVersion(game.version, "10.264")) {
itemData.enrichedDescription = await TextEditor.enrichHTML(
itemData.description,
{ async: true }
);
} else {
itemData.description = TextEditor.enrichHTML(
itemData.description,
htmlOptions
);
}
}

static chatListeners(html) {
html.on("click", ".card-buttons button", this._onChatCardAction.bind(this));
html.on("click", ".item-name", this._onChatCardToggleContent.bind(this));
}

getChatData(htmlOptions) {
const actorType = this?.type || this?.data?.type; //v9-compatibility

const actorData = this?.system || this?.data?.data; //v9-compatibility

const data = actorData.toObject(); //V10 Compatibility
async getChatData(htmlOptions) {
const itemType = this?.type || this?.data?.type; //v9-compatibility

// Rich text description
data.description = TextEditor.enrichHTML(data.description, htmlOptions);
const itemData = this?.system || this?.data?.data; //v9-compatibility

// Item properties
const props = [];

if (actorType == "weapon") {
data.tags.forEach((t) => props.push(t.value));
if (itemType == "weapon") {
itemData.tags.forEach((t) => props.push(t.value));
}
if (actorType == "spell") {
props.push(`${data.class} ${data.lvl}`, data.range, data.duration);
if (itemType == "spell") {
props.push(
`${itemData.class} ${itemData.lvl}`,
itemData.range,
itemData.duration
);
}
if (data.hasOwnProperty("equipped")) {
props.push(data.equipped ? "Equipped" : "Not Equipped");
if (itemData.hasOwnProperty("equipped")) {
props.push(itemData.equipped ? "Equipped" : "Not Equipped");
}

// Filter properties and return
data.properties = props.filter((p) => !!p);
return data;
itemData.properties = props.filter((p) => !!p);
return itemData;
}

rollWeapon(options = {}) {
Expand Down Expand Up @@ -185,9 +197,9 @@ export class OseItem extends Item {
getAutoTagList() {
const tagList = [];
const data = this?.system || this?.data?.data; //v9-compatibility
const actorType = this?.type || this?.data?.type; //v9-compatibility
const itemType = this?.type || this?.data?.type; //v9-compatibility

switch (actorType) {
switch (itemType) {
case "container":
case "item":
break;
Expand Down Expand Up @@ -316,18 +328,18 @@ export class OseItem extends Item {
* @return {Promise}
*/
async show() {
const actorType = this?.type || this?.data?.type; //v9-compatibility
const itemType = this?.type || this?.data?.type; //v9-compatibility
// Basic template rendering data
const token = this.actor.token; //v10: prototypeToken?
const templateData = {
actor: this.actor,
tokenId: token ? `${token.parent.id}.${token.id}` : null,
item: this.data,
data: this.getChatData(),
data: await this.getChatData(),
labels: this.labels,
isHealing: this.isHealing,
hasDamage: this.hasDamage,
isSpell: actorType === "spell",
isSpell: itemType === "spell",
hasSave: this.hasSave,
config: CONFIG.OSE,
};
Expand Down
4 changes: 2 additions & 2 deletions src/templates/actors/partials/actor-item-summary.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="item-description">
{{> (path "/templates/actors/partials/item-auto-tags-partial.html")
tags=item.data.data.autoTags}}
<div>{{{parseInline item.data.data.description}}}</div>
tags=item.system.autoTags}}
<div>{{{item.system.enrichedDescription}}}</div>
</div>
52 changes: 43 additions & 9 deletions src/templates/items/item-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,73 @@ <h1 class="charname">
<div class="stats">
<div class="form-group">
<div class="form-fields">
<input type="text" data-action="add-tag" title="{{localize 'OSE.items.typeTag'}}"
placeholder="{{localize 'OSE.items.enterTag'}}" />
<input
type="text"
data-action="add-tag"
title="{{localize 'OSE.items.typeTag'}}"
placeholder="{{localize 'OSE.items.enterTag'}}"
/>
</div>
</div>
<div class="form-group">
<label>{{localize 'OSE.items.Quantity'}}</label>
<div class="form-fields">
<input type="text" name="data.quantity.value" value="{{data.quantity.value}}" data-dtype="Number" />/<input type="text" name="data.quantity.max" value="{{data.quantity.max}}" data-dtype="Number" />
<input
type="text"
name="data.quantity.value"
value="{{data.quantity.value}}"
data-dtype="Number"
/>/<input
type="text"
name="data.quantity.max"
value="{{data.quantity.max}}"
data-dtype="Number"
/>
</div>
</div>
<div class="form-group">
<label>{{localize 'OSE.items.Treasure'}}</label>
<div class="form-fields">
<input type="checkbox" name="data.treasure" value="{{data.treasure}}" {{checked data.treasure}} data-dtype="Boolean"/>
<input
type="checkbox"
name="data.treasure"
value="{{data.treasure}}"
{{checked
data.treasure}}
data-dtype="Boolean"
/>
</div>
</div>
<div class="form-group">
<label>{{localize 'OSE.items.Cost'}}</label>
<div class="form-fields">
<input type="text" name="data.cost" value="{{data.cost}}" data-dtype="Number" />
<input
type="text"
name="data.cost"
value="{{data.cost}}"
data-dtype="Number"
/>
</div>
</div>
<div class="form-group">
<label>{{localize 'OSE.items.Weight'}}</label>
<div class="form-fields">
<input type="text" name="data.weight" value="{{data.weight}}" data-dtype="Number" />
<input
type="text"
name="data.weight"
value="{{data.weight}}"
data-dtype="Number"
/>
</div>
</div>
</div>
<div class="description weapon-editor">
{{editor content=data.description target="data.description" button=true
owner=owner editable=editable}}
{{#if (isV10)}} {{editor enrichedDescription
target="system.details.description" button=true editable=editable
async=true}} {{else}} {{editor content=data.details.biography
target="data.details.biography" button=true owner=owner
editable=editable }} {{/if}}
</div>
</div>
</section>
</form>
</form>

0 comments on commit 555bdd9

Please sign in to comment.