Skip to content

Commit

Permalink
Merge pull request dmdorman#1378 from aeauseth/main
Browse files Browse the repository at this point in the history
Drag and Drop items between containers/frameworks/compound powers.  Fixed equipment weight and price display.
  • Loading branch information
aeauseth authored Oct 27, 2024
2 parents abdbd33 + 8e48e68 commit 9334825
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Fixed INCREASEDEND cost and BARRIER active point calculation. [#1368](https://github.com/dmdorman/hero6e-foundryvtt/issues/1368)
- Frameworks, lists, and compound powers can be collapsed/expanded. [#1357](https://github.com/dmdorman/hero6e-foundryvtt/issues/1357)
- Initial support for dragging items into and out of frameworks, lists, and compound powers. [#1357](https://github.com/dmdorman/hero6e-foundryvtt/issues/1357)
- Fixed missing price & weight of equipment.

## Version 4.0.2

Expand Down
19 changes: 19 additions & 0 deletions module/actor/actor-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,28 @@ export class HeroSystemActorSheet extends ActorSheet {
// return super._onDropItem(event, data);
if (!this.actor.isOwner) return false;
const item = await Item.implementation.fromDropData(data);
if (!item) return;

const sameActor = item.actor?.id === this.actor.id;
if (sameActor) {
// check if we are dragging in or out of a parent item
if (!item.isContainer || item.system.XMLID === "COMPOUNDPOWER") {
const dropTarget = event.target.closest("[data-item-id]");
const item2 = item.actor.items.find((o) => o.id === dropTarget?.dataset.itemId);
if (!item.system.PARENTID && item2.isContainer) {
ui.notifications.info(`<b>${item.name}</b> was moved into to parent <b>${item2.name}</b>`);
await item.update({ "system.PARENTID": item2.system.ID });
} else if (item.system.PARENTID && !item2?.system.PARENTID) {
ui.notifications.info(
`<b>${item.name}</b> was removed from parent <b>${item.parentItem.name}</b>.`,
);
await item.update({ "system.-=PARENTID": null, type: item.parentItem.type });
} else if (!item.isContainer && item2?.isContainer) {
ui.notifications.info(`<b>${item.name}</b> was moved into to parent <b>${item2.name}</b>`);
await item.update({ "system.PARENTID": item2.system.ID });
}
}

return super._onDropItem(event, data);
}

Expand Down
8 changes: 5 additions & 3 deletions module/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,13 @@ export class HeroSystem6eActor extends Actor {
parseInt(game.settings.get(game.system.id, "equipmentWeightPercentage")) / 100.0;

// Hero Designer appears to store WEIGHT as LBS instead of KG.
const equipment = this.items.filter((o) => o.type === "equipment" && o.system.active);
const weightLbs = equipment.reduce((a, b) => a + parseFloat(b.system.WEIGHT), 0);
const equipment = this.items.filter(
(o) => o.type === "equipment" && (o.parentItem ? o.parentItem.system.active : o.system.active),
);
const weightLbs = equipment.reduce((a, b) => a + parseFloat(b.system?.WEIGHT || 0), 0);
const weightKg = (weightLbs / 2.2046226218) * equipmentWeightPercentage;

return Math.ceil(weightKg);
return weightKg.toFixed(1);
}

get netWorth() {
Expand Down
5 changes: 5 additions & 0 deletions module/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,7 @@ function addPower(powerDescription6e, powerOverrideFor5e) {
type: ["compound"],
behaviors: [],
costEnd: false,
isContainer: true,
},
{},
);
Expand All @@ -3234,6 +3235,7 @@ function addPower(powerDescription6e, powerOverrideFor5e) {
type: ["framework"],
behaviors: [],
costEnd: false,
isContainer: true,
});

addPower(
Expand All @@ -3242,6 +3244,7 @@ function addPower(powerDescription6e, powerOverrideFor5e) {
type: ["framework"],
behaviors: [],
costEnd: false,
isContainer: true,
},
{},
);
Expand All @@ -3252,6 +3255,7 @@ function addPower(powerDescription6e, powerOverrideFor5e) {
type: ["framework"],
behaviors: [],
costEnd: false,
isContainer: true,
},
{},
);
Expand All @@ -3262,6 +3266,7 @@ function addPower(powerDescription6e, powerOverrideFor5e) {
type: ["framework"],
behaviors: [],
costEnd: false,
isContainer: true,
},
{},
);
Expand Down
25 changes: 25 additions & 0 deletions module/item/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4837,6 +4837,15 @@ export class HeroSystem6eItem extends Item {
return "PD"; // Default
}

get isContainer() {
if (this.childItems.length) return true;

// A backpack from MiscEquipment.hdp is a CUSTOMPOWER
if (this.system.description.match(/can hold \d+kg/i)) return true;

return this.baseInfo.isContainer;
}

get killing() {
if (this.system.KILLING === true) {
return true;
Expand All @@ -4858,6 +4867,22 @@ export class HeroSystem6eItem extends Item {

return false;
}

get weightKg() {
const equipmentWeightPercentage =
parseInt(game.settings.get(game.system.id, "equipmentWeightPercentage")) / 100.0;
let weightLbs = parseFloat(this.system?.WEIGHT) || 0;
for (const child of this.childItems) {
weightLbs += parseFloat(child.system?.WEIGHT) || 0;
}
const weightKg = (weightLbs / 2.2046226218) * equipmentWeightPercentage;
return weightKg.toFixed(1);
}

get priceText() {
const price = parseFloat(this.system.PRICE) || 0;
return `$${price.toFixed(2)}`;
}
}

export function getItem(id) {
Expand Down
28 changes: 7 additions & 21 deletions templates/actor/actor-sheet-partial-equipment-item.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{else}}

<td width = "24px">
{{#if this.childItems.length}}
{{#if this.isContainer}}
{{#if this.system.collapse}}
<a class="item-image item-control item-expand" title="{{localize "ActorSheet.ExpandItem"}}" >
<i class="fas fa-square-caret-right fa-2x"></i>
Expand All @@ -37,15 +37,15 @@
{{{itemFullDescription this}}}
</td>

{{#if this.childIdx}}
{{#if this.isContainer}}
<td>{{this.system.end}}</td>
<td>{{this.system.PRICEtext}}</td>
<td>{{this.system.WEIGHTtext}}</td>
<td>{{priceText}}</td>
<td title="Total weight of container and contents in kg"><b>{{this.weightKg}}</b></td>
<td></td>
{{else}}
<td>{{this.system.end}}</td>
<td>{{this.system.PRICEtext}}</td>
<td>{{this.system.WEIGHTtext}}</td>
<td>{{this.priceText}}</td>
<td>{{this.weightKg}}</td>
<td>
<input class="item-toggle" type="checkbox" name="this.system.active" {{checked
this.system.active}} data-dtype="Boolean" />
Expand All @@ -60,28 +60,14 @@
Xname="this.system.active" {{checked this.system.active}} data-dtype="Boolean"
data-action="toggle" />
{{/if}}
{{!-- {{#if (ne this.system.subType "attack")}}
{{#if this.system.showToggle}}
<input class="item-toggle" type="checkbox"
Xname="this.system.active" {{checked this.system.active}} data-dtype="Boolean"
data-action="toggle" />
{{/if}}
{{#if this.system.roll}}
<button type="button" class="item-rollable" data-roll="{{this.system.roll}}"
data-label="{{this._id}}">{{numberFormat this.system.roll decimals=0
sign=false}}-</button>
{{/if}}
{{else}}
<a class="item-image item-rollable"><i class="fas fa-dice" title="{{this.name}}" width="24" height="24"></i></a>
{{/if}} --}}
</td>
{{/if}}

<td>
<a class="item-control item-chat" title="{{localize "ActorSheet.SendToChat"}}"><i
class="fas fa-comment-alt"></i></a>
<a class="item-control item-edit" title="{{localize "ActorSheet.EditItem"}}"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="{{localize "ActorSheet.DeleteItem"}}" {{#if this.childItems.length}}style="opacity:0.3"{{/if}}>
<a class="item-control item-delete" title="{{localize "ActorSheet.DeleteItem"}}">
<i class="fas fa-trash"></i>
</a>
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/actor/actor-sheet-partial-powers-item.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<td></td>
{{else}}
<td width = "24px">
{{#if this.childItems.length}}
{{#if this.isContainer}}
{{#if this.system.collapse}}
<a class="item-image item-control item-expand" title="{{localize "ActorSheet.ExpandItem"}}" >
<i class="fas fa-square-caret-right fa-2x"></i>
Expand Down

0 comments on commit 9334825

Please sign in to comment.