lua content pack environments test
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "../items/ItemDef.h"
|
||||
|
||||
#include "ContentPack.h"
|
||||
#include "../logic/scripting/scripting.h"
|
||||
|
||||
ContentBuilder::~ContentBuilder() {
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ void ContentLoader::loadBlock(Block& def, std::string full, std::string name) {
|
||||
|
||||
fs::path scriptfile = folder/fs::path("scripts/"+def.scriptName+".lua");
|
||||
if (fs::is_regular_file(scriptfile)) {
|
||||
scripting::load_block_script(full, scriptfile, def.rt.funcsset);
|
||||
scripting::load_block_script(env, full, scriptfile, def.rt.funcsset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,13 +267,16 @@ void ContentLoader::loadItem(ItemDef& def, std::string full, std::string name) {
|
||||
|
||||
fs::path scriptfile = folder/fs::path("scripts/"+def.scriptName+".lua");
|
||||
if (fs::is_regular_file(scriptfile)) {
|
||||
scripting::load_item_script(full, scriptfile, def.rt.funcsset);
|
||||
scripting::load_item_script(env, full, scriptfile, def.rt.funcsset);
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::load(ContentBuilder& builder) {
|
||||
std::cout << "-- loading pack [" << pack->id << "]" << std::endl;
|
||||
builder.add(new ContentPackRuntime(*pack));
|
||||
|
||||
auto runtime = new ContentPackRuntime(*pack, scripting::create_environment());
|
||||
builder.add(runtime);
|
||||
env = runtime->getEnvironment()->getId();
|
||||
|
||||
fixPackIndices();
|
||||
|
||||
@@ -281,7 +284,7 @@ void ContentLoader::load(ContentBuilder& builder) {
|
||||
|
||||
fs::path scriptFile = folder/fs::path("scripts/world.lua");
|
||||
if (fs::is_regular_file(scriptFile)) {
|
||||
scripting::load_world_script(pack->id, scriptFile);
|
||||
scripting::load_world_script(env, pack->id, scriptFile);
|
||||
}
|
||||
|
||||
if (!fs::is_regular_file(pack->getContentFile()))
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace dynamic {
|
||||
|
||||
class ContentLoader {
|
||||
const ContentPack* pack;
|
||||
int env = 0;
|
||||
|
||||
void loadBlock(Block& def, std::string full, std::string name);
|
||||
void loadCustomBlockModel(Block& def, dynamic::Map* primitives);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../files/files.h"
|
||||
#include "../files/engine_paths.h"
|
||||
#include "../data/dynamic.h"
|
||||
#include "../logic/scripting/scripting.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -150,5 +151,9 @@ void ContentPack::readPacks(const EnginePaths* paths,
|
||||
}
|
||||
}
|
||||
|
||||
ContentPackRuntime::ContentPackRuntime(ContentPack info) : info(info) {
|
||||
ContentPackRuntime::ContentPackRuntime(
|
||||
ContentPack info,
|
||||
std::unique_ptr<scripting::Environment> env
|
||||
) : info(info), env(std::move(env))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ class EnginePaths;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace scripting {
|
||||
class Environment;
|
||||
}
|
||||
|
||||
class contentpack_error : public std::runtime_error {
|
||||
std::string packId;
|
||||
fs::path folder;
|
||||
@@ -52,17 +56,25 @@ struct ContentPack {
|
||||
static fs::path findPack(
|
||||
const EnginePaths* paths,
|
||||
fs::path worldDir,
|
||||
std::string name);
|
||||
static void readPacks(const EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs,
|
||||
const std::vector<std::string>& names,
|
||||
fs::path worldDir);
|
||||
std::string name
|
||||
);
|
||||
|
||||
static void readPacks(
|
||||
const EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs,
|
||||
const std::vector<std::string>& names,
|
||||
fs::path worldDir
|
||||
);
|
||||
};
|
||||
|
||||
class ContentPackRuntime {
|
||||
ContentPack info;
|
||||
std::unique_ptr<scripting::Environment> env;
|
||||
public:
|
||||
ContentPackRuntime(ContentPack info);
|
||||
ContentPackRuntime(
|
||||
ContentPack info,
|
||||
std::unique_ptr<scripting::Environment> env
|
||||
);
|
||||
|
||||
inline const std::string& getId() {
|
||||
return info.id;
|
||||
@@ -71,6 +83,10 @@ public:
|
||||
inline const ContentPack& getInfo() const {
|
||||
return info;
|
||||
}
|
||||
|
||||
inline scripting::Environment* getEnvironment() const {
|
||||
return env.get();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CONTENT_CONTENT_PACK_H_
|
||||
|
||||
Reference in New Issue
Block a user