Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Dec 10, 2023
1 parent f6d9912 commit e759bb3
Show file tree
Hide file tree
Showing 17 changed files with 1,109 additions and 493 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"id": "item-piles",
"type": "module",
"compatibility": {
"minimum": "2.8.1",
"verified": "2.8.1"
"minimum": "2.8.6",
"verified": "2.8.6"
}
},
{
Expand Down
1 change: 0 additions & 1 deletion src/applications/auctioneer/Auctions/Auctions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import SortByTabs from "~/applications/auctioneer/Components/SortByTabs.svelte";
import OwnAuctionItem from "~/applications/auctioneer/Auctions/OwnAuctionItem.svelte";
import CreateAuctionSidebar from "~/applications/auctioneer/Auctions/CreateAuctionSidebar.svelte";
import { writable } from "svelte/store";
const store = getContext("store");
Expand Down
194 changes: 104 additions & 90 deletions src/applications/auctioneer/Auctions/CreateAuctionSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import { getContext } from "svelte";
import { get, writable } from "svelte/store";
import { TJSDocument } from "#runtime/svelte/store/fvtt/document";
import DropZone from "~/applications/auctioneer/Components/DropZone.svelte";
import CurrencyList from "~/applications/auctioneer/Auctions/CurrencyList.svelte";
import CONSTANTS from "~/constants.js";
import { getCurrencies } from "~/lib.js";
import { getCurrencies, getPriceFromData } from "~/lib.js";
import CurrencyStore from "~/applications/auctioneer/Auctions/currency-store.js";
import ReactiveButton from "~/applications/auctioneer/Components/ReactiveButton.svelte";
Expand All @@ -15,7 +14,9 @@
const flagStore = store.auctioneerFlags;
const flags = get(flagStore);
const itemDocStore = new TJSDocument();
const itemDocStore = store.auctionItemStore;
const actorDoc = store.actorDoc;
const newAuctionStore = store.newAuctionStore;
let showPrice = "bids";
const useSecondaryCurrencies = writable(false);
Expand All @@ -39,72 +40,42 @@
});
}
const potentialAuctionStore = writable({
itemData: false,
numAuctions: 1,
quantityPerAuction: 1,
hiddenQuantity: false,
priceIsPerQuantity: false
});
let baseDepositPrice;
let depositCurrenciesString;
let depositCurrencies;
$: {
baseDepositPrice = $newAuctionStore.depositPrice && $newAuctionStore.quantityPerAuction
? game.itempiles.API.calculateCurrencies(getPriceFromData($newAuctionStore.depositPrice)?.basePriceString, $newAuctionStore.quantityPerAuction, false) ?? false
: false;
depositCurrenciesString = baseDepositPrice
? game.itempiles.API.calculateCurrencies(baseDepositPrice, $newAuctionStore.numAuctions, false) ?? false
: false;
depositCurrencies = depositCurrenciesString
? getPriceFromData(depositCurrenciesString, $actorDoc)
: false;
}
const durationStore = writable(get(flagStore).minTimeLimit);
async function dropItem(dropData) {
const item = await Item.implementation.fromDropData(dropData);
if (!item.parent?.isOwner && !game.user.isGM) return;
if (currencies.some(currency => {
return currency.data.item
&& currency.data.item.name === item.name
&& currency.data.item.type === item.type
&& currency.data.item.img === item.img
})) {
return;
}
if (game.itempiles.API.isItemInvalid(item)) {
return;
}
const canItemStack = game.itempiles.API.canItemStack(item);
const itemQuantity = game.itempiles.API.getItemQuantity(item);
potentialAuctionStore.update(data => {
data.numAuctions = 1;
data.quantityPerAuction = itemQuantity;
data.hiddenQuantity = !canItemStack;
data.itemData = item.toObject();
data.itemCost = game.itempiles.API.getCostOfItem(item);
data.uuid = dropData.uuid;
return data;
});
itemDocStore.set(item);
}
function setMaxAuctions() {
const itemQuantity = game.itempiles.API.getItemQuantity($itemDocStore);
potentialAuctionStore.update(data => {
data.numAuctions = itemQuantity;
newAuctionStore.update(data => {
data.numAuctions = game.itempiles.API.getItemQuantity($itemDocStore);
data.quantityPerAuction = 1;
return data;
});
}
function setMaxPerAuction() {
const itemQuantity = game.itempiles.API.getItemQuantity($itemDocStore);
potentialAuctionStore.update(data => {
newAuctionStore.update(data => {
data.quantityPerAuction = Math.max(1, Math.floor(itemQuantity / data.numAuctions));
return data;
});
}
function numAuctionsChanged() {
const itemQuantity = game.itempiles.API.getItemQuantity($itemDocStore);
potentialAuctionStore.update(data => {
newAuctionStore.update(data => {
data.numAuctions = Math.min(data.numAuctions, itemQuantity);
data.quantityPerAuction = Math.min(data.quantityPerAuction, Math.floor(itemQuantity / data.numAuctions));
return data;
Expand All @@ -113,19 +84,22 @@
function numQuantityPerAuctionChanged() {
const itemQuantity = game.itempiles.API.getItemQuantity($itemDocStore);
potentialAuctionStore.update(data => {
newAuctionStore.update(data => {
data.quantityPerAuction = Math.min(data.quantityPerAuction, itemQuantity);
data.numAuctions = Math.min(data.numAuctions, Math.floor(itemQuantity / data.quantityPerAuction));
return data;
});
}
async function postAuctions() {
const result = await store.postAuctions({
numAuctions: $potentialAuctionStore.numAuctions,
quantityPerAuction: $potentialAuctionStore.quantityPerAuction,
itemData: $potentialAuctionStore.itemData,
uuid: $potentialAuctionStore.uuid,
async function createAuctions(withoutDeposit = false) {
const result = await store.createAuctions({
numAuctions: $newAuctionStore.numAuctions,
quantityPerAuction: $newAuctionStore.quantityPerAuction,
itemData: $newAuctionStore.itemData,
uuid: $newAuctionStore.uuid,
priceIsPerQuantity: $newAuctionStore.priceIsPerQuantity,
baseDepositPrice: withoutDeposit ? false : baseDepositPrice,
depositPrice: withoutDeposit ? false : depositCurrenciesString,
bidVisibility: $bidVisibility,
reserveLimitVisibility: $reserveLimitVisibility,
bidCurrencies: bidCurrencies.exportCurrencies(),
Expand All @@ -134,13 +108,16 @@
reserveCurrencies: reserveCurrencies.exportCurrencies(),
duration: $durationStore
});
if(!result) return;
potentialAuctionStore.set({
if (!result) return;
itemDocStore.set(undefined);
newAuctionStore.set({
itemData: false,
numAuctions: 1,
quantityPerAuction: 1,
hiddenQuantity: false,
priceIsPerQuantity: false
priceIsPerQuantity: false,
uuid: false,
depositPrice: false,
});
bidCurrencies.reset();
buyoutCurrencies.reset();
Expand All @@ -156,33 +133,57 @@
<div class="create-auctions">
<span class="auction-title" style="font-size: 1rem;">Auction Item</span>
<DropZone callback={dropItem} class="item-container">
<DropZone callback={store.onDropData} class="item-container">
<img class="item-image" src={$itemDocStore ? $itemDocStore.img : "icons/svg/coins.svg"}/>
{$itemDocStore ? $itemDocStore.name : "Drag & drop item"}
</DropZone>
<div class="stack-container auction-border-top">
<div class="auction-title">Num. Auctions</div>
<input bind:value={$potentialAuctionStore.numAuctions} disabled={!$itemDocStore} on:change={numAuctionsChanged}
type="number"/>
<button disabled={!$itemDocStore} on:click={setMaxAuctions} type="button">Max</button>
{#if !$potentialAuctionStore.hiddenQuantity}
{#if !$newAuctionStore.hiddenQuantity}
<div class="stack-container auction-border-top">
<div class="auction-title">Num. Auctions</div>
<input bind:value={$newAuctionStore.numAuctions} disabled={!$itemDocStore || $newAuctionStore.hiddenQuantity}
on:change={numAuctionsChanged}
type="number"/>
<button disabled={!$itemDocStore || $newAuctionStore.hiddenQuantity} on:click={setMaxAuctions} type="button">
Max
</button>
<span class="auction-title">Qty/Auctions</span>
<input type="number" bind:value={$potentialAuctionStore.quantityPerAuction} disabled={!$itemDocStore}
<input type="number" bind:value={$newAuctionStore.quantityPerAuction}
disabled={!$itemDocStore || $newAuctionStore.hiddenQuantity}
on:change={numQuantityPerAuctionChanged}/>
<button type="button" on:click={setMaxPerAuction} disabled={!$itemDocStore}>Max</button>
{/if}
</div>
<div class="auction-title" data-tooltip-direction="UP" data-tooltip="When enabled, this makes the price of the auction be multiplied by the quantity of the item in that auction">
<span>Price is per quantity:</span>
<input bind:checked={$potentialAuctionStore.priceIsPerQuantity} type="checkbox"/>
</div>
<button type="button" on:click={setMaxPerAuction} disabled={!$itemDocStore || $newAuctionStore.hiddenQuantity}>
Max
</button>
</div>
<div class="auction-title"
data-tooltip="When enabled, this makes the price of the auction be multiplied by the quantity of the item in that auction"
data-tooltip-direction="UP">
<span>Price is per quantity:</span>
<input bind:checked={$newAuctionStore.priceIsPerQuantity} type="checkbox"
disabled={!$itemDocStore || $newAuctionStore.hiddenQuantity}/>
</div>
{:else}
<div class="auction-border-top">
<div class="auction-title small-warning">Item cannot be stacked, only 1 auction can be created at a time.</div>
</div>
{/if}
{#if $flagStore.allowSecondaryCurrencies && hasSecondaryCurrencies}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="When enabled, this switches the currencies for this auction to use the alternative currencies">
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="When enabled, this switches the currencies for this auction to use the alternative currencies">
<input bind:checked={$useSecondaryCurrencies} type="checkbox"/> Use Other Currencies
</div>
{/if}
{#if $flagStore.auctionDeposit}
<div class="auction-title auction-border-top auction-deposit" data-tooltip-direction="UP"
data-tooltip="The amount you must pay in order to create this auction. If the auction succeeds, you get this back.">
<span>Auction deposit:</span>
<span class:cant-afford={depositCurrencies && !depositCurrencies.canBuy}>{depositCurrenciesString || "None"}</span>
</div>
{/if}
{#if $flagStore.auctionBidVisibility === CONSTANTS.VISIBILITY_KEYS.USER}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="This setting makes bids either visible or blind - the latter meaning people can only see their own bids">Bids Visibility</div>
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="This setting makes bids either visible or blind - the latter meaning people can only see their own bids">
Bids Visibility
</div>
{/if}
{#if $flagStore.auctionBidVisibility === CONSTANTS.VISIBILITY_KEYS.USER}
<div class="auction-title auction-visibility">
Expand All @@ -198,22 +199,25 @@
</div>
</div>
{:else if $flagStore.auctionBidVisibility === CONSTANTS.VISIBILITY_KEYS.VISIBLE}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="Bids for this auction will always be visible">
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="Bids for this auction will always be visible">
<span>Visible Bids</span>
</div>
{:else if $flagStore.auctionBidVisibility === CONSTANTS.VISIBILITY_KEYS.HIDDEN}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="Bids for this auction will always be blind - people can only see their own bids">
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="Bids for this auction will always be blind - people can only see their own bids">
<span>Hidden Bids</span>
</div>
{/if}
<div class="price-currencies-container-pair auction-border-top">
<CurrencyList bind:showPrice clickable={$flagStore.enableMinimumBid || $flagStore.enableReserveLimit}
currencyStore={bidCurrencies} label="Starting Bid" tooltip="Starting price for bids"
name="bids" {useSecondaryCurrencies}/>
currencyStore={bidCurrencies} label="Starting Bid" name="bids"
tooltip="Starting price for bids" {useSecondaryCurrencies}/>
<CurrencyList bind:showPrice caret={$flagStore.enableMinimumBid || $flagStore.enableReserveLimit}
clickable={$flagStore.enableMinimumBid || $flagStore.enableReserveLimit}
currencyStore={buyoutCurrencies} label="Buyout Price" tooltip="Price to pay to instantly win this auction"
name="bids" {useSecondaryCurrencies}/>
currencyStore={buyoutCurrencies} label="Buyout Price"
name="bids"
tooltip="Price to pay to instantly win this auction" {useSecondaryCurrencies}/>
</div>
{#if $flagStore.enableMinimumBid || $flagStore.enableReserveLimit}
<div class="price-currencies-container-pair auction-border-top">
Expand All @@ -231,7 +235,9 @@
{/if}
{#if $flagStore.enableReserveLimit}
{#if $flagStore.reserveLimitVisibility === CONSTANTS.VISIBILITY_KEYS.USER}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="This setting controls whether the reserve amount is visible or not">Reserve Visibility</div>
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="This setting controls whether the reserve amount is visible or not">Reserve Visibility
</div>
{/if}
{#if $flagStore.reserveLimitVisibility === CONSTANTS.VISIBILITY_KEYS.USER}
<div class="auction-title auction-visibility">
Expand All @@ -247,16 +253,19 @@
</div>
</div>
{:else if $flagStore.reserveLimitVisibility === CONSTANTS.VISIBILITY_KEYS.VISIBLE}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="Reserve amount is always visible">
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="Reserve amount is always visible">
<span>Visible Reserve</span>
</div>
{:else if $flagStore.reserveLimitVisibility === CONSTANTS.VISIBILITY_KEYS.HIDDEN}
<div class="auction-title auction-border-top" data-tooltip-direction="UP" data-tooltip="Reserve amount is always hidden">
<div class="auction-title auction-border-top" data-tooltip-direction="UP"
data-tooltip="Reserve amount is always hidden">
<span>Hidden Reserve</span>
</div>
{/if}
{/if}
<div class="auction-title auction-border-top auction-duration">
<div class="auction-title auction-border-top auction-duration" data-tooltip-direction="UP"
data-tooltip="How long this auction will remain active">
<span>Duration:</span>
<select bind:value={$durationStore}>
{#each validTimeLimits as [key, value]}
Expand All @@ -267,10 +276,15 @@
</div>
<div class="auction-post-button">
<ReactiveButton callback={postAuctions} disabled={!$potentialAuctionStore.itemData}>
<div class="auction-post-buttons">
<ReactiveButton callback={() => createAuctions()} disabled={!$newAuctionStore.itemData || (depositCurrencies && !depositCurrencies?.canBuy)}>
Post Auctions
</ReactiveButton>
{#if game.user.isGM}
<ReactiveButton callback={() => createAuctions(true)} disabled={!$newAuctionStore.itemData}>
Post Auctions Without Deposit
</ReactiveButton>
{/if}
</div>
</div>
3 changes: 1 addition & 2 deletions src/applications/auctioneer/Auctions/OwnAuctionItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { getContext } from "svelte";
import ItemName from "~/applications/auctioneer/Components/ItemName.svelte";
import AuctionEntryButtons from "~/applications/auctioneer/Components/AuctionEntryButtons.svelte";
import * as lib from "~/lib.js"
export let auction;
Expand All @@ -29,7 +28,7 @@
{auction.timeLeft.label}
</div>
<div class="auction-entry-text">
{auction.highBidder?.name ?? "No bids"}
{auction.highBidder || "No bids"}
</div>
<div class="auction-entry-text">
{CONSTANTS.BID_VISIBILITY_UI_LABELS[auction.bidVisibility]}
Expand Down
1 change: 0 additions & 1 deletion src/applications/auctioneer/Bids/BidItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import CONSTANTS from "~/constants.js";
import ItemName from "~/applications/auctioneer/Components/ItemName.svelte";
import AuctionEntryButtons from "~/applications/auctioneer/Components/AuctionEntryButtons.svelte";
import * as lib from "~/lib.js"
export let bid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
disabled={!auction.expired && !auction.won}>
Collect
</ReactiveButton>
<ReactiveButton callback={() => store.claimAuctions([auction], true)} completelyDisable
<ReactiveButton callback={() => store.claimAuctions([auction], true)}
disabled={auction.expired || auction.won}>
Cancel
</ReactiveButton>
Expand Down
Loading

0 comments on commit e759bb3

Please sign in to comment.