mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 04:52:52 +08:00
Re-generate textmap cache if an error occurs
This commit is contained in:
parent
8bb7ae22d0
commit
8ee3dec5df
@ -85,8 +85,13 @@ public final class Tools {
|
||||
void newTranslatedLine(String template, TextStrings... textstrings) {
|
||||
for (int i = 0; i < TextStrings.NUM_LANGUAGES; i++) {
|
||||
String s = template;
|
||||
for (int j = 0; j < textstrings.length; j++)
|
||||
for (int j = 0; j < textstrings.length; j++) try {
|
||||
s = s.replace("{" + j + "}", textstrings[j].strings[i]);
|
||||
} catch (NullPointerException ignored) {
|
||||
// TextMap cache is outdated.
|
||||
j--; // Retry the action.
|
||||
Language.loadTextMaps(true);
|
||||
}
|
||||
handbookBuilders.get(i).append(s + "\n");
|
||||
}
|
||||
}
|
||||
|
@ -314,11 +314,22 @@ public final class Language {
|
||||
return getTextMapKey((int) hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads game text maps with caching.
|
||||
*/
|
||||
public static void loadTextMaps() {
|
||||
// Check system timestamps on cache and resources
|
||||
try {
|
||||
long cacheModified = Files.getLastModifiedTime(TEXTMAP_CACHE_PATH).toMillis();
|
||||
Language.loadTextMaps(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads game language data (text maps).
|
||||
*
|
||||
* @param bypassCache Should the cache be bypassed?
|
||||
*/
|
||||
public static void loadTextMaps(boolean bypassCache) {
|
||||
// Check system timestamps on cache and resources
|
||||
if (!bypassCache) try {
|
||||
long cacheModified = Files.getLastModifiedTime(TEXTMAP_CACHE_PATH).toMillis();
|
||||
long textmapsModified =
|
||||
Files.list(getResourcePath("TextMap"))
|
||||
.filter(path -> path.toString().endsWith(".json"))
|
||||
@ -344,8 +355,8 @@ public final class Language {
|
||||
textMapStrings = loadTextMapsCache();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().debug("Exception while checking cache: ", e);
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger().error("Error loading textmaps cache: " + exception.toString());
|
||||
}
|
||||
|
||||
// Regenerate cache
|
||||
|
Loading…
Reference in New Issue
Block a user