mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-23 15:45:15 +00:00
store & reference pattern by name (#1766)
## Description: Store pattern by name instead of value. The worker replaces the pattern name with it's base64 when joining. This ensures the client & server are never out of sync after patterns are updated. * removed resizeObserver on the territory modal, it was causing some race conditions, and the modal is not resizable so it's unnecessary. * Moved PatternSchema to CosmeticSchema ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I have read and accepted the CLA agreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -4,14 +4,14 @@ import { getApiBase, getAuthHeader } from "./jwt";
|
||||
|
||||
export async function patterns(
|
||||
userMe: UserMeResponse | null,
|
||||
): Promise<Pattern[]> {
|
||||
): Promise<Map<string, Pattern>> {
|
||||
const cosmetics = await getCosmetics();
|
||||
|
||||
if (cosmetics === undefined) {
|
||||
return [];
|
||||
return new Map();
|
||||
}
|
||||
|
||||
const patterns: Pattern[] = [];
|
||||
const patterns: Map<string, Pattern> = new Map();
|
||||
const playerFlares = new Set(userMe?.player.flares);
|
||||
|
||||
for (const name in cosmetics.patterns) {
|
||||
@@ -20,10 +20,10 @@ export async function patterns(
|
||||
if (hasAccess) {
|
||||
// Remove product info because player already has access.
|
||||
patternData.product = null;
|
||||
patterns.push(patternData);
|
||||
patterns.set(name, patternData);
|
||||
} else if (patternData.product !== null) {
|
||||
// Player doesn't have access, but product is available for purchase.
|
||||
patterns.push(patternData);
|
||||
patterns.set(name, patternData);
|
||||
}
|
||||
// If player doesn't have access and product is null, don't show it.
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export async function handlePurchase(priceId: string) {
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
async function getCosmetics(): Promise<Cosmetics | undefined> {
|
||||
export async function getCosmetics(): Promise<Cosmetics | undefined> {
|
||||
try {
|
||||
const response = await fetch(`${getApiBase()}/cosmetics.json`);
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user