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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- **The catalogue and item import boxes show your game's own example.** Their grey hint showed Cities Without Number's weapons (a Zip Gun) and a fixed GEAR list in every game. Each now shows your own first section, in its own columns. A type with its own PRICE column also no longer lists price twice in the catalogue files.
- **Selling back typed gear from the shop window.** A line of one of your item types, or one of your own items, could be bought but not sold back: the shop window didn't recognize it, and the sale was refused. It now sells back at the shop's buyback rate, and a new browser test sells one and checks the money.
- **A catalogue section that names nothing is now said.** A section like `[rocks]`, which is neither a shelf nor one of your item types, used to be saved quietly where no shop would ever sell it. The preview now says so, listing your types, and its lines are not saved.
- **The bank's windows now follow the theme.** BANK.EXE, PAYROLL.EXE and the GM's BANK_ADMIN.EXE drew in the classic green and grey whatever theme was picked; their boxes, numbers, chart and celebrations now take the theme's colors.
Expand Down Expand Up @@ -105,6 +106,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

- **EDIT CURRENT in SHOP_CATALOGUES.** A new button beside DOWNLOAD CURRENT puts what your shops sell now straight into the box, ready to change, PREVIEW and SAVE, with no file to download and upload again. If the box already has text in it, it asks before replacing it.
- **Publishing tidies the shop catalogue.** When you publish a system, any catalogue line that is now exactly one of your items, same name, price and columns, is taken out of the file, since the item sells itself. That includes lines that ADD NEW LINES TO ITEMS turned into items. The builder's publish message says how many. Lines naming an item kept out of the shops stay, so they sell again if you switch it back on.
- **Catalogue lines can become items.** In SHOP_CATALOGUES, PREVIEW now offers ADD NEW LINES TO ITEMS, off to start. Switched on, it lists what it will add and how many items your system will hold. SAVE then makes each line that isn't one of your items yet into an item: of its section's type (a shelf's lines go to your DEFAULT type), with its columns, price and words, in the shops. They go into the builder's draft and are kept once you publish; until then the catalogue line sells them. If the builder is open, it takes them in, so its next save keeps them.
- **One-of-a-kind items sell back.** An item kept out of the shops is never on a shelf, but a player can still sell one to a shop that sells its type, at the item's own price times that shop's buyback rate. A ring sells at an Armorer, never at a Gun Shop.
Expand Down
8 changes: 4 additions & 4 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions e2e/COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ panel), so a control that looks fine but does nothing is caught for all of them.
| 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, but bought back at its price by a shop of its type (8a7a3c2); 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; sold back from the window at 50%), `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** |
| ADD NEW LINES TO ITEMS | a catalogue's new lines made items in the draft (8a7a4a), off to start; on PUBLISH the lines now exactly an item leave the file (8a7a4b) | `catalogue_into_items`, `CatalogueWindow`, `catalogueItems`, `BuilderScreen` | `catalogue-and-items` (the Hand Cannon into the draft, then out of the file once published) | **AT THE TABLE** |
| EDIT CURRENT | what the shops sell now in the catalogue box to change, asked first over text there (8a7a5) | `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** |
Expand Down
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ kept; the job itself stops at 30 (`timeout-minutes`), for a hang outside the tes
| `tests/shop-stress.spec.ts` | The shop under load in a real browser (8n3, the user asked for a 1000+ item stress test). A GUNS shelf of 1000 lines saved from SHOP_CATALOGUES; the player opens it (200 rows and SHOWING 200 OF 1000), scrolls to the end for 200 more, filters it key by key to Gun 99 (11 rows, found past the first page), clears it and sorts by PRICE both ways (Gun 0 and Gun 999 at the top in turn). Each step under 5 s; on a desk each took under half a second, and the times are logged. |
| `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; sold back from the window at the store's 50% (8a7a3c2), 900 left and off the sheet. Run once without the window's fix, it fails at that balance. |
| `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. With ADD NEW LINES TO ITEMS switched on (8a7a4a, off to start), the Hand Cannon becomes an item of WEAPONS at 900 in the builder's draft (ITEMS 3 OF 200 → 4), said on SAVE, the published system untouched; published (8a7a4b), the Hand Cannon's line leaves the file (dropped 1) and DOWNLOAD CURRENT has it only behind a #. |
| `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. With ADD NEW LINES TO ITEMS switched on (8a7a4a, off to start), the Hand Cannon becomes an item of WEAPONS at 900 in the builder's draft (ITEMS 3 OF 200 → 4), said on SAVE, the published system untouched; published (8a7a4b), the Hand Cannon's line leaves the file (dropped 1) and DOWNLOAD CURRENT has it only behind a #; EDIT CURRENT (8a7a5) asks before replacing the box's text, then fills it with what is on sale. |
| `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 |
Expand Down
12 changes: 11 additions & 1 deletion e2e/tests/catalogue-and-items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { signInAsGm, gmToken, runningSystem, openGameSystem, asGm } from './help
// 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 #. With ADD NEW LINES TO ITEMS on (8a7a4a), the Hand Cannon becomes
// an item of WEAPONS in the builder's draft, priced 900, the running game untouched until a publish; published (8a7a4b), its
// catalogue line, now exactly the item, leaves the file and the item sells itself.
// catalogue line, now exactly the item, leaves the file and the item sells itself. EDIT CURRENT (8a7a5) then puts what is on
// sale in the box, asking first as the box still holds the file.

const SYSTEM = (name: string) => ({
format: 1, name, core: { health: { model: 'pool' } },
Expand Down Expand Up @@ -85,4 +86,13 @@ test('a catalogue held against the game\'s items: one overruling, an exact copy
expect(then).toMatch(/^# Hand Cannon\s*, 900\s*, 3d6/m);
expect(then).not.toMatch(/^Hand Cannon/m);
expect(then).toMatch(/^Pistol\s*, 260\s*, 2d6/m);

// EDIT CURRENT: the box still holds the file, so it asks; replaced, the box is what is on sale now, ready to change.
const text = page.getByLabel('Catalogue text');
await page.getByRole('button', { name: 'EDIT CURRENT', exact: true }).click();
const asked = page.getByRole('group', { name: 'Replace the box' });
await asked.getByRole('button', { name: 'REPLACE', exact: true }).click();
await expect(page.getByText('What the shops sell now is in the box. Change it, then PREVIEW and SAVE.')).toBeVisible({ timeout: 15_000 });
await expect(text).toHaveValue(/^Pistol\s*, 260\s*, 2d6/m);
await expect(text).toHaveValue(/^# Hand Cannon\s*, 900/m);
});
45 changes: 42 additions & 3 deletions frontend/src/components/CatalogueWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from 'react';
import { DraggableWindow } from './DraggableWindow';
import { exampleFor, currentFor, type StoredEntry } from '../sheets/catalogueSchema';
import { exampleFor, currentFor, catalogueHint, type StoredEntry } from '../sheets/catalogueSchema';
import { catalogueLabel, type ShopStock } from '../data/buildingTypes';
import { downloadText } from '../utils/downloadText';
import { customTemplate } from '../sheets/customTemplates';
Expand Down Expand Up @@ -58,13 +58,17 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props)
const [preview, setPreview] = useState<Preview | null>(null);
/** The text that preview was of. SAVE is offered only while the box still matches it. */
const [previewedText, setPreviewedText] = useState<string | null>(null);
const [busy, setBusy] = useState<'preview' | 'save' | 'current' | null>(null);
const [busy, setBusy] = useState<'preview' | 'save' | 'current' | 'edit' | null>(null);
const [message, setMessage] = useState<{ tone: 'ok' | 'bad'; text: string } | null>(null);
/** ADD NEW LINES TO ITEMS (8a7a4a): off to start, afresh with each preview. */
const [toItems, setToItems] = useState(false);
const fileRef = useRef<HTMLInputElement>(null);
/** Set when this window asked for the current catalogues, so their arrival means "download". */
const awaitingCurrent = useRef(false);
/** Set when EDIT CURRENT asked for them (8a7a5), so their arrival fills the box instead. */
const awaitingEdit = useRef(false);
/** EDIT CURRENT asking before it replaces text in the box. */
const [askingEdit, setAskingEdit] = useState(false);

useEffect(() => {
if (!socket) return;
Expand Down Expand Up @@ -102,6 +106,16 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props)
* a state updater would run it twice wherever React calls updaters twice.
*/
const onCatalogues = (payload: { entries?: Partial<Record<ShopStock, StoredEntry[]>> }) => {
// EDIT CURRENT (8a7a5): what DOWNLOAD CURRENT would give, in the box to change, preview and save.
if (awaitingEdit.current) {
awaitingEdit.current = false;
setText(currentFor(system, payload?.entries ?? {}));
setPreview(null);
setPreviewedText(null);
setMessage({ tone: 'ok', text: 'What the shops sell now is in the box. Change it, then PREVIEW and SAVE.' });
setBusy(null);
return;
}
if (!awaitingCurrent.current) return;
awaitingCurrent.current = false;
downloadText(`${system}-storefronts-current.csv`, currentFor(system, payload?.entries ?? {}));
Expand Down Expand Up @@ -129,6 +143,14 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props)
const starter = itemsCatalogue(system, items);
const itemRows = preview ? itemsInPreview(system, items, preview.sections) : { matched: [], near: [] };

/** EDIT CURRENT (8a7a5): asks the server what the shops sell now; it arrives in the box. */
const editCurrent = () => {
if (!socket) return;
awaitingEdit.current = true;
setBusy('edit');
socket.emit('requestCatalogues');
};

const runPreview = () => {
if (!text.trim() || tooBig || !socket) return;
setMessage(null);
Expand Down Expand Up @@ -204,6 +226,14 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props)
socket?.emit('requestCatalogues');
}}
>{busy === 'current' ? 'FETCHING…' : 'DOWNLOAD CURRENT'}</button>
<button
type="button"
className="utility-btn"
style={btn}
disabled={busy !== null || !socket}
title="What the shops sell now, in the box to change: then PREVIEW and SAVE"
onClick={() => { if (text.trim()) setAskingEdit(true); else editCurrent(); }}
>{busy === 'edit' ? 'FETCHING…' : 'EDIT CURRENT'}</button>
{starter && (
<button
type="button"
Expand All @@ -229,10 +259,19 @@ export function CatalogueWindow({ pos, setPos, onClose, socket, system }: Props)
/>
</div>

{/* EDIT CURRENT over text in the box (8a7a5): asked first, so a half-typed file isn't lost. */}
{askingEdit && (
<div role="group" aria-label="Replace the box" style={{ ...mono(10), display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap', color: 'var(--warning)' }}>
<span>Replace what&apos;s in the box with what the shops sell now?</span>
<button type="button" className="utility-btn" style={btn} onClick={() => { setAskingEdit(false); editCurrent(); }}>REPLACE</button>
<button type="button" className="utility-btn" style={btn} onClick={() => setAskingEdit(false)}>KEEP</button>
</div>
)}

<textarea
value={text}
onChange={(e) => { setText(e.target.value); setMessage(null); }}
placeholder={'Paste a table here, or upload a file.\n\n[weapons]\nname, price, dmg\nZip Gun, 15, 1d4'}
placeholder={catalogueHint(system)}
aria-label="Catalogue text"
spellCheck={false}
style={{
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ItemsImport.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react';
import type { Definition, systemsApi } from '../sheets/systemsApi';
import {
MAX_BYTES, lineRange, exampleItemsFile, itemsListFile, itemsFileName, withImportedItems, itemPartText, itemIdsOf, type ItemsImportPreview,
MAX_BYTES, lineRange, exampleItemsFile, itemsListFile, itemsFileName, withImportedItems, itemPartText, itemIdsOf, itemsHint, type ItemsImportPreview,
} from '../sheets/itemsImport';
import { HINTS } from '../sheets/builderHelp';
import { FieldName } from './HelpHint';
Expand Down Expand Up @@ -133,7 +133,7 @@ export function ItemsImport({ definition, api, edit, onClose, onApplied }: Props
})}
</div>
<textarea ref={box} value={text} aria-label="Text to import" spellCheck={false} className="cyber-scroll"
placeholder={'Paste a table here, or upload a file. DOWNLOAD EXAMPLE gives one in the right shape.\n\n[gear]\nname, weight, price, needs, words\n\n[features]\nitem, feature, words, uses, refill'}
placeholder={itemsHint(definition)}
onChange={(e) => change(e.target.value)}
onScroll={(e) => { if (gutter.current) gutter.current.scrollTop = e.currentTarget.scrollTop; }}
style={{ ...lines, background: 'var(--black)', color: 'var(--green)', border: 0, resize: 'none', whiteSpace: 'pre', overflow: 'auto', height: '100%', width: '100%', outline: 'none' }} />
Expand Down
Loading
Loading