refactor
This commit is contained in:
@@ -225,7 +225,7 @@ static int l_load_texture(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_open_folder(lua::State* L) {
|
||||
auto path = engine->getPaths()->resolve(lua::require_string(L, 1));
|
||||
auto path = engine->getPaths().resolve(lua::require_string(L, 1));
|
||||
platform::open_folder(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace fs = std::filesystem;
|
||||
using namespace scripting;
|
||||
|
||||
static fs::path resolve_path(const std::string& path) {
|
||||
return engine->getPaths()->resolve(path);
|
||||
return engine->getPaths().resolve(path);
|
||||
}
|
||||
|
||||
static fs::path resolve_path_soft(const std::string& path) {
|
||||
if (path.find(':') == std::string::npos) {
|
||||
return fs::u8path("");
|
||||
}
|
||||
return engine->getPaths()->resolve(path, false);
|
||||
return engine->getPaths().resolve(path, false);
|
||||
}
|
||||
|
||||
static int l_find(lua::State* L) {
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
using namespace scripting;
|
||||
|
||||
static int l_save_fragment(lua::State* L) {
|
||||
auto paths = engine->getPaths();
|
||||
const auto& paths = engine->getPaths();
|
||||
auto fragment = lua::touserdata<lua::LuaVoxelFragment>(L, 1);
|
||||
auto file = paths->resolve(lua::require_string(L, 2), true);
|
||||
auto file = paths.resolve(lua::require_string(L, 2), true);
|
||||
auto map = fragment->getFragment()->serialize();
|
||||
auto bytes = json::to_binary(map, true);
|
||||
files::write_bytes(file, bytes.data(), bytes.size());
|
||||
@@ -35,9 +35,9 @@ static int l_create_fragment(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_load_fragment(lua::State* L) {
|
||||
auto paths = engine->getPaths();
|
||||
const auto& paths = engine->getPaths();
|
||||
auto filename = lua::require_string(L, 1);
|
||||
auto path = paths->resolve(filename);
|
||||
auto path = paths.resolve(filename);
|
||||
if (!std::filesystem::exists(path)) {
|
||||
throw std::runtime_error("file "+path.u8string()+" does not exist");
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static void resetPackBindings(fs::path& packFolder) {
|
||||
}
|
||||
|
||||
static int l_reset_bindings(lua::State*) {
|
||||
auto resFolder = engine->getPaths()->getResourcesFolder();
|
||||
auto resFolder = engine->getPaths().getResourcesFolder();
|
||||
resetPackBindings(resFolder);
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
resetPackBindings(pack.folder);
|
||||
|
||||
@@ -34,8 +34,8 @@ static int l_is_open(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_get_list(lua::State* L) {
|
||||
auto paths = engine->getPaths();
|
||||
auto worlds = paths->scanForWorlds();
|
||||
const auto& paths = engine->getPaths();
|
||||
auto worlds = paths.scanForWorlds();
|
||||
|
||||
lua::createtable(L, worlds.size(), 0);
|
||||
for (size_t i = 0; i < worlds.size(); i++) {
|
||||
@@ -104,7 +104,7 @@ static int l_get_seed(lua::State* L) {
|
||||
|
||||
static int l_exists(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto worldsDir = engine->getPaths()->getWorldFolderByName(name);
|
||||
auto worldsDir = engine->getPaths().getWorldFolderByName(name);
|
||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ const float* LuaHeightmap::getValues() const {
|
||||
}
|
||||
|
||||
static int l_dump(lua::State* L) {
|
||||
auto paths = scripting::engine->getPaths();
|
||||
const auto& paths = scripting::engine->getPaths();
|
||||
if (auto heightmap = touserdata<LuaHeightmap>(L, 1)) {
|
||||
auto file = paths->resolve(require_string(L, 2));
|
||||
auto file = paths.resolve(require_string(L, 2));
|
||||
uint w = heightmap->getWidth();
|
||||
uint h = heightmap->getHeight();
|
||||
ImageData image(ImageFormat::rgb888, w, h);
|
||||
|
||||
@@ -41,8 +41,8 @@ BlocksController* scripting::blocks = nullptr;
|
||||
LevelController* scripting::controller = nullptr;
|
||||
|
||||
void scripting::load_script(const fs::path& name, bool throwable) {
|
||||
auto paths = scripting::engine->getPaths();
|
||||
fs::path file = paths->getResourcesFolder() / fs::path("scripts") / name;
|
||||
const auto& paths = scripting::engine->getPaths();
|
||||
fs::path file = paths.getResourcesFolder() / fs::path("scripts") / name;
|
||||
std::string src = files::read_string(file);
|
||||
auto L = lua::get_main_state();
|
||||
lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string());
|
||||
@@ -66,7 +66,7 @@ int scripting::load_script(
|
||||
|
||||
void scripting::initialize(Engine* engine) {
|
||||
scripting::engine = engine;
|
||||
lua::initialize(*engine->getPaths(), engine->getCoreParameters());
|
||||
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
||||
|
||||
load_script(fs::path("stdlib.lua"), true);
|
||||
load_script(fs::path("classes.lua"), true);
|
||||
|
||||
@@ -18,7 +18,7 @@ Hud* scripting::hud = nullptr;
|
||||
WorldRenderer* scripting::renderer = nullptr;
|
||||
|
||||
static void load_script(const std::string& name) {
|
||||
auto file = engine->getPaths()->getResourcesFolder() / "scripts" / name;
|
||||
auto file = engine->getPaths().getResourcesFolder() / "scripts" / name;
|
||||
std::string src = files::read_string(file);
|
||||
logger.info() << "loading script " << file.u8string();
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
const fs::path& file,
|
||||
const std::string& dirPath
|
||||
) {
|
||||
auto L = create_state(*engine->getPaths(), StateType::GENERATOR);
|
||||
auto L = create_state(engine->getPaths(), StateType::GENERATOR);
|
||||
|
||||
return std::make_unique<LuaGeneratorScript>(L, def, file, dirPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user