Skip to content

Commit

Permalink
Added clear all items, better handling of image, added text editor fo…
Browse files Browse the repository at this point in the history
…r description
  • Loading branch information
Haxxer committed Sep 3, 2022
1 parent 3793f0b commit b0585c8
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 46 deletions.
11 changes: 5 additions & 6 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"ClickRoll": "Click roll to start",
"RolledTimes": "Rolled {rolls} times",
"KeepRolled": "Keep rolled",
"AddAll": "Add All Items"
"AddAll": "Add All Items",
"ClearAllItems": "Clear All Actor Items"
},
"Errors": {
"DisallowedItemDrop": "You cannot drop \"{type}\" items",
Expand Down Expand Up @@ -152,11 +153,9 @@
"Content": "This will reset all of the history of players having taken their share from this pile.<br><br>Are you sure you want to do this?",
"Confirm": "Reset Sharing Data"
},
"SwitchCurrencyType": {
"Title": "Switching Currency Type",
"Header": "Are you sure?",
"Content1": "Are you sure you want to switch currency type?",
"Content2": "This will reset the existing currency setup."
"ClearAllItems": {
"Title": "Clear All Actor Items",
"Content": "This will clear all of the actor's items, are you sure you want to do this?"
}
},
"Applications": {
Expand Down
8 changes: 8 additions & 0 deletions src/API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,14 @@ const API = {

},

getActorItems(actor) {
return PileUtilities.getActorItems(actor);
},

getActorCurrencies(actor) {
return PileUtilities.getActorCurrencies(actor);
},

updateTokenHud() {
return ItemPileSocket.executeForEveryone(ItemPileSocket.HANDLERS.RERENDER_TOKEN_HUD);
},
Expand Down
4 changes: 3 additions & 1 deletion src/applications/components/CustomDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
{#if icon}
<p class="header-icon"><i class="{icon}"></i></p>
{/if}
<p class="header"><strong>{header}</strong></p>
{#if header}
<p class="header"><strong>{header}</strong></p>
{/if}
{#if Array.isArray(content)}
{#each content as part}
<p>{@html part}</p>
Expand Down
2 changes: 1 addition & 1 deletion src/applications/components/PriceSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$: cantAfford = $prices.length > 0 && !$prices[$selectedPriceGroup]?.maxQuantity && item.store.recipient && !standalone;
$: cantAffordMultiplePrices = cantAfford && !$prices.filter(group => group.maxQuantity).length;
$: label.text = (standalone && $prices.length > 1 ? "<i class=\"fas fa-edit\"></i> " : "") + ($prices[$selectedPriceGroup]?.basePriceString ?? "Free");
$: label.text = (standalone && $prices.length > 1 ? "<i class=\"fas fa-edit\"></i> " : "") + ($prices[$selectedPriceGroup]?.free ? "Free" : $prices[$selectedPriceGroup]?.basePriceString);
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script>
import { localize } from '@typhonjs-fvtt/runtime/svelte/helper';
import { getContext } from "svelte";
import { ApplicationShell } from "@typhonjs-fvtt/runtime/svelte/component/core";
const { application } = getContext('external');
export let text;
export let elementRoot;
let form;
function requestSubmit() {
form.requestSubmit();
}
function submit() {
application.options.resolve(text);
application.close();
}
</script>

<svelte:options accessors={true}/>

<ApplicationShell bind:elementRoot>
<form class="item-piles-flexcol" bind:this={form} on:submit|once|preventDefault={submit} style="padding:0.5rem;"
autocomplete="off">

<textarea style="flex:1; resize: none;" bind:value={text}></textarea>

<footer class="sheet-footer item-piles-flexrow" style="margin-top: 1rem; flex: 0;">
<button type="button" on:click|once={requestSubmit}>
<i class="fas fa-check"></i>
{localize("Okay")}
</button>
<button type="button" on:click={() => { application.close() }}>
<i class="fas fa-times"></i>
{localize("Cancel")}
</button>
</footer>

</form>

</ApplicationShell>
56 changes: 56 additions & 0 deletions src/applications/dialogs/text-editor-dialog/text-editor-dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import CONSTANTS from "../../../constants/constants.js";

export default class TextEditorDialog extends FormApplication {

constructor(text, options) {
super();
this.text = text;
this.resolve = options.resolve;
}

static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
title: game.i18n.localize("ITEM-PILES.Applications.DropItem.Title"),
template: `${CONSTANTS.PATH}templates/text-editor.html`,
width: 430,
height: 350,
classes: ["item-piles-app"],
resizable: true
})
}

async getData(options) {
const data = super.getData(options);
data.text = this.text;
return data;
}

static getActiveApps(id) {
return Object.values(ui.windows).filter(app => app.id === `item-pile-text-editor-${id}`);
}

async _updateObject(event, formData) {
this.resolve(formData.text);
return this.close();
}

async close(options) {
this.resolve(null);
return super.close(options);
}

static async show(text, options = {}) {
const apps = options.id ? this.getActiveApps(options.id) : [];
if (apps.length) {
for (let app of apps) {
app.render(false, { focus: true });
}
return;
}
return new Promise((resolve) => {
options.resolve = resolve;
new this(text, options).render(true, { focus: true });
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
$: maxMerchantItemQuantity = $sellerPileData.infiniteQuantity ? Infinity : $itemMaxQuantityStore;
$: maxItemQuantity = $prices[$selectedPriceGroup].maxQuantity;
$: maxItemQuantity = $prices[$selectedPriceGroup]?.maxQuantity ?? Infinity;
$: maxItemPurchaseQuantity = Math.min(maxItemQuantity, maxMerchantItemQuantity);
function submit() {
Expand Down Expand Up @@ -81,7 +81,7 @@
</div>
<div
style="display:flex; justify-content:flex-end; align-items: center; text-align: right;">
style="display:flex; justify-content:flex-end; align-items: center; text-align: right;">
{#if maxItemQuantity}
<div style="display: flex; flex-direction: column; align-items: flex-end; margin-right: 0.5rem;">
<small>{localize("ITEM-PILES.Applications.TradeMerchantItem.Quantity")}</small>
Expand Down
40 changes: 31 additions & 9 deletions src/applications/item-pile-config/item-pile-config.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import { localize } from '@typhonjs-fvtt/runtime/svelte/helper';
import FilePicker from "../components/FilePicker.svelte";
import { TJSDialog } from '@typhonjs-fvtt/runtime/svelte/application';
import CONSTANTS from "../../constants/constants.js";
import * as SharingUtilities from "../../helpers/sharing-utilities.js";
import * as Helpers from "../../helpers/helpers.js";
import TextEditorDialogShell from "../dialogs/text-editor-dialog/text-editor-dialog-shell.svelte";
import PriceModifiersEditor from "../editors/price-modifiers-editor/price-modifiers-editor.js";
import CurrenciesEditor from "../editors/currencies-editor/currencies-editor.js";
import ItemFiltersEditor from "../editors/item-filters-editor/item-filters-editor.js";
Expand All @@ -19,6 +22,8 @@
from "../editors/item-type-price-modifiers-editor/item-type-price-modifiers-editor.js";
import * as PileUtilities from "../../helpers/pile-utilities.js";
import { ApplicationShell } from "@typhonjs-fvtt/runtime/svelte/component/core";
import { writable } from "svelte/store";
import TextEditorDialog from "../dialogs/text-editor-dialog/text-editor-dialog.js";
const { application } = getContext('external');
Expand All @@ -30,6 +35,10 @@
let pileData = PileUtilities.getActorFlagData(pileActor);
let deleteWhenEmptySetting = localize(Helpers.getSetting(SETTINGS.DELETE_EMPTY_PILES) ? "Yes" : "No");
let pileEnabled = writable(pileData.enabled);
$: pileData.enabled = $pileEnabled;
let hasOverrideCurrencies = typeof pileData?.overrideCurrencies === "object";
let hasOverrideItemFilters = typeof pileData?.overrideItemFilters === "object";
Expand Down Expand Up @@ -127,15 +136,28 @@
}).render(true);
}
async function showDescriptionDialog() {
return TextEditorDialog.show(pileData.description, { id: "item-pile-text-editor-" + pileActor.id }).then((result) => {
pileData.description = result || "";
});
}
function requestSubmit() {
form.requestSubmit();
}
let tabs = [
{ value: "mainsettings", label: "ITEM-PILES.Applications.ItemPileConfig.Main.Title", highlight: !pileData.enabled },
{ value: "merchant", label: "ITEM-PILES.Applications.ItemPileConfig.Merchant.Title" },
{ value: "othersettings", label: "ITEM-PILES.Applications.ItemPileConfig.Other.Title" },
];
let tabs = [];
$: {
tabs = [
{
value: "mainsettings",
label: "ITEM-PILES.Applications.ItemPileConfig.Main.Title",
highlight: !$pileEnabled
},
{ value: "merchant", label: "ITEM-PILES.Applications.ItemPileConfig.Merchant.Title" },
{ value: "othersettings", label: "ITEM-PILES.Applications.ItemPileConfig.Other.Title" }
]
}
let activeTab = "mainsettings";
Expand Down Expand Up @@ -163,10 +185,10 @@
</label>
<span class="item-piles-flexrow" style="max-width: 100px; justify-content: flex-end; align-items:center;">
{#if !pileData.enabled}
{#if !$pileEnabled}
<div style="flex:0 1 auto; margin-right: 1rem;" class="blob"><i class="fas fa-exclamation"></i></div>
{/if}
<span style="flex:0 1 auto;"><input type="checkbox" bind:checked={pileData.enabled}/></span>
<span style="flex:0 1 auto;"><input type="checkbox" bind:checked={$pileEnabled}/></span>
</span>
</div>
Expand All @@ -193,7 +215,7 @@
</label>
<select style="flex:4;" bind:value={pileData.deleteWhenEmpty}>
<option
value="default">{localize("ITEM-PILES.Applications.ItemPileConfig.Main.DeleteWhenEmptyDefault")}
value="default">{localize("ITEM-PILES.Applications.ItemPileConfig.Main.DeleteWhenEmptyDefault")}
({localize(deleteWhenEmptySetting)})
</option>
<option value="true">{localize("ITEM-PILES.Applications.ItemPileConfig.Main.DeleteWhenEmptyYes")}</option>
Expand All @@ -208,7 +230,7 @@
</label>
</div>
<div class="form-group">
<button type="button" style="flex:4;">
<button type="button" style="flex:4;" on:click={() => { showDescriptionDialog() }}>
{localize("ITEM-PILES.Applications.ItemPileConfig.Main.EditDescription")}
</button>
</div>
Expand Down
28 changes: 17 additions & 11 deletions src/applications/merchant-app/MerchantLeftPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
const pileDataStore = store.pileData;
const editPrices = store.editPrices;
const tabs = [
{
value: 'description',
label: 'ITEM-PILES.Merchant.Description',
hidden: !game.user.isGM && !pileDataStore.description
},
{ value: 'settings', label: 'ITEM-PILES.Merchant.Settings', hidden: !game.user.isGM },
];
let tabs = [];
let description = "";
let activeSidebarTab = false;
$: {
description = $pileDataStore.description;
tabs = [
{
value: 'description',
label: 'ITEM-PILES.Merchant.Description',
hidden: !game.user.isGM && description
},
{ value: 'settings', label: 'ITEM-PILES.Merchant.Settings', hidden: !game.user.isGM },
];
activeSidebarTab = activeSidebarTab || tabs.find(tab => !tab.hidden)?.value;
}
let activeSidebarTab = tabs.find(tab => !tab.hidden)?.value;
</script>
Expand All @@ -39,8 +45,8 @@
{#if activeSidebarTab === 'description'}
<div class="tab merchant-description">
{@html pileDataStore.description || ""}
{#if !pileDataStore.description}
{@html description || ""}
{#if !description}
<button type="button"
style="flex:1;">{localize("ITEM-PILES.Applications.ItemPileConfig.Main.EditDescription")}</button>
{/if}
Expand Down
Loading

0 comments on commit b0585c8

Please sign in to comment.