mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-09 14:02:58 +08:00
Add dumper for world areas
This commit is contained in:
parent
6cf9e03ead
commit
f1baaf5869
@ -9,6 +9,8 @@ import emu.grasscutter.game.inventory.ItemType;
|
||||
import emu.grasscutter.game.props.SceneType;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
import emu.grasscutter.utils.lang.Language;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -17,7 +19,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
public interface Dumpers {
|
||||
// See `src/handbook/data/README.md` for attributions.
|
||||
@ -337,6 +338,49 @@ public interface Dumpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps all areas to a CSV file.
|
||||
*
|
||||
* @param locale The language to dump the areas in.
|
||||
*/
|
||||
static void dumpAreas(String locale) {
|
||||
// Reload resources.
|
||||
ResourceLoader.loadAll();
|
||||
Language.loadTextMaps();
|
||||
|
||||
// Convert all known areas to an area map.
|
||||
var dump = new HashMap<Integer, AreaInfo>();
|
||||
GameData.getWorldAreaDataMap()
|
||||
.forEach(
|
||||
(id, area) -> {
|
||||
var langHash = area.getTextMapHash();
|
||||
dump.put(
|
||||
area.getChildArea() == 0 ?
|
||||
area.getParentArea() :
|
||||
area.getChildArea(),
|
||||
new AreaInfo(
|
||||
area.getParentArea(),
|
||||
langHash == 0
|
||||
? "Unknown"
|
||||
: Language.getTextMapKey(langHash).get(locale)
|
||||
));
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("areas.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,
|
||||
"id", "parent", "name"));
|
||||
} catch (IOException ignored) {
|
||||
throw new RuntimeException("Failed to write to file.");
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
class CommandInfo {
|
||||
public List<String> name;
|
||||
@ -414,6 +458,17 @@ public interface Dumpers {
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
class AreaInfo {
|
||||
public int parent;
|
||||
public String name;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.parent + "," + this.name;
|
||||
}
|
||||
}
|
||||
|
||||
enum Quality {
|
||||
LEGENDARY,
|
||||
EPIC,
|
||||
|
@ -1,17 +1,18 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import emu.grasscutter.BuildConfig;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||
import emu.grasscutter.tools.Dumpers;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
|
||||
/** A parser for start-up arguments. */
|
||||
public interface StartupArguments {
|
||||
@ -164,6 +165,7 @@ public interface StartupArguments {
|
||||
case "scenes" -> Dumpers.dumpScenes();
|
||||
case "entities" -> Dumpers.dumpEntities(language);
|
||||
case "quests" -> Dumpers.dumpQuests(language);
|
||||
case "areas" -> Dumpers.dumpAreas(language);
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info("Finished dumping.");
|
||||
|
Loading…
Reference in New Issue
Block a user