Refactor cosmetics.json (#1263)

## Description:

- Refactor cosmetics.json to use base64 as the lookup key, to reduce the
complexity of lookup.
- Add refine() logic to PatternSchema to check if the pattern is valid.
- Split PatternDecoder class out of Cosmetic.ts to resolve temporal
deadzone caused by static parsing of cosmetics.json with the new
refine().

## 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 understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors
This commit is contained in:
Scott Anderson
2025-06-23 20:14:36 -07:00
committed by GitHub
parent 1ce282d41b
commit 4680b04656
10 changed files with 135 additions and 169 deletions
+20 -1
View File
@@ -10,6 +10,7 @@ import {
PlayerType,
UnitType,
} from "./game/Game";
import { PatternDecoder } from "./PatternDecoder";
import { PlayerStatsSchema } from "./StatsSchemas";
import { flattenedEmojiTable } from "./Util";
@@ -178,7 +179,25 @@ export const AllPlayersStatsSchema = z.record(ID, PlayerStatsSchema);
export const UsernameSchema = SafeString;
export const FlagSchema = z.string().max(128).optional();
export const PatternSchema = z.string().max(128).base64().optional();
export const RequiredPatternSchema = z
.string()
.max(128)
.base64()
.refine(
(val) => {
try {
new PatternDecoder(val);
return true;
} catch (e) {
console.error(JSON.stringify(e.message, null, 2));
return false;
}
},
{
message: "Invalid pattern",
},
);
export const PatternSchema = RequiredPatternSchema.optional();
export const QuickChatKeySchema = z.enum(
Object.entries(quickChatData).flatMap(([category, entries]) =>