Add a dumper for entity info

This commit is contained in:
KingRainbow44 2023-04-10 00:59:31 -04:00
parent 16875e85ac
commit 5d90dd2827
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 49 additions and 0 deletions

View File

@ -204,6 +204,42 @@ public interface Dumpers {
}
}
/**
* Dumps all entities to a JSON file.
*
* @param locale The language to dump the entities in.
*/
static void dumpEntities(String locale) {
// Reload resources.
ResourceLoader.loadAll();
Language.loadTextMaps();
// Convert all known avatars to an avatar map.
var dump = new HashMap<Integer, EntityInfo>();
GameData.getMonsterDataMap().forEach((id, monster) -> {
var langHash = monster.getNameTextMapHash();
dump.put(id, new EntityInfo(
langHash == 0 ? monster.getMonsterName() :
Language.getTextMapKey(langHash).get(locale),
monster.getMonsterName()
));
});
try {
// Create a file for the dump.
var file = new File("entities.csv");
if (file.exists() && !file.delete())
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file.");
// Write the dump to the file.
Files.writeString(file.toPath(), Dumpers.miniEncode(dump));
} catch (IOException ignored) {
throw new RuntimeException("Failed to write to file.");
}
}
@AllArgsConstructor
class CommandInfo {
public List<String> name;
@ -254,6 +290,18 @@ public interface Dumpers {
}
}
@AllArgsConstructor
class EntityInfo {
public String name;
public String internal;
@Override
public String toString() {
return this.name + ","
+ this.internal;
}
}
enum Quality {
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN;

View File

@ -153,6 +153,7 @@ public final class StartupArguments {
case "avatars" -> Dumpers.dumpAvatars(language);
case "items" -> Dumpers.dumpItems(language);
case "scenes" -> Dumpers.dumpScenes();
case "entities" -> Dumpers.dumpEntities(language);
}
Grasscutter.getLogger().info("Finished dumping.");