From a8289b782f6016fa66710f2727f7ad104f9008d9 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 9 Apr 2023 20:25:21 -0400 Subject: [PATCH] Add a dumper for scene info --- .../grasscutter/data/excels/SceneData.java | 39 ++++++++------- .../java/emu/grasscutter/tools/Dumpers.java | 49 +++++++++++++++++-- .../grasscutter/utils/StartupArguments.java | 1 + 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/excels/SceneData.java b/src/main/java/emu/grasscutter/data/excels/SceneData.java index 8c933354b..10a7de0a6 100644 --- a/src/main/java/emu/grasscutter/data/excels/SceneData.java +++ b/src/main/java/emu/grasscutter/data/excels/SceneData.java @@ -1,19 +1,20 @@ -package emu.grasscutter.data.excels; - -import com.google.gson.annotations.SerializedName; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import emu.grasscutter.game.props.SceneType; -import lombok.Getter; - -@ResourceType(name = "SceneExcelConfigData.json") -@Getter -public class SceneData extends GameResource { - @Getter(onMethod_ = @Override) - private int id; - - @SerializedName("type") - private SceneType sceneType; - - private String scriptData; -} +package emu.grasscutter.data.excels; + +import com.google.gson.annotations.SerializedName; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.game.props.SceneType; +import lombok.Getter; + +@ResourceType(name = "SceneExcelConfigData.json") +@Getter +public class SceneData extends GameResource { + @Getter(onMethod_ = @Override) + private int id; + + @SerializedName("type") + private SceneType sceneType; + + private String scriptData; + private String levelEntityConfig; +} diff --git a/src/main/java/emu/grasscutter/tools/Dumpers.java b/src/main/java/emu/grasscutter/tools/Dumpers.java index aa4f1bd94..deaf5e757 100644 --- a/src/main/java/emu/grasscutter/tools/Dumpers.java +++ b/src/main/java/emu/grasscutter/tools/Dumpers.java @@ -6,6 +6,7 @@ import emu.grasscutter.command.CommandMap; import emu.grasscutter.data.GameData; import emu.grasscutter.data.ResourceLoader; import emu.grasscutter.game.inventory.ItemType; +import emu.grasscutter.game.props.SceneType; import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.Language; import lombok.AllArgsConstructor; @@ -140,8 +141,8 @@ public interface Dumpers { Language.loadTextMaps(); // Convert all known items to an item map. - var originalDump = new ArrayList(); - GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemData(id, + var originalDump = new ArrayList(); + GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemInfo(id, Language.getTextMapKey(item.getNameTextMapHash()).get(locale), Quality.from(item.getRankLevel()), item.getItemType(), item.getIcon().length() > 0 ? item.getIcon().substring(3) : "" @@ -149,7 +150,7 @@ public interface Dumpers { // Create a new dump with filtered duplicates. var names = new ArrayList(); - var dump = new HashMap(); + var dump = new HashMap(); originalDump.forEach(item -> { // Validate the item. 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(); + 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 class CommandInfo { public List name; @@ -197,7 +226,7 @@ public interface Dumpers { } @AllArgsConstructor - class ItemData { + class ItemInfo { public Integer id; public String name; 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 { LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN; diff --git a/src/main/java/emu/grasscutter/utils/StartupArguments.java b/src/main/java/emu/grasscutter/utils/StartupArguments.java index ab9534554..8c06d25fd 100644 --- a/src/main/java/emu/grasscutter/utils/StartupArguments.java +++ b/src/main/java/emu/grasscutter/utils/StartupArguments.java @@ -152,6 +152,7 @@ public final class StartupArguments { case "commands" -> Dumpers.dumpCommands(language); case "avatars" -> Dumpers.dumpAvatars(language); case "items" -> Dumpers.dumpItems(language); + case "scenes" -> Dumpers.dumpScenes(); } Grasscutter.getLogger().info("Finished dumping.");