mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-23 12:51:05 +00:00
Add crown cosmetic type (#4618)
## What Adds **crowns** as a new cosmetic category, wired end-to-end like flags/skins, plus a Crowns tab in the lobby cosmetics modal (#4617). Catalog shape in cosmetics.json: ```json "crowns": { "gold_crown": { "name": "gold_crown", "url": "...", "affiliateCode": null, "product": null, "priceHard": 5, "artist": "...", "rarity": "common" } } ``` ## Changes - **Core**: `CrownSchema` + optional `crowns` record in `CosmeticsSchema`; `crownName` in `PlayerCosmeticRefs`; resolved `crown: { name, url }` in `PlayerCosmetics` - **Server**: `isCrownAllowed` in the privilege checker — requires a `crown:*` or `crown:<name>` flare, resolves the ref to the catalog URL - **Client**: crown selection persisted under the `crown` localStorage key (stale/unowned selections self-clear), `crownRelationship` + resolve/refs wiring, `"crown"` purchase type, Crowns tab in the store, and a Crowns tab in the cosmetics modal (owned crowns + Default tile; selecting persists and keeps the modal open) - **i18n**: `store.crowns`, `store.no_crowns` - Tests for schema parsing, privilege checks, and cosmetic resolution ## Not in this PR - In-game rendering of `player.cosmetics.crown` (name pass / leaderboards / player panel) - API-side support (`/shop/purchase` accepting `cosmeticType: "crown"`, granting `crown:<name>` flares, serving `crowns` in cosmetics.json) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -294,6 +294,75 @@ describe("resolveCosmetics", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("crowns", () => {
|
||||
const crown = {
|
||||
name: "gold_crown",
|
||||
url: "http://localhost:8787/public/cosmetics/crown/gold",
|
||||
affiliateCode: null,
|
||||
product,
|
||||
priceSoft: undefined,
|
||||
priceHard: 5,
|
||||
artist: "sadfas",
|
||||
rarity: "common",
|
||||
};
|
||||
|
||||
test("includes crowns with correct key", () => {
|
||||
const cosmetics = makeCosmetics({
|
||||
crowns: { gold_crown: crown as any },
|
||||
});
|
||||
const result = resolveCosmetics(cosmetics, false, null);
|
||||
const crownItem = result.find((r) => r.key === "crown:gold_crown");
|
||||
expect(crownItem).toBeDefined();
|
||||
expect(crownItem?.cosmetic).toEqual(crown);
|
||||
expect(crownItem?.colorPalette).toBeNull();
|
||||
});
|
||||
|
||||
test("purchasable when user has no flares and priceHard exists", () => {
|
||||
const cosmetics = makeCosmetics({
|
||||
crowns: { gold_crown: crown as any },
|
||||
});
|
||||
const result = resolveCosmetics(cosmetics, makeUserMe(), null);
|
||||
const crownItem = result.find((r) => r.key === "crown:gold_crown");
|
||||
expect(crownItem?.relationship).toBe("purchasable");
|
||||
});
|
||||
|
||||
test("owned with wildcard flare", () => {
|
||||
const cosmetics = makeCosmetics({
|
||||
crowns: { gold_crown: crown as any },
|
||||
});
|
||||
const result = resolveCosmetics(cosmetics, makeUserMe(["crown:*"]), null);
|
||||
const crownItem = result.find((r) => r.key === "crown:gold_crown");
|
||||
expect(crownItem?.relationship).toBe("owned");
|
||||
});
|
||||
|
||||
test("owned with specific flare", () => {
|
||||
const cosmetics = makeCosmetics({
|
||||
crowns: { gold_crown: crown as any },
|
||||
});
|
||||
const result = resolveCosmetics(
|
||||
cosmetics,
|
||||
makeUserMe(["crown:gold_crown"]),
|
||||
null,
|
||||
);
|
||||
const crownItem = result.find((r) => r.key === "crown:gold_crown");
|
||||
expect(crownItem?.relationship).toBe("owned");
|
||||
});
|
||||
|
||||
test("blocked with no product and no price", () => {
|
||||
const freeCrown = {
|
||||
...crown,
|
||||
product: null,
|
||||
priceHard: undefined,
|
||||
};
|
||||
const cosmetics = makeCosmetics({
|
||||
crowns: { gold_crown: freeCrown as any },
|
||||
});
|
||||
const result = resolveCosmetics(cosmetics, makeUserMe(), null);
|
||||
const crownItem = result.find((r) => r.key === "crown:gold_crown");
|
||||
expect(crownItem?.relationship).toBe("blocked");
|
||||
});
|
||||
});
|
||||
|
||||
describe("groupCosmeticVariants", () => {
|
||||
const patternVariant = (
|
||||
patternName: string,
|
||||
|
||||
Reference in New Issue
Block a user