diff --git a/CHANGELOG.md b/CHANGELOG.md index 257fd954..b2e96a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- **The shop catalogue knows your items.** In a game whose items sell themselves, PREVIEW in SHOP_CATALOGUES now says how many of your items are also on sale, and which lines in your file overrule one ("Pistol: overrules the item, 200 → 260 in the shops"). A line that's exactly one of your items, same price and columns, is left out, since the item already sells itself. So is a line naming an item kept out of the shops. The preview says why for each line, and SAVE leaves out the same lines. - **PRICE and IN SHOPS in the ITEMS page's files.** In a game with item types of its own, DOWNLOAD EXAMPLE and DOWNLOAD THIS LIST have a price column (for a type without a PRICE column of its own) and an in shops column, yes or no. IMPORT reads them: write - to clear one, and a price or a yes/no that isn't one is skipped and named by its line. A list downloaded and imported back changes nothing. - **PRICE and IN SHOPS on the ITEMS page.** In a game with item types of its own, every item has a PRICE under its TYPE. If the type has a PRICE column, that column is shown there, once. Beside it, IN SHOPS says whether the shops sell the item: switched off, it's never sold and is tagged NOT SOLD in the list, for a one-of-a-kind ring or a quest item. A new item starts IN SHOPS and asks for its price until it has one. Moving an item to another type keeps its price. A PRICE column in the ITEMS import and downloads comes next. - **Your items sell themselves.** In a game with item types of its own, an item with a price is on sale by itself, at the shops its type is sold at, with no catalogue to upload first. If an item's type has a PRICE column of its own, that column is its price. A catalogue line with the same name as one of your items takes its place, at the catalogue's price, so you can still mark something up. An item can be kept out of the shops: it's never sold, not even from an old file, and can still be given. A player can sell one back at the shop's buyback rate. DOWNLOAD CURRENT lists your items behind a #, so uploading it back doesn't copy them. The PRICE and IN SHOPS boxes on the ITEMS page come next. diff --git a/README.md b/README.md index ee1e1baa..fd9042c1 100644 --- a/README.md +++ b/README.md @@ -422,7 +422,7 @@ CITY_NET/ │ │ ├── availability.js # Whether a system has shops: a sheet the shops know (a built-in, or any published custom system, whose purchases are inventory lines), with shops and the bank both on │ │ ├── catalogueParse.js # Reads a catalogue a GM pasted or uploaded: CSV, TSV or JSON, real RFC-4180 quoting, per-line problems rather than exceptions. The only reader - the preview is a round trip to it; a section per item type (8a7a1): [GUNS], [gun] or [MELEE WEAPONS] is lines of the system's own type, a type winning over a shelf of its name, each column read as it holds (numbers, PICK ONE's own word) and checked as the builder checks an item's, a row that doesn't fit left out and said, blanks kept and noted once a row; a section that is neither a type nor a shelf said, its rows not saved │ │ ├── catalogueStore.js # Uploaded catalogues in memory, added on top of the built-in ones, never replacing them. Holds one system at a time, and consults the built-in book only when that system is CWN - every other game's shops carry only what their GM uploaded. Requires nothing, so priceOf stays synchronous and the lot stays importable from a frontend test -│ │ ├── ownItems.js # The game's own items on the shelves (8a7a3a; decided 2026-11-21): each priced and IN SHOPS a line of its type's catalogue, its values and words as fields; the names of those turned off. Pure, worked out once per definition. The running game's own items (8a7a3a, ownItems.js, set by the sockets) sit under the uploaded lines: a line uploaded with an item's name wins, an item turned off keeps a line of its name off the shelves +│ │ ├── ownItems.js # The game's own items on the shelves (8a7a3a; decided 2026-11-21): each priced and IN SHOPS a line of its type's catalogue, its values and words as fields; the names of those turned off. Pure, worked out once per definition. A catalogue file held against them (againstItems, 8a7a3c1): an exact copy of an item left out, one kept out of the shops left out, one of an item's name overruling it, and how many sell themselves besides. The running game's own items (8a7a3a, ownItems.js, set by the sockets) sit under the uploaded lines: a line uploaded with an item's name wins, an item turned off keeps a line of its name off the shelves │ │ └── catalogueDb.js # The only piece that knows uploaded catalogues live in SQLite. A save replaces one catalogue wholesale, in a transaction │ ├── tokens/ │ │ ├── conditions.js # A token's conditions as stored ([{ id, left }]): read safely, checked against what the running system offers (one twice, an unknown one, rounds out of 1 to 99 refused by name; one that ends after rounds starting at its own), shown to everyone without the rounds left, a hidden one (a house rule off) kept as it was, and counted down a round at a time for a combat's tokens (tickCombat), coming off at none; `started` kept for one ending AT THE END OF ITS NEXT TURN, through an edit too (8a9a) @@ -605,7 +605,7 @@ CITY_NET/ │ ├── shop_sell.test.js # Selling a basket: a payout the client cannot talk up, the item really leaving the sheet, and nothing emptied when a basket fails part way │ ├── shop_buy_sockets.test.js # Buying through the socket as a cart of one, the old buy handler's cases moved across whole │ ├── shop_sell_sockets.test.js # Selling through the socket as a cart with nothing to buy, the old sell handler's cases moved across whole -│ ├── shop_items_on_sale.test.js # The game's own items on the shelves (8a7a3a): a price, its own or its type's PRICE column's; IN SHOPS, one saved before it by its price; checked and carried by the system file; the lines they make; under the uploads in the store (a line of an item's name wins, one turned off never sold); bought, sold back at the BUYBACK rate, not again in GIVE's type folders +│ ├── shop_items_on_sale.test.js # The game's own items on the shelves (8a7a3a): a price, its own or its type's PRICE column's; IN SHOPS, one saved before it by its price; checked and carried by the system file; the lines they make; under the uploads in the store (a line of an item's name wins, one turned off never sold); bought, sold back at the BUYBACK rate, not again in GIVE's type folders; a catalogue file held against them, its preview and its save (8a7a3c1) │ ├── shop_typed_lines.test.js # Lines of an item type sold and given (8a7a2): SOLD AT, the General Store unsaid, checked and carried by the system file; a typed line placed and stacked only onto the same thing untouched; bought at a shop that sells the type and refused at one that doesn't, sold back, given from GIVE │ ├── shop_catalogue_types.test.js # A catalogue section per item type (8a7a1): by name, one or id in any case, spaces, columns by name; a value that doesn't fit said in the builder's words; blanks one note; a type over a shelf of its name; JSON; a section that is neither said; through the sockets, the preview by the type's name, saved under it, sent to players │ ├── shop_catalogue_parse.test.js # Reading a GM's catalogue: commas inside names, semicolons from a European Excel, a byte-order mark, a price with its symbol; problems per line, never a throw @@ -890,7 +890,7 @@ CITY_NET/ │ │ │ ├── BuildingPreview.tsx # The corner picture: the GM's photo, else the building's own parts turning as a wireframe in its own small canvas, else the CITY_NET badge. The color is read from the theme's CSS variable where it sits - the info windows render outside the ThemeContext provider, so the context alone drew every theme in classic green │ │ │ ├── BuildingExtrasEditor.tsx # The photo and GM notes in the admin edit view. Nothing saves on its own: UPDATE_DATA_POINT commits them after the building saves, and a 200 with nothing in it - an old server not yet restarted - is reported rather than called saved │ │ │ ├── CityNetIcon.tsx # The CITY_NET badge from assets/citynet-logo.svg in the theme's colors, for anywhere that needs a picture and has none -│ │ │ ├── CatalogueWindow.tsx # Where a GM adds to what shops sell: download an example or the current list, paste or upload, preview, save. SAVE only ever stores text that was previewed, and the preview is the server's own parser, so it cannot show something different from what gets stored; a custom system's items (7e3c): DOWNLOAD ITEMS, and the preview naming the lines that are items and those only nearly named as one; a type's section by its name in the preview, its problems and the save (GUNS ×2), a line's blank columns noted as kept (8a7a1) +│ │ │ ├── CatalogueWindow.tsx # Where a GM adds to what shops sell: download an example or the current list, paste or upload, preview, save. SAVE only ever stores text that was previewed, and the preview is the server's own parser, so it cannot show something different from what gets stored; a custom system's items (7e3c): DOWNLOAD ITEMS, and the preview naming the lines that are items and those only nearly named as one; a type's section by its name in the preview, its problems and the save (GUNS ×2), a line's blank columns noted as kept (8a7a1); ALSO ON SALE FROM ITEMS, each line overruling an item and how, each left out and why (8a7a3c1) │ │ │ ├── EmptyShopSteps.tsx # What a GM is told when a shop has nothing on any shelf, which outside CWN is every new one: the steps to stock it, a button straight to SHOP_CATALOGUES, and the header line for that shop's section in this game. Shown where the building type is set and to an admin opening the shop. A game's own item types by their sections' names and columns ([WEAPONS], 8a7a2) │ │ │ ├── CyberwareSection.tsx # What the GEAR tab shows: a count, the humanity cost, and the way in. Says when pieces are still unplaced, because an import lands everything unfiled and nothing else would mention it │ │ │ ├── ImportPreviewWindow.tsx # What an import would do, in its own window: what was recognised, what the source never held, what a custom system's importer left and why (worked out, GM-only, not one of the choices), and which of your fields a replace would clear. The window is the confirmation — applying replaces the sheet @@ -1073,7 +1073,7 @@ CITY_NET/ │ │ │ ├── AdminPanel.tokencontrol.test.tsx # Handing a friendly NPC to the players running it: what the panel offers, what it sends, and never a grant on a token that can't carry one │ │ │ ├── BuildingWindow.test.tsx # A building's terminal window showing every player what it did before, the GM's notes offered to and fetched for the main admin only │ │ │ ├── BuildingExtrasEditor.test.tsx # The photo and GM notes staged until UPDATE_DATA_POINT, sending exactly what was staged, reporting every failure, never overwriting notes it couldn't load -│ │ │ ├── CatalogueWindow.test.tsx # Adding to the shops: SAVE only ever stores text that was previewed; DOWNLOAD ITEMS and the item lines and near misses in a preview, none on a game without items (7e3c); a type's section by its name, its problem, a blank noted, the save (8a7a1) +│ │ │ ├── CatalogueWindow.test.tsx # Adding to the shops: SAVE only ever stores text that was previewed; DOWNLOAD ITEMS and the item lines and near misses in a preview, none on a game without items (7e3c); a type's section by its name, its problem, a blank noted, the save (8a7a1); the file held against the game's items: the count, overrules, left out (8a7a3c1) │ │ │ ├── EmptyShopSteps.test.tsx # An empty shop telling the GM how to stock it, where the shop is set up │ │ │ ├── ShopWindow.test.tsx # The shop: what a building carries, and nothing reaching a sheet until the server says the account was charged │ │ │ ├── CyberwareWindow.cybermods.test.tsx # Fitting a cyberware mod the way a player reaches it, the UI honouring the server's fitting rules @@ -1555,6 +1555,7 @@ CITY_NET/ │ ├── shop-cart.spec.ts # A CWN Gun Shop at the table (8n1, a safety net before 8a7): the GM pays a player from PAYROLL.EXE, the player opens the shop from QUICK_ACCESS, a Light Pistol bought through the cart (what they have down 200, the pistol on the sheet), then sold back for 45% (up 90, the pistol gone) │ ├── shop-cart-items.spec.ts # A custom system's General Store at the table (8n1): the GM's catalogue saved from DOWNLOAD ITEMS with a ring and a rope while the player is online, both on the player's shelf, bought through the cart (505 paid, 495 left), both in the inventory, the ring known as the item it is │ ├── catalogue-types.spec.ts # A catalogue section per item type (8a7a1): [GUNS] in DOWNLOAD EXAMPLE, a file with a good gun, a bad AMMO and blanks previewed as GUNS ×2 with the problem and the note, saved, both guns back in DOWNLOAD CURRENT with their columns +│ ├── catalogue-and-items.spec.ts # A catalogue held against the game's items (8a7a3c1): the Pistol overruling 200 → 260, an exact Cutlass and a ring kept out of the shops left out, ALSO ON SALE FROM ITEMS; saved, the game's Cutlass behind a # in DOWNLOAD CURRENT │ ├── shop-typed-lines.spec.ts # Lines of an item type at the table (8a7a2): a [GUNS] catalogue saved, the General Store's GUNS shelf in the type's columns, a Pistol bought and landing as a Gun with its damage and ammo, another given from GIVE.EXE stacked onto it │ ├── shop-items-on-sale.spec.ts # The game's own items at the table (8a7a3a): a Pistol priced on ITEMS, no catalogue saved, on the General Store's WEAPONS shelf at 200 and a ring kept out of the shops not; bought, a Weapon on the gear with its damage │ ├── shop-items-catalogue.spec.ts # Items in the shops (7e3c): DOWNLOAD ITEMS, a price filled in, the preview naming the ring and a near miss, saved, on sale in GIVE.EXE's catalogue diff --git a/backend/__tests__/shop_items_on_sale.test.js b/backend/__tests__/shop_items_on_sale.test.js index 9fae92b0..bedc7d44 100644 --- a/backend/__tests__/shop_items_on_sale.test.js +++ b/backend/__tests__/shop_items_on_sale.test.js @@ -17,7 +17,9 @@ const require_ = createRequire(import.meta.url); const { itemPrice, inShops } = require_('../systemBuilder/itemTypes'); const { checkDefinition } = require_('../systemBuilder/definition'); const citysys = require_('../systemBuilder/citysys'); -const { ownStock } = require_('../shops/ownItems'); +const { ownStock, againstItems } = require_('../shops/ownItems'); +const { parseCatalogue } = require_('../shops/catalogueParse'); +const { typesOf } = require_('../systemBuilder/itemTypes'); const store = require_('../shops/catalogueStore'); const give = require_('../shops/give'); const runtime = require_('../systemBuilder/runtime'); @@ -143,6 +145,30 @@ describe('in the store, under the uploads', () => { }); }); +describe('a catalogue file held against them (8a7a3c1)', () => { + const parse = (text) => parseCatalogue(text, { types: typesOf(DEF), names: { known: () => true, refused: (n) => n } }).sections; + const FILE = '[WEAPONS]\nname, price, damage, description\nPistol, 200, 2d6, Snub.\nHand Cannon, 900, 3d6\n[ARMOR]\nname, price, defense\nRing of Might, 10, \nLeather Jacket, 75, 2\n'; + + it('an exact copy of an item left out; one kept out of the shops left out; one of an item\'s name otherwise overrules it', () => { + const held = againstItems(parse(FILE), DEF); + expect(Object.fromEntries(Object.entries(held.sections).map(([c, list]) => [c, list.map((e) => e.name)]))).toEqual({ 'type:weapons': ['Hand Cannon'], 'type:armor': ['Leather Jacket'] }); + expect(held.leftOut).toEqual([ + { line: 3, catalogue: 'type:weapons', name: 'Pistol', message: 'already on ITEMS at 200, the same in every column: left out, as it sells itself' }, + { line: 7, catalogue: 'type:armor', name: 'Ring of Might', message: 'kept out of the shops on ITEMS (IN SHOPS is off), so never sold: left out' }, + ]); + expect(held.overrules).toEqual([{ line: 8, catalogue: 'type:armor', name: 'Leather Jacket', from: 50, to: 75 }]); + expect(held.onSale).toBe(2); + }); + + it('a column apart, the price the same: it overrules the item\'s columns; a game without types of its own, nothing held', () => { + const held = againstItems(parse('[WEAPONS]\nname, price, damage, description\nPistol, 200, 2d8, Snub.\n'), DEF); + expect(held.overrules).toEqual([{ line: 3, catalogue: 'type:weapons', name: 'Pistol', from: 200, to: 200 }]); + expect(held.leftOut).toEqual([]); + const sections = { gear: [{ id: 'rope', name: 'Rope', price: 1, fields: {} }] }; + expect(againstItems(sections, { ...DEF, items: { list: DEF.items.list } })).toEqual({ sections, leftOut: [], overrules: [], onSale: 0 }); + }); +}); + describe('at the table', () => { const ID = 'sys_pricedpricedpric'; let db; @@ -217,6 +243,26 @@ describe('at the table', () => { expect(await checkout(kes, goods, { buys: [{ catalogue: 'type:weapons', itemId: 'pistol', qty: 1 }] })).toMatchObject({ ok: true, buys: [{ price: 260 }] }); }); + it('the catalogue preview says what the file does to the items, and the save leaves out what it said (8a7a3c1)', async () => { + const gm = await boot('gm', true); + const text = '[WEAPONS]\nname, price, damage, description\nPistol, 200, 2d6, Snub.\nHand Cannon, 900, 3d6\n[ARMOR]\nname, price, defense\nRing of Might, 10, \nLeather Jacket, 75, 2\n'; + gm.handlers.previewCatalogue({ text }); + const preview = (await last(gm.emitted, 'cataloguePreview')).data; + expect(preview.summary.map((x) => [x.label, x.count])).toEqual([['WEAPONS', 1], ['ARMOR', 1]]); + expect(preview.items).toEqual({ + onSale: 2, + overrules: [{ line: 8, catalogue: 'type:armor', name: 'Leather Jacket', from: 50, to: 75 }], + leftOut: [ + { line: 3, catalogue: 'type:weapons', name: 'Pistol', message: 'already on ITEMS at 200, the same in every column: left out, as it sells itself' }, + { line: 7, catalogue: 'type:armor', name: 'Ring of Might', message: 'kept out of the shops on ITEMS (IN SHOPS is off), so never sold: left out' }, + ], + }); + gm.handlers.saveCatalogue({ text }); + expect((await last(gm.emitted, 'catalogueSaved')).data).toMatchObject({ ok: true, saved: [{ catalogue: 'type:weapons', count: 1 }, { catalogue: 'type:armor', count: 1 }] }); + const rows = await new Promise((resolve, reject) => db.all('SELECT catalogue, name, price FROM shop_catalogues WHERE system = ? ORDER BY catalogue, name', [ID], (e, r) => (e ? reject(e) : resolve(r)))); + expect(rows).toEqual([{ catalogue: 'type:armor', name: 'Leather Jacket', price: 75 }, { catalogue: 'type:weapons', name: 'Hand Cannon', price: 900 }]); + }); + it('GIVE: the game\'s items in its own ITEMS folder, not again under their type', async () => { await boot('gm', true); expect(give.givable(ID).find((c) => c.catalogue === 'type:weapons')?.items ?? []).toEqual([]); diff --git a/backend/shops/ownItems.js b/backend/shops/ownItems.js index a40d1483..b61e6689 100644 --- a/backend/shops/ownItems.js +++ b/backend/shops/ownItems.js @@ -44,4 +44,41 @@ const ownStock = (definition) => { return out; }; -module.exports = { ITEM_PREFIX, ownStock }; +/** Two lines' fields alike, whatever order their keys came in. */ +const sameFields = (a, b) => { + const pairs = (o) => Object.keys(o || {}).sort().map((k) => [k, o[k]]); + return JSON.stringify(pairs(a)) === JSON.stringify(pairs(b)); +}; + +/** + * A catalogue file's lines held against the game's own items (8a7a3c1; decided 2026-11-21, mockup types-in-shops.html, + * questions 9 and 15): a line that is exactly an item IN SHOPS (its name, price and every column) is left out, the item + * selling itself, so nothing is kept twice; a line naming an item turned off is left out, the shops never selling it; a line + * of an item's name otherwise overrules it, said. { sections to save, leftOut, overrules, onSale: the items on sale besides }. + */ +const againstItems = (sections, definition) => { + const stock = ownStock(definition); + const leftOut = []; + const overrules = []; + const kept = {}; + for (const [catalogue, entries] of Object.entries(sections || {})) { + const items = stock.catalogues[catalogue] || []; + kept[catalogue] = (entries || []).filter((e) => { + const name = normaliseName(e && e.name); + const at = { line: (e && e.line) || 0, catalogue, name: e && e.name }; + if (stock.off.has(name)) { leftOut.push({ ...at, message: 'kept out of the shops on ITEMS (IN SHOPS is off), so never sold: left out' }); return false; } + const item = items.find((i) => normaliseName(i.name) === name); + if (!item) return true; + if (item.price === e.price && sameFields(item.fields, e.fields)) { + leftOut.push({ ...at, message: `already on ITEMS at ${item.price}, the same in every column: left out, as it sells itself` }); + return false; + } + overrules.push({ ...at, from: item.price, to: e.price }); + return true; + }); + } + const onSale = Object.values(stock.catalogues).reduce((n, list) => n + list.length, 0); + return { sections: kept, leftOut, overrules, onSale }; +}; + +module.exports = { ITEM_PREFIX, ownStock, againstItems }; diff --git a/backend/sockets/index.js b/backend/sockets/index.js index cf327613..dac16a9a 100644 --- a/backend/sockets/index.js +++ b/backend/sockets/index.js @@ -51,7 +51,7 @@ const { typesOf, ownTypes, typeShelvesAt } = require('../systemBuilder/itemTypes const { namesOf } = require('../systemBuilder/choices'); // The merged catalogue: what the app ships with, plus whatever a GM uploaded. const shopPrices = require('../shops/catalogueStore'); -const { ownStock } = require('../shops/ownItems'); +const { ownStock, againstItems } = require('../shops/ownItems'); // And the running game's own items, priced and IN SHOPS (8a7a3a), under the uploaded lines. shopPrices.setOwnSource((system) => ownStock(customSystems.definitionOf(system))); const catalogueDb = require('../shops/catalogueDb'); @@ -2488,11 +2488,14 @@ module.exports = (io, db, { elevatedUsers, emitUpdate, recordAction }) => { socket.on('previewCatalogue', (data) => { const info = userSockets.get(socket.id); if (!info || !info.isAdmin) return; - getGameSystem((sysErr, system) => previewCatalogue(data, sysErr ? {} : catalogueOptions(system))); + getGameSystem((sysErr, system) => previewCatalogue(data, sysErr ? {} : catalogueOptions(system), sysErr ? null : customSystems.definitionOf(system))); }); - const previewCatalogue = (data, options) => { - const parsed = catalogueParse.parseCatalogue(data && data.text, options); + const previewCatalogue = (data, options, definition) => { + const read = catalogueParse.parseCatalogue(data && data.text, options); + // Held against the game's own items (8a7a3c1): exact copies and items kept out of the shops left out, as the save does. + const held = againstItems(read.sections, definition); + const parsed = { ...read, sections: held.sections }; // An id that already exists in the book is an override rather than an addition, and // the GM should be told before they save rather than after. @@ -2511,6 +2514,7 @@ module.exports = (io, db, { elevatedUsers, emitUpdate, recordAction }) => { problems: parsed.problems, notes: parsed.notes, summary, + ...(held.onSale || held.leftOut.length || held.overrules.length ? { items: { onSale: held.onSale, overrules: held.overrules, leftOut: held.leftOut } } : {}), }); }; @@ -2528,7 +2532,9 @@ module.exports = (io, db, { elevatedUsers, emitUpdate, recordAction }) => { getGameSystem((sysErr, system) => { if (sysErr) return refuse('no_system'); - const parsed = catalogueParse.parseCatalogue(data && data.text, catalogueOptions(system)); + const read = catalogueParse.parseCatalogue(data && data.text, catalogueOptions(system)); + // As the preview said (8a7a3c1): a line that is exactly one of the game's items, or one kept out of the shops, isn't saved. + const parsed = { ...read, sections: againstItems(read.sections, customSystems.definitionOf(system)).sections }; const wanted = Object.keys(parsed.sections); if (!wanted.length) return refuse('empty'); diff --git a/e2e/COVERAGE.md b/e2e/COVERAGE.md index 7cc23ca9..eb3f4513 100644 --- a/e2e/COVERAGE.md +++ b/e2e/COVERAGE.md @@ -35,6 +35,7 @@ panel), so a control that looks fine but does nothing is caught for all of them. | Shop catalogues by item type | a section per item type (8a7a1), its columns checked, blanks kept | `shop_catalogue_types`, `catalogueTypes` | `catalogue-types`, `shop-typed-lines` (bought at the General Store and given, landing typed, 8a7a2) | **AT THE TABLE** | | An item type's SOLD AT | the kinds of shop that sell its lines (8a7a2), the General Store where unsaid; set in the builder in 8a7b | `shop_typed_lines`, `typedShelves` | `shop-typed-lines` (unsaid: the General Store) | **AT THE TABLE** unsaid; a kind of shop picked waits for 8a7b's box | | An item's PRICE and IN SHOPS | priced and IN SHOPS, it sells itself at its type's shops (8a7a3a); off, never sold, not even from a file; a type's PRICE column read as its price; set on ITEMS under TYPE, NOT SOLD in the list, a new item's price asked for (8a7a3b1); in the ITEMS import and downloads, price and in shops columns (8a7a3b2) | `shop_items_on_sale`, `itemPrice`, `ItemsPage`, `system_builder_items_import`, `itemsImport` | `shop-items-on-sale` (a type's PRICE column; a ring turned off), `builder-item-price` (set by clicks), `builder-items-import` (imported priced and IN SHOPS) | **AT THE TABLE** | +| A catalogue file held against the game's items | an exact copy of an item left out, an item kept out of the shops left out, one of an item's name overruling it, ALSO ON SALE FROM ITEMS (8a7a3c1) | `shop_items_on_sale`, `CatalogueWindow` | `catalogue-and-items` | **AT THE TABLE** | | Building types and catalogues renamed or off | | `buildings` | | **GAP** | | Currencies | several, decimals, a catalogue's currency, the cart per currency, PAYROLL | `currencies`, `currency_icons`, `catalogue_currency`, `bank_currencies`, `shop_checkout_currencies` | | **GAP** | | The bank's celebrations | on / off | `bank` | | **GAP** | diff --git a/e2e/README.md b/e2e/README.md index 620b79cc..c474610b 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -218,6 +218,7 @@ kept; the job itself stops at 30 (`timeout-minutes`), for a hang outside the tes | `tests/shop-cart-items.spec.ts` | A custom system's General Store at the table (8n1). The GM starts a catalogue from DOWNLOAD ITEMS, the ring priced at 500 and a rope at 5, and saves it while the player is online (this found the player's shops empty: fixed); pays the player 1,000; the player's store has both lines, both bought through the cart, the receipt saying 505 paid and 495 left; both in the inventory, the ring known as the item it is, to WEAR and ATTUNE | | `tests/shop-items-on-sale.spec.ts` | The game's own items at the table (8a7a3a), found by the user testing 8a7a2. A game whose WEAPONS type has a PRICE column, its Pistol priced 200 and a Ring of Might kept out of the shops, and no catalogue saved: the player's General Store has the Pistol on its WEAPONS shelf at 200 with its damage, never the ring, and no empty-shop steps; bought through the cart, it lands on the gear as a Weapon with its damage. | | `tests/shop-typed-lines.spec.ts` | Lines of an item type at the table (8a7a2). A game with a GUNS type (DAMAGE, AMMO) and no SOLD AT, so sold at the General Store: the GM saves a [GUNS] catalogue with a Pistol and pays the player 1000; the player's General Store has a GUNS tab saying GOES INTO YOUR GEAR AS A GUN, sortable by DAMAGE and AMMO; the Pistol bought through the cart lands on the sheet as a Gun with its damage and ammo, and one given from GIVE.EXE stacks onto it. | +| `tests/catalogue-and-items.spec.ts` | A catalogue file held against the game's own items (8a7a3c1). WEAPONS selling a Pistol at 200 and a Cutlass at 120 by themselves, a Ring of Might kept out of the shops: a file with the Pistol at 260, the Cutlass exactly as it is, the Ring and a Hand Cannon previews as WEAPONS ×2, ALSO ON SALE FROM ITEMS: 2 (1 overruled by this file), the Pistol overruling 200 → 260, the Cutlass and the Ring left out and why; saved as WEAPONS ×2, DOWNLOAD CURRENT has the Pistol at 260, the Hand Cannon and the game's Cutlass behind a #, no Ring. | | `tests/catalogue-types.spec.ts` | A catalogue section per item type (8a7a1). In a game with a GUNS type (DAMAGE, AMMO, GRADE), DOWNLOAD EXAMPLE has a [GUNS] section in those columns; a file with a good pistol, a Hand Cannon whose AMMO is "six" and a Blank Gun with columns left blank previews as 2 ROWS READ · 1 PROBLEM, GUNS ×2, the cannon said by its line and the blanks noted as kept; SAVE says GUNS ×2; DOWNLOAD CURRENT has the pistol and the blank gun with their columns, never the cannon | | `tests/shop-items-catalogue.spec.ts` | Items in the shops (7e3c): CATALOGUES.EXE's DOWNLOAD ITEMS gives the ring on the gear's shelf, its price blank; with a price filled in and a line named Ring of Migt, the preview names RING OF MIGHT as an item and the other as nearly it; saved, GIVE.EXE lists the ring from the gear's catalogue at 500 beside the system's ITEMS | | `tests/sheet-level-up.spec.ts` | Going up a level (7d2b): XP reaches the next level and LEVEL UP READY blinks, opening LEVEL_UP.EXE (7d3a), where the player picks which of two classes goes up, leaves and comes back to it where they were, sees what the new level unlocks and FINISHES. In the window (7d3b) a Path Soldier 2 opens is picked, FINISH waiting for it, and then a class not held yet is taken up at level 1; what's past it carries over, with no + on a class, and LEVEL_DOWN brings READY back. With milestone there's no XP anywhere: the GM's LEVEL_UP gives a level, the rail blinks, the player takes it, and a stat called level can't be typed. An uploaded sheet brings its XP under the game's word, and one with none keeps what they have (7d2c). FILL IT IN FOR THEM (7d7a): the GM, on a player's sheet at level 1 with no XP, opens LEVEL_UP.EXE for them, adds a Path they don't meet, and finishes with nothing rolled: Soldier 2, the Path under its feature, health at its average | diff --git a/e2e/tests/catalogue-and-items.spec.ts b/e2e/tests/catalogue-and-items.spec.ts new file mode 100644 index 00000000..ba14825e --- /dev/null +++ b/e2e/tests/catalogue-and-items.spec.ts @@ -0,0 +1,66 @@ +import { test, expect } from '@playwright/test'; +import { readFile } from 'fs/promises'; +import { signInAsGm, gmToken, runningSystem, openGameSystem } from './helpers'; + +// A catalogue file held against the game's own items (8a7a3c1; mockup docs/mockups/types-in-shops.html, answered 2026-11-21). +// A game whose WEAPONS sell themselves (a Pistol at 200, a Cutlass at 120) and a Ring of Might kept out of the shops: a file +// with the Pistol at 260, the Cutlass exactly as it is, the Ring and a Hand Cannon previews as WEAPONS ×2, ALSO ON SALE FROM +// ITEMS: 2 (1 overruled), the Pistol overruling 200 → 260, the Cutlass and the Ring left out and why; saved, DOWNLOAD CURRENT +// has the file's two lines and the game's items behind a #. + +const SYSTEM = (name: string) => ({ + format: 1, name, core: { health: { model: 'pool' } }, + stats: [{ id: 'abilities', label: 'ABILITIES', stats: [{ id: 'might', label: 'Might' }] }], + items: { + types: [{ id: 'weapons', label: 'WEAPONS', one: 'Weapon', columns: [ + { id: 'damage', label: 'DAMAGE', kind: 'damage' }, + { id: 'price', label: 'PRICE', kind: 'number' }, + ] }], + list: [ + { id: 'pistol', label: 'Pistol', type: 'weapons', values: { damage: '2d6', price: 200 } }, + { id: 'cutlass', label: 'Cutlass', type: 'weapons', values: { damage: '1d8', price: 120 } }, + { id: 'ring', label: 'Ring of Might', type: 'weapons', price: 5000, in_shops: false }, + ], + }, +}); + +test('a catalogue held against the game\'s items: one overruling, an exact copy and a ring kept out left out, saved (8a7a3c1)', async ({ page, request }, info) => { + test.setTimeout(120_000); + const again = info.retry ? `_${info.retry + 1}` : ''; + const gm = await gmToken(request); + await runningSystem(request, gm, SYSTEM(`Itemfile${again}`)); + + await page.setViewportSize({ width: 1280, height: 800 }); + await signInAsGm(page); + await openGameSystem(page); + await page.getByRole('button', { name: 'SHOP_CATALOGUES', exact: true }).click(); + + await page.getByLabel('Catalogue text').fill([ + '[WEAPONS]', + 'name, price, damage', + 'Pistol, 260, 2d6', + 'Cutlass, 120, 1d8', + 'Ring of Might, 10, 1d4', + 'Hand Cannon, 900, 3d6', + ].join('\n')); + await page.getByRole('button', { name: 'PREVIEW', exact: true }).click(); + await expect(page.getByText('2 ROWS READ')).toBeVisible({ timeout: 15_000 }); + await expect(page.getByText(/^WEAPONS ×2/)).toBeVisible(); + await expect(page.getByTestId('catalogue-on-sale')).toHaveText('ALSO ON SALE FROM ITEMS: 2 (1 overruled by this file)'); + await expect(page.getByTestId('catalogue-overrules')).toHaveText('LINE 3 [WEAPONS] Pistol: overrules the item, 200 → 260 in the shops'); + await expect(page.getByTestId('catalogue-left-out')).toHaveText([ + 'LINE 4 [WEAPONS] Cutlass: already on ITEMS at 120, the same in every column: left out, as it sells itself', + 'LINE 5 [WEAPONS] Ring of Might: kept out of the shops on ITEMS (IN SHOPS is off), so never sold: left out', + ]); + + await page.getByRole('button', { name: 'SAVE', exact: true }).click(); + await expect(page.getByText('Saved: WEAPONS ×2. The shops have it now.')).toBeVisible({ timeout: 15_000 }); + + // On sale now: the file's two lines, and the game's own Cutlass behind a # (the Pistol's line stands in for its item). + const [current] = await Promise.all([page.waitForEvent('download'), page.getByRole('button', { name: 'DOWNLOAD CURRENT', exact: true }).click()]); + const now = await readFile(await current.path(), 'utf8'); + expect(now).toMatch(/^Pistol\s*, 260\s*, 2d6/m); + expect(now).toMatch(/^Hand Cannon\s*, 900\s*, 3d6/m); + expect(now).toMatch(/^# Cutlass\s*, 120\s*, 1d8/m); + expect(now).not.toMatch(/Ring of Might/); +}); diff --git a/frontend/src/components/CatalogueWindow.tsx b/frontend/src/components/CatalogueWindow.tsx index ddd615e6..61b15130 100644 --- a/frontend/src/components/CatalogueWindow.tsx +++ b/frontend/src/components/CatalogueWindow.tsx @@ -34,7 +34,9 @@ interface Props { interface Problem { line: number; catalogue?: string; name?: string; message: string } interface Summary { catalogue: string; count: number; overrides: string[]; label?: string } /** `notes` (8a7a1): what a type's line left blank, nothing wrong. */ -interface Preview { problems: Problem[]; notes?: Problem[]; summary: Summary[]; format: string | null; sections?: Record } +/** The file held against the game's own items (8a7a3c1): how many sell themselves, lines overruling one, lines left out. */ +interface AgainstItems { onSale: number; overrules: (Omit & { from: number; to: number })[]; leftOut: Problem[] } +interface Preview { problems: Problem[]; notes?: Problem[]; summary: Summary[]; format: string | null; sections?: Record; items?: AgainstItems } /** * Socket.io refuses a message over a megabyte by default, and says nothing useful when it @@ -307,6 +309,28 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props) ))} + {/* The game's own items (8a7a3c1; mockup types-in-shops.html): what sells itself besides, and lines it overrules + or leaves out, so a GM sees why a Pistol is 260 and not 200. */} + {preview.items && (() => { + const where = (p: Omit) => `${p.line > 0 ? `LINE ${p.line}` : 'FILE'}${p.catalogue ? ` [${sectionName(p.catalogue)}]` : ''}${p.name ? ` ${p.name}` : ''}`; + const own = preview.items; + return <> + {own.onSale > 0 && ( +
+ ALSO ON SALE FROM ITEMS: {own.onSale}{own.overrules.length > 0 ? ` (${own.overrules.length} overruled by this file)` : ''} +
+ )} + {own.overrules.map((p, i) => ( +
+ {where(p)}: overrules the item, {p.from === p.to ? 'its columns' : `${p.from} → ${p.to}`} in the shops +
+ ))} + {own.leftOut.map((p, i) => ( +
{where(p)}: {p.message}
+ ))} + ; + })()} + {preview.problems.map((p, i) => (
{p.line > 0 ? `LINE ${p.line}` : 'FILE'} diff --git a/frontend/src/components/__tests__/CatalogueWindow.test.tsx b/frontend/src/components/__tests__/CatalogueWindow.test.tsx index 4a7ef9e8..90bd834e 100644 --- a/frontend/src/components/__tests__/CatalogueWindow.test.tsx +++ b/frontend/src/components/__tests__/CatalogueWindow.test.tsx @@ -322,3 +322,38 @@ describe("a type's section (8a7a1)", () => { expect(screen.getByText('Saved: GUNS ×2. The shops have it now.')).toBeInTheDocument(); }); }); + +describe('the file held against the game\'s own items (8a7a3c1)', () => { + const ITEMS = { + onSale: 9, + overrules: [{ line: 4, catalogue: 'type:guns', name: 'Pistol', from: 200, to: 260 }, { line: 5, catalogue: 'type:guns', name: 'Derringer', from: 90, to: 90 }], + leftOut: [{ line: 6, catalogue: 'type:guns', name: 'Cutlass', message: 'already on ITEMS at 120, the same in every column: left out, as it sells itself' }], + }; + const preview = (items?: object) => reply('cataloguePreview', { + format: 'delimited', summary: [{ catalogue: 'type:guns', count: 2, overrides: [], label: 'GUNS' }], problems: [], ...(items ? { items } : {}), + }); + + it('how many sell themselves besides, each line overruling one and how, each left out and why', async () => { + show(); + type('[GUNS]\nname, price\nPistol, 260'); + await userEvent.click(button('PREVIEW')); + preview(ITEMS); + expect(screen.getByTestId('catalogue-on-sale')).toHaveTextContent('ALSO ON SALE FROM ITEMS: 9 (2 overruled by this file)'); + expect(screen.getAllByTestId('catalogue-overrules').map((n) => n.textContent)).toEqual([ + 'LINE 4 [GUNS] Pistol: overrules the item, 200 → 260 in the shops', + 'LINE 5 [GUNS] Derringer: overrules the item, its columns in the shops', + ]); + expect(screen.getByTestId('catalogue-left-out')).toHaveTextContent('LINE 6 [GUNS] Cutlass: already on ITEMS at 120, the same in every column: left out, as it sells itself'); + }); + + it('none overruled: the count alone; a game with no items of its own: nothing said', async () => { + show(); + type('[GUNS]\nname, price\nPistol, 260'); + await userEvent.click(button('PREVIEW')); + preview({ onSale: 3, overrules: [], leftOut: [] }); + expect(screen.getByTestId('catalogue-on-sale')).toHaveTextContent(/^ALSO ON SALE FROM ITEMS: 3$/); + preview(); + expect(screen.queryByTestId('catalogue-on-sale')).toBeNull(); + expect(screen.queryByTestId('catalogue-overrules')).toBeNull(); + }); +});