update generators scanning
This commit is contained in:
parent
39030efd74
commit
c46090f881
@ -1,4 +1,4 @@
|
|||||||
biomes = json.parse(file.read("base:generators/demo/biomes.json"))
|
biomes = json.parse(file.read("base:generators/demo.files/biomes.json"))
|
||||||
|
|
||||||
function place_structures(x, z, w, d, seed, hmap)
|
function place_structures(x, z, w, d, seed, hmap)
|
||||||
local placements = {}
|
local placements = {}
|
||||||
@ -51,13 +51,22 @@ static void detect_defs(
|
|||||||
}
|
}
|
||||||
if (fs::is_regular_file(file) && files::is_data_file(file)) {
|
if (fs::is_regular_file(file) && files::is_data_file(file)) {
|
||||||
detected.push_back(prefix.empty() ? name : prefix + ":" + name);
|
detected.push_back(prefix.empty() ? name : prefix + ":" + name);
|
||||||
} else if (fs::is_directory(file)) {
|
} else if (fs::is_directory(file) &&
|
||||||
|
file.extension() != fs::u8path(".files")) {
|
||||||
detect_defs(file, name, detected);
|
detect_defs(file, name, detected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ContentLoader::scanContent(
|
||||||
|
const ContentPack& pack, ContentType type
|
||||||
|
) {
|
||||||
|
std::vector<std::string> detected;
|
||||||
|
detect_defs(pack.folder / ContentPack::getFolderFor(type), pack.id, detected);
|
||||||
|
return detected;
|
||||||
|
}
|
||||||
|
|
||||||
bool ContentLoader::fixPackIndices(
|
bool ContentLoader::fixPackIndices(
|
||||||
const fs::path& folder,
|
const fs::path& folder,
|
||||||
dv::value& indicesRoot,
|
dv::value& indicesRoot,
|
||||||
|
|||||||
@ -63,6 +63,11 @@ public:
|
|||||||
dv::value& indicesRoot,
|
dv::value& indicesRoot,
|
||||||
const std::string& contentSection
|
const std::string& contentSection
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static std::vector<std::string> scanContent(
|
||||||
|
const ContentPack& pack, ContentType type
|
||||||
|
);
|
||||||
|
|
||||||
void fixPackIndices();
|
void fixPackIndices();
|
||||||
void load();
|
void load();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
|
#include "content_fwd.hpp"
|
||||||
|
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ struct ContentPack {
|
|||||||
static inline const fs::path BLOCKS_FOLDER = "blocks";
|
static inline const fs::path BLOCKS_FOLDER = "blocks";
|
||||||
static inline const fs::path ITEMS_FOLDER = "items";
|
static inline const fs::path ITEMS_FOLDER = "items";
|
||||||
static inline const fs::path ENTITIES_FOLDER = "entities";
|
static inline const fs::path ENTITIES_FOLDER = "entities";
|
||||||
|
static inline const fs::path GENERATORS_FOLDER = "generators";
|
||||||
static const std::vector<std::string> RESERVED_NAMES;
|
static const std::vector<std::string> RESERVED_NAMES;
|
||||||
|
|
||||||
static bool is_pack(const fs::path& folder);
|
static bool is_pack(const fs::path& folder);
|
||||||
@ -69,6 +71,16 @@ struct ContentPack {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static ContentPack createCore(const EnginePaths*);
|
static ContentPack createCore(const EnginePaths*);
|
||||||
|
|
||||||
|
static inline fs::path getFolderFor(ContentType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ContentType::BLOCK: return ContentPack::BLOCKS_FOLDER;
|
||||||
|
case ContentType::ITEM: return ContentPack::ITEMS_FOLDER;
|
||||||
|
case ContentType::ENTITY: return ContentPack::ENTITIES_FOLDER;
|
||||||
|
case ContentType::GENERATOR: return ContentPack::GENERATORS_FOLDER;
|
||||||
|
case ContentType::NONE: return fs::u8path("");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ContentPackStats {
|
struct ContentPackStats {
|
||||||
|
|||||||
@ -74,7 +74,7 @@ void ContentLoader::loadGenerator(
|
|||||||
map.at("biome_parameters").get(def.biomeParameters);
|
map.at("biome_parameters").get(def.biomeParameters);
|
||||||
map.at("sea_level").get(def.seaLevel);
|
map.at("sea_level").get(def.seaLevel);
|
||||||
|
|
||||||
auto folder = generatorsDir / fs::u8path(name);
|
auto folder = generatorsDir / fs::u8path(name + ".files");
|
||||||
auto scriptFile = folder / fs::u8path("script.lua");
|
auto scriptFile = folder / fs::u8path("script.lua");
|
||||||
|
|
||||||
auto structuresFile = folder / STRUCTURES_FILE;
|
auto structuresFile = folder / STRUCTURES_FILE;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
|
#include "content/ContentLoader.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "files/engine_paths.hpp"
|
||||||
#include "files/settings_io.hpp"
|
#include "files/settings_io.hpp"
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
@ -14,6 +15,8 @@
|
|||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "world/generator/WorldGenerator.hpp"
|
#include "world/generator/WorldGenerator.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
|
#include "util/listutil.hpp"
|
||||||
|
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
@ -180,18 +183,26 @@ static int l_get_default_generator(lua::State* L) {
|
|||||||
/// @brief Get a list of all world generators
|
/// @brief Get a list of all world generators
|
||||||
/// @return A table with the IDs of all world generators
|
/// @return A table with the IDs of all world generators
|
||||||
static int l_get_generators(lua::State* L) {
|
static int l_get_generators(lua::State* L) {
|
||||||
if (content == nullptr) {
|
const auto& packs = engine->getContentPacks();
|
||||||
throw std::runtime_error("content is not initialized");
|
|
||||||
}
|
lua::createtable(L, 0, 0);
|
||||||
const auto& generators = content->generators.getDefs();
|
|
||||||
lua::createtable(L, generators.size(), 0);
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& [name, _] : generators) {
|
auto names = ContentLoader::scanContent(
|
||||||
|
ContentPack::createCore(engine->getPaths()), ContentType::GENERATOR);
|
||||||
|
for (const auto& name : names) {
|
||||||
lua::pushstring(L, name);
|
lua::pushstring(L, name);
|
||||||
lua::rawseti(L, i + 1);
|
lua::rawseti(L, i + 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
for (const auto& pack : packs) {
|
||||||
|
auto names = ContentLoader::scanContent(pack, ContentType::GENERATOR);
|
||||||
|
for (const auto& name : names) {
|
||||||
|
lua::pushstring(L, name);
|
||||||
|
lua::rawseti(L, i + 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user