add 'player-entity' to defaults.toml
This commit is contained in:
parent
f0c7bc6377
commit
3430e5cd6f
@ -1 +1,2 @@
|
|||||||
generator = "core:default"
|
generator = "core:default"
|
||||||
|
player-entity = ""
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
generator = "base:demo"
|
generator = "base:demo"
|
||||||
|
player-entity = "base:player"
|
||||||
|
|||||||
@ -34,12 +34,14 @@ Content::Content(
|
|||||||
UptrsMap<std::string, ContentPackRuntime> packs,
|
UptrsMap<std::string, ContentPackRuntime> packs,
|
||||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
||||||
ResourceIndicesSet resourceIndices
|
ResourceIndicesSet resourceIndices,
|
||||||
|
dv::value defaults
|
||||||
)
|
)
|
||||||
: indices(std::move(indices)),
|
: indices(std::move(indices)),
|
||||||
packs(std::move(packs)),
|
packs(std::move(packs)),
|
||||||
blockMaterials(std::move(blockMaterials)),
|
blockMaterials(std::move(blockMaterials)),
|
||||||
skeletons(std::move(skeletons)),
|
skeletons(std::move(skeletons)),
|
||||||
|
defaults(std::move(defaults)),
|
||||||
blocks(std::move(blocks)),
|
blocks(std::move(blocks)),
|
||||||
items(std::move(items)),
|
items(std::move(items)),
|
||||||
entities(std::move(entities)),
|
entities(std::move(entities)),
|
||||||
|
|||||||
@ -201,6 +201,7 @@ class Content {
|
|||||||
UptrsMap<std::string, ContentPackRuntime> packs;
|
UptrsMap<std::string, ContentPackRuntime> packs;
|
||||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
||||||
|
dv::value defaults = nullptr;
|
||||||
public:
|
public:
|
||||||
ContentUnitDefs<Block> blocks;
|
ContentUnitDefs<Block> blocks;
|
||||||
ContentUnitDefs<ItemDef> items;
|
ContentUnitDefs<ItemDef> items;
|
||||||
@ -219,7 +220,8 @@ public:
|
|||||||
UptrsMap<std::string, ContentPackRuntime> packs,
|
UptrsMap<std::string, ContentPackRuntime> packs,
|
||||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
||||||
ResourceIndicesSet resourceIndices
|
ResourceIndicesSet resourceIndices,
|
||||||
|
dv::value defaults
|
||||||
);
|
);
|
||||||
~Content();
|
~Content();
|
||||||
|
|
||||||
@ -231,6 +233,10 @@ public:
|
|||||||
return resourceIndices[static_cast<size_t>(type)];
|
return resourceIndices[static_cast<size_t>(type)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const dv::value& getDefaults() const {
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
const rigging::SkeletonConfig* getSkeleton(const std::string& id) const;
|
const rigging::SkeletonConfig* getSkeleton(const std::string& id) const;
|
||||||
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
||||||
const ContentPackRuntime* getPackRuntime(const std::string& id) const;
|
const ContentPackRuntime* getPackRuntime(const std::string& id) const;
|
||||||
|
|||||||
@ -84,7 +84,8 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
|||||||
std::move(packs),
|
std::move(packs),
|
||||||
std::move(blockMaterials),
|
std::move(blockMaterials),
|
||||||
std::move(skeletons),
|
std::move(skeletons),
|
||||||
std::move(resourceIndices)
|
std::move(resourceIndices),
|
||||||
|
std::move(defaults)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Now, it's time to resolve foreign keys
|
// Now, it's time to resolve foreign keys
|
||||||
|
|||||||
@ -73,6 +73,7 @@ public:
|
|||||||
ContentUnitBuilder<EntityDef> entities {allNames, ContentType::ENTITY};
|
ContentUnitBuilder<EntityDef> entities {allNames, ContentType::ENTITY};
|
||||||
ContentUnitBuilder<GeneratorDef> generators {allNames, ContentType::GENERATOR};
|
ContentUnitBuilder<GeneratorDef> generators {allNames, ContentType::GENERATOR};
|
||||||
ResourceIndicesSet resourceIndices {};
|
ResourceIndicesSet resourceIndices {};
|
||||||
|
dv::value defaults = nullptr;
|
||||||
|
|
||||||
~ContentBuilder();
|
~ContentBuilder();
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
#include "data/dv_util.hpp"
|
#include "data/dv_util.hpp"
|
||||||
#include "data/StructLayout.hpp"
|
#include "data/StructLayout.hpp"
|
||||||
#include "presets/ParticlesPreset.hpp"
|
#include "presets/ParticlesPreset.hpp"
|
||||||
|
#include "io/engine_paths.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace data;
|
using namespace data;
|
||||||
@ -760,6 +761,10 @@ void ContentLoader::load() {
|
|||||||
|
|
||||||
auto folder = pack->folder;
|
auto folder = pack->folder;
|
||||||
|
|
||||||
|
builder.defaults = paths.readCombinedObject(
|
||||||
|
EnginePaths::CONFIG_DEFAULTS.string()
|
||||||
|
);
|
||||||
|
|
||||||
// Load world generators
|
// Load world generators
|
||||||
io::path generatorsDir = folder / "generators";
|
io::path generatorsDir = folder / "generators";
|
||||||
foreach_file(generatorsDir, [this](const io::path& file) {
|
foreach_file(generatorsDir, [this](const io::path& file) {
|
||||||
|
|||||||
@ -39,8 +39,7 @@ public:
|
|||||||
|
|
||||||
static std::tuple<std::string, std::string> parsePath(std::string_view view);
|
static std::tuple<std::string, std::string> parsePath(std::string_view view);
|
||||||
|
|
||||||
static inline auto CONFIG_DEFAULTS =
|
static inline io::path CONFIG_DEFAULTS = "config/defaults.toml";
|
||||||
std::filesystem::u8path("config/defaults.toml");
|
|
||||||
private:
|
private:
|
||||||
std::filesystem::path userFilesFolder {"."};
|
std::filesystem::path userFilesFolder {"."};
|
||||||
std::filesystem::path resourcesFolder {"res"};
|
std::filesystem::path resourcesFolder {"res"};
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/generator/VoxelFragment.hpp"
|
#include "world/generator/VoxelFragment.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
|
#include "content/Content.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "../lua_custom_types.hpp"
|
#include "../lua_custom_types.hpp"
|
||||||
|
|
||||||
@ -69,8 +70,9 @@ static int l_get_generators(lua::State* L) {
|
|||||||
/// @brief Get the default world generator
|
/// @brief Get the default world generator
|
||||||
/// @return The ID of the default world generator
|
/// @return The ID of the default world generator
|
||||||
static int l_get_default_generator(lua::State* L) {
|
static int l_get_default_generator(lua::State* L) {
|
||||||
|
// content is not initialized yet
|
||||||
auto combined = engine->getResPaths()->readCombinedObject(
|
auto combined = engine->getResPaths()->readCombinedObject(
|
||||||
EnginePaths::CONFIG_DEFAULTS.u8string()
|
EnginePaths::CONFIG_DEFAULTS.string()
|
||||||
);
|
);
|
||||||
return lua::pushstring(L, combined["generator"].asString());
|
return lua::pushstring(L, combined["generator"].asString());
|
||||||
}
|
}
|
||||||
@ -81,4 +83,5 @@ const luaL_Reg generationlib[] = {
|
|||||||
{"load_fragment", lua::wrap<l_load_fragment>},
|
{"load_fragment", lua::wrap<l_load_fragment>},
|
||||||
{"get_generators", lua::wrap<l_get_generators>},
|
{"get_generators", lua::wrap<l_get_generators>},
|
||||||
{"get_default_generator", lua::wrap<l_get_default_generator>},
|
{"get_default_generator", lua::wrap<l_get_default_generator>},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|||||||
@ -63,10 +63,14 @@ Player::~Player() = default;
|
|||||||
|
|
||||||
void Player::updateEntity() {
|
void Player::updateEntity() {
|
||||||
if (eid == ENTITY_AUTO) {
|
if (eid == ENTITY_AUTO) {
|
||||||
auto& def = level.content.entities.require("base:player");
|
const auto& defaults = level.content.getDefaults();
|
||||||
eid = level.entities->spawn(def, getPosition());
|
const auto& defName = defaults["player-entity"].asString();
|
||||||
if (auto entity = level.entities->get(eid)) {
|
if (!defName.empty()) {
|
||||||
entity->setPlayer(id);
|
auto& def = level.content.entities.require(defName);
|
||||||
|
eid = level.entities->spawn(def, getPosition());
|
||||||
|
if (auto entity = level.entities->get(eid)) {
|
||||||
|
entity->setPlayer(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (auto entity = level.entities->get(eid)) {
|
} else if (auto entity = level.entities->get(eid)) {
|
||||||
position = entity->getTransform().pos;
|
position = entity->getTransform().pos;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user