mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 07:10:46 +00:00
Add a dumper for scene info
This commit is contained in:
parent
faadffda21
commit
a8289b782f
@ -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;
|
||||
}
|
||||
|
@ -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<ItemData>();
|
||||
GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemData(id,
|
||||
var originalDump = new ArrayList<ItemInfo>();
|
||||
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<String>();
|
||||
var dump = new HashMap<Integer, ItemData>();
|
||||
var dump = new HashMap<Integer, ItemInfo>();
|
||||
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<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
|
||||
class CommandInfo {
|
||||
public List<String> 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;
|
||||
|
||||
|
@ -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.");
|
||||
|
Loading…
Reference in New Issue
Block a user