Skip to content

Commit

Permalink
Actually implement clickable items
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jan 8, 2022
1 parent 8f9102b commit b7d40c6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
6 changes: 4 additions & 2 deletions scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ export default class API {
static async _turnTokensIntoItemPiles(targetUuids, pileSettings = {}, tokenSettings = {}) {

const tokenUpdateGroups = {};
const defaults = foundry.utils.duplicate(CONSTANTS.PILE_DEFAULTS);

for(const targetUuid of targetUuids) {

let target = await fromUuid(targetUuid);

const existingPileSettings = foundry.utils.mergeObject(CONSTANTS.PILE_DEFAULTS, lib.getItemPileData(target));
const existingPileSettings = foundry.utils.mergeObject(defaults, lib.getItemPileData(target));
pileSettings = foundry.utils.mergeObject(existingPileSettings, pileSettings);
pileSettings.enabled = true;

Expand Down Expand Up @@ -365,12 +366,13 @@ export default class API {
static async _revertTokensFromItemPiles(targetUuids, tokenSettings) {

const tokenUpdateGroups = {};
const defaults = foundry.utils.duplicate(CONSTANTS.PILE_DEFAULTS);

for(const targetUuid of targetUuids) {

let target = await fromUuid(targetUuid);

const pileSettings = foundry.utils.mergeObject(CONSTANTS.PILE_DEFAULTS, lib.getItemPileData(target));
const pileSettings = foundry.utils.mergeObject(defaults, lib.getItemPileData(target));
pileSettings.enabled = false;

const [_, sceneId, __, tokenId] = targetUuid.split('.');
Expand Down
9 changes: 7 additions & 2 deletions scripts/formapplications/itemPileConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CONSTANTS from "../constants.js";
import API from "../api.js";
import { ItemPileAttributeEditor } from "./itemPileAttributeEditor.js";
import * as lib from "../lib/lib.js";
import { itemPileSocket } from "../socket.js";

export class ItemPileConfig extends FormApplication {

Expand Down Expand Up @@ -152,7 +153,9 @@ export class ItemPileConfig extends FormApplication {

async _updateObject(event, formData) {

const data = foundry.utils.mergeObject(CONSTANTS.PILE_DEFAULTS, formData);
let defaults = foundry.utils.duplicate(CONSTANTS.PILE_DEFAULTS);

const data = foundry.utils.mergeObject(defaults, formData);

const checked = this.element.find('.item-pile-config-override-attributes-checkbox').is(":checked");

Expand All @@ -168,7 +171,9 @@ export class ItemPileConfig extends FormApplication {
"false": false
}[formData.deleteWhenEmpty];

API.updateItemPile(this.document, data)
API.updateItemPile(this.document, data).then(() => {
API.rerenderItemPileInventoryApplication(this.document.uuid);
});

}

Expand Down
2 changes: 2 additions & 0 deletions scripts/formapplications/itemPileInventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class ItemPileInventory extends FormApplication {
data.attributes = this.attributes.length ? this.attributes : this.getPileAttributeData();
data.hasItems = API.getItemPileItems(this.pile).length > 0;
data.hasAttributes = data?.attributes?.length;
data.canInspectItems = pileData.canInspectItems || game.user.isGM;
console.log(data.canInspectItems)
}

data.isEmpty = lib.isItemPileEmpty(this.pile);
Expand Down
5 changes: 4 additions & 1 deletion scripts/lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ export function getItemPileData(inDocument){
inDocument = inDocument?.token;
}
try{
return foundry.utils.duplicate(inDocument.getFlag(CONSTANTS.MODULE_NAME, CONSTANTS.FLAG_NAME) ?? {});
let data = inDocument.getFlag(CONSTANTS.MODULE_NAME, CONSTANTS.FLAG_NAME);
if(!data) return {};
let defaults = foundry.utils.duplicate(CONSTANTS.PILE_DEFAULTS);
return foundry.utils.mergeObject(defaults, data);
}catch(err){
return {};
}
Expand Down
6 changes: 1 addition & 5 deletions styles/module.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
flex: 4;
}

.item-piles-item-row .item-piles-name .item-piles-clickable{
.item-piles-item-row .item-piles-name .item-piles-item-clickable{
cursor: pointer;
}

.item-piles-item-row .item-piles-name .item-piles-clickable:hover{
text-shadow: 0 0 8px var(--color-shadow-primary);
}

.item-piles-item-row .item-piles-quantity{
flex: 0.75;
margin-left: 0.5rem;
Expand Down
6 changes: 5 additions & 1 deletion templates/item-pile-inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
{{#each items as |item id|}}
<div class="flexrow item-piles-item-row {{#unless item.maxQuantity}}item-pile-item-disabled{{/unless}}" data-item-id="{{item.id}}" data-item-type="{{item.type}}">
<img class="item-piles-img" src="{{item.img}}"/>
<div class="item-piles-name item-piles-text"><a class="item-piles-item-clickable">{{item.name}}</a></div>
<div class="item-piles-name item-piles-text">
{{#if @root.canInspectItems}}<a class="item-piles-item-clickable">{{/if}}
{{item.name}}
{{#if @root.canInspectItems}}</a>{{/if}}
</div>
{{#if @root.hasRecipient}}
<input class="item-piles-quantity" type="number" min="1" value="{{item.currentQuantity}}" max="{{item.quantity}}" {{#unless item.maxQuantity}}disabled{{/unless}}/>
{{/if}}
Expand Down

0 comments on commit b7d40c6

Please sign in to comment.