mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
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:
+20
-1
@@ -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]) =>
|
||||
|
||||
Reference in New Issue
Block a user