fix content control (#538)

* update ContentControl
* feat: more debug logging
* fix engine paths
This commit is contained in:
MihailRis 2025-07-01 23:38:00 +03:00 committed by GitHub
parent af3c315c04
commit 215ae02fa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 30 additions and 18 deletions

View File

@ -54,7 +54,7 @@ void ContentControl::resetContent() {
scripting::cleanup(); scripting::cleanup();
std::vector<PathsRoot> resRoots; std::vector<PathsRoot> resRoots;
{ {
auto pack = ContentPack::createCore(paths); auto pack = ContentPack::createCore();
resRoots.push_back({"core", pack.folder}); resRoots.push_back({"core", pack.folder});
load_configs(input, pack.folder); load_configs(input, pack.folder);
} }
@ -66,8 +66,7 @@ void ContentControl::resetContent() {
content.reset(); content.reset();
scripting::on_content_reset(); scripting::on_content_reset();
contentPacks.clear(); setContentPacksRaw(manager->getAll(basePacks));
contentPacks = manager->getAll(basePacks);
postContent(); postContent();
} }
@ -98,10 +97,8 @@ void ContentControl::loadContent() {
ContentBuilder contentBuilder; ContentBuilder contentBuilder;
corecontent::setup(input, contentBuilder); corecontent::setup(input, contentBuilder);
auto corePack = ContentPack::createCore(paths); allPacks = contentPacks;
allPacks.insert(allPacks.begin(), ContentPack::createCore());
auto allPacks = contentPacks;
allPacks.insert(allPacks.begin(), corePack);
// Setup filesystem entry points // Setup filesystem entry points
std::vector<PathsRoot> resRoots; std::vector<PathsRoot> resRoots;
@ -122,14 +119,21 @@ void ContentControl::loadContent() {
postContent(); postContent();
} }
std::vector<ContentPack>& ContentControl::getContentPacks() { void ContentControl::setContentPacksRaw(std::vector<ContentPack>&& packs) {
if (content) {
throw std::runtime_error("setContentPacksRaw called with content loaded");
}
contentPacks = std::move(packs);
allPacks = contentPacks;
allPacks.insert(allPacks.begin(), ContentPack::createCore());
}
const std::vector<ContentPack>& ContentControl::getContentPacks() const {
return contentPacks; return contentPacks;
} }
std::vector<ContentPack> ContentControl::getAllContentPacks() { const std::vector<ContentPack>& ContentControl::getAllContentPacks() const {
auto packs = contentPacks; return allPacks;
packs.insert(packs.begin(), ContentPack::createCore(paths));
return packs;
} }
PacksManager& ContentControl::scan() { PacksManager& ContentControl::scan() {

View File

@ -40,8 +40,10 @@ public:
void loadContent(); void loadContent();
std::vector<ContentPack>& getContentPacks(); void setContentPacksRaw(std::vector<ContentPack>&& packs);
std::vector<ContentPack> getAllContentPacks();
const std::vector<ContentPack>& getContentPacks() const;
const std::vector<ContentPack>& getAllContentPacks() const;
PacksManager& scan(); PacksManager& scan();
private: private:
@ -52,4 +54,5 @@ private:
std::vector<std::string> basePacks; std::vector<std::string> basePacks;
std::unique_ptr<PacksManager> manager; std::unique_ptr<PacksManager> manager;
std::vector<ContentPack> contentPacks; std::vector<ContentPack> contentPacks;
std::vector<ContentPack> allPacks; // includes 'core'
}; };

View File

@ -13,7 +13,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
ContentPack ContentPack::createCore(const EnginePaths& paths) { ContentPack ContentPack::createCore() {
return ContentPack { return ContentPack {
"core", "Core", ENGINE_VERSION_STRING, "", "", "res:", {} "core", "Core", ENGINE_VERSION_STRING, "", "", "res:", {}
}; };

View File

@ -73,7 +73,7 @@ struct ContentPack {
const std::string& name const std::string& name
); );
static ContentPack createCore(const EnginePaths&); static ContentPack createCore();
static inline io::path getFolderFor(ContentType type) { static inline io::path getFolderFor(ContentType type) {
switch (type) { switch (type) {

View File

@ -115,6 +115,7 @@ LevelScreen::~LevelScreen() {
void LevelScreen::initializeContent() { void LevelScreen::initializeContent() {
auto& content = controller->getLevel()->content; auto& content = controller->getLevel()->content;
for (auto& entry : content.getPacks()) { for (auto& entry : content.getPacks()) {
logger.info() << "initializing pack '" << entry.first << "'";
initializePack(entry.second.get()); initializePack(entry.second.get());
} }
scripting::on_frontend_init( scripting::on_frontend_init(

View File

@ -149,8 +149,12 @@ void EnginePaths::setProjectFolder(std::filesystem::path folder) {
} }
void EnginePaths::setCurrentWorldFolder(io::path folder) { void EnginePaths::setCurrentWorldFolder(io::path folder) {
if (folder.empty()) {
io::remove_device("world");
} else {
io::create_subdevice("world", "user", folder);
}
this->currentWorldFolder = std::move(folder); this->currentWorldFolder = std::move(folder);
io::create_subdevice("world", "user", currentWorldFolder);
} }
std::string EnginePaths::mount(const io::path& file) { std::string EnginePaths::mount(const io::path& file) {

View File

@ -323,7 +323,7 @@ static void reconfig_packs_outside(
names.erase(std::find(names.begin(), names.end(), id)); names.erase(std::find(names.begin(), names.end(), id));
} }
names = manager.assemble(names); names = manager.assemble(names);
contentControl.getContentPacks() = manager.getAll(names); contentControl.setContentPacksRaw(manager.getAll(names));
} }
static void reconfig_packs_inside( static void reconfig_packs_inside(