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 @@ -106,6 +106,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

- **A game's own shops on the map.** BUILDING TYPE now lists the shops your game made (an Apothecary, a Fence) first, under THIS GAME'S SHOPS, then the app's under SHOPS and its other buildings under OTHER BUILDINGS, in every game. A building set to one gets a SHOP button, its window named as the game names it and selling the item types SOLD AT it. A shop that sells nothing but buys anything opens on SELL, and its BUY folder says it only buys. A building keeps another game's own shop when it is saved again.
- **SOLD AT on an item type, and + NEW SHOP.** On the builder's ITEMS page, each type now shows the game's shops as buttons, by what this game calls them: tick the kinds of shop that sell its lines, or none to have it only given. Type a name into + NEW SHOP (an Apothecary, a Fence) to make a kind of shop of your game's own, shown dashed and ticked. A type from a preset starts at its shop: WEAPON the Gun Shop, ARMOR the Armorer, CONSUMABLE the Clinic, GEAR the General Store; SPELL is sold nowhere, with a Magic Shop ready to ADD.
- **PLAYERS CHANGE GEAR.** A new switch on the GAME tab's house rules, on to start, for systems with their own item types. Switched off, only the GM changes the columns of a player's gear (a weapon's DAMAGE, a potion's HEALS): the player's card shows them but can't change them, and says "ONLY THE GM CHANGES THESE AT THIS TABLE". Players still name, count, move, add and remove their things, and the GM can always change anything.
- **UNIQUE on GEAR.** A thing changed from the item it is named after (the Cutlass made 2d8) now says UNIQUE on its line; hover it for the item's own value and who changed it, and when (a player by name, or the GM). In its card, each column made its own says UNIQUE with the item's value beside it and a THE ITEM'S button to put it back. Type unique in FIND to list them. SHEET.EXE and the sheet's own tab are the same.
Expand Down
12 changes: 7 additions & 5 deletions README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions backend/__tests__/system_builder_own_shops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ describe('at the table', () => {
expect((await give(id, 'tavern')).status).toBe(400);
});

it('a building keeps another game\'s own shop when saved again (8a7b3a); a new unknown one is still refused', async () => {
const id = await stall('apothecary');
await install({ ...HERBAL([]), items: { types: [{ ...POTIONS, sold_at: [] }], list: [] } });
expect((await give(id, 'apothecary')).status).toBe(200);
expect((await get(db, 'SELECT building_type FROM locations WHERE id = ?', [id])).building_type).toBe('apothecary');
expect((await give(id, 'tavern')).status).toBe(400);
expect((await give(id, '')).status).toBe(200);
expect((await give(id, 'apothecary')).status).toBe(400);
});

it('sells the types that tick it, at their price; the General Store doesn\'t; off, or in another game, it is no shop', async () => {
const shop = await stall('apothecary');
const goods = await stall('general_store');
Expand Down
12 changes: 7 additions & 5 deletions backend/routes/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ module.exports = (db, io, { emitUpdate, recordAction }) => {
*/
router.patch('/:id/building-type', authenticate, (req, res) => withShopSystem(res, (system) => {
const { building_type, buyback_pct } = req.body;
// A value nobody recognises would put a SHOP button on a building that cannot sell
// anything, so it is refused rather than stored and puzzled over later.
// The app's types, or one of the running game's own shops (8a7b).
if (!isValidType(building_type) && !ownShopOf(customSystems.definitionOf(system), building_type)) return res.status(400).json({ error: 'Unknown building type' });

const next = building_type === '' || building_type === undefined ? null : building_type;

/**
Expand All @@ -198,6 +193,13 @@ module.exports = (db, io, { emitUpdate, recordAction }) => {
db.get('SELECT id, building_type FROM locations WHERE id = ?', [req.params.id], (err, row) => {
if (err) return res.status(500).json({ error: err.message });
if (!row) return res.status(404).json({ error: 'Not found' });
// A value nobody recognises would put a SHOP button on a building that cannot sell
// anything, so it is refused rather than stored and puzzled over later: the app's types,
// or one of the running game's own shops (8a7b). One the building already has (another
// game's own shop, 8a7b3a) is kept, as saving the building sends it again.
if (next !== null && next !== row.building_type && !isValidType(next) && !ownShopOf(customSystems.definitionOf(system), next)) {
return res.status(400).json({ error: 'Unknown building type' });
}
// A type this game turned off is not one a building can be given here. One already given
// keeps it, unused, for when the type is turned back on - and saving the building again
// (the editor sends its type on every save) is not giving it anything new.
Expand Down
2 changes: 1 addition & 1 deletion e2e/COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +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** |
| The shops under load | 1000+ lines on a shelf, 200 items, a full cart, a long gear list (8n3); a long shelf drawn 200 rows at a time | `shop_stress`, `ShopWindow` | `shop-stress` | **AT THE TABLE** |
| An item type's SOLD AT | the kinds of shop that sell its lines (8a7a2), the General Store where unsaid; ticked in the builder (8a7b2), each preset at its shop | `shop_typed_lines`, `typedShelves`, `gameShops`, `ItemsPage` | `shop-typed-lines` (unsaid: the General Store), `builder-sold-at` (ticked by clicks: a Pistol bought at a Gun Shop) | **AT THE TABLE** |
| The game's own shops, and what a shop BUYS | an Apothecary or a Fence of the game's own (8a7b1a), on or off; a shop's BUYS, WHAT IT SELLS or ANYTHING, every priced thing at the building's BUYBACK rate (8a7b1b) | `system_builder_own_shops`, `gameShops`, `system_builder_shop_buys`, `shopBuys`, `ShopWindow` | `builder-sold-at` (an Apothecary made by + NEW SHOP, saved) | **GAP** at the table until a building can be one: BUYS and the BUILDING TYPE list in 8a7b3, each with its journey |
| The game's own shops, and what a shop BUYS | an Apothecary or a Fence of the game's own (8a7b1a), on or off; a shop's BUYS, WHAT IT SELLS or ANYTHING, every priced thing at the building's BUYBACK rate (8a7b1b) | `system_builder_own_shops`, `gameShops`, `system_builder_shop_buys`, `shopBuys`, `ownShopsTable`, `AdminPanel`, `ShopWindow` | `builder-sold-at` (an Apothecary made by + NEW SHOP, saved), `shop-own-kinds` (an Apothecary picked in BUILDING TYPE selling its draught; a Fence on ANYTHING opening on SELL and taking it back) | **AT THE TABLE**; set from FEATURES (rename, off, BUYS, DELETE) in 8a7b3b |
| An item type's ON THE SHEET band | EQUIPPED, USABLE or PACK (G1), PACK where unsaid; the sheet's GEAR tab in those bands plus STASH, closed to start, a band's head closing it, remembered (G2); a thing worn, attuned or installed in EQUIPPED whatever its type, a closed band something lands in lit until opened (G3) | `system_builder_item_types`, `itemTypes`, `ItemsPage`, `gearBands`, `GearTypeTables` | `builder-item-types` (the WEAPON preset EQUIPPED), `sheet-gear-bands` (a Sword, a Draught and a Rope in EQUIPPED, USABLE and PACK; the Sword stashed into STASH; USABLE kept closed; a Cloak of GEAR worn into a closed EQUIPPED, its head lit, taken off back into PACK) | **AT THE TABLE** |
| PLAYERS CHANGE GEAR | the GAME tab's switch, on to start, offered where a system makes its own item types (G6a, G6b): off, a player's gear columns are the GM's | `players_change_gear` setting, `switches.gear`, `uniqueLines.keepColumns`, `GearTypeTables` | `sheet-players-change-gear` (off: DAMAGE read only and said; the GM changes it, UNIQUE by the GM; on: the player changes it) | **AT THE TABLE** |
| 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** |
Expand Down
1 change: 1 addition & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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/shop-own-kinds.spec.ts` | The game's own shops at the table (8a7b3a). A game with an Apothecary selling its POTIONS and a Fence that sells nothing and BUYS anything. The GM picks a building out in QUICK_ACCESS, EDITs it and finds both first in BUILDING TYPE, under THIS GAME'S SHOPS, picks Apothecary (its buy-back rate box appears) and saves; paid 100, the player's Apothecary window is headed APOTHECARY and sells the Healing Draught (60 left); the Fence's window opens on SELL with the draught there, its BUY folder says THIS SHOP ONLY BUYS, and the draught sells back at 45% of 40 (78). |
| `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 |
Expand Down
89 changes: 89 additions & 0 deletions e2e/tests/shop-own-kinds.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { test, expect } from '@playwright/test';
import { signInAsGm, signInAsPlayer, gmToken, asGm, runningSystem, approvedPlayer } from './helpers';
import { playerToken, payPlayer } from './shops';

// The game's own shops at the table (8a7b3a; approved mockup docs/mockups/types-in-shops.html, sections 3 and 4). A game with
// an Apothecary selling its POTIONS and a Fence that sells nothing and BUYS anything. The GM makes a building an Apothecary
// from BUILDING TYPE, under THIS GAME'S SHOPS; the player buys a Healing Draught there, then takes it to the Fence, whose
// window opens on SELL, its BUY folder saying it only buys, and sells it back at the app's 45%.

const SYSTEM = (name: string) => ({
format: 1, name, core: { health: { model: 'pool' } },
stats: [{ id: 'abilities', label: 'ABILITIES', stats: [{ id: 'might', label: 'Might' }] }],
buildings: { shops: [{ id: 'apothecary', name: 'Apothecary' }, { id: 'fence', name: 'Fence', buys: 'anything' }] },
items: {
types: [{ id: 'potions', label: 'POTIONS', one: 'Potion', sold_at: ['apothecary'], columns: [{ id: 'heals', label: 'HEALS', kind: 'dice' }] }],
list: [{ id: 'draught', label: 'Healing Draught', type: 'potions', values: { heals: '2d4' }, price: 40, in_shops: true }],
},
});

test('the game\'s own shops: an Apothecary picked under THIS GAME\'S SHOPS sells a draught; a Fence that only buys takes it back (8a7b3a)', async ({ page, browser, request }, info) => {
test.setTimeout(180_000);
const again = info.retry ? `_${info.retry + 1}` : '';
const gm = await gmToken(request);
await runningSystem(request, gm, SYSTEM(`Herbfall${again}`));
const player = { username: `e2e_herbfall${again}`, password: 'e2e-player-password' };
await approvedPlayer(request, gm, player);
await playerToken(request, gm, player.username);
const shop = `HERBFALL_MOSS${again}`;
const fence = `HERBFALL_DOOR${again}`;
await asGm(request, gm, 'post', '/api/locations', { name: shop, description: '', shape: 'box', x: 12, y: 0, z: 12, width: 2, height: 2, depth: 2 });
const door = await asGm(request, gm, 'post', '/api/locations', { name: fence, description: '', shape: 'box', x: 16, y: 0, z: 12, width: 2, height: 2, depth: 2 });
const typed = await request.patch(`/api/locations/${door.data[0].id}/building-type`, { data: { building_type: 'fence' }, headers: { Authorization: `Bearer ${gm}` } });
expect(typed.ok(), await typed.text()).toBe(true);

// The player, online and with a sheet opened once.
const context = await browser.newContext({ baseURL: info.project.use.baseURL, viewport: { width: 1280, height: 800 } });
const mine = await context.newPage();
await signInAsPlayer(mine, player);
await mine.getByRole('button', { name: 'CHARACTER_CONTROLS', exact: true }).click();
await mine.getByRole('button', { name: 'CHARACTER_SHEET', exact: true }).click();
await expect(mine.getByRole('group', { name: 'Vitals' })).toBeVisible({ timeout: 15_000 });
await mine.keyboard.press('Escape');

// The GM: the building picked out, EDIT, BUILDING TYPE has the game's own under THIS GAME'S SHOPS; Apothecary, saved.
await page.setViewportSize({ width: 1280, height: 800 });
await signInAsGm(page);
await page.getByRole('button', { name: 'QUICK_ACCESS', exact: true }).click();
const gmList = page.locator('.quick-access-panel');
await gmList.getByText(/DEFINED_STRUCTURES/).click();
await gmList.getByText(shop, { exact: true }).click();
await page.locator('.selection-panel').getByRole('button', { name: 'EDIT', exact: true }).click();
const picker = page.getByLabel('Building type');
await expect(picker.locator('optgroup').first()).toHaveAttribute('label', 'THIS GAME\'S SHOPS');
await expect(picker.locator('optgroup[label="THIS GAME\'S SHOPS"] option')).toHaveText(['Apothecary', 'Fence']);
await picker.selectOption('apothecary');
await expect(page.getByLabel('Buy-back rate for this shop')).toBeVisible();
await page.getByRole('button', { name: 'UPDATE_DATA_POINT', exact: true }).click();
await expect(page.getByText('CHANGES_SAVED', { exact: true })).toBeVisible({ timeout: 15_000 });
await page.getByRole('button', { name: 'ACKNOWLEDGE', exact: true }).click();
await expect.poll(async () => (await asGm(request, gm, 'get', '/api/locations')).find((l: { name: string }) => l.name === shop)?.building_type, { timeout: 15_000 }).toBe('apothecary');
await payPlayer(page, player.username, 100);

// The Apothecary: named as the game names it, its POTIONS on sale; a draught bought.
await mine.getByRole('button', { name: 'QUICK_ACCESS', exact: true }).click();
const list = mine.locator('.quick-access-panel');
await list.getByText(/DEFINED_STRUCTURES/).click();
await list.getByText(shop, { exact: true }).click();
await mine.getByRole('button', { name: 'SHOP', exact: true }).click();
const moss = mine.locator('.win95-window', { has: mine.getByText(`SHOP.EXE · ${shop}`, { exact: true }) });
await expect(moss.getByText(/^APOTHECARY · 1 LINE/)).toBeVisible({ timeout: 15_000 });
await moss.getByRole('button', { name: 'Add Healing Draught to the cart' }).click();
await moss.getByRole('tab', { name: 'CART' }).click();
await moss.getByRole('button', { name: 'CHECK OUT' }).click();
await expect(moss.getByRole('tabpanel')).toContainText('BALANCE 60cr', { timeout: 15_000 });
await mine.keyboard.press('Escape');

// The Fence: open on SELL, the draught there; BUY says it only buys; sold back at 45% of 40.
await list.getByText(fence, { exact: true }).click();
await mine.getByRole('button', { name: 'SHOP', exact: true }).click();
const back = mine.locator('.win95-window', { has: mine.getByText(`SHOP.EXE · ${fence}`, { exact: true }) });
await expect(back.getByRole('tab', { name: 'SELL' })).toHaveAttribute('aria-selected', 'true', { timeout: 15_000 });
await back.getByRole('button', { name: 'Add Healing Draught to the cart' }).click({ timeout: 15_000 });
await back.getByRole('tab', { name: 'BUY' }).click();
await expect(back.getByTestId('shop-sells-nothing')).toHaveText('THIS SHOP ONLY BUYS: it sells nothing, and takes anything with a price. Open SELL.');
await back.getByRole('tab', { name: 'CART' }).click();
await back.getByRole('button', { name: 'CHECK OUT' }).click();
await expect(back.getByRole('tabpanel')).toContainText('BALANCE 78cr', { timeout: 15_000 });
await context.close();
});
Loading
Loading