Add Minetest interface (not used yet)
parent
41f40db5b0
commit
935b87e292
|
@ -41,6 +41,7 @@ set(NBGEN_SRC
|
||||||
src/MediaManager.cpp
|
src/MediaManager.cpp
|
||||||
src/Node.cpp
|
src/Node.cpp
|
||||||
src/NodeBox.cpp
|
src/NodeBox.cpp
|
||||||
|
src/minetest.cpp
|
||||||
src/FileFormat/FileFormat.cpp
|
src/FileFormat/FileFormat.cpp
|
||||||
src/FileFormat/NBE.cpp
|
src/FileFormat/NBE.cpp
|
||||||
src/FileFormat/Lua.cpp
|
src/FileFormat/Lua.cpp
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "modes/NodeEditor.hpp"
|
#include "modes/NodeEditor.hpp"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "minetest.hpp"
|
||||||
|
|
||||||
Editor::Editor() :
|
Editor::Editor() :
|
||||||
state(NULL),
|
state(NULL),
|
||||||
|
@ -72,6 +73,9 @@ bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf)
|
||||||
|
|
||||||
proj->media.debug();
|
proj->media.debug();
|
||||||
|
|
||||||
|
Minetest mt(conf);
|
||||||
|
mt.findMinetest();
|
||||||
|
|
||||||
// Load user interface
|
// Load user interface
|
||||||
LoadScene();
|
LoadScene();
|
||||||
state->SelectMode(0);
|
state->SelectMode(0);
|
||||||
|
|
|
@ -62,6 +62,7 @@ int main(int argc, char *argv[]) {
|
||||||
conf->set("driver", "opengl");
|
conf->set("driver", "opengl");
|
||||||
conf->set("hide_sidebar", "false");
|
conf->set("hide_sidebar", "false");
|
||||||
conf->set("save_directory", "");
|
conf->set("save_directory", "");
|
||||||
|
conf->set("minetest_root", "");
|
||||||
conf->set("always_show_position_handle", "false");
|
conf->set("always_show_position_handle", "false");
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
conf->set("vsync", "false");
|
conf->set("vsync", "false");
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
#include "minetest.hpp"
|
||||||
|
#include "util/string.hpp"
|
||||||
|
#include "util/filesys.hpp"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define DIR_DELIM "\\"
|
||||||
|
#else
|
||||||
|
#define DIR_DELIM "/"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Minetest::Minetest(Configuration *conf):
|
||||||
|
_conf(conf), minetest_dir("")
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool Minetest::findMinetest()
|
||||||
|
{
|
||||||
|
std::cerr << "Looking in settings for minetest_root" << std::endl;
|
||||||
|
std::string path = _conf->get("minetest_root");
|
||||||
|
if (path != "") {
|
||||||
|
if (PathExists(path.c_str())) {
|
||||||
|
std::cerr << "Minetest found at " << path.c_str() << std::endl;
|
||||||
|
minetest_dir = path;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
std::cerr << "Searching in system-wide" << std::endl;
|
||||||
|
path = getenv("HOME");
|
||||||
|
path += "/.minetest/";
|
||||||
|
std::cerr << path.c_str() << std::endl;
|
||||||
|
|
||||||
|
if (PathExists(path.c_str())) {
|
||||||
|
std::cerr << "Minetest found at " << path.c_str() << std::endl;
|
||||||
|
minetest_dir = path;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::cerr << "Finding relative to nbe" << std::endl;
|
||||||
|
path = getSaveLoadDirectory(_conf->get("save_directory"), _conf->getBool("installed"));
|
||||||
|
if (PathExists((path + "../minetest/").c_str())) {
|
||||||
|
std::cerr << "Minetest found at " << (path + "../minetest/").c_str() << std::endl;
|
||||||
|
minetest_dir = path + "../minetest/";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cerr << "Minetest not found!" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Minetest::runMod(const std::string &modname, const std::string &modpath,
|
||||||
|
const std::string &world, bool new_world)
|
||||||
|
{
|
||||||
|
if (new_world) {
|
||||||
|
// Delete old world folder
|
||||||
|
std::string param = minetest_dir + DIR_DELIM "worlds" DIR_DELIM + world;
|
||||||
|
remove(param.c_str());
|
||||||
|
|
||||||
|
// Create new world folder
|
||||||
|
CreateDir(param.c_str());
|
||||||
|
|
||||||
|
// world.mt
|
||||||
|
param = minetest_dir + DIR_DELIM "worlds" DIR_DELIM + world + DIR_DELIM "world.mt";
|
||||||
|
std::ofstream file(param.c_str());
|
||||||
|
file << "gameid = minetest\n";
|
||||||
|
file << "backend = sqlite3\n";
|
||||||
|
file << "load_mod_" << modname.c_str() << " = true\n";
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create mod folder in world
|
||||||
|
std::string cmd = minetest_dir + DIR_DELIM "worlds" DIR_DELIM + world + DIR_DELIM "worldmods";
|
||||||
|
CreateDir(cmd);
|
||||||
|
|
||||||
|
// Install mod
|
||||||
|
cmd = minetest_dir + DIR_DELIM "worlds" DIR_DELIM + world + DIR_DELIM "worldmods" DIR_DELIM + modname;
|
||||||
|
rename(modpath.c_str(), cmd.c_str());
|
||||||
|
|
||||||
|
// Run minetest
|
||||||
|
std::string exec = minetest_dir + DIR_DELIM "bin" DIR_DELIM "minetest";
|
||||||
|
#ifdef _WIN32
|
||||||
|
exec += ".exe";
|
||||||
|
#endif
|
||||||
|
exec += " --worldname " + world + " --go";
|
||||||
|
system(exec.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef MINETEST_HPP_INCLUDED
|
||||||
|
#define MINETEST_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "common.hpp"
|
||||||
|
#include "Configuration.hpp"
|
||||||
|
|
||||||
|
class Minetest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Minetest(Configuration *conf);
|
||||||
|
bool findMinetest();
|
||||||
|
bool runMod(const std::string &modname, const std::string &modpath,
|
||||||
|
const std::string &world = "nbe_test", bool new_world = true);
|
||||||
|
private:
|
||||||
|
Configuration *_conf;
|
||||||
|
std::string minetest_dir;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue