Merge pull request #679 from MihailRis/custom-entry-points
Custom content sources
This commit is contained in:
commit
a82054a6da
@ -168,3 +168,21 @@ app.create_memory_device(
|
|||||||
```
|
```
|
||||||
|
|
||||||
Creates an in-memory filesystem.
|
Creates an in-memory filesystem.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
app.get_content_sources() -> table<string>
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns a list of content sources (paths), in descending priority order.
|
||||||
|
|
||||||
|
``lua
|
||||||
|
app.set_content_sources(sources: table<string>)
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets a list of content sources (paths). Specified in descending priority order.
|
||||||
|
|
||||||
|
``lua
|
||||||
|
app.reset_content_sources()
|
||||||
|
```
|
||||||
|
|
||||||
|
Resets content sources.
|
||||||
|
|||||||
@ -168,3 +168,21 @@ app.create_memory_device(
|
|||||||
```
|
```
|
||||||
|
|
||||||
Создаёт файловую систему в памяти.
|
Создаёт файловую систему в памяти.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
app.get_content_sources() -> table<string>
|
||||||
|
```
|
||||||
|
|
||||||
|
Возвращает список источников контента (путей), в порядке убывания приоритета.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
app.set_content_sources(sources: table<string>)
|
||||||
|
```
|
||||||
|
|
||||||
|
Устанавливает список источников контента (путей). Указывается в порядке убывания приоритета.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
app.reset_content_sources()
|
||||||
|
```
|
||||||
|
|
||||||
|
Сбрасывает список источников контента.
|
||||||
|
|||||||
@ -16,6 +16,13 @@ static void load_configs(Input& input, const io::path& root) {
|
|||||||
auto configFolder = root / "config";
|
auto configFolder = root / "config";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<io::path> default_content_sources {
|
||||||
|
"world:content",
|
||||||
|
"user:content",
|
||||||
|
"project:content",
|
||||||
|
"res:content",
|
||||||
|
};
|
||||||
|
|
||||||
ContentControl::ContentControl(
|
ContentControl::ContentControl(
|
||||||
const Project& project,
|
const Project& project,
|
||||||
EnginePaths& paths,
|
EnginePaths& paths,
|
||||||
@ -27,12 +34,7 @@ ContentControl::ContentControl(
|
|||||||
postContent(std::move(postContent)),
|
postContent(std::move(postContent)),
|
||||||
basePacks(project.basePacks),
|
basePacks(project.basePacks),
|
||||||
manager(std::make_unique<PacksManager>()) {
|
manager(std::make_unique<PacksManager>()) {
|
||||||
manager->setSources({
|
manager->setSources(default_content_sources);
|
||||||
"world:content",
|
|
||||||
"user:content",
|
|
||||||
"project:content",
|
|
||||||
"res:content",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentControl::~ContentControl() = default;
|
ContentControl::~ContentControl() = default;
|
||||||
@ -68,6 +70,7 @@ void ContentControl::resetContent(const std::vector<std::string>& nonReset) {
|
|||||||
scripting::on_content_reset();
|
scripting::on_content_reset();
|
||||||
|
|
||||||
setContentPacksRaw(manager->getAll(basePacks));
|
setContentPacksRaw(manager->getAll(basePacks));
|
||||||
|
resetContentSources();
|
||||||
|
|
||||||
postContent();
|
postContent();
|
||||||
}
|
}
|
||||||
@ -139,3 +142,15 @@ PacksManager& ContentControl::scan() {
|
|||||||
manager->scan();
|
manager->scan();
|
||||||
return *manager;
|
return *manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentControl::setContentSources(std::vector<io::path> sources) {
|
||||||
|
manager->setSources(std::move(sources));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentControl::resetContentSources() {
|
||||||
|
manager->setSources(default_content_sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<io::path>& ContentControl::getContentSources() const {
|
||||||
|
return manager->getSources();
|
||||||
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "io/path.hpp"
|
||||||
#include "ContentPack.hpp"
|
#include "ContentPack.hpp"
|
||||||
|
|
||||||
class Content;
|
class Content;
|
||||||
@ -13,10 +14,6 @@ class EnginePaths;
|
|||||||
class Input;
|
class Input;
|
||||||
struct Project;
|
struct Project;
|
||||||
|
|
||||||
namespace io {
|
|
||||||
class path;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ContentControl {
|
class ContentControl {
|
||||||
public:
|
public:
|
||||||
ContentControl(
|
ContentControl(
|
||||||
@ -46,6 +43,10 @@ public:
|
|||||||
const std::vector<ContentPack>& getAllContentPacks() const;
|
const std::vector<ContentPack>& getAllContentPacks() const;
|
||||||
|
|
||||||
PacksManager& scan();
|
PacksManager& scan();
|
||||||
|
|
||||||
|
void setContentSources(std::vector<io::path> sources);
|
||||||
|
void resetContentSources();
|
||||||
|
const std::vector<io::path>& getContentSources() const;
|
||||||
private:
|
private:
|
||||||
EnginePaths& paths;
|
EnginePaths& paths;
|
||||||
Input& input;
|
Input& input;
|
||||||
|
|||||||
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
PacksManager::PacksManager() = default;
|
PacksManager::PacksManager() = default;
|
||||||
|
|
||||||
|
const std::vector<io::path>& PacksManager::getSources() const {
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
|
|
||||||
void PacksManager::setSources(std::vector<io::path> sources) {
|
void PacksManager::setSources(std::vector<io::path> sources) {
|
||||||
this->sources = std::move(sources);
|
this->sources = std::move(sources);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,9 @@ class PacksManager {
|
|||||||
public:
|
public:
|
||||||
PacksManager();
|
PacksManager();
|
||||||
|
|
||||||
|
/// @brief Get current content packs sources
|
||||||
|
const std::vector<io::path>& getSources() const;
|
||||||
|
|
||||||
/// @brief Set content packs sources (search folders)
|
/// @brief Set content packs sources (search folders)
|
||||||
void setSources(std::vector<io::path> sources);
|
void setSources(std::vector<io::path> sources);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
#include "io/io.hpp"
|
#include "io/io.hpp"
|
||||||
#include "io/devices/MemoryDevice.hpp"
|
#include "io/devices/MemoryDevice.hpp"
|
||||||
|
#include "engine/Engine.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
|
#include "logic/scripting/scripting.hpp"
|
||||||
|
|
||||||
|
using namespace scripting;
|
||||||
|
|
||||||
static int l_create_memory_device(lua::State* L) {
|
static int l_create_memory_device(lua::State* L) {
|
||||||
std::string name = lua::require_string(L, 1);
|
std::string name = lua::require_string(L, 1);
|
||||||
@ -18,8 +23,41 @@ static int l_create_memory_device(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_content_sources(lua::State* L) {
|
||||||
|
const auto& sources = engine->getContentControl().getContentSources();
|
||||||
|
lua::createtable(L, static_cast<int>(sources.size()), 0);
|
||||||
|
for (size_t i = 0; i < sources.size(); i++) {
|
||||||
|
lua::pushlstring(L, sources[i].string());
|
||||||
|
lua::rawseti(L, static_cast<int>(i + 1));
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_content_sources(lua::State* L) {
|
||||||
|
if (!lua::istable(L, 1)) {
|
||||||
|
throw std::runtime_error("table expected as argument 1");
|
||||||
|
}
|
||||||
|
int len = lua::objlen(L, 1);
|
||||||
|
std::vector<io::path> sources;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
lua::rawgeti(L, i + 1);
|
||||||
|
sources.emplace_back(std::string(lua::require_lstring(L, -1)));
|
||||||
|
lua::pop(L);
|
||||||
|
}
|
||||||
|
engine->getContentControl().setContentSources(std::move(sources));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_reset_content_sources(lua::State* L) {
|
||||||
|
engine->getContentControl().resetContentSources();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg applib[] = {
|
const luaL_Reg applib[] = {
|
||||||
{"create_memory_device", lua::wrap<l_create_memory_device>},
|
{"create_memory_device", lua::wrap<l_create_memory_device>},
|
||||||
|
{"get_content_sources", lua::wrap<l_get_content_sources>},
|
||||||
|
{"set_content_sources", lua::wrap<l_set_content_sources>},
|
||||||
|
{"reset_content_sources", lua::wrap<l_reset_content_sources>},
|
||||||
// see libcore.cpp an stdlib.lua
|
// see libcore.cpp an stdlib.lua
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user