world creation content menu
This commit is contained in:
@@ -247,6 +247,13 @@ void Engine::loadContent() {
|
||||
onAssetsLoaded();
|
||||
}
|
||||
|
||||
void Engine::resetContent() {
|
||||
auto manager = createPacksManager(fs::path());
|
||||
manager.scan();
|
||||
contentPacks = manager.getAll(basePacks);
|
||||
loadContent();
|
||||
}
|
||||
|
||||
void Engine::loadWorldContent(const fs::path& folder) {
|
||||
contentPacks.clear();
|
||||
auto packNames = ContentPack::worldPacksList(folder);
|
||||
@@ -304,6 +311,10 @@ std::vector<ContentPack>& Engine::getContentPacks() {
|
||||
return contentPacks;
|
||||
}
|
||||
|
||||
std::vector<std::string>& Engine::getBasePacks() {
|
||||
return basePacks;
|
||||
}
|
||||
|
||||
EnginePaths* Engine::getPaths() {
|
||||
return paths;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class Engine : public util::ObjectsKeeper {
|
||||
std::queue<runnable> postRunnables;
|
||||
std::recursive_mutex postRunnablesMutex;
|
||||
std::unique_ptr<EngineController> controller;
|
||||
std::vector<std::string> basePacks {"base"};
|
||||
|
||||
uint64_t frame = 0;
|
||||
double lastTime = 0.0;
|
||||
@@ -87,6 +88,8 @@ public:
|
||||
|
||||
/// @brief Load all selected content-packs and reload assets
|
||||
void loadContent();
|
||||
|
||||
void resetContent();
|
||||
|
||||
/// @brief Collect world content-packs and load content
|
||||
/// @see loadContent
|
||||
@@ -120,6 +123,8 @@ public:
|
||||
/// @brief Get selected content packs
|
||||
std::vector<ContentPack>& getContentPacks();
|
||||
|
||||
std::vector<std::string>& getBasePacks();
|
||||
|
||||
/// @brief Get current screen
|
||||
std::shared_ptr<Screen> getScreen();
|
||||
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
#include "../../engine.h"
|
||||
|
||||
MenuScreen::MenuScreen(Engine* engine) : Screen(engine) {
|
||||
engine->getContentPacks().clear();
|
||||
engine->loadContent();
|
||||
|
||||
engine->resetContent();
|
||||
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->reset();
|
||||
menu->setPage("main");
|
||||
|
||||
@@ -178,7 +178,6 @@ void EngineController::createWorld(
|
||||
EnginePaths* paths = engine->getPaths();
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
||||
try {
|
||||
engine->loadAllPacks();
|
||||
engine->loadContent();
|
||||
paths->setWorldFolder(folder);
|
||||
} catch (const contentpack_error& error) {
|
||||
@@ -223,7 +222,6 @@ void EngineController::reconfigPacks(
|
||||
std::vector<std::string> packsToRemove
|
||||
) {
|
||||
auto content = engine->getContent();
|
||||
auto world = controller->getLevel()->getWorld();
|
||||
bool hasIndices = false;
|
||||
|
||||
std::stringstream ss;
|
||||
@@ -238,21 +236,33 @@ void EngineController::reconfigPacks(
|
||||
}
|
||||
|
||||
runnable removeFunc = [=]() {
|
||||
controller->saveWorld();
|
||||
auto manager = engine->createPacksManager(world->wfile->getFolder());
|
||||
manager.scan();
|
||||
if (controller == nullptr) {
|
||||
auto manager = engine->createPacksManager(fs::path(""));
|
||||
manager.scan();
|
||||
std::vector<std::string> names = engine->getBasePacks();
|
||||
for (auto& name : packsToAdd) {
|
||||
names.push_back(name);
|
||||
}
|
||||
engine->getContentPacks() = manager.getAll(names);
|
||||
} else {
|
||||
auto world = controller->getLevel()->getWorld();
|
||||
auto wfile = world->wfile.get();
|
||||
controller->saveWorld();
|
||||
auto manager = engine->createPacksManager(wfile->getFolder());
|
||||
manager.scan();
|
||||
|
||||
auto names = PacksManager::getNames(world->getPacks());
|
||||
for (const auto& id : packsToAdd) {
|
||||
names.push_back(id);
|
||||
auto names = PacksManager::getNames(world->getPacks());
|
||||
for (const auto& id : packsToAdd) {
|
||||
names.push_back(id);
|
||||
}
|
||||
for (const auto& id : packsToRemove) {
|
||||
manager.exclude(id);
|
||||
names.erase(std::find(names.begin(), names.end(), id));
|
||||
}
|
||||
wfile->removeIndices(packsToRemove);
|
||||
wfile->writePacks(manager.getAll(names));
|
||||
reopenWorld(world);
|
||||
}
|
||||
for (const auto& id : packsToRemove) {
|
||||
manager.exclude(id);
|
||||
names.erase(std::find(names.begin(), names.end(), id));
|
||||
}
|
||||
world->wfile->removeIndices(packsToRemove);
|
||||
world->wfile->writePacks(manager.getAll(names));
|
||||
reopenWorld(world);
|
||||
};
|
||||
|
||||
if (hasIndices) {
|
||||
|
||||
@@ -30,6 +30,7 @@ static int l_pack_get_folder(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// @brief pack.get_installed() -> array<string>
|
||||
static int l_pack_get_installed(lua_State* L) {
|
||||
auto& packs = scripting::engine->getContentPacks();
|
||||
lua_createtable(L, packs.size(), 0);
|
||||
@@ -40,9 +41,12 @@ static int l_pack_get_installed(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// @brief pack.get_available() -> array<string>
|
||||
/// @brief pack.get_available() -> array<string>
|
||||
static int l_pack_get_available(lua_State* L) {
|
||||
auto worldFolder = scripting::level->getWorld()->wfile->getFolder();
|
||||
fs::path worldFolder("");
|
||||
if (scripting::level) {
|
||||
worldFolder = scripting::level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
auto manager = scripting::engine->createPacksManager(worldFolder);
|
||||
manager.scan();
|
||||
|
||||
@@ -131,7 +135,10 @@ static int l_pack_get_info(lua_State* L) {
|
||||
});
|
||||
if (found == packs.end()) {
|
||||
// TODO: optimize
|
||||
auto worldFolder = scripting::level->getWorld()->wfile->getFolder();
|
||||
fs::path worldFolder("");
|
||||
if (scripting::level) {
|
||||
worldFolder = scripting::level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
auto manager = scripting::engine->createPacksManager(worldFolder);
|
||||
manager.scan();
|
||||
auto vec = manager.getAll({packid});
|
||||
@@ -144,10 +151,21 @@ static int l_pack_get_info(lua_State* L) {
|
||||
return l_pack_get_info(L, pack, content);
|
||||
}
|
||||
|
||||
static int l_pack_get_base_packs(lua_State* L) {
|
||||
auto& packs = scripting::engine->getBasePacks();
|
||||
lua_createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
lua_pushstring(L, packs[i].c_str());
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg packlib [] = {
|
||||
{"get_folder", lua_wrap_errors<l_pack_get_folder>},
|
||||
{"get_installed", lua_wrap_errors<l_pack_get_installed>},
|
||||
{"get_available", lua_wrap_errors<l_pack_get_available>},
|
||||
{"get_info", lua_wrap_errors<l_pack_get_info>},
|
||||
{"get_base_packs", lua_wrap_errors<l_pack_get_base_packs>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user