Add a dumper for scene info

This commit is contained in:
KingRainbow44 2023-04-09 20:25:21 -04:00
parent faadffda21
commit a8289b782f
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 66 additions and 23 deletions

View File

@ -16,4 +16,5 @@ public class SceneData extends GameResource {
private SceneType sceneType; private SceneType sceneType;
private String scriptData; private String scriptData;
private String levelEntityConfig;
} }

View File

@ -6,6 +6,7 @@ import emu.grasscutter.command.CommandMap;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader; import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.Language; import emu.grasscutter.utils.Language;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -140,8 +141,8 @@ public interface Dumpers {
Language.loadTextMaps(); Language.loadTextMaps();
// Convert all known items to an item map. // Convert all known items to an item map.
var originalDump = new ArrayList<ItemData>(); var originalDump = new ArrayList<ItemInfo>();
GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemData(id, GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemInfo(id,
Language.getTextMapKey(item.getNameTextMapHash()).get(locale), Language.getTextMapKey(item.getNameTextMapHash()).get(locale),
Quality.from(item.getRankLevel()), item.getItemType(), Quality.from(item.getRankLevel()), item.getItemType(),
item.getIcon().length() > 0 ? item.getIcon().substring(3) : "" item.getIcon().length() > 0 ? item.getIcon().substring(3) : ""
@ -149,7 +150,7 @@ public interface Dumpers {
// Create a new dump with filtered duplicates. // Create a new dump with filtered duplicates.
var names = new ArrayList<String>(); var names = new ArrayList<String>();
var dump = new HashMap<Integer, ItemData>(); var dump = new HashMap<Integer, ItemInfo>();
originalDump.forEach(item -> { originalDump.forEach(item -> {
// Validate the item. // Validate the item.
if (item.name.contains("[CHS]")) return; if (item.name.contains("[CHS]")) return;
@ -175,6 +176,34 @@ public interface Dumpers {
} }
} }
/**
* Dumps all scenes to a JSON file.
*/
static void dumpScenes() {
// Reload resources.
ResourceLoader.loadAll();
Language.loadTextMaps();
// Convert all known scenes to a scene map.
var dump = new HashMap<Integer, SceneInfo>();
GameData.getSceneDataMap().forEach((id, scene) ->
dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType())));
try {
// Create a file for the dump.
var file = new File("scenes.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;
@ -197,7 +226,7 @@ public interface Dumpers {
} }
@AllArgsConstructor @AllArgsConstructor
class ItemData { class ItemInfo {
public Integer id; public Integer id;
public String name; public String name;
public Quality quality; public Quality quality;
@ -213,6 +242,18 @@ public interface Dumpers {
} }
} }
@AllArgsConstructor
class SceneInfo {
public String identifier;
public SceneType type;
@Override
public String toString() {
return this.identifier + ","
+ this.type;
}
}
enum Quality { enum Quality {
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN; LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN;

View File

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