mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +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(
|
protected abstract _groupedGameStrings(
|
||||||
locale: string,
|
locale: string,
|
||||||
group: string,
|
group: string
|
||||||
prefix: boolean
|
|
||||||
): Promise<Record<string, string>>;
|
): Promise<Record<string, string>>;
|
||||||
async groupedGameStrings(locale: string, group: string, prefix = true) {
|
async groupedGameStrings(locale: string, group: string, prefix: boolean) {
|
||||||
this.assertLocale(locale);
|
this.assertLocale(locale);
|
||||||
|
|
||||||
if (this._groupedGameStringsCache[locale] === undefined) {
|
if (this._groupedGameStringsCache[locale] === undefined) {
|
||||||
@@ -95,10 +94,19 @@ export abstract class AbstractAPI {
|
|||||||
|
|
||||||
if (this._groupedGameStringsCache[locale][group] === undefined) {
|
if (this._groupedGameStringsCache[locale][group] === undefined) {
|
||||||
this._groupedGameStringsCache[locale][group] =
|
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> = {};
|
private _avatarCache: Record<string, Avatar> = {};
|
||||||
|
|||||||
@@ -12,29 +12,15 @@ export class ClientAPI extends AbstractAPI {
|
|||||||
throw new Error("Cannot fetch full game strings on client");
|
throw new Error("Cannot fetch full game strings on client");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _groupedGameStrings(
|
protected async _groupedGameStrings(locale: string, group: string) {
|
||||||
locale: string,
|
|
||||||
group: string,
|
|
||||||
prefix: boolean
|
|
||||||
) {
|
|
||||||
const response = await fetch(`/api/game-strings/${locale}/${group}.json`);
|
const response = await fetch(`/api/game-strings/${locale}/${group}.json`);
|
||||||
const json = (await response.json()) as Record<string, string>;
|
const json = (await response.json()) as Record<string, string>;
|
||||||
|
return json;
|
||||||
if (!prefix) return json;
|
|
||||||
|
|
||||||
const strings: Record<string, string> = {};
|
|
||||||
|
|
||||||
for (const key in json) {
|
|
||||||
strings[`${group}__${key}`] = json[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _strings(locale: string) {
|
protected async _strings(locale: string) {
|
||||||
const response = await fetch(`/api/strings/${locale}.json`);
|
const response = await fetch(`/api/strings/${locale}.json`);
|
||||||
const json = (await response.json()) as Strings;
|
const json = (await response.json()) as Strings;
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,17 +101,14 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _groupedGameStrings(
|
protected async _groupedGameStrings(locale: string, group: string) {
|
||||||
locale: string,
|
|
||||||
group: string,
|
|
||||||
prefix: boolean
|
|
||||||
) {
|
|
||||||
const strings = await this.gameStrings(locale);
|
const strings = await this.gameStrings(locale);
|
||||||
const filtered: Record<string, string> = {};
|
const filtered: Record<string, string> = {};
|
||||||
|
|
||||||
for (const key in strings) {
|
for (const key in strings) {
|
||||||
if (key.startsWith(`${group}__`)) {
|
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() {
|
protected async _tankList() {
|
||||||
const group = this.metadata.group("TankEntity");
|
const group = this.metadata.group("TankEntity");
|
||||||
const list: TankListEntry[] = [];
|
const list: TankListEntry[] = [];
|
||||||
const strings = await this.groupedGameStrings("en", "TankEntity");
|
const strings = await this.groupedGameStrings("en", "TankEntity", true);
|
||||||
|
|
||||||
for (const item of group) {
|
for (const item of group) {
|
||||||
const tankCatalog = item.TankCatalog();
|
const tankCatalog = item.TankCatalog();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useLocale } from "./useLocale";
|
|||||||
export function useGameStrings(group: string) {
|
export function useGameStrings(group: string) {
|
||||||
const { locale } = useLocale();
|
const { locale } = useLocale();
|
||||||
const strings = useAwait(
|
const strings = useAwait(
|
||||||
() => api.groupedGameStrings(locale, group),
|
() => api.groupedGameStrings(locale, group, true),
|
||||||
`game-strings-${locale}-${group}`
|
`game-strings-${locale}-${group}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user