Skip to content

Commit

Permalink
Merge pull request #370 from toastygm/tom
Browse files Browse the repository at this point in the history
Tom
  • Loading branch information
toastygm authored Jan 22, 2023
2 parents 7a7f046 + 4deba39 commit 26b0976
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 52 deletions.
14 changes: 7 additions & 7 deletions module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class HarnMasterActor extends Actor {
this.calcTotalGearWeight();

// Prepare data items unique to containers
if (actorData.type === 'container') {
if (this.type === 'container') {
actorData.capacity.value = actorData.totalWeight;
actorData.capacity.pct = Math.round(((actorData.capacity.max - actorData.capacity.value) / (actorData.capacity.max || 1)) * 100);
actorData.capacity.pct = Math.max(Math.min(actorData.capacity.pct, 100), 0); // ensure value is between 0 and 100 inclusive)
Expand Down Expand Up @@ -312,6 +312,12 @@ export class HarnMasterActor extends Actor {

const eph = actorData.eph;

this._calcGearWeightTotals();

if (this.type === 'container') {
return;
}

// store AE-affected ability scores
actorData.abilities.strength.modified = eph.strength;
actorData.abilities.stamina.modified = eph.stamina;
Expand All @@ -327,12 +333,6 @@ export class HarnMasterActor extends Actor {
actorData.abilities.morality.modified = eph.morality;
actorData.abilities.comeliness.modified = eph.comeliness;

this._calcGearWeightTotals();

if (this.type === 'container') {
return;
}

// All common character and creature derived data below here

// Since active effects may have modified these values, we must ensure
Expand Down
54 changes: 28 additions & 26 deletions module/actor/base-actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,41 +146,43 @@ export class HarnMasterBaseActorSheet extends ActorSheet {

const droppedItem = await Item.fromDropData(data);

// Check if coming from a compendium pack
if (droppedItem.pack) {
return super._onDropItem(event, data)
}

// Skills, spells, etc. (non-gear)
if (!droppedItem.type.endsWith("gear")) {
return super._onDropItem(event, data);
}

// Gear coming from world items list
if (!droppedItem.parent) {
return super._onDropItem(event, data);
}

// At this point we know the item is some sort of gear, and coming from an actor

// Destination containerid: set to 'on-person' if a containerid can't be found
const closestContainer = event.target.closest('[data-container-id]');
const destContainer = closestContainer?.dataset.containerId ? closestContainer.dataset.containerId : 'on-person';

if (droppedItem.parent) {
if ((droppedItem.parent.isToken && this.actor.token?.id === droppedItem.parent.token.id) ||
(!droppedItem.parent.isToken && !this.actor.isToken && droppedItem.parent.id === this.actor.id)) {
// Dropping an item into the same actor (Token or Linked)

// If the item is some type of gear (other than containergear), then
// make sure we set the container to the same as the dropped location
// (this allows people to move items into containers easily)
if (droppedItem.type.endsWith('gear') && droppedItem.type !== 'containergear') {
if (droppedItem.system.container !== destContainer) {
await droppedItem.update({'system.container': destContainer });
}
// Dropping an item into the same actor (Token or Linked)
if ((droppedItem.parent.isToken && this.actor.token?.id === droppedItem.parent.token.id) ||
(!droppedItem.parent.isToken && !this.actor.isToken && droppedItem.parent.id === this.actor.id)) {
// If the item is some type of gear (other than containergear), then
// make sure we set the container to the same as the dropped location
// (this allows people to move items into containers easily)
if (droppedItem.type.endsWith('gear') && droppedItem.type !== 'containergear') {
if (droppedItem.system.container !== destContainer) {
await droppedItem.update({'system.container': destContainer });
}

return super._onDropItem(event, data);
}
}

// Skills, spells, etc. (non-gear) coming from a item list or compendium
if (!droppedItem.type.endsWith("gear")) {
return super._onDropItem(event, data);
}

// Check if coming from a compendium pack
if (droppedItem.pack) {
return super._onDropItem(event, data)
}

// At this point we know this dropped item comes from another actor,
// and it is some sort of "gear". Go ahead and process the drop, but
// track the result.
// At this point we know this dropped item is Gear coming from an actor,

// Containers are a special case, and they need to be processed specially
if (droppedItem.type === 'containergear') return await this._moveContainer(event, droppedItem);
Expand Down Expand Up @@ -254,7 +256,7 @@ export class HarnMasterBaseActorSheet extends ActorSheet {
// Render modal dialog
let dlgTemplate = "systems/hmk/templates/dialog/item-qty.html";
let dialogData = {
itemName: data.name,
itemName: item.name,
sourceName: item.parent.name,
targetName: this.actor.name,
maxItems: item.system.quantity,
Expand Down
6 changes: 3 additions & 3 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "hm3",
"title": "HarnMaster 3",
"description": "The HarnMaster system for FoundryVTT!",
"version": "1.4.5",
"version": "1.4.6",
"authors": [
{
"name": "Toasty",
Expand All @@ -20,7 +20,7 @@
"minimumCoreVersion": "10",
"compatibility": {
"minimum": "10",
"verified": "10.288"
"verified": "10.291"
},
"esmodules": [
"module/hm3.js"
Expand Down Expand Up @@ -263,7 +263,7 @@
],
"socket": true,
"manifest": "https://github.com/toastygm/HarnMaster-3-FoundryVTT/releases/latest/download/system.json",
"download": "https://github.com/toastygm/HarnMaster-3-FoundryVTT/releases/download/v1.4.5/system.zip",
"download": "https://github.com/toastygm/HarnMaster-3-FoundryVTT/releases/download/v1.4.6/system.zip",
"gridDistance": 5,
"gridUnits": "ft",
"primaryTokenAttribute": "shockIndex"
Expand Down
31 changes: 15 additions & 16 deletions templates/actor/container-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,45 +77,44 @@ <h1 class="charname"><input name="name" type="text" value="{{actor.name}}" place
{{#each containers as |citem cid|}}
<ol class="items-list gear-list">
<li class="items-header gear flexrow" data-container-id="{{cid}}"
data-container-name="{{citem.data.name}}">
<h3 class="item-name gear-name">{{citem.data.name}}<a class="more-info"
data-journal-entry="Character - Gear Tab - Containers"><i
data-container-name="{{citem.name}}">
<h3 class="item-name gear-name">{{citem.name}}<a class="more-info"
data-journal-entry="Sheet - Gear Tab"><i
class="far fa-question-circle"></i></a></h3>
<div class="item-detail gear-type">Type</div>
<div class="item-detail gear-qty">Qty</div>
<div class="item-detail gear-weight">Weight</div>
<div class="item-detail gear-notes">Notes</div>
<div
class="item detail gear-capacity {{#if (gt citem.system.capacity.value citem.system.capacity.max)}}overcapacity{{/if}}">
Capacity: {{citem.system.capacity.value}}/{{citem.system.capacity.max}}</div>
<div class="item detail gear-capacity {{#if (gt system.capacity.value system.capacity.max)}}overcapacity{{/if}}">
Capacity: {{system.capacity.value}}/{{system.capacity.max}}</div>
<div class="item-controls">
<a class="item-control item-create active" title="Add Gear" data-type="gear"
data-container-id="{{cid}}" data-container-name="{{citem.data.name}}"><i
data-container-id="{{cid}}" data-container-name="{{citem.name}}"><i
class="fas fa-plus"></i> Add</a>
</div>
</li>
<ol class="item-list gear-list">
{{#each ../items as | item |}}
{{#if (and (endswith item.type "gear") (eq item.data.container cid))}}
<li class="item gear-item {{#unless adata.isCarried}}nocarry{{/unless}} flexrow"
data-item-id="{{item._id}}" data-item-name="{{item.name}}"
data-container-id="{{cid}}" data-container-name="{{citem.data.name}}">
{{#if (and (endswith item.type "gear") (eq item.system.container cid))}}
<li class="item gear-item {{#unless system.isCarried}}nocarry{{/unless}} flexrow"
data-item-id="{{item.id}}" data-item-name="{{item.name}}"
data-container-id="{{cid}}" data-container-name="{{citem.name}}">
<div class="item-name gear-name flexrow">
<div class="item-image" style="background-image: url('{{item.img}}')"></div>
<h4>{{item.name}}</h4>
</div>
<div class="item-detail gear-type">{{lookup ../../gearTypes item.type}}</div>
<div class="item-detail gear-qty">{{adata.quantity}}</div>
<div class="item-detail gear-weight">{{adata.weight}}</div>
<div class="item-detail gear-notes">{{adata.notes}}</div>
<div class="item-detail gear-qty">{{system.quantity}}</div>
<div class="item-detail gear-weight">{{system.weight}}</div>
<div class="item-detail gear-notes">{{system.notes}}</div>
<div class="item-controls-wide">
{{#if (eq cid "on-person")}}
{{#unless (or (eq item.type "containergear") (eq item.type "miscgear"))}}
<a class="item-control item-equip" title="Equip"><i
class="{{#if adata.isEquipped}}active{{/if}} fas fa-shield-alt"></i></a>
class="{{#if system.isEquipped}}active{{/if}} fas fa-shield-alt"></i></a>
{{/unless}}
<a class="item-control item-carry" title="Carry"><i
class="{{#if adata.isCarried}}active{{/if}} fas fa-suitcase"></i></a>
class="{{#if system.isCarried}}active{{/if}} fas fa-suitcase"></i></a>
{{/if}}
<a class="item-control item-edit" title="Edit"><i
class="active fas fa-edit"></i></a>
Expand Down

0 comments on commit 26b0976

Please sign in to comment.