mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-13 16:22:52 +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.game.props.SceneType;
|
||||||
import emu.grasscutter.utils.JsonUtils;
|
import emu.grasscutter.utils.JsonUtils;
|
||||||
import emu.grasscutter.utils.lang.Language;
|
import emu.grasscutter.utils.lang.Language;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -17,7 +19,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
public interface Dumpers {
|
public interface Dumpers {
|
||||||
// See `src/handbook/data/README.md` for attributions.
|
// 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
|
@AllArgsConstructor
|
||||||
class CommandInfo {
|
class CommandInfo {
|
||||||
public List<String> name;
|
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 {
|
enum Quality {
|
||||||
LEGENDARY,
|
LEGENDARY,
|
||||||
EPIC,
|
EPIC,
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package emu.grasscutter.utils;
|
package emu.grasscutter.utils;
|
||||||
|
|
||||||
import static emu.grasscutter.config.Configuration.*;
|
|
||||||
|
|
||||||
import ch.qos.logback.classic.Level;
|
import ch.qos.logback.classic.Level;
|
||||||
import ch.qos.logback.classic.Logger;
|
import ch.qos.logback.classic.Logger;
|
||||||
import emu.grasscutter.BuildConfig;
|
import emu.grasscutter.BuildConfig;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||||
import emu.grasscutter.tools.Dumpers;
|
import emu.grasscutter.tools.Dumpers;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
import static emu.grasscutter.config.Configuration.*;
|
||||||
|
|
||||||
/** A parser for start-up arguments. */
|
/** A parser for start-up arguments. */
|
||||||
public interface StartupArguments {
|
public interface StartupArguments {
|
||||||
@ -164,6 +165,7 @@ public interface StartupArguments {
|
|||||||
case "scenes" -> Dumpers.dumpScenes();
|
case "scenes" -> Dumpers.dumpScenes();
|
||||||
case "entities" -> Dumpers.dumpEntities(language);
|
case "entities" -> Dumpers.dumpEntities(language);
|
||||||
case "quests" -> Dumpers.dumpQuests(language);
|
case "quests" -> Dumpers.dumpQuests(language);
|
||||||
|
case "areas" -> Dumpers.dumpAreas(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Finished dumping.");
|
Grasscutter.getLogger().info("Finished dumping.");
|
||||||
|
Loading…
Reference in New Issue
Block a user