Polish CE sell/buy UI and strip-union table corner sprites.
Sell uses the bag grid with a clickable market-price hint; buy search no longer opens chat; table L/T bends keep concave corners for line tables.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -237,7 +237,7 @@
<div id="market-orders"></div>
</section>
<section id="market-pane-sell" class="market-pane" data-pane="sell" hidden>
<div id="market-sell-list" class="market-sell-list"></div>
<div id="market-sell-list" class="item-grid"></div>
<p id="market-sell-selected" class="hint">Select an item from your bag</p>
<label class="send-row">Quantity
<input id="market-sell-qty" type="number" min="1" step="1" value="1">
@@ -246,7 +246,10 @@
<input id="market-sell-min" type="number" min="1" step="1" value="1">
</label>
<p id="market-sell-fee" class="hint"></p>
<button id="market-sell-confirm" type="button">Place sell order</button>
<div class="market-sell-actions">
<button id="market-sell-confirm" type="button">Place sell order</button>
<button id="market-sell-suggest" type="button" class="market-price-suggest" hidden></button>
</div>
</section>
<section id="market-pane-buy" class="market-pane" data-pane="buy" hidden>
<label class="send-row">Search items
@@ -237,7 +237,7 @@ <div id="market-orders"></div> <div id="market-orders"></div> </section> </section> <section id="market-pane-sell" class="market-pane" data-pane="sell" hidden> <section id="market-pane-sell" class="market-pane" data-pane="sell" hidden> <div id="market-sell-list" class="market-sell-list"></div> <div id="market-sell-list" class="item-grid"></div> <p id="market-sell-selected" class="hint">Select an item from your bag</p> <p id="market-sell-selected" class="hint">Select an item from your bag</p> <label class="send-row">Quantity <label class="send-row">Quantity <input id="market-sell-qty" type="number" min="1" step="1" value="1"> <input id="market-sell-qty" type="number" min="1" step="1" value="1">@@ -246,7 +246,10 @@ <input id="market-sell-min" type="number" min="1" step="1" value="1"> <input id="market-sell-min" type="number" min="1" step="1" value="1"> </label> </label> <p id="market-sell-fee" class="hint"></p> <p id="market-sell-fee" class="hint"></p> <button id="market-sell-confirm" type="button">Place sell order</button> <div class="market-sell-actions"> <button id="market-sell-confirm" type="button">Place sell order</button> <button id="market-sell-suggest" type="button" class="market-price-suggest" hidden></button> </div> </section> </section> <section id="market-pane-buy" class="market-pane" data-pane="buy" hidden> <section id="market-pane-buy" class="market-pane" data-pane="buy" hidden> <label class="send-row">Search items <label class="send-row">Search items@@ -1,8 +1,12 @@
/**
* Generate 16×16 magenta table PNGs for neighbor-connect masks 0–15.
* Reads the artist `wood.png`, remaps browns → magenta (tintable), then
* extends the tabletop along connected cardinals (no diagonals).
* Legs stay on free south edges; extra legs appear on long spans.
*
* Geometry is a **strip union** (horizontal bar ∪ vertical bar), so L/T/+ bends
* keep a concave inner corner instead of filling the AABB. Straight runs stay
* one tile wide. Future filled rectangles (2×3, etc.) can add alternate corner
* sprites keyed by diagonal neighbors without changing these line pieces.
*
* Legs stay on free south edges of the footprint.
*/
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
@@ -147,6 +151,18 @@ function setPx (rgba, x, y, color)
rgba[i + 3] = color[3];
}
function isAlreadyMagenta (rgba)
{
for (let i = 0; i < rgba.length; i += 4)
{
if (rgba[i + 3] < 8)
{ continue; }
if (Math.abs(rgba[i] - rgba[i + 2]) > 2 || rgba[i + 1] >= rgba[i])
{ return false; }
}
return true;
}
/** Remap any opaque pixel into the magenta tint family (R≈B, G<R). */
function toMagenta (r, g, b, a)
{
@@ -155,7 +171,6 @@ function toMagenta (r, g, b, a)
const L = Math.max(1, Math.max(r, g, b));
const minC = Math.min(r, g, b);
const chroma = (L - minC) / 255;
// Slight G softens grain; keep rims more saturated (low G).
const gMag = Math.min(L - 1, Math.round(L * (0.08 + (1 - chroma) * 0.22)));
return [L, Math.max(0, gMag), L, 255];
}
@@ -181,9 +196,29 @@ function sampleTop (base, x, y)
return getPx(base, sx, sy);
}
/**
* Line-table footprint: union of an E–W bar (core height) and an N–S bar (core width),
* each extended only along connected cardinals. Leaves concave cutouts for L/T bends.
*/
function isTabletopPixel (x, y, connectN, connectE, connectS, connectW)
{
const inCoreX = x >= BASE.x0 && x <= BASE.x1;
const inCoreY = y >= BASE.y0 && y <= BASE.y1;
const inHBar = inCoreY && (
inCoreX
|| (connectW && x < BASE.x0)
|| (connectE && x > BASE.x1)
);
const inVBar = inCoreX && (
inCoreY
|| (connectN && y < BASE.y0)
|| (connectS && y > BASE.y1)
);
return inHBar || inVBar;
}
function drawLeg (rgba, base, anchorX, topY)
{
// Artist legs: 3×2 under the top at (4,12) and (9,12).
const pattern = [
[getPx(base, 4, 12), getPx(base, 5, 12), getPx(base, 6, 12)],
[getPx(base, 4, 13), getPx(base, 5, 13), getPx(base, 6, 13)]
@@ -198,6 +233,20 @@ function drawLeg (rgba, base, anchorX, topY)
}
}
function rimFlags (x, y, connectN, connectE, connectS, connectW)
{
const n = isTabletopPixel(x, y - 1, connectN, connectE, connectS, connectW);
const e = isTabletopPixel(x + 1, y, connectN, connectE, connectS, connectW);
const s = isTabletopPixel(x, y + 1, connectN, connectE, connectS, connectW);
const w = isTabletopPixel(x - 1, y, connectN, connectE, connectS, connectW);
return {
onN: !n,
onE: !e,
onS: !s,
onW: !w
};
}
function paintTable (mask, base)
{
const rgba = new Uint8Array(SIZE * SIZE * 4);
@@ -212,64 +261,67 @@ function paintTable (mask, base)
return rgba;
}
const topX0 = connectW ? 0 : BASE.x0;
const topX1 = connectE ? SIZE - 1 : BASE.x1;
const topY0 = connectN ? 0 : BASE.y0;
const topY1 = connectS ? SIZE - 1 : BASE.y1;
for (let y = topY0; y <= topY1; y++)
for (let y = 0; y < SIZE; y++)
{
for (let x = topX0; x <= topX1; x++)
for (let x = 0; x < SIZE; x++)
{
const onN = y === topY0 && !connectN;
const onS = y === topY1 && !connectS;
const onW = x === topX0 && !connectW;
const onE = x === topX1 && !connectE;
if (!isTabletopPixel(x, y, connectN, connectE, connectS, connectW))
{ continue; }
const rim = rimFlags(x, y, connectN, connectE, connectS, connectW);
let color;
if (onN)
if (rim.onN)
{ color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y0); }
else if (onS)
else if (rim.onS)
{ color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y1); }
else if (onW)
else if (rim.onW)
{ color = sampleTop(base, BASE.x0, Math.min(BASE.y1, Math.max(BASE.y0, y))); }
else if (onE)
else if (rim.onE)
{ color = sampleTop(base, BASE.x1, Math.min(BASE.y1, Math.max(BASE.y0, y))); }
else
{
// Interior: wrap the artist's fill so long spans keep grain.
const ix = BASE.x0 + 1 + ((x - topX0) % (BASE.x1 - BASE.x0 - 1));
const iy = BASE.y0 + 1 + ((y - topY0) % (BASE.y1 - BASE.y0 - 1));
const ix = BASE.x0 + 1 + ((x - BASE.x0 + SIZE) % (BASE.x1 - BASE.x0 - 1));
const iy = BASE.y0 + 1 + ((y - BASE.y0 + SIZE) % (BASE.y1 - BASE.y0 - 1));
color = sampleTop(base, ix, iy);
}
setPx(rgba, x, y, color);
}
}
// Front legs only when this tile is a south terminus (perspective).
if (!connectS && topY1 + 2 < SIZE)
// Front legs on free south edge of the footprint (line tables only show these).
if (!connectS)
{
const span = topX1 - topX0 + 1;
const anchors = [];
if (span <= 10)
const footY = BASE.y1;
if (footY + 2 < SIZE)
{
anchors.push(topX0 + 1);
anchors.push(Math.max(topX0 + 1, topX1 - 3));
}
else
{
for (let x = topX0 + 1; x <= topX1 - 3; x += 5)
{ anchors.push(x); }
const last = topX1 - 3;
if (anchors[anchors.length - 1] !== last)
{ anchors.push(last); }
}
const seen = new Set();
for (const ax of anchors)
{
if (seen.has(ax))
{ continue; }
seen.add(ax);
drawLeg(rgba, base, ax, topY1);
const anchors = [];
for (let x = 0; x < SIZE; )
{
if (!isTabletopPixel(x, footY, connectN, connectE, connectS, connectW))
{
x++;
continue;
}
let x1 = x;
while (x1 + 1 < SIZE && isTabletopPixel(x1 + 1, footY, connectN, connectE, connectS, connectW))
{ x1++; }
const span = x1 - x + 1;
if (span >= 3)
{
anchors.push(x + 1);
if (span >= 8)
{ anchors.push(x1 - 2); }
}
x = x1 + 1;
}
const seen = new Set();
for (const ax of anchors)
{
const clamped = Math.max(0, Math.min(SIZE - 3, ax));
if (seen.has(clamped))
{ continue; }
seen.add(clamped);
drawLeg(rgba, base, clamped, footY);
}
}
}
@@ -277,13 +329,13 @@ function paintTable (mask, base)
}
const source = decodePngRgba(readFileSync(SOURCE));
const base = magentaize(source);
const base = isAlreadyMagenta(source) ? source : magentaize(source);
mkdirSync(OUT, { recursive: true });
// Replace artist wood.png with magenta base (same silhouette).
writeFileSync(SOURCE, encodePng(base));
if (!isAlreadyMagenta(source))
{ writeFileSync(SOURCE, encodePng(base)); }
for (let mask = 0; mask < 16; mask++)
{
writeFileSync(join(OUT, `${mask}.png`), encodePng(paintTable(mask, base)));
}
console.log(`Wrote magenta table sprites wood.png + 0–15 to ${OUT}`);
console.log(`Wrote strip-union table sprites 0–15 to ${OUT}`);
@@ -1,8 +1,12 @@/**/** * Generate 16×16 magenta table PNGs for neighbor-connect masks 0–15. * Generate 16×16 magenta table PNGs for neighbor-connect masks 0–15. * Reads the artist `wood.png`, remaps browns → magenta (tintable), then * * extends the tabletop along connected cardinals (no diagonals). * Geometry is a **strip union** (horizontal bar ∪ vertical bar), so L/T/+ bends * Legs stay on free south edges; extra legs appear on long spans. * keep a concave inner corner instead of filling the AABB. Straight runs stay * one tile wide. Future filled rectangles (2×3, etc.) can add alternate corner * sprites keyed by diagonal neighbors without changing these line pieces. * * Legs stay on free south edges of the footprint. */ */import { mkdirSync, readFileSync, writeFileSync } from "node:fs";import { mkdirSync, readFileSync, writeFileSync } from "node:fs";import { deflateSync, inflateSync } from "node:zlib";import { deflateSync, inflateSync } from "node:zlib";@@ -147,6 +151,18 @@ function setPx (rgba, x, y, color) rgba[i + 3] = color[3]; rgba[i + 3] = color[3];}}function isAlreadyMagenta (rgba){ for (let i = 0; i < rgba.length; i += 4) { if (rgba[i + 3] < 8) { continue; } if (Math.abs(rgba[i] - rgba[i + 2]) > 2 || rgba[i + 1] >= rgba[i]) { return false; } } return true;}/** Remap any opaque pixel into the magenta tint family (R≈B, G<R). *//** Remap any opaque pixel into the magenta tint family (R≈B, G<R). */function toMagenta (r, g, b, a)function toMagenta (r, g, b, a){{@@ -155,7 +171,6 @@ function toMagenta (r, g, b, a) const L = Math.max(1, Math.max(r, g, b)); const L = Math.max(1, Math.max(r, g, b)); const minC = Math.min(r, g, b); const minC = Math.min(r, g, b); const chroma = (L - minC) / 255; const chroma = (L - minC) / 255; // Slight G softens grain; keep rims more saturated (low G). const gMag = Math.min(L - 1, Math.round(L * (0.08 + (1 - chroma) * 0.22))); const gMag = Math.min(L - 1, Math.round(L * (0.08 + (1 - chroma) * 0.22))); return [L, Math.max(0, gMag), L, 255]; return [L, Math.max(0, gMag), L, 255];}}@@ -181,9 +196,29 @@ function sampleTop (base, x, y) return getPx(base, sx, sy); return getPx(base, sx, sy);}}/** * Line-table footprint: union of an E–W bar (core height) and an N–S bar (core width), * each extended only along connected cardinals. Leaves concave cutouts for L/T bends. */function isTabletopPixel (x, y, connectN, connectE, connectS, connectW){ const inCoreX = x >= BASE.x0 && x <= BASE.x1; const inCoreY = y >= BASE.y0 && y <= BASE.y1; const inHBar = inCoreY && ( inCoreX || (connectW && x < BASE.x0) || (connectE && x > BASE.x1) ); const inVBar = inCoreX && ( inCoreY || (connectN && y < BASE.y0) || (connectS && y > BASE.y1) ); return inHBar || inVBar;}function drawLeg (rgba, base, anchorX, topY)function drawLeg (rgba, base, anchorX, topY){{ // Artist legs: 3×2 under the top at (4,12) and (9,12). const pattern = [ const pattern = [ [getPx(base, 4, 12), getPx(base, 5, 12), getPx(base, 6, 12)], [getPx(base, 4, 12), getPx(base, 5, 12), getPx(base, 6, 12)], [getPx(base, 4, 13), getPx(base, 5, 13), getPx(base, 6, 13)] [getPx(base, 4, 13), getPx(base, 5, 13), getPx(base, 6, 13)]@@ -198,6 +233,20 @@ function drawLeg (rgba, base, anchorX, topY) } }}}function rimFlags (x, y, connectN, connectE, connectS, connectW){ const n = isTabletopPixel(x, y - 1, connectN, connectE, connectS, connectW); const e = isTabletopPixel(x + 1, y, connectN, connectE, connectS, connectW); const s = isTabletopPixel(x, y + 1, connectN, connectE, connectS, connectW); const w = isTabletopPixel(x - 1, y, connectN, connectE, connectS, connectW); return { onN: !n, onE: !e, onS: !s, onW: !w };}function paintTable (mask, base)function paintTable (mask, base){{ const rgba = new Uint8Array(SIZE * SIZE * 4); const rgba = new Uint8Array(SIZE * SIZE * 4);@@ -212,64 +261,67 @@ function paintTable (mask, base) return rgba; return rgba; } } const topX0 = connectW ? 0 : BASE.x0; for (let y = 0; y < SIZE; y++) const topX1 = connectE ? SIZE - 1 : BASE.x1; const topY0 = connectN ? 0 : BASE.y0; const topY1 = connectS ? SIZE - 1 : BASE.y1; for (let y = topY0; y <= topY1; y++) { { for (let x = topX0; x <= topX1; x++) for (let x = 0; x < SIZE; x++) { { const onN = y === topY0 && !connectN; if (!isTabletopPixel(x, y, connectN, connectE, connectS, connectW)) const onS = y === topY1 && !connectS; { continue; } const onW = x === topX0 && !connectW; const rim = rimFlags(x, y, connectN, connectE, connectS, connectW); const onE = x === topX1 && !connectE; let color; let color; if (onN) if (rim.onN) { color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y0); } { color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y0); } else if (onS) else if (rim.onS) { color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y1); } { color = sampleTop(base, Math.min(BASE.x1, Math.max(BASE.x0, x)), BASE.y1); } else if (onW) else if (rim.onW) { color = sampleTop(base, BASE.x0, Math.min(BASE.y1, Math.max(BASE.y0, y))); } { color = sampleTop(base, BASE.x0, Math.min(BASE.y1, Math.max(BASE.y0, y))); } else if (onE) else if (rim.onE) { color = sampleTop(base, BASE.x1, Math.min(BASE.y1, Math.max(BASE.y0, y))); } { color = sampleTop(base, BASE.x1, Math.min(BASE.y1, Math.max(BASE.y0, y))); } else else { { // Interior: wrap the artist's fill so long spans keep grain. const ix = BASE.x0 + 1 + ((x - BASE.x0 + SIZE) % (BASE.x1 - BASE.x0 - 1)); const ix = BASE.x0 + 1 + ((x - topX0) % (BASE.x1 - BASE.x0 - 1)); const iy = BASE.y0 + 1 + ((y - BASE.y0 + SIZE) % (BASE.y1 - BASE.y0 - 1)); const iy = BASE.y0 + 1 + ((y - topY0) % (BASE.y1 - BASE.y0 - 1)); color = sampleTop(base, ix, iy); color = sampleTop(base, ix, iy); } } setPx(rgba, x, y, color); setPx(rgba, x, y, color); } } } } // Front legs only when this tile is a south terminus (perspective). // Front legs on free south edge of the footprint (line tables only show these). if (!connectS && topY1 + 2 < SIZE) if (!connectS) { { const span = topX1 - topX0 + 1; const footY = BASE.y1; const anchors = []; if (footY + 2 < SIZE) if (span <= 10) { { anchors.push(topX0 + 1); const anchors = []; anchors.push(Math.max(topX0 + 1, topX1 - 3)); for (let x = 0; x < SIZE; ) } { else if (!isTabletopPixel(x, footY, connectN, connectE, connectS, connectW)) { { for (let x = topX0 + 1; x <= topX1 - 3; x += 5) x++; { anchors.push(x); } continue; const last = topX1 - 3; } if (anchors[anchors.length - 1] !== last) let x1 = x; { anchors.push(last); } while (x1 + 1 < SIZE && isTabletopPixel(x1 + 1, footY, connectN, connectE, connectS, connectW)) } { x1++; } const seen = new Set(); const span = x1 - x + 1; for (const ax of anchors) if (span >= 3) { { if (seen.has(ax)) anchors.push(x + 1); { continue; } if (span >= 8) seen.add(ax); { anchors.push(x1 - 2); } drawLeg(rgba, base, ax, topY1); } x = x1 + 1; } const seen = new Set(); for (const ax of anchors) { const clamped = Math.max(0, Math.min(SIZE - 3, ax)); if (seen.has(clamped)) { continue; } seen.add(clamped); drawLeg(rgba, base, clamped, footY); } } } } }@@ -277,13 +329,13 @@ function paintTable (mask, base)}}const source = decodePngRgba(readFileSync(SOURCE));const source = decodePngRgba(readFileSync(SOURCE));const base = magentaize(source);const base = isAlreadyMagenta(source) ? source : magentaize(source);mkdirSync(OUT, { recursive: true });mkdirSync(OUT, { recursive: true });// Replace artist wood.png with magenta base (same silhouette).if (!isAlreadyMagenta(source))writeFileSync(SOURCE, encodePng(base));{ writeFileSync(SOURCE, encodePng(base)); }for (let mask = 0; mask < 16; mask++)for (let mask = 0; mask < 16; mask++){{ writeFileSync(join(OUT, `${mask}.png`), encodePng(paintTable(mask, base))); writeFileSync(join(OUT, `${mask}.png`), encodePng(paintTable(mask, base)));}}console.log(`Wrote magenta table sprites wood.png + 0–15 to ${OUT}`);console.log(`Wrote strip-union table sprites 0–15 to ${OUT}`);@@ -74,6 +74,10 @@ export function initChat ({ socket, MessageType, getSettings })
{ return; }
if (document.activeElement === input)
{ return; }
const focus = document.activeElement;
const tag = focus?.tagName;
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || focus?.isContentEditable)
{ return; }
if (!playingHudReady())
{ return; }
event.preventDefault();
@@ -74,6 +74,10 @@ export function initChat ({ socket, MessageType, getSettings }) { return; } { return; } if (document.activeElement === input) if (document.activeElement === input) { return; } { return; } const focus = document.activeElement; const tag = focus?.tagName; if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || focus?.isContentEditable) { return; } if (!playingHudReady()) if (!playingHudReady()) { return; } { return; } event.preventDefault(); event.preventDefault();@@ -99,7 +99,7 @@ function uiBlocked ()
{
return !!(social?.isBlocking() || chat?.isBlocking() || inventory?.isBlocking()
|| crafting?.isBlocking() || alchemy?.isBlocking() || shop?.isBlocking()
|| contextMenu?.isOpen() || death?.isBlocking());
|| market?.isBlocking() || contextMenu?.isOpen() || death?.isBlocking());
}
function clearPendingPickup ()
@@ -99,7 +99,7 @@ function uiBlocked (){{ return !!(social?.isBlocking() || chat?.isBlocking() || inventory?.isBlocking() return !!(social?.isBlocking() || chat?.isBlocking() || inventory?.isBlocking() || crafting?.isBlocking() || alchemy?.isBlocking() || shop?.isBlocking() || crafting?.isBlocking() || alchemy?.isBlocking() || shop?.isBlocking() || contextMenu?.isOpen() || death?.isBlocking()); || market?.isBlocking() || contextMenu?.isOpen() || death?.isBlocking());}}function clearPendingPickup ()function clearPendingPickup ()@@ -4,6 +4,7 @@ import {
itemAssetPathForStack,
formatQuantity
} from "/shared/definitions/items.js";
import { INVENTORY_SLOTS } from "/shared/items/inventory.js";
import { marketOrderListingFee } from "/shared/market/exchange.js";
import { countMarketFunds, resolveMarketSellListing } from "/shared/market/funds.js";
import { applyItemIcon } from "../render/potionIcon.js";
@@ -31,6 +32,7 @@ export function initMarket ({
const sellQty = document.getElementById("market-sell-qty");
const sellMin = document.getElementById("market-sell-min");
const sellFee = document.getElementById("market-sell-fee");
const sellSuggest = document.getElementById("market-sell-suggest");
const coinsEl = document.getElementById("market-coins");
const hintEl = document.getElementById("market-hint");
const tabs = [...document.querySelectorAll(".market-tab")];
@@ -58,7 +60,13 @@ export function initMarket ({
for (const pane of panes)
{ pane.hidden = pane.dataset.pane !== tab; }
if (tab === "sell")
{ renderSellables(); }
{
renderSellables();
const slots = getInventorySlots?.() ?? [];
const slot = selectedSellSlot == null ? null : slots[selectedSellSlot];
const listing = slot ? resolveMarketSellListing(slot) : null;
updateSellSuggest(listing?.itemId ?? null);
}
if (tab === "buy")
{ updateBuyFee(); }
if (tab === "orders")
@@ -85,11 +93,13 @@ export function initMarket ({
buySearch?.addEventListener("keydown", (event) =>
{
event.stopPropagation();
if (event.key !== "Enter")
{ return; }
event.preventDefault();
runBuySearch(buySearch.value ?? "");
});
buySearch?.addEventListener("keyup", (event) => event.stopPropagation());
buyQty?.addEventListener("input", () => updateBuyFee());
buyMax?.addEventListener("input", () => updateBuyFee());
@@ -120,6 +130,15 @@ export function initMarket ({
});
});
sellSuggest?.addEventListener("click", () =>
{
const price = Number(sellSuggest.dataset.price);
if (!(price > 0) || !sellMin)
{ return; }
sellMin.value = String(price);
updateSellFee();
});
function close ()
{
if (!open)
@@ -179,6 +198,33 @@ export function initMarket ({
}
}
function hintPriceForItem (itemId)
{
const entry = catalog.find((row) => (row.itemId | 0) === (itemId | 0));
const price = entry?.hintPrice;
if (price == null || !(Number(price) > 0))
{ return null; }
return Math.max(1, Math.round(Number(price)));
}
function updateSellSuggest (itemId = null)
{
if (!sellSuggest)
{ return; }
const price = itemId == null ? null : hintPriceForItem(itemId);
if (price == null)
{
sellSuggest.hidden = true;
sellSuggest.dataset.price = "";
sellSuggest.textContent = "";
return;
}
sellSuggest.hidden = false;
sellSuggest.dataset.price = String(price);
sellSuggest.textContent = `Market ~${formatQuantity(price)}`;
sellSuggest.title = "Use shopkeeper market price (seed + last-sale lerp) as min price";
}
function renderOrders ()
{
ordersEl.replaceChildren();
@@ -249,59 +295,77 @@ export function initMarket ({
}
}
function selectSellSlot (slotIndex, slot, listing)
{
selectedSellSlot = slotIndex;
sellQtyLocked = !!listing.quantityLocked;
if (sellQty)
{
sellQty.value = String(listing.quantityLocked
? listing.quantity
: Math.min(listing.quantity, Math.max(1, slot.quantity | 0)));
sellQty.readOnly = sellQtyLocked;
sellQty.disabled = sellQtyLocked;
if (!sellQtyLocked)
{ sellQty.max = String(Math.max(1, slot.quantity | 0)); }
else
{ sellQty.removeAttribute("max"); }
}
if (sellSelected)
{
sellSelected.textContent = listing.isCheque
? `Selling cheque for ${listing.quantity}× ${listing.displayName} (quantity locked)`
: `Selling ${itemDisplayName(slot)}`;
}
updateSellSuggest(listing.itemId);
renderSellables();
updateSellFee();
}
function renderSellables ()
{
sellList.replaceChildren();
const slots = getInventorySlots?.() ?? [];
slots.forEach((slot, slotIndex) =>
const count = Math.max(INVENTORY_SLOTS, slots.length);
for (let slotIndex = 0; slotIndex < count; slotIndex++)
{
if (!slot || slot.itemId == null)
{ return; }
const listing = resolveMarketSellListing(slot);
if (!listing)
{ return; }
const def = itemDefinition(slot.itemId);
if (!def || def.marketplaceSellable === false)
{ return; }
const row = document.createElement("button");
row.type = "button";
row.className = "market-sell-row";
if (selectedSellSlot === slotIndex)
{ row.classList.add("selected"); }
const icon = document.createElement("img");
icon.alt = "";
applyItemIcon(icon, itemAssetPathForStack(slot));
const label = document.createElement("span");
if (listing.isCheque)
{
label.textContent = `Cheque: ${listing.displayName} ×${formatQuantity(listing.quantity)}`;
}
else
const slot = slots[slotIndex] ?? null;
const button = document.createElement("button");
button.type = "button";
const listing = slot ? resolveMarketSellListing(slot) : null;
const sellable = !!listing && itemDefinition(slot.itemId)?.marketplaceSellable !== false;
button.className = `item-slot${selectedSellSlot === slotIndex ? " selected" : ""}`;
if (slot && !sellable)
{ button.classList.add("disabled"); }
button.title = slot
? (sellable
? (listing.isCheque
? `Cheque: ${listing.displayName} ×${formatQuantity(listing.quantity)}`
: `${itemDisplayName(slot)} ×${formatQuantity(slot.quantity)}`)
: `${itemDisplayName(slot)} (cannot list)`)
: "";
if (slot)
{
label.textContent = `${itemDisplayName(slot)} ×${formatQuantity(slot.quantity)}`;
}
row.append(icon, label);
row.addEventListener("click", () =>
{
selectedSellSlot = slotIndex;
sellQtyLocked = !!listing.quantityLocked;
if (sellQty)
{
sellQty.value = String(listing.quantity);
sellQty.readOnly = sellQtyLocked;
sellQty.disabled = sellQtyLocked;
}
if (sellSelected)
const img = document.createElement("img");
img.alt = itemDisplayName(slot);
applyItemIcon(img, slot, itemAssetPathForStack(slot));
button.append(img);
if ((slot.quantity | 0) > 1)
{
sellSelected.textContent = listing.isCheque
? `Selling cheque for ${listing.quantity}× ${listing.displayName} (quantity locked)`
: `Selling ${itemDisplayName(slot)}`;
const qty = document.createElement("span");
qty.className = "qty";
qty.textContent = formatQuantity(slot.quantity);
button.append(qty);
}
renderSellables();
updateSellFee();
}
button.addEventListener("click", () =>
{
if (!sellable)
{ return; }
selectSellSlot(slotIndex, slot, listing);
});
sellList.append(row);
});
sellList.append(button);
}
}
function refreshChrome ()
@@ -331,14 +395,18 @@ export function initMarket ({
selectedSellSlot = null;
selectedBuyItemId = null;
sellQtyLocked = false;
updateSellSuggest(null);
if (sellQty)
{
sellQty.readOnly = false;
sellQty.disabled = false;
sellQty.value = "1";
sellQty.removeAttribute("max");
}
if (buySearch)
{ buySearch.value = ""; }
if (sellSelected)
{ sellSelected.textContent = "Select an item from your bag"; }
if (title)
{ title.textContent = payload.displayName || "Central Exchange"; }
if (hintEl)
@@ -376,6 +444,10 @@ export function initMarket ({
{
return open;
},
isBlocking ()
{
return open;
},
close
};
}
@@ -4,6 +4,7 @@ import { itemAssetPathForStack, itemAssetPathForStack, formatQuantity formatQuantity} from "/shared/definitions/items.js";} from "/shared/definitions/items.js";import { INVENTORY_SLOTS } from "/shared/items/inventory.js";import { marketOrderListingFee } from "/shared/market/exchange.js";import { marketOrderListingFee } from "/shared/market/exchange.js";import { countMarketFunds, resolveMarketSellListing } from "/shared/market/funds.js";import { countMarketFunds, resolveMarketSellListing } from "/shared/market/funds.js";import { applyItemIcon } from "../render/potionIcon.js";import { applyItemIcon } from "../render/potionIcon.js";@@ -31,6 +32,7 @@ export function initMarket ({ const sellQty = document.getElementById("market-sell-qty"); const sellQty = document.getElementById("market-sell-qty"); const sellMin = document.getElementById("market-sell-min"); const sellMin = document.getElementById("market-sell-min"); const sellFee = document.getElementById("market-sell-fee"); const sellFee = document.getElementById("market-sell-fee"); const sellSuggest = document.getElementById("market-sell-suggest"); const coinsEl = document.getElementById("market-coins"); const coinsEl = document.getElementById("market-coins"); const hintEl = document.getElementById("market-hint"); const hintEl = document.getElementById("market-hint"); const tabs = [...document.querySelectorAll(".market-tab")]; const tabs = [...document.querySelectorAll(".market-tab")];@@ -58,7 +60,13 @@ export function initMarket ({ for (const pane of panes) for (const pane of panes) { pane.hidden = pane.dataset.pane !== tab; } { pane.hidden = pane.dataset.pane !== tab; } if (tab === "sell") if (tab === "sell") { renderSellables(); } { renderSellables(); const slots = getInventorySlots?.() ?? []; const slot = selectedSellSlot == null ? null : slots[selectedSellSlot]; const listing = slot ? resolveMarketSellListing(slot) : null; updateSellSuggest(listing?.itemId ?? null); } if (tab === "buy") if (tab === "buy") { updateBuyFee(); } { updateBuyFee(); } if (tab === "orders") if (tab === "orders")@@ -85,11 +93,13 @@ export function initMarket ({ buySearch?.addEventListener("keydown", (event) => buySearch?.addEventListener("keydown", (event) => { { event.stopPropagation(); if (event.key !== "Enter") if (event.key !== "Enter") { return; } { return; } event.preventDefault(); event.preventDefault(); runBuySearch(buySearch.value ?? ""); runBuySearch(buySearch.value ?? ""); }); }); buySearch?.addEventListener("keyup", (event) => event.stopPropagation()); buyQty?.addEventListener("input", () => updateBuyFee()); buyQty?.addEventListener("input", () => updateBuyFee()); buyMax?.addEventListener("input", () => updateBuyFee()); buyMax?.addEventListener("input", () => updateBuyFee());@@ -120,6 +130,15 @@ export function initMarket ({ }); }); }); }); sellSuggest?.addEventListener("click", () => { const price = Number(sellSuggest.dataset.price); if (!(price > 0) || !sellMin) { return; } sellMin.value = String(price); updateSellFee(); }); function close () function close () { { if (!open) if (!open)@@ -179,6 +198,33 @@ export function initMarket ({ } } } } function hintPriceForItem (itemId) { const entry = catalog.find((row) => (row.itemId | 0) === (itemId | 0)); const price = entry?.hintPrice; if (price == null || !(Number(price) > 0)) { return null; } return Math.max(1, Math.round(Number(price))); } function updateSellSuggest (itemId = null) { if (!sellSuggest) { return; } const price = itemId == null ? null : hintPriceForItem(itemId); if (price == null) { sellSuggest.hidden = true; sellSuggest.dataset.price = ""; sellSuggest.textContent = ""; return; } sellSuggest.hidden = false; sellSuggest.dataset.price = String(price); sellSuggest.textContent = `Market ~${formatQuantity(price)}`; sellSuggest.title = "Use shopkeeper market price (seed + last-sale lerp) as min price"; } function renderOrders () function renderOrders () { { ordersEl.replaceChildren(); ordersEl.replaceChildren();@@ -249,59 +295,77 @@ export function initMarket ({ } } } } function selectSellSlot (slotIndex, slot, listing) { selectedSellSlot = slotIndex; sellQtyLocked = !!listing.quantityLocked; if (sellQty) { sellQty.value = String(listing.quantityLocked ? listing.quantity : Math.min(listing.quantity, Math.max(1, slot.quantity | 0))); sellQty.readOnly = sellQtyLocked; sellQty.disabled = sellQtyLocked; if (!sellQtyLocked) { sellQty.max = String(Math.max(1, slot.quantity | 0)); } else { sellQty.removeAttribute("max"); } } if (sellSelected) { sellSelected.textContent = listing.isCheque ? `Selling cheque for ${listing.quantity}× ${listing.displayName} (quantity locked)` : `Selling ${itemDisplayName(slot)}`; } updateSellSuggest(listing.itemId); renderSellables(); updateSellFee(); } function renderSellables () function renderSellables () { { sellList.replaceChildren(); sellList.replaceChildren(); const slots = getInventorySlots?.() ?? []; const slots = getInventorySlots?.() ?? []; slots.forEach((slot, slotIndex) => const count = Math.max(INVENTORY_SLOTS, slots.length); for (let slotIndex = 0; slotIndex < count; slotIndex++) { { if (!slot || slot.itemId == null) const slot = slots[slotIndex] ?? null; { return; } const button = document.createElement("button"); const listing = resolveMarketSellListing(slot); button.type = "button"; if (!listing) const listing = slot ? resolveMarketSellListing(slot) : null; { return; } const sellable = !!listing && itemDefinition(slot.itemId)?.marketplaceSellable !== false; const def = itemDefinition(slot.itemId); button.className = `item-slot${selectedSellSlot === slotIndex ? " selected" : ""}`; if (!def || def.marketplaceSellable === false) if (slot && !sellable) { return; } { button.classList.add("disabled"); } const row = document.createElement("button"); button.title = slot row.type = "button"; ? (sellable row.className = "market-sell-row"; ? (listing.isCheque if (selectedSellSlot === slotIndex) ? `Cheque: ${listing.displayName} ×${formatQuantity(listing.quantity)}` { row.classList.add("selected"); } : `${itemDisplayName(slot)} ×${formatQuantity(slot.quantity)}`) const icon = document.createElement("img"); : `${itemDisplayName(slot)} (cannot list)`) icon.alt = ""; : ""; applyItemIcon(icon, itemAssetPathForStack(slot)); if (slot) const label = document.createElement("span"); if (listing.isCheque) { label.textContent = `Cheque: ${listing.displayName} ×${formatQuantity(listing.quantity)}`; } else { { label.textContent = `${itemDisplayName(slot)} ×${formatQuantity(slot.quantity)}`; const img = document.createElement("img"); } img.alt = itemDisplayName(slot); row.append(icon, label); applyItemIcon(img, slot, itemAssetPathForStack(slot)); row.addEventListener("click", () => button.append(img); { if ((slot.quantity | 0) > 1) selectedSellSlot = slotIndex; sellQtyLocked = !!listing.quantityLocked; if (sellQty) { sellQty.value = String(listing.quantity); sellQty.readOnly = sellQtyLocked; sellQty.disabled = sellQtyLocked; } if (sellSelected) { { sellSelected.textContent = listing.isCheque const qty = document.createElement("span"); ? `Selling cheque for ${listing.quantity}× ${listing.displayName} (quantity locked)` qty.className = "qty"; : `Selling ${itemDisplayName(slot)}`; qty.textContent = formatQuantity(slot.quantity); button.append(qty); } } renderSellables(); } updateSellFee(); button.addEventListener("click", () => { if (!sellable) { return; } selectSellSlot(slotIndex, slot, listing); }); }); sellList.append(row); sellList.append(button); }); } } } function refreshChrome () function refreshChrome ()@@ -331,14 +395,18 @@ export function initMarket ({ selectedSellSlot = null; selectedSellSlot = null; selectedBuyItemId = null; selectedBuyItemId = null; sellQtyLocked = false; sellQtyLocked = false; updateSellSuggest(null); if (sellQty) if (sellQty) { { sellQty.readOnly = false; sellQty.readOnly = false; sellQty.disabled = false; sellQty.disabled = false; sellQty.value = "1"; sellQty.value = "1"; sellQty.removeAttribute("max"); } } if (buySearch) if (buySearch) { buySearch.value = ""; } { buySearch.value = ""; } if (sellSelected) { sellSelected.textContent = "Select an item from your bag"; } if (title) if (title) { title.textContent = payload.displayName || "Central Exchange"; } { title.textContent = payload.displayName || "Central Exchange"; } if (hintEl) if (hintEl)@@ -376,6 +444,10 @@ export function initMarket ({ { { return open; return open; }, }, isBlocking () { return open; }, close close }; };}}@@ -1150,8 +1150,7 @@ a { color: #d4c48a; }
margin-top: 0.25rem;
}
.market-catalog,
.market-sell-list {
.market-catalog {
display: flex;
flex-direction: column;
gap: 0.25rem;
@@ -1160,8 +1159,12 @@ a { color: #d4c48a; }
margin-bottom: 0.5rem;
}
#market-sell-list.item-grid {
max-height: none;
margin-bottom: 0.5rem;
}
.market-catalog-row,
.market-sell-row,
.market-order-row {
display: flex;
align-items: center;
@@ -1174,15 +1177,12 @@ a { color: #d4c48a; }
text-align: left;
}
.market-catalog-row.selected,
.market-sell-row.selected {
.market-catalog-row.selected {
border-color: #6a8caf;
}
.market-sell-row img {
width: 24px;
height: 24px;
image-rendering: pixelated;
#market-sell-list .item-slot.disabled {
opacity: 0.4;
}
#market-sell-qty:disabled,
@@ -1190,6 +1190,31 @@ a { color: #d4c48a; }
opacity: 0.7;
}
.market-sell-actions {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 0.75rem;
margin-top: 0.5rem;
}
.market-price-suggest {
margin: 0;
padding: 0;
border: none;
background: transparent;
color: #9aa3b2;
font: inherit;
font-size: 0.85rem;
text-align: right;
cursor: pointer;
}
.market-price-suggest:hover {
color: #d4c48a;
text-decoration: underline;
}
#shop-qty-backdrop {
z-index: 7;
@@ -1150,8 +1150,7 @@ a { color: #d4c48a; } margin-top: 0.25rem; margin-top: 0.25rem;}}.market-catalog,.market-catalog {.market-sell-list { display: flex; display: flex; flex-direction: column; flex-direction: column; gap: 0.25rem; gap: 0.25rem;@@ -1160,8 +1159,12 @@ a { color: #d4c48a; } margin-bottom: 0.5rem; margin-bottom: 0.5rem;}}#market-sell-list.item-grid { max-height: none; margin-bottom: 0.5rem;}.market-catalog-row,.market-catalog-row,.market-sell-row,.market-order-row {.market-order-row { display: flex; display: flex; align-items: center; align-items: center;@@ -1174,15 +1177,12 @@ a { color: #d4c48a; } text-align: left; text-align: left;}}.market-catalog-row.selected,.market-catalog-row.selected {.market-sell-row.selected { border-color: #6a8caf; border-color: #6a8caf;}}.market-sell-row img {#market-sell-list .item-slot.disabled { width: 24px; opacity: 0.4; height: 24px; image-rendering: pixelated;}}#market-sell-qty:disabled,#market-sell-qty:disabled,@@ -1190,6 +1190,31 @@ a { color: #d4c48a; } opacity: 0.7; opacity: 0.7;}}.market-sell-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.75rem; margin-top: 0.5rem;}.market-price-suggest { margin: 0; padding: 0; border: none; background: transparent; color: #9aa3b2; font: inherit; font-size: 0.85rem; text-align: right; cursor: pointer;}.market-price-suggest:hover { color: #d4c48a; text-decoration: underline;}#shop-qty-backdrop {#shop-qty-backdrop { z-index: 7; z-index: 7;