Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 47 additions & 1 deletion backend/__tests__/shop_items_on_sale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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([]);
Expand Down
Loading
Loading