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

View File

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

View File

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

View File

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

View File

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

View File

@ -149,8 +149,12 @@ void EnginePaths::setProjectFolder(std::filesystem::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);
io::create_subdevice("world", "user", currentWorldFolder);
}
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 = manager.assemble(names);
contentControl.getContentPacks() = manager.getAll(names);
contentControl.setContentPacksRaw(manager.getAll(names));
}
static void reconfig_packs_inside(