mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: store trimmed only in cache
This commit is contained in:
1 parent
4a6f5845f9
commit
3b4e089756
4 files changed
+20
-29
No files matched your search
@@ -83,10 +83,9 @@ export abstract class AbstractAPI {
|
||||
> = {};
|
||||
protected abstract _groupedGameStrings(
|
||||
locale: string,
|
||||
group: string,
|
||||
prefix: boolean
|
||||
group: string
|
||||
): Promise<Record<string, string>>;
|
||||
async groupedGameStrings(locale: string, group: string, prefix = true) {
|
||||
async groupedGameStrings(locale: string, group: string, prefix: boolean) {
|
||||
this.assertLocale(locale);
|
||||
|
||||
if (this._groupedGameStringsCache[locale] === undefined) {
|
||||
@@ -95,10 +94,19 @@ export abstract class AbstractAPI {
|
||||
|
||||
if (this._groupedGameStringsCache[locale][group] === undefined) {
|
||||
this._groupedGameStringsCache[locale][group] =
|
||||
await this._groupedGameStrings(locale, group, prefix);
|
||||
await this._groupedGameStrings(locale, group);
|
||||
}
|
||||
|
||||
return this._groupedGameStringsCache[locale][group];
|
||||
if (!prefix) return this._groupedGameStringsCache[locale][group];
|
||||
|
||||
const strings: Record<string, string> = {};
|
||||
|
||||
for (const key in this._groupedGameStringsCache[locale][group]) {
|
||||
strings[`${group}__${key}`] =
|
||||
this._groupedGameStringsCache[locale][group][key];
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
private _avatarCache: Record<string, Avatar> = {};
|
||||
|
||||
@@ -12,29 +12,15 @@ export class ClientAPI extends AbstractAPI {
|
||||
throw new Error("Cannot fetch full game strings on client");
|
||||
}
|
||||
|
||||
protected async _groupedGameStrings(
|
||||
locale: string,
|
||||
group: string,
|
||||
prefix: boolean
|
||||
) {
|
||||
protected async _groupedGameStrings(locale: string, group: string) {
|
||||
const response = await fetch(`/api/game-strings/${locale}/${group}.json`);
|
||||
const json = (await response.json()) as Record<string, string>;
|
||||
|
||||
if (!prefix) return json;
|
||||
|
||||
const strings: Record<string, string> = {};
|
||||
|
||||
for (const key in json) {
|
||||
strings[`${group}__${key}`] = json[key];
|
||||
}
|
||||
|
||||
return strings;
|
||||
return json;
|
||||
}
|
||||
|
||||
protected async _strings(locale: string) {
|
||||
const response = await fetch(`/api/strings/${locale}.json`);
|
||||
const json = (await response.json()) as Strings;
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -101,17 +101,14 @@ export class ServerAPI extends AbstractAPI {
|
||||
return strings;
|
||||
}
|
||||
|
||||
protected async _groupedGameStrings(
|
||||
locale: string,
|
||||
group: string,
|
||||
prefix: boolean
|
||||
) {
|
||||
protected async _groupedGameStrings(locale: string, group: string) {
|
||||
const strings = await this.gameStrings(locale);
|
||||
const filtered: Record<string, string> = {};
|
||||
|
||||
for (const key in strings) {
|
||||
if (key.startsWith(`${group}__`)) {
|
||||
filtered[prefix ? key : key.substring(group.length + 2)] = strings[key];
|
||||
const trimmed = key.substring(group.length + 2);
|
||||
filtered[trimmed] = strings[key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +130,7 @@ export class ServerAPI extends AbstractAPI {
|
||||
protected async _tankList() {
|
||||
const group = this.metadata.group("TankEntity");
|
||||
const list: TankListEntry[] = [];
|
||||
const strings = await this.groupedGameStrings("en", "TankEntity");
|
||||
const strings = await this.groupedGameStrings("en", "TankEntity", true);
|
||||
|
||||
for (const item of group) {
|
||||
const tankCatalog = item.TankCatalog();
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useLocale } from "./useLocale";
|
||||
export function useGameStrings(group: string) {
|
||||
const { locale } = useLocale();
|
||||
const strings = useAwait(
|
||||
() => api.groupedGameStrings(locale, group),
|
||||
() => api.groupedGameStrings(locale, group, true),
|
||||
`game-strings-${locale}-${group}`
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user