world creation content menu
This commit is contained in:
parent
5402872c28
commit
bab806c2f8
@ -7,6 +7,7 @@ rem_packs = {}
|
|||||||
|
|
||||||
function apply()
|
function apply()
|
||||||
core.reconfig_packs(add_packs, rem_packs)
|
core.reconfig_packs(add_packs, rem_packs)
|
||||||
|
menu:back()
|
||||||
end
|
end
|
||||||
|
|
||||||
function refresh_changes()
|
function refresh_changes()
|
||||||
@ -74,6 +75,7 @@ end
|
|||||||
function refresh()
|
function refresh()
|
||||||
packs_installed = pack.get_installed()
|
packs_installed = pack.get_installed()
|
||||||
packs_available = pack.get_available()
|
packs_available = pack.get_available()
|
||||||
|
base_packs = pack.get_base_packs()
|
||||||
packs_all = {unpack(packs_installed)}
|
packs_all = {unpack(packs_installed)}
|
||||||
required = {}
|
required = {}
|
||||||
for i,k in ipairs(packs_available) do
|
for i,k in ipairs(packs_available) do
|
||||||
@ -82,14 +84,13 @@ function refresh()
|
|||||||
|
|
||||||
local packs_cur = document.packs_cur
|
local packs_cur = document.packs_cur
|
||||||
local packs_add = document.packs_add
|
local packs_add = document.packs_add
|
||||||
|
|
||||||
packs_cur:clear()
|
packs_cur:clear()
|
||||||
packs_add:clear()
|
packs_add:clear()
|
||||||
|
|
||||||
for i,id in ipairs(packs_installed) do
|
for i,id in ipairs(packs_installed) do
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
packinfo.index = i
|
packinfo.index = i
|
||||||
callback = id ~= "base" and string.format('move_pack("%s")', id) or nil
|
callback = not table.has(base_packs, id) and string.format('move_pack("%s")', id) or nil
|
||||||
packinfo.error = check_dependencies(packinfo)
|
packinfo.error = check_dependencies(packinfo)
|
||||||
place_pack(packs_cur, packinfo, callback)
|
place_pack(packs_cur, packinfo, callback)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
<button onclick='save_state() menu.page="generators"' id='generator_btn'>
|
<button onclick='save_state() menu.page="generators"' id='generator_btn'>
|
||||||
@World generator
|
@World generator
|
||||||
</button>
|
</button>
|
||||||
|
<button id='content_btn' onclick='save_state() menu.page="content"'/>
|
||||||
<button onclick='create_world()' margin='1,20,1,1'>
|
<button onclick='create_world()' margin='1,20,1,1'>
|
||||||
@Create World
|
@Create World
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@ -30,6 +30,9 @@ function create_world()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_open()
|
function on_open()
|
||||||
|
document.content_btn.text = string.format(
|
||||||
|
"%s [%s]", gui.str("Content", "menu"), #pack.get_installed()
|
||||||
|
)
|
||||||
if settings.generator == nil then
|
if settings.generator == nil then
|
||||||
settings.generator = core.get_default_generator()
|
settings.generator = core.get_default_generator()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -263,6 +263,17 @@ function table.remove_value(t, x)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function table.tostring(t)
|
||||||
|
local s = '['
|
||||||
|
for i,v in ipairs(t) do
|
||||||
|
s = s..tostring(v)
|
||||||
|
if i < #t then
|
||||||
|
s = s..', '
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return s..']'
|
||||||
|
end
|
||||||
|
|
||||||
-- Deprecated functions
|
-- Deprecated functions
|
||||||
block_index = block.index
|
block_index = block.index
|
||||||
block_name = block.name
|
block_name = block.name
|
||||||
|
|||||||
@ -247,6 +247,13 @@ void Engine::loadContent() {
|
|||||||
onAssetsLoaded();
|
onAssetsLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::resetContent() {
|
||||||
|
auto manager = createPacksManager(fs::path());
|
||||||
|
manager.scan();
|
||||||
|
contentPacks = manager.getAll(basePacks);
|
||||||
|
loadContent();
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::loadWorldContent(const fs::path& folder) {
|
void Engine::loadWorldContent(const fs::path& folder) {
|
||||||
contentPacks.clear();
|
contentPacks.clear();
|
||||||
auto packNames = ContentPack::worldPacksList(folder);
|
auto packNames = ContentPack::worldPacksList(folder);
|
||||||
@ -304,6 +311,10 @@ std::vector<ContentPack>& Engine::getContentPacks() {
|
|||||||
return contentPacks;
|
return contentPacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>& Engine::getBasePacks() {
|
||||||
|
return basePacks;
|
||||||
|
}
|
||||||
|
|
||||||
EnginePaths* Engine::getPaths() {
|
EnginePaths* Engine::getPaths() {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ class Engine : public util::ObjectsKeeper {
|
|||||||
std::queue<runnable> postRunnables;
|
std::queue<runnable> postRunnables;
|
||||||
std::recursive_mutex postRunnablesMutex;
|
std::recursive_mutex postRunnablesMutex;
|
||||||
std::unique_ptr<EngineController> controller;
|
std::unique_ptr<EngineController> controller;
|
||||||
|
std::vector<std::string> basePacks {"base"};
|
||||||
|
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
double lastTime = 0.0;
|
double lastTime = 0.0;
|
||||||
@ -88,6 +89,8 @@ public:
|
|||||||
/// @brief Load all selected content-packs and reload assets
|
/// @brief Load all selected content-packs and reload assets
|
||||||
void loadContent();
|
void loadContent();
|
||||||
|
|
||||||
|
void resetContent();
|
||||||
|
|
||||||
/// @brief Collect world content-packs and load content
|
/// @brief Collect world content-packs and load content
|
||||||
/// @see loadContent
|
/// @see loadContent
|
||||||
/// @param folder world folder
|
/// @param folder world folder
|
||||||
@ -120,6 +123,8 @@ public:
|
|||||||
/// @brief Get selected content packs
|
/// @brief Get selected content packs
|
||||||
std::vector<ContentPack>& getContentPacks();
|
std::vector<ContentPack>& getContentPacks();
|
||||||
|
|
||||||
|
std::vector<std::string>& getBasePacks();
|
||||||
|
|
||||||
/// @brief Get current screen
|
/// @brief Get current screen
|
||||||
std::shared_ptr<Screen> getScreen();
|
std::shared_ptr<Screen> getScreen();
|
||||||
|
|
||||||
|
|||||||
@ -10,8 +10,7 @@
|
|||||||
#include "../../engine.h"
|
#include "../../engine.h"
|
||||||
|
|
||||||
MenuScreen::MenuScreen(Engine* engine) : Screen(engine) {
|
MenuScreen::MenuScreen(Engine* engine) : Screen(engine) {
|
||||||
engine->getContentPacks().clear();
|
engine->resetContent();
|
||||||
engine->loadContent();
|
|
||||||
|
|
||||||
auto menu = engine->getGUI()->getMenu();
|
auto menu = engine->getGUI()->getMenu();
|
||||||
menu->reset();
|
menu->reset();
|
||||||
|
|||||||
@ -178,7 +178,6 @@ void EngineController::createWorld(
|
|||||||
EnginePaths* paths = engine->getPaths();
|
EnginePaths* paths = engine->getPaths();
|
||||||
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
||||||
try {
|
try {
|
||||||
engine->loadAllPacks();
|
|
||||||
engine->loadContent();
|
engine->loadContent();
|
||||||
paths->setWorldFolder(folder);
|
paths->setWorldFolder(folder);
|
||||||
} catch (const contentpack_error& error) {
|
} catch (const contentpack_error& error) {
|
||||||
@ -223,7 +222,6 @@ void EngineController::reconfigPacks(
|
|||||||
std::vector<std::string> packsToRemove
|
std::vector<std::string> packsToRemove
|
||||||
) {
|
) {
|
||||||
auto content = engine->getContent();
|
auto content = engine->getContent();
|
||||||
auto world = controller->getLevel()->getWorld();
|
|
||||||
bool hasIndices = false;
|
bool hasIndices = false;
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -238,21 +236,33 @@ void EngineController::reconfigPacks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
runnable removeFunc = [=]() {
|
runnable removeFunc = [=]() {
|
||||||
controller->saveWorld();
|
if (controller == nullptr) {
|
||||||
auto manager = engine->createPacksManager(world->wfile->getFolder());
|
auto manager = engine->createPacksManager(fs::path(""));
|
||||||
manager.scan();
|
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());
|
auto names = PacksManager::getNames(world->getPacks());
|
||||||
for (const auto& id : packsToAdd) {
|
for (const auto& id : packsToAdd) {
|
||||||
names.push_back(id);
|
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) {
|
if (hasIndices) {
|
||||||
|
|||||||
@ -30,6 +30,7 @@ static int l_pack_get_folder(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief pack.get_installed() -> array<string>
|
||||||
static int l_pack_get_installed(lua_State* L) {
|
static int l_pack_get_installed(lua_State* L) {
|
||||||
auto& packs = scripting::engine->getContentPacks();
|
auto& packs = scripting::engine->getContentPacks();
|
||||||
lua_createtable(L, packs.size(), 0);
|
lua_createtable(L, packs.size(), 0);
|
||||||
@ -42,7 +43,10 @@ static int l_pack_get_installed(lua_State* L) {
|
|||||||
|
|
||||||
/// @brief pack.get_available() -> array<string>
|
/// @brief pack.get_available() -> array<string>
|
||||||
static int l_pack_get_available(lua_State* L) {
|
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);
|
auto manager = scripting::engine->createPacksManager(worldFolder);
|
||||||
manager.scan();
|
manager.scan();
|
||||||
|
|
||||||
@ -131,7 +135,10 @@ static int l_pack_get_info(lua_State* L) {
|
|||||||
});
|
});
|
||||||
if (found == packs.end()) {
|
if (found == packs.end()) {
|
||||||
// TODO: optimize
|
// 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);
|
auto manager = scripting::engine->createPacksManager(worldFolder);
|
||||||
manager.scan();
|
manager.scan();
|
||||||
auto vec = manager.getAll({packid});
|
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);
|
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 [] = {
|
const luaL_Reg packlib [] = {
|
||||||
{"get_folder", lua_wrap_errors<l_pack_get_folder>},
|
{"get_folder", lua_wrap_errors<l_pack_get_folder>},
|
||||||
{"get_installed", lua_wrap_errors<l_pack_get_installed>},
|
{"get_installed", lua_wrap_errors<l_pack_get_installed>},
|
||||||
{"get_available", lua_wrap_errors<l_pack_get_available>},
|
{"get_available", lua_wrap_errors<l_pack_get_available>},
|
||||||
{"get_info", lua_wrap_errors<l_pack_get_info>},
|
{"get_info", lua_wrap_errors<l_pack_get_info>},
|
||||||
|
{"get_base_packs", lua_wrap_errors<l_pack_get_base_packs>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user