mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
add required components check
This commit is contained in:
parent
28385f236c
commit
ea0d23831f
3 changed files with 17 additions and 2 deletions
|
|
@ -188,6 +188,7 @@ public:
|
||||||
ContentUnitDefs<GeneratorDef> generators;
|
ContentUnitDefs<GeneratorDef> generators;
|
||||||
std::unique_ptr<DrawGroups> const drawGroups;
|
std::unique_ptr<DrawGroups> const drawGroups;
|
||||||
ResourceIndicesSet resourceIndices {};
|
ResourceIndicesSet resourceIndices {};
|
||||||
|
std::set<std::string> components {};
|
||||||
|
|
||||||
Content(
|
Content(
|
||||||
std::unique_ptr<ContentIndices> indices,
|
std::unique_ptr<ContentIndices> indices,
|
||||||
|
|
|
||||||
|
|
@ -506,6 +506,7 @@ void ContentLoader::loadScripts(Content& content) {
|
||||||
scripting::on_scripts_loading();
|
scripting::on_scripts_loading();
|
||||||
load_scripts(content, content.blocks);
|
load_scripts(content, content.blocks);
|
||||||
load_scripts(content, content.items);
|
load_scripts(content, content.items);
|
||||||
|
auto& tmpContent = content;
|
||||||
|
|
||||||
for (const auto& [packid, runtime] : content.getPacks()) {
|
for (const auto& [packid, runtime] : content.getPacks()) {
|
||||||
auto env = runtime->getEnvironment();
|
auto env = runtime->getEnvironment();
|
||||||
|
|
@ -516,7 +517,7 @@ void ContentLoader::loadScripts(Content& content) {
|
||||||
|
|
||||||
// Load entity components
|
// Load entity components
|
||||||
io::path componentsDir = folder / "scripts/components";
|
io::path componentsDir = folder / "scripts/components";
|
||||||
foreach_file(componentsDir, [&pack, env](const io::path& file) {
|
foreach_file(componentsDir, [&pack, env, &tmpContent](const io::path& file) {
|
||||||
auto name = pack.id + ":" + file.stem();
|
auto name = pack.id + ":" + file.stem();
|
||||||
scripting::load_entity_component(
|
scripting::load_entity_component(
|
||||||
env,
|
env,
|
||||||
|
|
@ -524,9 +525,21 @@ void ContentLoader::loadScripts(Content& content) {
|
||||||
file,
|
file,
|
||||||
pack.id + ":scripts/components/" + file.name()
|
pack.id + ":scripts/components/" + file.name()
|
||||||
);
|
);
|
||||||
|
tmpContent.components.insert(name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& [eid, def] : content.entities.getDefs()) {
|
||||||
|
for (const auto& instance : def->components) {
|
||||||
|
if (content.components.find(instance.component) == content.components.end()) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"component " + instance.component +
|
||||||
|
" is not available (required by entity " + eid + ")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scripting::on_content_loaded();
|
scripting::on_content_loaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -744,9 +744,10 @@ void scripting::load_entity_component(
|
||||||
const io::path& file,
|
const io::path& file,
|
||||||
const std::string& fileName
|
const std::string& fileName
|
||||||
) {
|
) {
|
||||||
|
logger.info() << "script (component) " << file.string();
|
||||||
|
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
std::string src = io::read_string(file);
|
std::string src = io::read_string(file);
|
||||||
logger.info() << "script (component) " << file.string();
|
|
||||||
lua::loadbuffer(L, *env, src, fileName);
|
lua::loadbuffer(L, *env, src, fileName);
|
||||||
lua::store_in_registry(L, lua::CHUNKS_TABLE, name);
|
lua::store_in_registry(L, lua::CHUNKS_TABLE, name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue