mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 05:09:17 +00:00
Add a dumper for entity info
This commit is contained in:
parent
16875e85ac
commit
5d90dd2827
@ -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
|
@AllArgsConstructor
|
||||||
class CommandInfo {
|
class CommandInfo {
|
||||||
public List<String> name;
|
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 {
|
enum Quality {
|
||||||
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN;
|
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN;
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ public final class StartupArguments {
|
|||||||
case "avatars" -> Dumpers.dumpAvatars(language);
|
case "avatars" -> Dumpers.dumpAvatars(language);
|
||||||
case "items" -> Dumpers.dumpItems(language);
|
case "items" -> Dumpers.dumpItems(language);
|
||||||
case "scenes" -> Dumpers.dumpScenes();
|
case "scenes" -> Dumpers.dumpScenes();
|
||||||
|
case "entities" -> Dumpers.dumpEntities(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Finished dumping.");
|
Grasscutter.getLogger().info("Finished dumping.");
|
||||||
|
Loading…
Reference in New Issue
Block a user