replace biomes.json with biomes.toml & make it combined object
This commit is contained in:
@@ -28,8 +28,10 @@ using namespace data;
|
||||
|
||||
static debug::Logger logger("content-loader");
|
||||
|
||||
ContentLoader::ContentLoader(ContentPack* pack, ContentBuilder& builder)
|
||||
: pack(pack), builder(builder) {
|
||||
ContentLoader::ContentLoader(
|
||||
ContentPack* pack, ContentBuilder& builder, const ResPaths& paths
|
||||
)
|
||||
: pack(pack), builder(builder), paths(paths) {
|
||||
auto runtime = std::make_unique<ContentPackRuntime>(
|
||||
*pack, scripting::create_pack_environment(*pack)
|
||||
);
|
||||
|
||||
@@ -16,6 +16,7 @@ struct EntityDef;
|
||||
struct ContentPack;
|
||||
struct GeneratorDef;
|
||||
|
||||
class ResPaths;
|
||||
class ContentBuilder;
|
||||
class ContentPackRuntime;
|
||||
struct ContentPackStats;
|
||||
@@ -26,6 +27,7 @@ class ContentLoader {
|
||||
scriptenv env;
|
||||
ContentBuilder& builder;
|
||||
ContentPackStats* stats;
|
||||
const ResPaths& paths;
|
||||
|
||||
void loadBlock(
|
||||
Block& def, const std::string& full, const std::string& name
|
||||
@@ -55,7 +57,11 @@ class ContentLoader {
|
||||
|
||||
void loadContent(const dv::value& map);
|
||||
public:
|
||||
ContentLoader(ContentPack* pack, ContentBuilder& builder);
|
||||
ContentLoader(
|
||||
ContentPack* pack,
|
||||
ContentBuilder& builder,
|
||||
const ResPaths& paths
|
||||
);
|
||||
|
||||
// Refresh pack content.json
|
||||
static bool fixPackIndices(
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
#include "../ContentPack.hpp"
|
||||
|
||||
#include "files/files.hpp"
|
||||
#include "files/engine_paths.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "world/generator/GeneratorDef.hpp"
|
||||
#include "world/generator/VoxelFragment.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
||||
static BlocksLayer load_layer(
|
||||
const dv::value& map, uint& lastLayersHeight, bool& hasResizeableLayer
|
||||
@@ -167,11 +169,10 @@ static void load_structures(GeneratorDef& def, const fs::path& structuresFile) {
|
||||
}
|
||||
|
||||
static inline const auto STRUCTURES_FILE = fs::u8path("structures.json");
|
||||
static inline const auto BIOMES_FILE = fs::u8path("biomes.json");
|
||||
static inline const auto BIOMES_FILE = fs::u8path("biomes.toml");
|
||||
static inline const auto GENERATORS_DIR = fs::u8path("generators");
|
||||
|
||||
static void load_biomes(GeneratorDef& def, const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
static void load_biomes(GeneratorDef& def, const dv::value& root) {
|
||||
for (const auto& [biomeName, biomeMap] : root.asObject()) {
|
||||
try {
|
||||
def.biomes.push_back(
|
||||
@@ -205,14 +206,16 @@ void ContentLoader::loadGenerator(
|
||||
if (fs::exists(structuresFile)) {
|
||||
load_structures(def, structuresFile);
|
||||
}
|
||||
auto biomesFiles = folder / BIOMES_FILE;
|
||||
if (!fs::exists(biomesFiles)) {
|
||||
|
||||
auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE;
|
||||
auto biomesMap = paths.readCombinedObject(biomesFile.u8string());
|
||||
if (biomesMap.empty()) {
|
||||
throw std::runtime_error(
|
||||
BIOMES_FILE.u8string() +
|
||||
": file not found (at least one biome required)"
|
||||
"generator " + util::quote(def.name) +
|
||||
": at least one biome required"
|
||||
);
|
||||
}
|
||||
load_biomes(def, biomesFiles);
|
||||
load_biomes(def, biomesMap);
|
||||
def.script = scripting::load_generator(
|
||||
def, scriptFile, pack->id+":generators/"+name+".files");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user