mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 19:12:20 +00:00
bd9ef9a317
## What Adds a new **`effects`** cosmetic category alongside `skins`/`flags`. Each effect is discriminated by **`effectType`** (only `transportShipTrail` today), whose visual config lives in **`attributes`** (`solid` / `rainbow` / `pulse` / `gradient`). Schema matches the production cosmetics.json shape exactly (incl. the `url` field). **This PR is UI + taxonomy only — the in-game WebGL trail rendering is intentionally deferred.** ## UI - **Store** gains an **"Effects"** tab. - **Home page** gains an **"Effects"** button opening a picker modal. - Both render effects **grouped by `effectType` with a sub-header per type**, via a shared `<effects-grid>` Lit element (`mode="select"` for the picker, `mode="purchase"` for the store). The picker shows owned effects + a Default tile and persists per-type; the store shows purchasable effects. ## Data flow - Ownership via `effect:*` / `effect:<name>` flares (reuses `cosmeticRelationship`). - Selection is a per-`effectType` map persisted in UserSettings (`settings.effects`). - Server validates in `isEffectAllowed`, wired into `isAllowed`. - `getPlayerCosmeticsRefs` / `getPlayerCosmetics` resolve effects the same way as skins/flags (kept-on-fetch-failure, server is authority). ## Tests - `tsc --noEmit`, ESLint, Prettier clean; full suite green. - New: `CosmeticSchemas` parse tests (incl. parsing the **real** `read_transport_trail` entry), `UserSettings` per-type selection, and `Privilege` effect validation. ## Notes / follow-ups - The effect's display label shows **"Boat Trail"** for the `transportShipTrail` type (friendlier than the id). - Closed-source API gap: `/shop/purchase` (`purchaseWithCurrency`) needs to learn `"effect"` for **currency** purchase of effects; the **dollar/product** purchase path already works. Client types were widened accordingly. - In-game wake rendering can be ported from #4416. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { EFFECTS_KEY, UserSettings } from "../src/core/game/UserSettings";
|
|
|
|
describe("UserSettings effect selection", () => {
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
// UserSettings keeps a static in-memory cache; reset it too so each test
|
|
// reads fresh from the (cleared) localStorage.
|
|
(
|
|
UserSettings as unknown as { cache: Map<string, string | null> }
|
|
).cache.clear();
|
|
});
|
|
|
|
it("sets and reads a per-effectType selection", () => {
|
|
const s = new UserSettings();
|
|
s.setSelectedEffectName("transportShipTrail", "spectrum");
|
|
expect(s.getSelectedEffectName("transportShipTrail")).toBe("spectrum");
|
|
});
|
|
|
|
it("returns null when nothing is selected", () => {
|
|
expect(
|
|
new UserSettings().getSelectedEffectName("transportShipTrail"),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("clearing the last selection removes the storage key", () => {
|
|
const s = new UserSettings();
|
|
s.setSelectedEffectName("transportShipTrail", "spectrum");
|
|
s.setSelectedEffectName("transportShipTrail", undefined);
|
|
expect(s.getSelectedEffectName("transportShipTrail")).toBeNull();
|
|
expect(localStorage.getItem(EFFECTS_KEY)).toBeNull();
|
|
});
|
|
|
|
it("clearing one effectType leaves other types intact", () => {
|
|
const s = new UserSettings();
|
|
// Seed two types directly (only one real effectType exists today).
|
|
localStorage.setItem(
|
|
EFFECTS_KEY,
|
|
JSON.stringify({ transportShipTrail: "spectrum", future: "x" }),
|
|
);
|
|
s.setSelectedEffectName("transportShipTrail", undefined);
|
|
expect(s.getSelectedEffects()).toEqual({ future: "x" });
|
|
});
|
|
|
|
it("returns an empty map for a corrupt blob", () => {
|
|
localStorage.setItem(EFFECTS_KEY, "not json");
|
|
expect(new UserSettings().getSelectedEffects()).toEqual({});
|
|
});
|
|
});
|