Smooth chunk loading and improve shopkeeper item picker.
Preload assets with a login progress UI, warm GPU textures after startGame, and spread chunk bakes and atlas uploads across frames. Let editors add any item to shop stock and honor explicit catalog lines on the server.
@@ -162,6 +162,11 @@
162
162
<div class="shop-item-search-body">
163
163
<input id="shop-item-search-input" type="search" placeholder="Search items…" autocomplete="off">
164
164
<div id="shop-item-search-results"></div>
165
<div id="shop-item-search-footer" class="shop-item-search-footer">
166
<button id="shop-item-search-prev" type="button">Previous</button>
167
<span id="shop-item-search-page" class="hint"></span>
168
<button id="shop-item-search-next" type="button">Next</button>
169
</div>
165
170
</div>
166
171
</div>
167
172
@@ -162,6 +162,11 @@162
<div class="shop-item-search-body">162
<div class="shop-item-search-body">163
<input id="shop-item-search-input" type="search" placeholder="Search items…" autocomplete="off">163
<input id="shop-item-search-input" type="search" placeholder="Search items…" autocomplete="off">164
<div id="shop-item-search-results"></div>164
<div id="shop-item-search-results"></div>165
<div id="shop-item-search-footer" class="shop-item-search-footer">166
<button id="shop-item-search-prev" type="button">Previous</button>167
<span id="shop-item-search-page" class="hint"></span>168
<button id="shop-item-search-next" type="button">Next</button>169
</div>165
</div>170
</div>166
</div>171
</div>167
172
@@ -527,6 +527,10 @@
527
527
<section class="panel">
528
528
<h1>Questward</h1>
529
529
<p id="status">Connecting…</p>
530
<div id="asset-load" class="asset-load" hidden>
531
<progress id="asset-load-bar" max="100" value="0"></progress>
532
<p id="asset-load-label" class="hint">Loading assets…</p>
533
</div>
530
534
<p id="auth-actions" class="auth-actions">
531
535
<a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>
532
536
<a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>
@@ -527,6 +527,10 @@527
<section class="panel">527
<section class="panel">528
<h1>Questward</h1>528
<h1>Questward</h1>529
<p id="status">Connecting…</p>529
<p id="status">Connecting…</p>530
<div id="asset-load" class="asset-load" hidden>531
<progress id="asset-load-bar" max="100" value="0"></progress>532
<p id="asset-load-label" class="hint">Loading assets…</p>533
</div>530
<p id="auth-actions" class="auth-actions">534
<p id="auth-actions" class="auth-actions">531
<a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>535
<a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>532
<a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>536
<a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>@@ -906,11 +906,15 @@ async function main ()
906
906
907
907
catalog = await loadSpriteCatalog();
908
908
imageUrlByName = new Map((catalog.images ?? []).map((entry) => [entry.name, entry.url]));
909
await preloadCatalogImages(game, catalog);
909
await preloadCatalogImages(game, catalog, {
910
onProgress ({ loaded, total })
911
{
912
$("who").textContent = `${accountLabel} · loading sprites ${loaded}/${total}`;
913
}
914
});
910
915
applySpriteSheets(game.images, catalog);
911
916
scene = new Scene(250, 56, 64, 64);
912
917
game.loadScene(scene);
913
useNearestNeighbour(scene, game.images);
914
918
view = new WorldView(game, scene, catalog);
915
919
view.followPlayer = false;
916
920
view.setGraphicsPrefs(loadGraphicsSettings());
@@ -1214,6 +1218,7 @@ async function main ()
1214
1218
dialoguesModal = initDialoguesModal({ socket, MessageType });
1215
1219
initSidePanelTabs();
1216
1220
game.startGame();
1221
useNearestNeighbour(scene, game.images);
1217
1222
await socket.connect();
1218
1223
}
1219
1224
@@ -906,11 +906,15 @@ async function main ()906
906
907
catalog = await loadSpriteCatalog();907
catalog = await loadSpriteCatalog();908
imageUrlByName = new Map((catalog.images ?? []).map((entry) => [entry.name, entry.url]));908
imageUrlByName = new Map((catalog.images ?? []).map((entry) => [entry.name, entry.url]));909
await preloadCatalogImages(game, catalog);909
await preloadCatalogImages(game, catalog, {910
onProgress ({ loaded, total })911
{912
$("who").textContent = `${accountLabel} · loading sprites ${loaded}/${total}`;913
}914
});910
applySpriteSheets(game.images, catalog);915
applySpriteSheets(game.images, catalog);911
scene = new Scene(250, 56, 64, 64);916
scene = new Scene(250, 56, 64, 64);912
game.loadScene(scene);917
game.loadScene(scene);913
useNearestNeighbour(scene, game.images);914
view = new WorldView(game, scene, catalog);918
view = new WorldView(game, scene, catalog);915
view.followPlayer = false;919
view.followPlayer = false;916
view.setGraphicsPrefs(loadGraphicsSettings());920
view.setGraphicsPrefs(loadGraphicsSettings());@@ -1214,6 +1218,7 @@ async function main ()1214
dialoguesModal = initDialoguesModal({ socket, MessageType });1218
dialoguesModal = initDialoguesModal({ socket, MessageType });1215
initSidePanelTabs();1219
initSidePanelTabs();1216
game.startGame();1220
game.startGame();1221
useNearestNeighbour(scene, game.images);1217
await socket.connect();1222
await socket.connect();1218
}1223
}1219
1224
@@ -12,14 +12,14 @@ import {
12
12
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";
13
13
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
14
14
import { centralExchangeStaffCount } from "/shared/market/exchange.js";
15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing } from "/shared/definitions/items.js";
15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
16
16
import { EQUIPMENT_SLOTS } from "/shared/items/inventory.js";
17
import { listNpcShopSellableItems } from "/shared/shop/pricing.js";
18
17
import { normalizeRgb } from "/shared/render/tint.js";
19
18
import { createDimensionCombobox } from "./dimensionCombobox.js";
20
19
import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js";
21
20
22
21
const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);
22
const ITEM_SEARCH_PAGE_SIZE = 40;
23
23
24
24
/** Items that can be worn in a given equipment slot. */
25
25
export function listEquippableItemsForSlot (slot)
@@ -90,6 +90,9 @@ export function initTileConfigModal ({
90
90
const itemSearchTitle = itemSearchModal?.querySelector("h2") ?? null;
91
91
const itemSearchInput = document.getElementById("shop-item-search-input");
92
92
const itemSearchResults = document.getElementById("shop-item-search-results");
93
const itemSearchPrev = document.getElementById("shop-item-search-prev");
94
const itemSearchNext = document.getElementById("shop-item-search-next");
95
const itemSearchPageLabel = document.getElementById("shop-item-search-page");
93
96
const dyeBackdrop = document.getElementById("equip-dye-backdrop");
94
97
const dyeModal = document.getElementById("equip-dye-modal");
95
98
const dyeTitle = document.getElementById("equip-dye-title");
@@ -115,6 +118,10 @@ export function initTileConfigModal ({
115
118
/** @type {{ dialogueId: string, label: string, unique?: boolean }[]} */
116
119
let dialogueOptions = [];
117
120
let pendingDialogueId = null;
121
/** @type {number} */
122
let itemSearchPage = 0;
123
/** @type {{ itemId: number, displayName: string, key: string }[] | null} */
124
let itemSearchMatches = null;
118
125
/** @type {ReturnType<typeof createDimensionCombobox>|null} */
119
126
let doorwayDimCombo = null;
120
127
@@ -135,6 +142,8 @@ export function initTileConfigModal ({
135
142
function closeItemSearch ()
136
143
{
137
144
itemSearchMode = null;
145
itemSearchPage = 0;
146
itemSearchMatches = null;
138
147
if (itemSearchBackdrop)
139
148
{ itemSearchBackdrop.hidden = true; }
140
149
if (itemSearchModal)
@@ -160,9 +169,11 @@ export function initTileConfigModal ({
160
169
if (itemSearchTitle)
161
170
{ itemSearchTitle.textContent = heading ?? "Choose item"; }
162
171
itemSearchInput.value = "";
172
itemSearchPage = 0;
173
itemSearchMatches = null;
163
174
itemSearchInput.placeholder = itemSearchMode?.kind === "equip"
164
175
? "Search equipment…"
165
: "Search items…";
176
: "Search all items…";
166
177
renderItemSearchResults("");
167
178
itemSearchBackdrop.hidden = false;
168
179
itemSearchModal.hidden = false;
@@ -173,37 +184,69 @@ export function initTileConfigModal ({
173
184
{
174
185
if (itemSearchMode?.kind === "equip")
175
186
{ return listEquippableItemsForSlot(itemSearchMode.slot); }
176
return listNpcShopSellableItems();
187
return listAllItemPickerEntries();
177
188
}
178
189
179
function renderItemSearchResults (query)
190
function filterItemSearchMatches (query)
180
191
{
181
if (!itemSearchResults)
182
{ return; }
183
itemSearchResults.innerHTML = "";
184
192
const q = String(query ?? "").trim().toLowerCase();
185
193
const taken = itemSearchMode?.kind === "sells"
186
194
? new Set(sellsDraft.map((line) => line.itemId))
187
195
: null;
188
const matches = candidateItems().filter((item) =>
196
return candidateItems().filter((item) =>
189
197
{
190
198
if (taken?.has(item.itemId))
191
199
{ return false; }
192
200
if (!q)
193
201
{ return true; }
194
return item.displayName.toLowerCase().includes(q) || item.key.toLowerCase().includes(q);
195
}).slice(0, 120);
196
if (!matches.length)
202
const idText = String(item.itemId);
203
return item.displayName.toLowerCase().includes(q)
204
|| item.key.toLowerCase().includes(q)
205
|| idText.includes(q);
206
});
207
}
208
209
function renderItemSearchResults (query)
210
{
211
if (!itemSearchResults)
212
{ return; }
213
itemSearchResults.innerHTML = "";
214
itemSearchMatches = filterItemSearchMatches(query);
215
const total = itemSearchMatches.length;
216
const pageCount = Math.max(1, Math.ceil(total / ITEM_SEARCH_PAGE_SIZE));
217
if (itemSearchPage >= pageCount)
218
{ itemSearchPage = Math.max(0, pageCount - 1); }
219
const start = itemSearchPage * ITEM_SEARCH_PAGE_SIZE;
220
const pageItems = itemSearchMatches.slice(start, start + ITEM_SEARCH_PAGE_SIZE);
221
if (itemSearchPageLabel)
197
222
{
198
itemSearchResults.textContent = "No matching items.";
223
itemSearchPageLabel.textContent = total
224
? `${start + 1}–${start + pageItems.length} of ${total}`
225
: "No items";
226
}
227
if (itemSearchPrev)
228
{ itemSearchPrev.disabled = itemSearchPage <= 0; }
229
if (itemSearchNext)
230
{ itemSearchNext.disabled = itemSearchPage >= pageCount - 1; }
231
if (!pageItems.length)
232
{
233
itemSearchResults.textContent = total
234
? "No items on this page."
235
: "No matching items.";
199
236
return;
200
237
}
201
for (const item of matches)
238
for (const item of pageItems)
202
239
{
203
240
const row = document.createElement("button");
204
241
row.type = "button";
205
242
row.className = "shop-item-search-row";
206
row.textContent = item.displayName;
243
const name = document.createElement("span");
244
name.className = "shop-item-search-row-name";
245
name.textContent = item.displayName;
246
const key = document.createElement("span");
247
key.className = "shop-item-search-row-key";
248
key.textContent = `${item.key} · #${item.itemId}`;
249
row.append(name, key);
207
250
row.addEventListener("click", () =>
208
251
{
209
252
if (itemSearchMode?.kind === "equip")
@@ -493,7 +536,7 @@ export function initTileConfigModal ({
493
536
494
537
const hint = document.createElement("p");
495
538
hint.className = "hint";
496
hint.textContent = "Quantity 0 = infinite stock. Limited stock restocks daily at 00:00 server time. Buys items: pays 80% market for transferable bag goods (not blank cheques); filled cheques sell as reserved goods with a 5% admin fee; extras resell at 120% until restock.";
539
hint.textContent = "Quantity 0 = infinite stock. Limited stock restocks daily at 00:00 server time. Any item can be listed for sale. Buys items: pays 80% market for transferable bag goods (not blank cheques); filled cheques sell as reserved goods with a 5% admin fee; extras resell at 120% until restock.";
497
540
wrap.append(hint);
498
541
499
542
sellsDraft = (config.sells ?? []).map((line) =>
@@ -752,7 +795,26 @@ export function initTileConfigModal ({
752
795
backdrop.addEventListener("click", () => show(false));
753
796
document.getElementById("shop-item-search-close")?.addEventListener("click", () => closeItemSearch());
754
797
itemSearchBackdrop?.addEventListener("click", () => closeItemSearch());
755
itemSearchInput?.addEventListener("input", () => renderItemSearchResults(itemSearchInput.value));
798
itemSearchInput?.addEventListener("input", () =>
799
{
800
itemSearchPage = 0;
801
renderItemSearchResults(itemSearchInput.value);
802
});
803
itemSearchPrev?.addEventListener("click", () =>
804
{
805
if (itemSearchPage <= 0)
806
{ return; }
807
itemSearchPage -= 1;
808
renderItemSearchResults(itemSearchInput?.value ?? "");
809
});
810
itemSearchNext?.addEventListener("click", () =>
811
{
812
const pageCount = Math.max(1, Math.ceil((itemSearchMatches?.length ?? 0) / ITEM_SEARCH_PAGE_SIZE));
813
if (itemSearchPage >= pageCount - 1)
814
{ return; }
815
itemSearchPage += 1;
816
renderItemSearchResults(itemSearchInput?.value ?? "");
817
});
756
818
document.getElementById("equip-dye-close")?.addEventListener("click", () => closeDyePicker());
757
819
dyeBackdrop?.addEventListener("click", () => closeDyePicker());
758
820
document.getElementById("equip-dye-apply")?.addEventListener("click", () =>
@@ -12,14 +12,14 @@ import {12
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";12
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";13
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";13
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";14
import { centralExchangeStaffCount } from "/shared/market/exchange.js";14
import { centralExchangeStaffCount } from "/shared/market/exchange.js";15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing } from "/shared/definitions/items.js";15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";16
import { EQUIPMENT_SLOTS } from "/shared/items/inventory.js";16
import { EQUIPMENT_SLOTS } from "/shared/items/inventory.js";17
import { listNpcShopSellableItems } from "/shared/shop/pricing.js";18
import { normalizeRgb } from "/shared/render/tint.js";17
import { normalizeRgb } from "/shared/render/tint.js";19
import { createDimensionCombobox } from "./dimensionCombobox.js";18
import { createDimensionCombobox } from "./dimensionCombobox.js";20
import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js";19
import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js";21
20
22
const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);21
const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);22
const ITEM_SEARCH_PAGE_SIZE = 40;23
23
24
/** Items that can be worn in a given equipment slot. */24
/** Items that can be worn in a given equipment slot. */25
export function listEquippableItemsForSlot (slot)25
export function listEquippableItemsForSlot (slot)@@ -90,6 +90,9 @@ export function initTileConfigModal ({90
const itemSearchTitle = itemSearchModal?.querySelector("h2") ?? null;90
const itemSearchTitle = itemSearchModal?.querySelector("h2") ?? null;91
const itemSearchInput = document.getElementById("shop-item-search-input");91
const itemSearchInput = document.getElementById("shop-item-search-input");92
const itemSearchResults = document.getElementById("shop-item-search-results");92
const itemSearchResults = document.getElementById("shop-item-search-results");93
const itemSearchPrev = document.getElementById("shop-item-search-prev");94
const itemSearchNext = document.getElementById("shop-item-search-next");95
const itemSearchPageLabel = document.getElementById("shop-item-search-page");93
const dyeBackdrop = document.getElementById("equip-dye-backdrop");96
const dyeBackdrop = document.getElementById("equip-dye-backdrop");94
const dyeModal = document.getElementById("equip-dye-modal");97
const dyeModal = document.getElementById("equip-dye-modal");95
const dyeTitle = document.getElementById("equip-dye-title");98
const dyeTitle = document.getElementById("equip-dye-title");@@ -115,6 +118,10 @@ export function initTileConfigModal ({115
/** @type {{ dialogueId: string, label: string, unique?: boolean }[]} */118
/** @type {{ dialogueId: string, label: string, unique?: boolean }[]} */116
let dialogueOptions = [];119
let dialogueOptions = [];117
let pendingDialogueId = null;120
let pendingDialogueId = null;121
/** @type {number} */122
let itemSearchPage = 0;123
/** @type {{ itemId: number, displayName: string, key: string }[] | null} */124
let itemSearchMatches = null;118
/** @type {ReturnType<typeof createDimensionCombobox>|null} */125
/** @type {ReturnType<typeof createDimensionCombobox>|null} */119
let doorwayDimCombo = null;126
let doorwayDimCombo = null;120
127
@@ -135,6 +142,8 @@ export function initTileConfigModal ({135
function closeItemSearch ()142
function closeItemSearch ()136
{143
{137
itemSearchMode = null;144
itemSearchMode = null;145
itemSearchPage = 0;146
itemSearchMatches = null;138
if (itemSearchBackdrop)147
if (itemSearchBackdrop)139
{ itemSearchBackdrop.hidden = true; }148
{ itemSearchBackdrop.hidden = true; }140
if (itemSearchModal)149
if (itemSearchModal)@@ -160,9 +169,11 @@ export function initTileConfigModal ({160
if (itemSearchTitle)169
if (itemSearchTitle)161
{ itemSearchTitle.textContent = heading ?? "Choose item"; }170
{ itemSearchTitle.textContent = heading ?? "Choose item"; }162
itemSearchInput.value = "";171
itemSearchInput.value = "";172
itemSearchPage = 0;173
itemSearchMatches = null;163
itemSearchInput.placeholder = itemSearchMode?.kind === "equip"174
itemSearchInput.placeholder = itemSearchMode?.kind === "equip"164
? "Search equipment…"175
? "Search equipment…"165
: "Search items…";176
: "Search all items…";166
renderItemSearchResults("");177
renderItemSearchResults("");167
itemSearchBackdrop.hidden = false;178
itemSearchBackdrop.hidden = false;168
itemSearchModal.hidden = false;179
itemSearchModal.hidden = false;@@ -173,37 +184,69 @@ export function initTileConfigModal ({173
{184
{174
if (itemSearchMode?.kind === "equip")185
if (itemSearchMode?.kind === "equip")175
{ return listEquippableItemsForSlot(itemSearchMode.slot); }186
{ return listEquippableItemsForSlot(itemSearchMode.slot); }176
return listNpcShopSellableItems();187
return listAllItemPickerEntries();177
}188
}178
189
179
function renderItemSearchResults (query)190
function filterItemSearchMatches (query)180
{191
{181
if (!itemSearchResults)182
{ return; }183
itemSearchResults.innerHTML = "";184
const q = String(query ?? "").trim().toLowerCase();192
const q = String(query ?? "").trim().toLowerCase();185
const taken = itemSearchMode?.kind === "sells"193
const taken = itemSearchMode?.kind === "sells"186
? new Set(sellsDraft.map((line) => line.itemId))194
? new Set(sellsDraft.map((line) => line.itemId))187
: null;195
: null;188
const matches = candidateItems().filter((item) =>196
return candidateItems().filter((item) =>189
{197
{190
if (taken?.has(item.itemId))198
if (taken?.has(item.itemId))191
{ return false; }199
{ return false; }192
if (!q)200
if (!q)193
{ return true; }201
{ return true; }194
return item.displayName.toLowerCase().includes(q) || item.key.toLowerCase().includes(q);202
const idText = String(item.itemId);195
}).slice(0, 120);203
return item.displayName.toLowerCase().includes(q)196
if (!matches.length)204
|| item.key.toLowerCase().includes(q)205
|| idText.includes(q);206
});207
}208
209
function renderItemSearchResults (query)210
{211
if (!itemSearchResults)212
{ return; }213
itemSearchResults.innerHTML = "";214
itemSearchMatches = filterItemSearchMatches(query);215
const total = itemSearchMatches.length;216
const pageCount = Math.max(1, Math.ceil(total / ITEM_SEARCH_PAGE_SIZE));217
if (itemSearchPage >= pageCount)218
{ itemSearchPage = Math.max(0, pageCount - 1); }219
const start = itemSearchPage * ITEM_SEARCH_PAGE_SIZE;220
const pageItems = itemSearchMatches.slice(start, start + ITEM_SEARCH_PAGE_SIZE);221
if (itemSearchPageLabel)197
{222
{198
itemSearchResults.textContent = "No matching items.";223
itemSearchPageLabel.textContent = total224
? `${start + 1}–${start + pageItems.length} of ${total}`225
: "No items";226
}227
if (itemSearchPrev)228
{ itemSearchPrev.disabled = itemSearchPage <= 0; }229
if (itemSearchNext)230
{ itemSearchNext.disabled = itemSearchPage >= pageCount - 1; }231
if (!pageItems.length)232
{233
itemSearchResults.textContent = total234
? "No items on this page."235
: "No matching items.";199
return;236
return;200
}237
}201
for (const item of matches)238
for (const item of pageItems)202
{239
{203
const row = document.createElement("button");240
const row = document.createElement("button");204
row.type = "button";241
row.type = "button";205
row.className = "shop-item-search-row";242
row.className = "shop-item-search-row";206
row.textContent = item.displayName;243
const name = document.createElement("span");244
name.className = "shop-item-search-row-name";245
name.textContent = item.displayName;246
const key = document.createElement("span");247
key.className = "shop-item-search-row-key";248
key.textContent = `${item.key} · #${item.itemId}`;249
row.append(name, key);207
row.addEventListener("click", () =>250
row.addEventListener("click", () =>208
{251
{209
if (itemSearchMode?.kind === "equip")252
if (itemSearchMode?.kind === "equip")@@ -493,7 +536,7 @@ export function initTileConfigModal ({493
536
494
const hint = document.createElement("p");537
const hint = document.createElement("p");495
hint.className = "hint";538
hint.className = "hint";496
hint.textContent = "Quantity 0 = infinite stock. Limited stock restocks daily at 00:00 server time. Buys items: pays 80% market for transferable bag goods (not blank cheques); filled cheques sell as reserved goods with a 5% admin fee; extras resell at 120% until restock.";539
hint.textContent = "Quantity 0 = infinite stock. Limited stock restocks daily at 00:00 server time. Any item can be listed for sale. Buys items: pays 80% market for transferable bag goods (not blank cheques); filled cheques sell as reserved goods with a 5% admin fee; extras resell at 120% until restock.";497
wrap.append(hint);540
wrap.append(hint);498
541
499
sellsDraft = (config.sells ?? []).map((line) =>542
sellsDraft = (config.sells ?? []).map((line) =>@@ -752,7 +795,26 @@ export function initTileConfigModal ({752
backdrop.addEventListener("click", () => show(false));795
backdrop.addEventListener("click", () => show(false));753
document.getElementById("shop-item-search-close")?.addEventListener("click", () => closeItemSearch());796
document.getElementById("shop-item-search-close")?.addEventListener("click", () => closeItemSearch());754
itemSearchBackdrop?.addEventListener("click", () => closeItemSearch());797
itemSearchBackdrop?.addEventListener("click", () => closeItemSearch());755
itemSearchInput?.addEventListener("input", () => renderItemSearchResults(itemSearchInput.value));798
itemSearchInput?.addEventListener("input", () =>799
{800
itemSearchPage = 0;801
renderItemSearchResults(itemSearchInput.value);802
});803
itemSearchPrev?.addEventListener("click", () =>804
{805
if (itemSearchPage <= 0)806
{ return; }807
itemSearchPage -= 1;808
renderItemSearchResults(itemSearchInput?.value ?? "");809
});810
itemSearchNext?.addEventListener("click", () =>811
{812
const pageCount = Math.max(1, Math.ceil((itemSearchMatches?.length ?? 0) / ITEM_SEARCH_PAGE_SIZE));813
if (itemSearchPage >= pageCount - 1)814
{ return; }815
itemSearchPage += 1;816
renderItemSearchResults(itemSearchInput?.value ?? "");817
});756
document.getElementById("equip-dye-close")?.addEventListener("click", () => closeDyePicker());818
document.getElementById("equip-dye-close")?.addEventListener("click", () => closeDyePicker());757
dyeBackdrop?.addEventListener("click", () => closeDyePicker());819
dyeBackdrop?.addEventListener("click", () => closeDyePicker());758
document.getElementById("equip-dye-apply")?.addEventListener("click", () =>820
document.getElementById("equip-dye-apply")?.addEventListener("click", () =>@@ -4,7 +4,7 @@ import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, reso
4
4
import { OVERWORLD_ID } from "/shared/world/dimensions.js";
5
5
import { GameSocket, defaultSocketUrl } from "../net/socket.js";
6
6
import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";
7
import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour } from "../render/sprites.js";
7
import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour, playImagesFromCatalog } from "../render/sprites.js";
8
8
import { WorldView } from "../render/worldView.js";
9
9
import { initSocial } from "./social.js";
10
10
import { initChat } from "./chat.js";
@@ -41,6 +41,10 @@ const overlay = document.getElementById("overlay");
41
41
const statusEl = document.getElementById("status");
42
42
const characterList = document.getElementById("character-list");
43
43
const errorEl = document.getElementById("error");
44
const assetLoadEl = document.getElementById("asset-load");
45
const assetLoadBar = document.getElementById("asset-load-bar");
46
const assetLoadLabel = document.getElementById("asset-load-label");
47
const createCharacterOpen = document.getElementById("create-character-open");
44
48
const worldTooltip = document.getElementById("world-tooltip");
45
49
46
50
let socket;
@@ -93,6 +97,25 @@ function showError (message)
93
97
errorEl.textContent = message ?? "";
94
98
}
95
99
100
function setAssetLoading (active, { loaded = 0, total = 0, phase = "" } = {})
101
{
102
if (assetLoadEl)
103
{ assetLoadEl.hidden = !active; }
104
if (characterList)
105
{ characterList.hidden = active; }
106
if (createCharacterOpen)
107
{ createCharacterOpen.hidden = active; }
108
if (!active)
109
{ return; }
110
if (assetLoadBar && total > 0)
111
{ assetLoadBar.value = Math.round((loaded / total) * 100); }
112
if (assetLoadLabel)
113
{
114
assetLoadLabel.textContent = phase
115
|| (total > 0 ? `Loading assets… ${loaded}/${total}` : "Loading assets…");
116
}
117
}
118
96
119
function renderCharacters (characters)
97
120
{
98
121
characterList.innerHTML = "";
@@ -898,6 +921,9 @@ function startPlay (payload)
898
921
scene = new Scene(0, 0, window.innerWidth, window.innerHeight);
899
922
game.loadScene(scene);
900
923
useNearestNeighbour(scene, game.images);
924
}
925
if (!view)
926
{
901
927
view = new WorldView(game, scene, catalog);
902
928
graphicsSettingsUi?.apply();
903
929
const ticker = new GameObject(0, 0, null, 10);
@@ -1011,9 +1037,24 @@ async function main ()
1011
1037
return;
1012
1038
}
1013
1039
1040
setAssetLoading(true, { phase: "Loading catalog…" });
1014
1041
catalog = await loadSpriteCatalog();
1015
await preloadCatalogImages(game, catalog);
1042
const assetTotal = playImagesFromCatalog(catalog).length;
1043
setAssetLoading(true, { loaded: 0, total: assetTotal, phase: "Loading assets…" });
1044
await preloadCatalogImages(game, catalog, {
1045
onProgress ({ loaded, total })
1046
{
1047
setAssetLoading(true, { loaded, total });
1048
}
1049
});
1016
1050
applySpriteSheets(game.images, catalog);
1051
if (!scene)
1052
{
1053
scene = new Scene(0, 0, window.innerWidth, window.innerHeight);
1054
game.loadScene(scene);
1055
}
1056
setAssetLoading(false);
1057
statusEl.textContent = "Connecting…";
1017
1058
createHairControls = bindHairControls({
1018
1059
root: document.getElementById("create-hair"),
1019
1060
resolveSpriteUrl (name)
@@ -1187,6 +1228,7 @@ async function main ()
1187
1228
MessageType
1188
1229
});
1189
1230
game.startGame();
1231
useNearestNeighbour(scene, game.images);
1190
1232
1191
1233
socket = new GameSocket(defaultSocketUrl(), (message) =>
1192
1234
{
@@ -4,7 +4,7 @@ import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, reso4
import { OVERWORLD_ID } from "/shared/world/dimensions.js";4
import { OVERWORLD_ID } from "/shared/world/dimensions.js";5
import { GameSocket, defaultSocketUrl } from "../net/socket.js";5
import { GameSocket, defaultSocketUrl } from "../net/socket.js";6
import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";6
import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";7
import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour } from "../render/sprites.js";7
import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour, playImagesFromCatalog } from "../render/sprites.js";8
import { WorldView } from "../render/worldView.js";8
import { WorldView } from "../render/worldView.js";9
import { initSocial } from "./social.js";9
import { initSocial } from "./social.js";10
import { initChat } from "./chat.js";10
import { initChat } from "./chat.js";@@ -41,6 +41,10 @@ const overlay = document.getElementById("overlay");41
const statusEl = document.getElementById("status");41
const statusEl = document.getElementById("status");42
const characterList = document.getElementById("character-list");42
const characterList = document.getElementById("character-list");43
const errorEl = document.getElementById("error");43
const errorEl = document.getElementById("error");44
const assetLoadEl = document.getElementById("asset-load");45
const assetLoadBar = document.getElementById("asset-load-bar");46
const assetLoadLabel = document.getElementById("asset-load-label");47
const createCharacterOpen = document.getElementById("create-character-open");44
const worldTooltip = document.getElementById("world-tooltip");48
const worldTooltip = document.getElementById("world-tooltip");45
49
46
let socket;50
let socket;@@ -93,6 +97,25 @@ function showError (message)93
errorEl.textContent = message ?? "";97
errorEl.textContent = message ?? "";94
}98
}95
99
100
function setAssetLoading (active, { loaded = 0, total = 0, phase = "" } = {})101
{102
if (assetLoadEl)103
{ assetLoadEl.hidden = !active; }104
if (characterList)105
{ characterList.hidden = active; }106
if (createCharacterOpen)107
{ createCharacterOpen.hidden = active; }108
if (!active)109
{ return; }110
if (assetLoadBar && total > 0)111
{ assetLoadBar.value = Math.round((loaded / total) * 100); }112
if (assetLoadLabel)113
{114
assetLoadLabel.textContent = phase115
|| (total > 0 ? `Loading assets… ${loaded}/${total}` : "Loading assets…");116
}117
}118
96
function renderCharacters (characters)119
function renderCharacters (characters)97
{120
{98
characterList.innerHTML = "";121
characterList.innerHTML = "";@@ -898,6 +921,9 @@ function startPlay (payload)898
scene = new Scene(0, 0, window.innerWidth, window.innerHeight);921
scene = new Scene(0, 0, window.innerWidth, window.innerHeight);899
game.loadScene(scene);922
game.loadScene(scene);900
useNearestNeighbour(scene, game.images);923
useNearestNeighbour(scene, game.images);924
}925
if (!view)926
{901
view = new WorldView(game, scene, catalog);927
view = new WorldView(game, scene, catalog);902
graphicsSettingsUi?.apply();928
graphicsSettingsUi?.apply();903
const ticker = new GameObject(0, 0, null, 10);929
const ticker = new GameObject(0, 0, null, 10);@@ -1011,9 +1037,24 @@ async function main ()1011
return;1037
return;1012
}1038
}1013
1039
1040
setAssetLoading(true, { phase: "Loading catalog…" });1014
catalog = await loadSpriteCatalog();1041
catalog = await loadSpriteCatalog();1015
await preloadCatalogImages(game, catalog);1042
const assetTotal = playImagesFromCatalog(catalog).length;1043
setAssetLoading(true, { loaded: 0, total: assetTotal, phase: "Loading assets…" });1044
await preloadCatalogImages(game, catalog, {1045
onProgress ({ loaded, total })1046
{1047
setAssetLoading(true, { loaded, total });1048
}1049
});1016
applySpriteSheets(game.images, catalog);1050
applySpriteSheets(game.images, catalog);1051
if (!scene)1052
{1053
scene = new Scene(0, 0, window.innerWidth, window.innerHeight);1054
game.loadScene(scene);1055
}1056
setAssetLoading(false);1057
statusEl.textContent = "Connecting…";1017
createHairControls = bindHairControls({1058
createHairControls = bindHairControls({1018
root: document.getElementById("create-hair"),1059
root: document.getElementById("create-hair"),1019
resolveSpriteUrl (name)1060
resolveSpriteUrl (name)@@ -1187,6 +1228,7 @@ async function main ()1187
MessageType1228
MessageType1188
});1229
});1189
game.startGame();1230
game.startGame();1231
useNearestNeighbour(scene, game.images);1190
1232
1191
socket = new GameSocket(defaultSocketUrl(), (message) =>1233
socket = new GameSocket(defaultSocketUrl(), (message) =>1192
{1234
{@@ -27,13 +27,26 @@ export async function loadSpriteCatalog ()
27
27
* Load catalog images without aborting the whole client when one file is missing.
28
28
* Failed entries are logged and omitted from `game.images`.
29
29
*/
30
export async function preloadCatalogImages (game, catalog)
30
export async function preloadCatalogImages (game, catalog, { onProgress } = {})
31
31
{
32
const images = playImagesFromCatalog(catalog);
33
const total = images.length;
34
let loaded = 0;
32
35
const failed = [];
33
await Promise.all(playImagesFromCatalog(catalog).map((imageData) => loadOneImage(game, imageData).catch((error) =>
36
const report = (name) =>
37
{
38
loaded += 1;
39
onProgress?.({ loaded, total, name });
40
};
41
await Promise.all(images.map((imageData) => loadOneImage(game, imageData).then((sprite) =>
42
{
43
report(imageData.name);
44
return sprite;
45
}).catch((error) =>
34
46
{
35
47
console.error(error.message ?? error);
36
48
failed.push({ name: imageData.name, url: imageData.url });
49
report(imageData.name);
37
50
})));
38
51
if (failed.length)
39
52
{ console.warn(`Skipped ${failed.length} missing/broken sprite(s).`, failed.map((entry) => entry.name)); }
@@ -27,13 +27,26 @@ export async function loadSpriteCatalog ()27
* Load catalog images without aborting the whole client when one file is missing.27
* Load catalog images without aborting the whole client when one file is missing.28
* Failed entries are logged and omitted from `game.images`.28
* Failed entries are logged and omitted from `game.images`.29
*/29
*/30
export async function preloadCatalogImages (game, catalog)30
export async function preloadCatalogImages (game, catalog, { onProgress } = {})31
{31
{32
const images = playImagesFromCatalog(catalog);33
const total = images.length;34
let loaded = 0;32
const failed = [];35
const failed = [];33
await Promise.all(playImagesFromCatalog(catalog).map((imageData) => loadOneImage(game, imageData).catch((error) =>36
const report = (name) =>37
{38
loaded += 1;39
onProgress?.({ loaded, total, name });40
};41
await Promise.all(images.map((imageData) => loadOneImage(game, imageData).then((sprite) =>42
{43
report(imageData.name);44
return sprite;45
}).catch((error) =>34
{46
{35
console.error(error.message ?? error);47
console.error(error.message ?? error);36
failed.push({ name: imageData.name, url: imageData.url });48
failed.push({ name: imageData.name, url: imageData.url });49
report(imageData.name);37
})));50
})));38
if (failed.length)51
if (failed.length)39
{ console.warn(`Skipped ${failed.length} missing/broken sprite(s).`, failed.map((entry) => entry.name)); }52
{ console.warn(`Skipped ${failed.length} missing/broken sprite(s).`, failed.map((entry) => entry.name)); }@@ -369,6 +369,12 @@ export class WorldView
369
369
{
370
370
#chunkRebuildKeys = new Set();
371
371
#chunkRebuildRaf = 0;
372
#edgesDirty = false;
373
#CHUNK_REBUILD_BATCH = 2;
374
#pendingTextureCanvases = [];
375
#pendingTextureCanvasSet = new Set();
376
#textureWarmRaf = 0;
377
#TEXTURE_WARM_BATCH = 2;
372
378
373
379
constructor(game, scene, catalog = { grounds: {}, blocks: {} })
374
380
{
@@ -531,13 +537,13 @@ export class WorldView
531
537
{ return; }
532
538
const key = `${snapshot.chunkX},${snapshot.chunkY}`;
533
539
this.chunks.set(key, snapshot);
534
this.#rebuildChunk(snapshot);
540
this.#scheduleChunkRebuild(snapshot);
535
541
this.#redrawPreview();
536
542
this.#refreshWaterCoastsNear(snapshot.chunkX, snapshot.chunkY);
537
543
if (snapshot.staticOnly)
538
544
{
539
545
this.#stripChunkDynamic(snapshot.chunkX, snapshot.chunkY);
540
this.#rebuildAllEdges();
546
this.#scheduleEdgeRebuild();
541
547
return;
542
548
}
543
549
for (const entity of snapshot.entities ?? [])
@@ -549,7 +555,7 @@ export class WorldView
549
555
}
550
556
for (const item of snapshot.groundItems ?? [])
551
557
{ this.upsertGroundItem(item); }
552
this.#rebuildAllEdges();
558
this.#scheduleEdgeRebuild();
553
559
}
554
560
555
561
setLocalEntity (entityId, tileX, tileY, gait, sex, firstName = "", lastName = "", characterId = null, layers = null, health = null, maxHealth = null)
@@ -2492,20 +2498,47 @@ export class WorldView
2492
2498
if (!snapshot)
2493
2499
{ return; }
2494
2500
this.#chunkRebuildKeys.add(`${snapshot.chunkX},${snapshot.chunkY}`);
2501
this.#ensureChunkFlushScheduled();
2502
}
2503
2504
#scheduleEdgeRebuild ()
2505
{
2506
this.#edgesDirty = true;
2507
this.#ensureChunkFlushScheduled();
2508
}
2509
2510
#ensureChunkFlushScheduled ()
2511
{
2495
2512
if (this.#chunkRebuildRaf)
2496
2513
{ return; }
2497
this.#chunkRebuildRaf = requestAnimationFrame(() =>
2514
this.#chunkRebuildRaf = requestAnimationFrame(() => this.#flushChunkWork());
2515
}
2516
2517
#flushChunkWork ()
2518
{
2519
this.#chunkRebuildRaf = 0;
2520
const keys = [...this.#chunkRebuildKeys];
2521
const batch = keys.slice(0, this.#CHUNK_REBUILD_BATCH);
2522
const rest = keys.slice(this.#CHUNK_REBUILD_BATCH);
2523
this.#chunkRebuildKeys.clear();
2524
for (const key of rest)
2525
{ this.#chunkRebuildKeys.add(key); }
2526
for (const key of batch)
2498
2527
{
2499
this.#chunkRebuildRaf = 0;
2500
const keys = [...this.#chunkRebuildKeys];
2501
this.#chunkRebuildKeys.clear();
2502
for (const key of keys)
2503
{
2504
const snap = this.chunks.get(key);
2505
if (snap)
2506
{ this.#rebuildChunk(snap); }
2507
}
2508
});
2528
const snap = this.chunks.get(key);
2529
if (snap)
2530
{ this.#rebuildChunk(snap); }
2531
}
2532
if (this.#chunkRebuildKeys.size)
2533
{
2534
this.#ensureChunkFlushScheduled();
2535
return;
2536
}
2537
if (this.#edgesDirty)
2538
{
2539
this.#rebuildAllEdges();
2540
this.#edgesDirty = false;
2541
}
2509
2542
}
2510
2543
2511
2544
#previewEqual (a, b)
@@ -2611,6 +2644,47 @@ export class WorldView
2611
2644
baked.chunkX = snapshot.chunkX;
2612
2645
baked.chunkY = snapshot.chunkY;
2613
2646
this.#layoutBakedChunk(snapshot);
2647
this.#queueBakedChunkTextures(baked);
2648
}
2649
2650
#queueBakedChunkTextures (baked)
2651
{
2652
if (!baked)
2653
{ return; }
2654
const canvases = [
2655
baked.groundCanvas,
2656
...(baked.blockCanvases ?? []),
2657
baked.bloomCanvas,
2658
baked.lightmapCanvas
2659
];
2660
for (const canvas of canvases)
2661
{
2662
if (!canvas || this.#pendingTextureCanvasSet.has(canvas))
2663
{ continue; }
2664
this.#pendingTextureCanvasSet.add(canvas);
2665
this.#pendingTextureCanvases.push(canvas);
2666
}
2667
this.#scheduleTextureWarm();
2668
}
2669
2670
#scheduleTextureWarm ()
2671
{
2672
if (this.#textureWarmRaf)
2673
{ return; }
2674
this.#textureWarmRaf = requestAnimationFrame(() => this.#flushTextureWarm());
2675
}
2676
2677
#flushTextureWarm ()
2678
{
2679
this.#textureWarmRaf = 0;
2680
const batch = this.#pendingTextureCanvases.splice(0, this.#TEXTURE_WARM_BATCH);
2681
for (const canvas of batch)
2682
{
2683
this.#pendingTextureCanvasSet.delete(canvas);
2684
setNearestFilter(this.scene, canvas);
2685
}
2686
if (this.#pendingTextureCanvases.length)
2687
{ this.#scheduleTextureWarm(); }
2614
2688
}
2615
2689
2616
2690
#applyAtlasLighting (object, lightmapImage, lightRow)
@@ -2657,11 +2731,6 @@ export class WorldView
2657
2731
baked.bloomObject.layer = ySortLayer(top + chunkPx, SORT_BLOCK);
2658
2732
baked.bloomObject.renderer.layer = RENDER_LAYER_BLOOM;
2659
2733
this.#markSortDirty();
2660
setNearestFilter(this.scene, baked.groundCanvas);
2661
for (const canvas of baked.blockCanvases)
2662
{ setNearestFilter(this.scene, canvas); }
2663
setNearestFilter(this.scene, baked.bloomCanvas);
2664
setNearestFilter(this.scene, baked.lightmapCanvas);
2665
2734
}
2666
2735
2667
2736
#destroyBakedChunk (key)
@@ -369,6 +369,12 @@ export class WorldView369
{369
{370
#chunkRebuildKeys = new Set();370
#chunkRebuildKeys = new Set();371
#chunkRebuildRaf = 0;371
#chunkRebuildRaf = 0;372
#edgesDirty = false;373
#CHUNK_REBUILD_BATCH = 2;374
#pendingTextureCanvases = [];375
#pendingTextureCanvasSet = new Set();376
#textureWarmRaf = 0;377
#TEXTURE_WARM_BATCH = 2;372
378
373
constructor(game, scene, catalog = { grounds: {}, blocks: {} })379
constructor(game, scene, catalog = { grounds: {}, blocks: {} })374
{380
{@@ -531,13 +537,13 @@ export class WorldView531
{ return; }537
{ return; }532
const key = `${snapshot.chunkX},${snapshot.chunkY}`;538
const key = `${snapshot.chunkX},${snapshot.chunkY}`;533
this.chunks.set(key, snapshot);539
this.chunks.set(key, snapshot);534
this.#rebuildChunk(snapshot);540
this.#scheduleChunkRebuild(snapshot);535
this.#redrawPreview();541
this.#redrawPreview();536
this.#refreshWaterCoastsNear(snapshot.chunkX, snapshot.chunkY);542
this.#refreshWaterCoastsNear(snapshot.chunkX, snapshot.chunkY);537
if (snapshot.staticOnly)543
if (snapshot.staticOnly)538
{544
{539
this.#stripChunkDynamic(snapshot.chunkX, snapshot.chunkY);545
this.#stripChunkDynamic(snapshot.chunkX, snapshot.chunkY);540
this.#rebuildAllEdges();546
this.#scheduleEdgeRebuild();541
return;547
return;542
}548
}543
for (const entity of snapshot.entities ?? [])549
for (const entity of snapshot.entities ?? [])@@ -549,7 +555,7 @@ export class WorldView549
}555
}550
for (const item of snapshot.groundItems ?? [])556
for (const item of snapshot.groundItems ?? [])551
{ this.upsertGroundItem(item); }557
{ this.upsertGroundItem(item); }552
this.#rebuildAllEdges();558
this.#scheduleEdgeRebuild();553
}559
}554
560
555
setLocalEntity (entityId, tileX, tileY, gait, sex, firstName = "", lastName = "", characterId = null, layers = null, health = null, maxHealth = null)561
setLocalEntity (entityId, tileX, tileY, gait, sex, firstName = "", lastName = "", characterId = null, layers = null, health = null, maxHealth = null)@@ -2492,20 +2498,47 @@ export class WorldView2492
if (!snapshot)2498
if (!snapshot)2493
{ return; }2499
{ return; }2494
this.#chunkRebuildKeys.add(`${snapshot.chunkX},${snapshot.chunkY}`);2500
this.#chunkRebuildKeys.add(`${snapshot.chunkX},${snapshot.chunkY}`);2501
this.#ensureChunkFlushScheduled();2502
}2503
2504
#scheduleEdgeRebuild ()2505
{2506
this.#edgesDirty = true;2507
this.#ensureChunkFlushScheduled();2508
}2509
2510
#ensureChunkFlushScheduled ()2511
{2495
if (this.#chunkRebuildRaf)2512
if (this.#chunkRebuildRaf)2496
{ return; }2513
{ return; }2497
this.#chunkRebuildRaf = requestAnimationFrame(() =>2514
this.#chunkRebuildRaf = requestAnimationFrame(() => this.#flushChunkWork());2515
}2516
2517
#flushChunkWork ()2518
{2519
this.#chunkRebuildRaf = 0;2520
const keys = [...this.#chunkRebuildKeys];2521
const batch = keys.slice(0, this.#CHUNK_REBUILD_BATCH);2522
const rest = keys.slice(this.#CHUNK_REBUILD_BATCH);2523
this.#chunkRebuildKeys.clear();2524
for (const key of rest)2525
{ this.#chunkRebuildKeys.add(key); }2526
for (const key of batch)2498
{2527
{2499
this.#chunkRebuildRaf = 0;2528
const snap = this.chunks.get(key);2500
const keys = [...this.#chunkRebuildKeys];2529
if (snap)2501
this.#chunkRebuildKeys.clear();2530
{ this.#rebuildChunk(snap); }2502
for (const key of keys)2531
}2503
{2532
if (this.#chunkRebuildKeys.size)2504
const snap = this.chunks.get(key);2533
{2505
if (snap)2534
this.#ensureChunkFlushScheduled();2506
{ this.#rebuildChunk(snap); }2535
return;2507
}2536
}2508
});2537
if (this.#edgesDirty)2538
{2539
this.#rebuildAllEdges();2540
this.#edgesDirty = false;2541
}2509
}2542
}2510
2543
2511
#previewEqual (a, b)2544
#previewEqual (a, b)@@ -2611,6 +2644,47 @@ export class WorldView2611
baked.chunkX = snapshot.chunkX;2644
baked.chunkX = snapshot.chunkX;2612
baked.chunkY = snapshot.chunkY;2645
baked.chunkY = snapshot.chunkY;2613
this.#layoutBakedChunk(snapshot);2646
this.#layoutBakedChunk(snapshot);2647
this.#queueBakedChunkTextures(baked);2648
}2649
2650
#queueBakedChunkTextures (baked)2651
{2652
if (!baked)2653
{ return; }2654
const canvases = [2655
baked.groundCanvas,2656
...(baked.blockCanvases ?? []),2657
baked.bloomCanvas,2658
baked.lightmapCanvas2659
];2660
for (const canvas of canvases)2661
{2662
if (!canvas || this.#pendingTextureCanvasSet.has(canvas))2663
{ continue; }2664
this.#pendingTextureCanvasSet.add(canvas);2665
this.#pendingTextureCanvases.push(canvas);2666
}2667
this.#scheduleTextureWarm();2668
}2669
2670
#scheduleTextureWarm ()2671
{2672
if (this.#textureWarmRaf)2673
{ return; }2674
this.#textureWarmRaf = requestAnimationFrame(() => this.#flushTextureWarm());2675
}2676
2677
#flushTextureWarm ()2678
{2679
this.#textureWarmRaf = 0;2680
const batch = this.#pendingTextureCanvases.splice(0, this.#TEXTURE_WARM_BATCH);2681
for (const canvas of batch)2682
{2683
this.#pendingTextureCanvasSet.delete(canvas);2684
setNearestFilter(this.scene, canvas);2685
}2686
if (this.#pendingTextureCanvases.length)2687
{ this.#scheduleTextureWarm(); }2614
}2688
}2615
2689
2616
#applyAtlasLighting (object, lightmapImage, lightRow)2690
#applyAtlasLighting (object, lightmapImage, lightRow)@@ -2657,11 +2731,6 @@ export class WorldView2657
baked.bloomObject.layer = ySortLayer(top + chunkPx, SORT_BLOCK);2731
baked.bloomObject.layer = ySortLayer(top + chunkPx, SORT_BLOCK);2658
baked.bloomObject.renderer.layer = RENDER_LAYER_BLOOM;2732
baked.bloomObject.renderer.layer = RENDER_LAYER_BLOOM;2659
this.#markSortDirty();2733
this.#markSortDirty();2660
setNearestFilter(this.scene, baked.groundCanvas);2661
for (const canvas of baked.blockCanvases)2662
{ setNearestFilter(this.scene, canvas); }2663
setNearestFilter(this.scene, baked.bloomCanvas);2664
setNearestFilter(this.scene, baked.lightmapCanvas);2665
}2734
}2666
2735
2667
#destroyBakedChunk (key)2736
#destroyBakedChunk (key)@@ -1005,8 +1005,8 @@ label { display: block; margin: 0.4rem 0; }
1005
1005
top: 18vh;
1006
1006
left: 50%;
1007
1007
transform: translateX(-50%);
1008
width: min(380px, 90vw);
1009
max-height: 60vh;
1008
width: min(420px, 92vw);
1009
max-height: 70vh;
1010
1010
display: flex;
1011
1011
flex-direction: column;
1012
1012
background: #161a22;
@@ -1048,6 +1048,34 @@ label { display: block; margin: 0.4rem 0; }
1048
1048
.shop-item-search-row {
1049
1049
text-align: left;
1050
1050
padding: 0.4rem 0.5rem;
1051
display: flex;
1052
flex-direction: column;
1053
align-items: flex-start;
1054
gap: 0.1rem;
1055
}
1056
1057
.shop-item-search-row-name {
1058
font: inherit;
1059
color: inherit;
1060
}
1061
1062
.shop-item-search-row-key {
1063
font-size: 0.78rem;
1064
color: #9aa3b2;
1065
}
1066
1067
.shop-item-search-footer {
1068
display: flex;
1069
align-items: center;
1070
justify-content: space-between;
1071
gap: 0.5rem;
1072
flex-shrink: 0;
1073
}
1074
1075
#shop-item-search-page {
1076
flex: 1;
1077
text-align: center;
1078
font-variant-numeric: tabular-nums;
1051
1079
}
1052
1080
1053
1081
#tile-tooltip {
@@ -1005,8 +1005,8 @@ label { display: block; margin: 0.4rem 0; }1005
top: 18vh;1005
top: 18vh;1006
left: 50%;1006
left: 50%;1007
transform: translateX(-50%);1007
transform: translateX(-50%);1008
width: min(380px, 90vw);1008
width: min(420px, 92vw);1009
max-height: 60vh;1009
max-height: 70vh;1010
display: flex;1010
display: flex;1011
flex-direction: column;1011
flex-direction: column;1012
background: #161a22;1012
background: #161a22;@@ -1048,6 +1048,34 @@ label { display: block; margin: 0.4rem 0; }1048
.shop-item-search-row {1048
.shop-item-search-row {1049
text-align: left;1049
text-align: left;1050
padding: 0.4rem 0.5rem;1050
padding: 0.4rem 0.5rem;1051
display: flex;1052
flex-direction: column;1053
align-items: flex-start;1054
gap: 0.1rem;1055
}1056
1057
.shop-item-search-row-name {1058
font: inherit;1059
color: inherit;1060
}1061
1062
.shop-item-search-row-key {1063
font-size: 0.78rem;1064
color: #9aa3b2;1065
}1066
1067
.shop-item-search-footer {1068
display: flex;1069
align-items: center;1070
justify-content: space-between;1071
gap: 0.5rem;1072
flex-shrink: 0;1073
}1074
1075
#shop-item-search-page {1076
flex: 1;1077
text-align: center;1078
font-variant-numeric: tabular-nums;1051
}1079
}1052
1080
1053
#tile-tooltip {1081
#tile-tooltip {@@ -5,7 +5,8 @@
5
5
color: #e8e4d9;
6
6
}
7
7
8
html, body {
8
html,
9
body {
9
10
margin: 0;
10
11
height: 100%;
11
12
overflow: hidden;
@@ -33,7 +34,8 @@ html, body {
33
34
background: #101216;
34
35
}
35
36
36
#overlay[hidden], #hud[hidden] {
37
#overlay[hidden],
38
#hud[hidden] {
37
39
display: none !important;
38
40
}
39
41
@@ -98,7 +100,7 @@ html, body {
98
100
color: #9aa3b2;
99
101
}
100
102
101
.settings-group + .settings-group {
103
.settings-group+.settings-group {
102
104
margin-top: 0.85rem;
103
105
}
104
106
@@ -252,6 +254,7 @@ html, body {
252
254
margin: 0.35rem 0 0.75rem;
253
255
border-bottom: 1px solid #2c3340;
254
256
}
257
255
258
.create-tab {
256
259
flex: 1 1 0;
257
260
border: 0;
@@ -260,17 +263,20 @@ html, body {
260
263
color: #9aa3b2;
261
264
padding: 0.5rem 0.4rem;
262
265
}
266
263
267
.create-tab.active {
264
268
color: #e8e4d9;
265
269
background: #222833;
266
270
box-shadow: inset 0 -2px 0 #6a8cbf;
267
271
}
272
268
273
.create-clothing {
269
274
display: grid;
270
275
grid-template-columns: 88px 1fr;
271
276
gap: 0.65rem 0.75rem;
272
277
align-items: start;
273
278
}
279
274
280
.create-clothing canvas {
275
281
width: 80px;
276
282
height: 96px;
@@ -278,44 +284,52 @@ html, body {
278
284
background: #0e1116;
279
285
border: 1px solid #2c3340;
280
286
}
287
281
288
.create-clothing-fields {
282
289
display: flex;
283
290
flex-direction: column;
284
291
gap: 0.35rem;
285
292
min-width: 0;
286
293
}
294
287
295
.create-dye-fieldset {
288
296
margin: 0.35rem 0 0;
289
297
padding: 0.45rem 0.55rem 0.55rem;
290
298
border: 1px solid #2c3340;
291
299
border-radius: 0.25rem;
292
300
}
301
293
302
.create-dye-fieldset legend {
294
303
padding: 0 0.25rem;
295
304
color: #9aa3b2;
296
305
font-size: 0.85rem;
297
306
}
307
298
308
.create-dye-fieldset label {
299
309
margin: 0.25rem 0;
300
310
}
311
301
312
.create-dye-fieldset input[type="range"] {
302
313
flex: 1 1 auto;
303
314
min-width: 0;
304
315
}
305
316
306
#create-panel #create-form > button[type="submit"] {
317
#create-panel #create-form>button[type="submit"] {
307
318
width: 100%;
308
319
margin-top: 0.75rem;
309
320
}
310
321
311
label, .character-row {
322
label,
323
.character-row {
312
324
display: flex;
313
325
gap: 0.5rem;
314
326
align-items: center;
315
327
margin: 0.5rem 0;
316
328
}
317
329
318
input, select, button {
330
input,
331
select,
332
button {
319
333
font: inherit;
320
334
background: #101216;
321
335
color: inherit;
@@ -327,9 +341,50 @@ button {
327
341
cursor: pointer;
328
342
}
329
343
330
.error { color: #f0a0a0; min-height: 1.2em; }
331
.hint { color: #9aa3b2; font-size: 0.9rem; }
332
a { color: #d4c48a; }
344
.error {
345
color: #f0a0a0;
346
min-height: 1.2em;
347
}
348
349
.hint {
350
color: #9aa3b2;
351
font-size: 0.9rem;
352
}
353
354
.asset-load {
355
width: min(22rem, 100%);
356
margin: 0.75rem 0 0.5rem;
357
}
358
359
.asset-load progress {
360
display: block;
361
width: 100%;
362
height: 0.55rem;
363
}
364
365
.asset-load progress::-webkit-progress-bar {
366
background: #1a1f28;
367
border-radius: 0.2rem;
368
}
369
370
.asset-load progress::-webkit-progress-value {
371
background: #d4c48a;
372
border-radius: 0.2rem;
373
}
374
375
.asset-load progress::-moz-progress-bar {
376
background: #d4c48a;
377
border-radius: 0.2rem;
378
}
379
380
#asset-load-label {
381
margin: 0.45rem 0 0;
382
text-align: center;
383
}
384
385
a {
386
color: #d4c48a;
387
}
333
388
334
389
.hair-controls {
335
390
display: grid;
@@ -717,7 +772,8 @@ a { color: #d4c48a; }
717
772
cursor: not-allowed;
718
773
}
719
774
720
#bag-panel, #bank-panel {
775
#bag-panel,
776
#bank-panel {
721
777
position: fixed;
722
778
z-index: 5;
723
779
top: 48px;
@@ -1094,6 +1150,7 @@ a { color: #d4c48a; }
1094
1150
padding-bottom: 0.5rem;
1095
1151
border-bottom: 1px solid #2c3340;
1096
1152
}
1153
1097
1154
.craft-material-controls[hidden] {
1098
1155
display: none !important;
1099
1156
}
@@ -1121,6 +1178,7 @@ a { color: #d4c48a; }
1121
1178
font-size: 0.85rem;
1122
1179
color: #c8c2b4;
1123
1180
}
1181
1124
1182
.craft-tailor-dye[hidden] {
1125
1183
display: none !important;
1126
1184
}
@@ -1342,7 +1400,8 @@ a { color: #d4c48a; }
1342
1400
line-height: 1.45;
1343
1401
}
1344
1402
1345
#friends-panel h2, #friends-panel h3 {
1403
#friends-panel h2,
1404
#friends-panel h3 {
1346
1405
margin: 0.4rem 0;
1347
1406
font-size: 0.95rem;
1348
1407
}
@@ -2197,4 +2256,4 @@ a { color: #d4c48a; }
2197
2256
#quests-list-backdrop[hidden],
2198
2257
#quests-detail-backdrop[hidden] {
2199
2258
display: none !important;
2200
}
2259
}
@@ -5,7 +5,8 @@5
color: #e8e4d9;5
color: #e8e4d9;6
}6
}7
7
8
html, body {8
html,9
body {9
margin: 0;10
margin: 0;10
height: 100%;11
height: 100%;11
overflow: hidden;12
overflow: hidden;@@ -33,7 +34,8 @@ html, body {33
background: #101216;34
background: #101216;34
}35
}35
36
36
#overlay[hidden], #hud[hidden] {37
#overlay[hidden],38
#hud[hidden] {37
display: none !important;39
display: none !important;38
}40
}39
41
@@ -98,7 +100,7 @@ html, body {98
color: #9aa3b2;100
color: #9aa3b2;99
}101
}100
102
101
.settings-group + .settings-group {103
.settings-group+.settings-group {102
margin-top: 0.85rem;104
margin-top: 0.85rem;103
}105
}104
106
@@ -252,6 +254,7 @@ html, body {252
margin: 0.35rem 0 0.75rem;254
margin: 0.35rem 0 0.75rem;253
border-bottom: 1px solid #2c3340;255
border-bottom: 1px solid #2c3340;254
}256
}257
255
.create-tab {258
.create-tab {256
flex: 1 1 0;259
flex: 1 1 0;257
border: 0;260
border: 0;@@ -260,17 +263,20 @@ html, body {260
color: #9aa3b2;263
color: #9aa3b2;261
padding: 0.5rem 0.4rem;264
padding: 0.5rem 0.4rem;262
}265
}266
263
.create-tab.active {267
.create-tab.active {264
color: #e8e4d9;268
color: #e8e4d9;265
background: #222833;269
background: #222833;266
box-shadow: inset 0 -2px 0 #6a8cbf;270
box-shadow: inset 0 -2px 0 #6a8cbf;267
}271
}272
268
.create-clothing {273
.create-clothing {269
display: grid;274
display: grid;270
grid-template-columns: 88px 1fr;275
grid-template-columns: 88px 1fr;271
gap: 0.65rem 0.75rem;276
gap: 0.65rem 0.75rem;272
align-items: start;277
align-items: start;273
}278
}279
274
.create-clothing canvas {280
.create-clothing canvas {275
width: 80px;281
width: 80px;276
height: 96px;282
height: 96px;@@ -278,44 +284,52 @@ html, body {278
background: #0e1116;284
background: #0e1116;279
border: 1px solid #2c3340;285
border: 1px solid #2c3340;280
}286
}287
281
.create-clothing-fields {288
.create-clothing-fields {282
display: flex;289
display: flex;283
flex-direction: column;290
flex-direction: column;284
gap: 0.35rem;291
gap: 0.35rem;285
min-width: 0;292
min-width: 0;286
}293
}294
287
.create-dye-fieldset {295
.create-dye-fieldset {288
margin: 0.35rem 0 0;296
margin: 0.35rem 0 0;289
padding: 0.45rem 0.55rem 0.55rem;297
padding: 0.45rem 0.55rem 0.55rem;290
border: 1px solid #2c3340;298
border: 1px solid #2c3340;291
border-radius: 0.25rem;299
border-radius: 0.25rem;292
}300
}301
293
.create-dye-fieldset legend {302
.create-dye-fieldset legend {294
padding: 0 0.25rem;303
padding: 0 0.25rem;295
color: #9aa3b2;304
color: #9aa3b2;296
font-size: 0.85rem;305
font-size: 0.85rem;297
}306
}307
298
.create-dye-fieldset label {308
.create-dye-fieldset label {299
margin: 0.25rem 0;309
margin: 0.25rem 0;300
}310
}311
301
.create-dye-fieldset input[type="range"] {312
.create-dye-fieldset input[type="range"] {302
flex: 1 1 auto;313
flex: 1 1 auto;303
min-width: 0;314
min-width: 0;304
}315
}305
316
306
#create-panel #create-form > button[type="submit"] {317
#create-panel #create-form>button[type="submit"] {307
width: 100%;318
width: 100%;308
margin-top: 0.75rem;319
margin-top: 0.75rem;309
}320
}310
321
311
label, .character-row {322
label,323
.character-row {312
display: flex;324
display: flex;313
gap: 0.5rem;325
gap: 0.5rem;314
align-items: center;326
align-items: center;315
margin: 0.5rem 0;327
margin: 0.5rem 0;316
}328
}317
329
318
input, select, button {330
input,331
select,332
button {319
font: inherit;333
font: inherit;320
background: #101216;334
background: #101216;321
color: inherit;335
color: inherit;@@ -327,9 +341,50 @@ button {327
cursor: pointer;341
cursor: pointer;328
}342
}329
343
330
.error { color: #f0a0a0; min-height: 1.2em; }344
.error {331
.hint { color: #9aa3b2; font-size: 0.9rem; }345
color: #f0a0a0;332
a { color: #d4c48a; }346
min-height: 1.2em;347
}348
349
.hint {350
color: #9aa3b2;351
font-size: 0.9rem;352
}353
354
.asset-load {355
width: min(22rem, 100%);356
margin: 0.75rem 0 0.5rem;357
}358
359
.asset-load progress {360
display: block;361
width: 100%;362
height: 0.55rem;363
}364
365
.asset-load progress::-webkit-progress-bar {366
background: #1a1f28;367
border-radius: 0.2rem;368
}369
370
.asset-load progress::-webkit-progress-value {371
background: #d4c48a;372
border-radius: 0.2rem;373
}374
375
.asset-load progress::-moz-progress-bar {376
background: #d4c48a;377
border-radius: 0.2rem;378
}379
380
#asset-load-label {381
margin: 0.45rem 0 0;382
text-align: center;383
}384
385
a {386
color: #d4c48a;387
}333
388
334
.hair-controls {389
.hair-controls {335
display: grid;390
display: grid;@@ -717,7 +772,8 @@ a { color: #d4c48a; }717
cursor: not-allowed;772
cursor: not-allowed;718
}773
}719
774
720
#bag-panel, #bank-panel {775
#bag-panel,776
#bank-panel {721
position: fixed;777
position: fixed;722
z-index: 5;778
z-index: 5;723
top: 48px;779
top: 48px;@@ -1094,6 +1150,7 @@ a { color: #d4c48a; }1094
padding-bottom: 0.5rem;1150
padding-bottom: 0.5rem;1095
border-bottom: 1px solid #2c3340;1151
border-bottom: 1px solid #2c3340;1096
}1152
}1153
1097
.craft-material-controls[hidden] {1154
.craft-material-controls[hidden] {1098
display: none !important;1155
display: none !important;1099
}1156
}@@ -1121,6 +1178,7 @@ a { color: #d4c48a; }1121
font-size: 0.85rem;1178
font-size: 0.85rem;1122
color: #c8c2b4;1179
color: #c8c2b4;1123
}1180
}1181
1124
.craft-tailor-dye[hidden] {1182
.craft-tailor-dye[hidden] {1125
display: none !important;1183
display: none !important;1126
}1184
}@@ -1342,7 +1400,8 @@ a { color: #d4c48a; }1342
line-height: 1.45;1400
line-height: 1.45;1343
}1401
}1344
1402
1345
#friends-panel h2, #friends-panel h3 {1403
#friends-panel h2,1404
#friends-panel h3 {1346
margin: 0.4rem 0;1405
margin: 0.4rem 0;1347
font-size: 0.95rem;1406
font-size: 0.95rem;1348
}1407
}@@ -2197,4 +2256,4 @@ a { color: #d4c48a; }2197
#quests-list-backdrop[hidden],2256
#quests-list-backdrop[hidden],2198
#quests-detail-backdrop[hidden] {2257
#quests-detail-backdrop[hidden] {2199
display: none !important;2258
display: none !important;2200
}2259
}@@ -20,7 +20,6 @@ import {
20
20
takeFromSlot
21
21
} from "../../../shared/items/inventory.js";
22
22
import {
23
canSellInNpcShop,
24
23
canPlayerSellToNpc,
25
24
resolveShopSellQuote,
26
25
shopUnitPrice,
@@ -299,8 +298,6 @@ function shopStockView (world, shop, now)
299
298
for (const line of shop.catalog ?? [])
300
299
{
301
300
const itemId = line.itemId | 0;
302
if (!canSellInNpcShop(itemId))
303
{ continue; }
304
301
const def = itemDefinition(itemId);
305
302
if (!def)
306
303
{ continue; }
@@ -323,7 +320,7 @@ function shopStockView (world, shop, now)
323
320
{
324
321
const itemId = key | 0;
325
322
const available = boughtAvailable(shop, itemId);
326
if (available <= 0 || !canSellInNpcShop(itemId))
323
if (available <= 0)
327
324
{ continue; }
328
325
const def = itemDefinition(itemId);
329
326
if (!def)
@@ -432,8 +429,13 @@ export function buyFromShop (world, sessionId, characterId, npcEntityId, itemId,
432
429
ensureShopRestocked(shop, now);
433
430
const listing = parseListing(listingId, itemId, source);
434
431
const buyItemId = listing.itemId;
435
if (!canSellInNpcShop(buyItemId))
436
{ throw userError("That item cannot be sold here."); }
432
if (listing.source === "stock")
433
{
434
if (!catalogLine(shop, buyItemId))
435
{ throw userError("That item cannot be sold here."); }
436
}
437
else if (boughtAvailable(shop, buyItemId) <= 0)
438
{ throw userError("Not enough stock."); }
437
439
438
440
const qty = Math.max(1, quantity | 0 || 1);
439
441
const def = itemDefinition(buyItemId);
@@ -20,7 +20,6 @@ import {20
takeFromSlot20
takeFromSlot21
} from "../../../shared/items/inventory.js";21
} from "../../../shared/items/inventory.js";22
import {22
import {23
canSellInNpcShop,24
canPlayerSellToNpc,23
canPlayerSellToNpc,25
resolveShopSellQuote,24
resolveShopSellQuote,26
shopUnitPrice,25
shopUnitPrice,@@ -299,8 +298,6 @@ function shopStockView (world, shop, now)299
for (const line of shop.catalog ?? [])298
for (const line of shop.catalog ?? [])300
{299
{301
const itemId = line.itemId | 0;300
const itemId = line.itemId | 0;302
if (!canSellInNpcShop(itemId))303
{ continue; }304
const def = itemDefinition(itemId);301
const def = itemDefinition(itemId);305
if (!def)302
if (!def)306
{ continue; }303
{ continue; }@@ -323,7 +320,7 @@ function shopStockView (world, shop, now)323
{320
{324
const itemId = key | 0;321
const itemId = key | 0;325
const available = boughtAvailable(shop, itemId);322
const available = boughtAvailable(shop, itemId);326
if (available <= 0 || !canSellInNpcShop(itemId))323
if (available <= 0)327
{ continue; }324
{ continue; }328
const def = itemDefinition(itemId);325
const def = itemDefinition(itemId);329
if (!def)326
if (!def)@@ -432,8 +429,13 @@ export function buyFromShop (world, sessionId, characterId, npcEntityId, itemId,432
ensureShopRestocked(shop, now);429
ensureShopRestocked(shop, now);433
const listing = parseListing(listingId, itemId, source);430
const listing = parseListing(listingId, itemId, source);434
const buyItemId = listing.itemId;431
const buyItemId = listing.itemId;435
if (!canSellInNpcShop(buyItemId))432
if (listing.source === "stock")436
{ throw userError("That item cannot be sold here."); }433
{434
if (!catalogLine(shop, buyItemId))435
{ throw userError("That item cannot be sold here."); }436
}437
else if (boughtAvailable(shop, buyItemId) <= 0)438
{ throw userError("Not enough stock."); }437
439
438
const qty = Math.max(1, quantity | 0 || 1);440
const qty = Math.max(1, quantity | 0 || 1);439
const def = itemDefinition(buyItemId);441
const def = itemDefinition(buyItemId);@@ -1,20 +1,22 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import {
4
shopUnitPrice,
5
undiscountedMarketValue,
6
undiscountedMarketCoins,
7
marketValueAsCoins,
8
canSellInNpcShop,
9
canPlayerSellToNpc,
10
shopBuyFromPlayerPrice,
11
shopBoughtResalePrice,
12
shopChequeAdminFee,
13
resolveShopSellQuote,
14
shopRestockDayKey,
15
lerp
16
} from "../../shared/shop/pricing.js";
17
import { ItemId } from "../../shared/definitions/items.js";
3
import
4
{
5
shopUnitPrice,
6
undiscountedMarketValue,
7
undiscountedMarketCoins,
8
marketValueAsCoins,
9
canSellInNpcShop,
10
canPlayerSellToNpc,
11
shopBuyFromPlayerPrice,
12
shopBoughtResalePrice,
13
shopChequeAdminFee,
14
resolveShopSellQuote,
15
shopRestockDayKey,
16
lerp
17
} from "../../shared/shop/pricing.js";
18
import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";
19
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
18
20
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";
19
21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
20
22
import { Component } from "../src/ecs/components.js";
@@ -35,6 +37,103 @@ function boughtQty (shop, itemId)
35
37
return raw.quantity | 0 || 0;
36
38
}
37
39
40
test("listAllItemPickerEntries includes paper and bronze gather tools", () =>
41
{
42
const ids = new Set(listAllItemPickerEntries().map((entry) => entry.itemId));
43
assert.ok(ids.has(ItemId.paper));
44
assert.ok(ids.has(CraftingItemId.bronzeAxe));
45
assert.ok(ids.has(CraftingItemId.bronzePickaxe));
46
assert.equal(canSellInNpcShop(ItemId.paper), false);
47
assert.equal(canSellInNpcShop(CraftingItemId.bronzeAxe), false);
48
});
49
50
test("buy paper from a shopkeeper with explicit catalog", () =>
51
{
52
const harness = makeSimulation({ workerCount: 1 });
53
try
54
{
55
const data = createEmptyChunkData();
56
data.open = true;
57
data.spawners = [{
58
localX: 9,
59
localY: 8,
60
config: {
61
mobTypeId: MobId.humanoid,
62
maxAlive: 1,
63
spawnRangeTiles: 1,
64
maxWanderRangeTiles: 1,
65
sex: "male",
66
displayName: "Stationer",
67
sells: [{ itemId: ItemId.paper, quantity: 0 }],
68
hiddenDiscount: 1,
69
equipment: { chest: ItemId.clothShirt }
70
}
71
}];
72
harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data));
73
harness.simulation.reloadWorld();
74
75
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
76
const funded = addCoinsToSlots(emptySlots(), 20);
77
assert.equal(funded.ok, true);
78
harness.stateDb.saveBag(character.character_id, {
79
inventory: funded.slots,
80
equipment: emptyEquipment(),
81
vault: [],
82
vaultReserved: []
83
});
84
const playerId = harness.simulation.spawnCharacter(1, character);
85
harness.simulation.step();
86
harness.advance(50);
87
harness.simulation.step();
88
89
const record = harness.simulation.entityRecord(playerId);
90
const worker = harness.simulation.workers[record.workerId];
91
let npcId = null;
92
for (const entity of worker.world.ecs.query(Component.shop, Component.creature))
93
{
94
if (entity.creature.mobTypeId === MobId.humanoid)
95
{
96
npcId = entity.entityId;
97
break;
98
}
99
}
100
assert.ok(npcId, "expected a humanoid shopkeeper");
101
102
const npcHandle = worker.world.ecs.handleOf(npcId);
103
const npcPos = worker.world.ecs.get(npcHandle, Component.position);
104
const playerHandle = worker.world.ecs.handleOf(playerId);
105
const playerPos = worker.world.ecs.get(playerHandle, Component.position);
106
playerPos.tileX = npcPos.tileX;
107
playerPos.tileY = npcPos.tileY;
108
109
harness.simulation.enqueue(1, {
110
type: "interact",
111
characterId: character.character_id,
112
targetEntityId: npcId
113
});
114
const open = harness.simulation.step();
115
const shopOpen = open.events.find((event) => event.type === "shop-open");
116
assert.ok(shopOpen, JSON.stringify(open.events));
117
assert.ok(shopOpen.stock.some((row) => row.itemId === ItemId.paper));
118
119
harness.simulation.enqueue(1, {
120
type: "buy-from-shop",
121
characterId: character.character_id,
122
npcEntityId: npcId,
123
itemId: ItemId.paper,
124
quantity: 1,
125
listingId: `stock:${ItemId.paper}`
126
});
127
const buy = harness.simulation.step();
128
assert.equal(buy.events.some((event) => event.type === "command-error"), false, JSON.stringify(buy.events));
129
const bag = harness.simulation.bagOf(playerId);
130
const paper = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.paper);
131
assert.ok(paper, JSON.stringify(bag.inventory));
132
}
133
finally
134
{ harness.close(); }
135
});
136
38
137
test("shop prices fall back to seedValue and apply hidden discount", () =>
39
138
{
40
139
assert.equal(undiscountedMarketValue(ItemId.copperOre), 5);
@@ -1,20 +1,22 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import {3
import4
shopUnitPrice,4
{5
undiscountedMarketValue,5
shopUnitPrice,6
undiscountedMarketCoins,6
undiscountedMarketValue,7
marketValueAsCoins,7
undiscountedMarketCoins,8
canSellInNpcShop,8
marketValueAsCoins,9
canPlayerSellToNpc,9
canSellInNpcShop,10
shopBuyFromPlayerPrice,10
canPlayerSellToNpc,11
shopBoughtResalePrice,11
shopBuyFromPlayerPrice,12
shopChequeAdminFee,12
shopBoughtResalePrice,13
resolveShopSellQuote,13
shopChequeAdminFee,14
shopRestockDayKey,14
resolveShopSellQuote,15
lerp15
shopRestockDayKey,16
} from "../../shared/shop/pricing.js";16
lerp17
import { ItemId } from "../../shared/definitions/items.js";17
} from "../../shared/shop/pricing.js";18
import { ItemId, listAllItemPickerEntries } from "../../shared/definitions/items.js";19
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";18
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";20
import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js";19
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";21
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";20
import { Component } from "../src/ecs/components.js";22
import { Component } from "../src/ecs/components.js";@@ -35,6 +37,103 @@ function boughtQty (shop, itemId)35
return raw.quantity | 0 || 0;37
return raw.quantity | 0 || 0;36
}38
}37
39
40
test("listAllItemPickerEntries includes paper and bronze gather tools", () =>41
{42
const ids = new Set(listAllItemPickerEntries().map((entry) => entry.itemId));43
assert.ok(ids.has(ItemId.paper));44
assert.ok(ids.has(CraftingItemId.bronzeAxe));45
assert.ok(ids.has(CraftingItemId.bronzePickaxe));46
assert.equal(canSellInNpcShop(ItemId.paper), false);47
assert.equal(canSellInNpcShop(CraftingItemId.bronzeAxe), false);48
});49
50
test("buy paper from a shopkeeper with explicit catalog", () =>51
{52
const harness = makeSimulation({ workerCount: 1 });53
try54
{55
const data = createEmptyChunkData();56
data.open = true;57
data.spawners = [{58
localX: 9,59
localY: 8,60
config: {61
mobTypeId: MobId.humanoid,62
maxAlive: 1,63
spawnRangeTiles: 1,64
maxWanderRangeTiles: 1,65
sex: "male",66
displayName: "Stationer",67
sells: [{ itemId: ItemId.paper, quantity: 0 }],68
hiddenDiscount: 1,69
equipment: { chest: ItemId.clothShirt }70
}71
}];72
harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data));73
harness.simulation.reloadWorld();74
75
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });76
const funded = addCoinsToSlots(emptySlots(), 20);77
assert.equal(funded.ok, true);78
harness.stateDb.saveBag(character.character_id, {79
inventory: funded.slots,80
equipment: emptyEquipment(),81
vault: [],82
vaultReserved: []83
});84
const playerId = harness.simulation.spawnCharacter(1, character);85
harness.simulation.step();86
harness.advance(50);87
harness.simulation.step();88
89
const record = harness.simulation.entityRecord(playerId);90
const worker = harness.simulation.workers[record.workerId];91
let npcId = null;92
for (const entity of worker.world.ecs.query(Component.shop, Component.creature))93
{94
if (entity.creature.mobTypeId === MobId.humanoid)95
{96
npcId = entity.entityId;97
break;98
}99
}100
assert.ok(npcId, "expected a humanoid shopkeeper");101
102
const npcHandle = worker.world.ecs.handleOf(npcId);103
const npcPos = worker.world.ecs.get(npcHandle, Component.position);104
const playerHandle = worker.world.ecs.handleOf(playerId);105
const playerPos = worker.world.ecs.get(playerHandle, Component.position);106
playerPos.tileX = npcPos.tileX;107
playerPos.tileY = npcPos.tileY;108
109
harness.simulation.enqueue(1, {110
type: "interact",111
characterId: character.character_id,112
targetEntityId: npcId113
});114
const open = harness.simulation.step();115
const shopOpen = open.events.find((event) => event.type === "shop-open");116
assert.ok(shopOpen, JSON.stringify(open.events));117
assert.ok(shopOpen.stock.some((row) => row.itemId === ItemId.paper));118
119
harness.simulation.enqueue(1, {120
type: "buy-from-shop",121
characterId: character.character_id,122
npcEntityId: npcId,123
itemId: ItemId.paper,124
quantity: 1,125
listingId: `stock:${ItemId.paper}`126
});127
const buy = harness.simulation.step();128
assert.equal(buy.events.some((event) => event.type === "command-error"), false, JSON.stringify(buy.events));129
const bag = harness.simulation.bagOf(playerId);130
const paper = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.paper);131
assert.ok(paper, JSON.stringify(bag.inventory));132
}133
finally134
{ harness.close(); }135
});136
38
test("shop prices fall back to seedValue and apply hidden discount", () =>137
test("shop prices fall back to seedValue and apply hidden discount", () =>39
{138
{40
assert.equal(undiscountedMarketValue(ItemId.copperOre), 5);139
assert.equal(undiscountedMarketValue(ItemId.copperOre), 5);