diff --git a/src/client/Main.ts b/src/client/Main.ts index 046becf7c..2ac00af2d 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -483,6 +483,13 @@ class Client { console.log(`joining lobby ${lobbyId}`); } } + if (decodedHash.startsWith("#affiliate=")) { + const affiliateCode = decodedHash.replace("#affiliate=", ""); + strip(); + if (affiliateCode) { + this.patternsModal.open(affiliateCode); + } + } } private async handleJoinLobby(event: CustomEvent) { diff --git a/src/client/TerritoryPatternsModal.ts b/src/client/TerritoryPatternsModal.ts index 995246f37..53357f792 100644 --- a/src/client/TerritoryPatternsModal.ts +++ b/src/client/TerritoryPatternsModal.ts @@ -27,6 +27,8 @@ export class TerritoryPatternsModal extends LitElement { private isActive = false; + private affiliateCode: string | null = null; + constructor() { super(); } @@ -51,6 +53,17 @@ export class TerritoryPatternsModal extends LitElement { private renderPatternGrid(): TemplateResult { const buttons: TemplateResult[] = []; for (const [name, pattern] of this.patterns) { + if (this.affiliateCode === null) { + if (pattern.affiliateCode !== null && pattern.product !== null) { + // Patterns with affiliate code are not for sale by default. + continue; + } + } else { + if (pattern.affiliateCode !== this.affiliateCode) { + continue; + } + } + buttons.push(html` - this.selectPattern(null)} - > + ${this.affiliateCode === null + ? html` + this.selectPattern(null)} + > + ` + : html``} ${buttons} `; @@ -86,13 +103,15 @@ export class TerritoryPatternsModal extends LitElement { `; } - public async open() { + public async open(affiliateCode?: string) { this.isActive = true; + this.affiliateCode = affiliateCode ?? null; await this.refresh(); } public close() { this.isActive = false; + this.affiliateCode = null; this.modalEl?.close(); } diff --git a/src/core/CosmeticSchemas.ts b/src/core/CosmeticSchemas.ts index f52c811c1..5ff3d23fc 100644 --- a/src/core/CosmeticSchemas.ts +++ b/src/core/CosmeticSchemas.ts @@ -44,6 +44,7 @@ export const PatternSchema = z export const PatternInfoSchema = z.object({ name: PatternNameSchema, pattern: PatternSchema, + affiliateCode: z.string().nullable(), product: ProductSchema.nullable(), });