scriptenv?
This commit is contained in:
parent
d213902648
commit
635e512142
@ -16,7 +16,6 @@
|
|||||||
#include "../content/Content.h"
|
#include "../content/Content.h"
|
||||||
#include "../content/ContentPack.h"
|
#include "../content/ContentPack.h"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../logic/scripting/Environment.h"
|
|
||||||
|
|
||||||
static debug::Logger logger("assets-loader");
|
static debug::Logger logger("assets-loader");
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ bool AssetsLoader::loadNext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addLayouts(int env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
void addLayouts(scriptenv env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
||||||
if (!fs::is_directory(folder)) {
|
if (!fs::is_directory(folder)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,7 +196,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
|||||||
auto pack = entry.second.get();
|
auto pack = entry.second.get();
|
||||||
auto& info = pack->getInfo();
|
auto& info = pack->getInfo();
|
||||||
fs::path folder = info.folder / fs::path("layouts");
|
fs::path folder = info.folder / fs::path("layouts");
|
||||||
addLayouts(pack->getEnvironment()->getId(), info.id, folder, loader);
|
addLayouts(pack->getEnvironment(), info.id, folder, loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loader.add(AssetType::atlas, TEXTURES_FOLDER+"/blocks", "blocks");
|
loader.add(AssetType::atlas, TEXTURES_FOLDER+"/blocks", "blocks");
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Assets.h"
|
#include "Assets.h"
|
||||||
#include "../interfaces/Task.h"
|
#include "../interfaces/Task.h"
|
||||||
|
#include "../typedefs.h"
|
||||||
#include "../delegates.h"
|
#include "../delegates.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -35,9 +36,9 @@ struct AssetCfg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct LayoutCfg : AssetCfg {
|
struct LayoutCfg : AssetCfg {
|
||||||
int env;
|
scriptenv env;
|
||||||
|
|
||||||
LayoutCfg(int env) : env(env) {}
|
LayoutCfg(scriptenv env) : env(env) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SoundCfg : AssetCfg {
|
struct SoundCfg : AssetCfg {
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "ContentPack.h"
|
#include "ContentPack.h"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../logic/scripting/Environment.h"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@ -328,7 +327,7 @@ void ContentLoader::load(ContentBuilder& builder) {
|
|||||||
|
|
||||||
auto runtime = new ContentPackRuntime(*pack, scripting::create_pack_environment(*pack));
|
auto runtime = new ContentPackRuntime(*pack, scripting::create_pack_environment(*pack));
|
||||||
builder.add(runtime);
|
builder.add(runtime);
|
||||||
env = runtime->getEnvironment()->getId();
|
env = runtime->getEnvironment();
|
||||||
ContentPackStats& stats = runtime->getStatsWriteable();
|
ContentPackStats& stats = runtime->getStatsWriteable();
|
||||||
|
|
||||||
fixPackIndices();
|
fixPackIndices();
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace dynamic {
|
|||||||
|
|
||||||
class ContentLoader {
|
class ContentLoader {
|
||||||
const ContentPack* pack;
|
const ContentPack* pack;
|
||||||
int env = 0;
|
scriptenv env;
|
||||||
|
|
||||||
void loadBlock(Block& def, std::string full, std::string name);
|
void loadBlock(Block& def, std::string full, std::string name);
|
||||||
void loadCustomBlockModel(Block& def, dynamic::Map* primitives);
|
void loadCustomBlockModel(Block& def, dynamic::Map* primitives);
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
#include "../files/files.h"
|
#include "../files/files.h"
|
||||||
#include "../files/engine_paths.h"
|
#include "../files/engine_paths.h"
|
||||||
#include "../data/dynamic.h"
|
#include "../data/dynamic.h"
|
||||||
#include "../logic/scripting/Environment.h"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@ -141,7 +140,7 @@ fs::path ContentPack::findPack(const EnginePaths* paths, fs::path worldDir, std:
|
|||||||
|
|
||||||
ContentPackRuntime::ContentPackRuntime(
|
ContentPackRuntime::ContentPackRuntime(
|
||||||
ContentPack info,
|
ContentPack info,
|
||||||
std::unique_ptr<scripting::Environment> env
|
scriptenv env
|
||||||
) : info(info), env(std::move(env))
|
) : info(info), env(std::move(env))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef CONTENT_CONTENT_PACK_H_
|
#ifndef CONTENT_CONTENT_PACK_H_
|
||||||
#define CONTENT_CONTENT_PACK_H_
|
#define CONTENT_CONTENT_PACK_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -85,11 +87,11 @@ struct ContentPackStats {
|
|||||||
class ContentPackRuntime {
|
class ContentPackRuntime {
|
||||||
ContentPack info;
|
ContentPack info;
|
||||||
ContentPackStats stats {};
|
ContentPackStats stats {};
|
||||||
std::unique_ptr<scripting::Environment> env;
|
scriptenv env;
|
||||||
public:
|
public:
|
||||||
ContentPackRuntime(
|
ContentPackRuntime(
|
||||||
ContentPack info,
|
ContentPack info,
|
||||||
std::unique_ptr<scripting::Environment> env
|
scriptenv env
|
||||||
);
|
);
|
||||||
~ContentPackRuntime();
|
~ContentPackRuntime();
|
||||||
|
|
||||||
@ -109,8 +111,8 @@ public:
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline scripting::Environment* getEnvironment() const {
|
inline scriptenv getEnvironment() const {
|
||||||
return env.get();
|
return env;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -185,6 +185,7 @@ Engine::~Engine() {
|
|||||||
}
|
}
|
||||||
content.reset();
|
content.reset();
|
||||||
assets.reset();
|
assets.reset();
|
||||||
|
gui.reset();
|
||||||
audio::close();
|
audio::close();
|
||||||
scripting::close();
|
scripting::close();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
#include "../items/Inventory.h"
|
#include "../items/Inventory.h"
|
||||||
#include "../items/ItemDef.h"
|
#include "../items/ItemDef.h"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../logic/scripting/Environment.h"
|
|
||||||
#include "../maths/voxmaths.h"
|
#include "../maths/voxmaths.h"
|
||||||
#include "../objects/Player.h"
|
#include "../objects/Player.h"
|
||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
@ -372,7 +371,7 @@ void InventoryView::setInventory(std::shared_ptr<Inventory> inventory) {
|
|||||||
|
|
||||||
static slotcallback readSlotFunc(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelement& element, const std::string& attr) {
|
static slotcallback readSlotFunc(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelement& element, const std::string& attr) {
|
||||||
auto consumer = scripting::create_int_array_consumer(
|
auto consumer = scripting::create_int_array_consumer(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr(attr).getText()
|
element->attr(attr).getText()
|
||||||
);
|
);
|
||||||
return [=](uint slot, ItemStack& stack) {
|
return [=](uint slot, ItemStack& stack) {
|
||||||
|
|||||||
@ -10,8 +10,8 @@ UiDocument::UiDocument(
|
|||||||
std::string id,
|
std::string id,
|
||||||
uidocscript script,
|
uidocscript script,
|
||||||
std::shared_ptr<gui::UINode> root,
|
std::shared_ptr<gui::UINode> root,
|
||||||
std::unique_ptr<scripting::Environment> env
|
scriptenv env
|
||||||
) : id(id), script(script), root(root), env(std::move(env)) {
|
) : id(id), script(script), root(root), env(env) {
|
||||||
gui::UINode::getIndices(root, map);
|
gui::UINode::getIndices(root, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,19 +47,19 @@ const uidocscript& UiDocument::getScript() const {
|
|||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UiDocument::getEnvironment() const {
|
scriptenv UiDocument::getEnvironment() const {
|
||||||
return env->getId();
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string name, fs::path file) {
|
std::unique_ptr<UiDocument> UiDocument::read(scriptenv penv, std::string name, fs::path file) {
|
||||||
const std::string text = files::read_string(file);
|
const std::string text = files::read_string(file);
|
||||||
auto xmldoc = xml::parse(file.u8string(), text);
|
auto xmldoc = xml::parse(file.u8string(), text);
|
||||||
|
|
||||||
auto env = penv == -1
|
auto env = penv == nullptr
|
||||||
? std::make_unique<scripting::Environment>(0)
|
? scripting::get_root_environment()
|
||||||
: scripting::create_doc_environment(penv, name);
|
: scripting::create_doc_environment(penv, name);
|
||||||
|
|
||||||
gui::UiXmlReader reader(*env);
|
gui::UiXmlReader reader(env);
|
||||||
InventoryView::createReaders(reader);
|
InventoryView::createReaders(reader);
|
||||||
auto view = reader.readXML(
|
auto view = reader.readXML(
|
||||||
file.u8string(), xmldoc->getRoot()
|
file.u8string(), xmldoc->getRoot()
|
||||||
@ -68,12 +68,12 @@ std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string name, fs::pat
|
|||||||
uidocscript script {};
|
uidocscript script {};
|
||||||
auto scriptFile = fs::path(file.u8string()+".lua");
|
auto scriptFile = fs::path(file.u8string()+".lua");
|
||||||
if (fs::is_regular_file(scriptFile)) {
|
if (fs::is_regular_file(scriptFile)) {
|
||||||
scripting::load_layout_script(env->getId(), name, scriptFile, script);
|
scripting::load_layout_script(env, name, scriptFile, script);
|
||||||
}
|
}
|
||||||
return std::make_unique<UiDocument>(name, script, view, std::move(env));
|
return std::make_unique<UiDocument>(name, script, view, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
|
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
|
||||||
auto document = read(-1, file.filename().u8string(), file);
|
auto document = read(nullptr, file.filename().u8string(), file);
|
||||||
return document->getRoot();
|
return document->getRoot();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#ifndef FRONTEND_UI_DOCUMENT_H_
|
#ifndef FRONTEND_UI_DOCUMENT_H_
|
||||||
#define FRONTEND_UI_DOCUMENT_H_
|
#define FRONTEND_UI_DOCUMENT_H_
|
||||||
|
|
||||||
#include "../logic/scripting/Environment.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -14,12 +14,7 @@ namespace gui {
|
|||||||
class UINode;
|
class UINode;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace scripting {
|
|
||||||
class Environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct uidocscript {
|
struct uidocscript {
|
||||||
int environment;
|
|
||||||
bool onopen : 1;
|
bool onopen : 1;
|
||||||
bool onclose : 1;
|
bool onclose : 1;
|
||||||
};
|
};
|
||||||
@ -31,13 +26,13 @@ class UiDocument {
|
|||||||
uidocscript script;
|
uidocscript script;
|
||||||
uinodes_map map;
|
uinodes_map map;
|
||||||
std::shared_ptr<gui::UINode> root;
|
std::shared_ptr<gui::UINode> root;
|
||||||
std::unique_ptr<scripting::Environment> env;
|
scriptenv env;
|
||||||
public:
|
public:
|
||||||
UiDocument(
|
UiDocument(
|
||||||
std::string id,
|
std::string id,
|
||||||
uidocscript script,
|
uidocscript script,
|
||||||
std::shared_ptr<gui::UINode> root,
|
std::shared_ptr<gui::UINode> root,
|
||||||
std::unique_ptr<scripting::Environment> env
|
scriptenv env
|
||||||
);
|
);
|
||||||
|
|
||||||
void rebuildIndices();
|
void rebuildIndices();
|
||||||
@ -48,9 +43,9 @@ public:
|
|||||||
const std::shared_ptr<gui::UINode> getRoot() const;
|
const std::shared_ptr<gui::UINode> getRoot() const;
|
||||||
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||||
const uidocscript& getScript() const;
|
const uidocscript& getScript() const;
|
||||||
int getEnvironment() const;
|
scriptenv getEnvironment() const;
|
||||||
|
|
||||||
static std::unique_ptr<UiDocument> read(int env, std::string name, fs::path file);
|
static std::unique_ptr<UiDocument> read(scriptenv parent_env, std::string name, fs::path file);
|
||||||
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ void menus::create_menus(Engine* engine) {
|
|||||||
auto file = engine->getResPaths()->find("layouts/pages/"+name+".xml");
|
auto file = engine->getResPaths()->find("layouts/pages/"+name+".xml");
|
||||||
auto fullname = "core:pages/"+name;
|
auto fullname = "core:pages/"+name;
|
||||||
|
|
||||||
auto document = UiDocument::read(0, fullname, file).release();
|
auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release();
|
||||||
engine->getAssets()->store(document, fullname);
|
engine->getAssets()->store(document, fullname);
|
||||||
scripting::on_ui_open(document, nullptr, glm::ivec3());
|
scripting::on_ui_open(document, nullptr, glm::ivec3());
|
||||||
return document->getRoot();
|
return document->getRoot();
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
#include "../logic/LevelController.h"
|
#include "../logic/LevelController.h"
|
||||||
#include "../logic/scripting/scripting_hud.h"
|
#include "../logic/scripting/scripting_hud.h"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../logic/scripting/Environment.h"
|
|
||||||
#include "../objects/Player.h"
|
#include "../objects/Player.h"
|
||||||
#include "../physics/Hitbox.h"
|
#include "../physics/Hitbox.h"
|
||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
@ -113,7 +112,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine) {
|
|||||||
const ContentPack& info = pack->getInfo();
|
const ContentPack& info = pack->getInfo();
|
||||||
fs::path scriptFile = info.folder/fs::path("scripts/hud.lua");
|
fs::path scriptFile = info.folder/fs::path("scripts/hud.lua");
|
||||||
if (fs::is_regular_file(scriptFile)) {
|
if (fs::is_regular_file(scriptFile)) {
|
||||||
scripting::load_hud_script(pack->getEnvironment()->getId(), info.id, scriptFile);
|
scripting::load_hud_script(pack->getEnvironment(), info.id, scriptFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scripting::on_frontend_init(hud.get());
|
scripting::on_frontend_init(hud.get());
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "../../logic/scripting/Environment.h"
|
#include "../../logic/scripting/scripting.h"
|
||||||
#include "../../frontend/locale/langs.h"
|
#include "../../frontend/locale/langs.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
#include "../../delegates.h"
|
#include "../../delegates.h"
|
||||||
@ -32,12 +32,12 @@ std::shared_ptr<Button> guiutil::gotoButton(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, int envid) {
|
std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scriptenv env) {
|
||||||
scripting::Environment env(envid);
|
if (env == nullptr) {
|
||||||
|
env = scripting::get_root_environment();
|
||||||
|
}
|
||||||
UiXmlReader reader(env);
|
UiXmlReader reader(env);
|
||||||
auto node = reader.readXML("<string>", source);
|
return reader.readXML("<string>", source);
|
||||||
env.release();
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
|
void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
#include "../../typedefs.h"
|
||||||
#include "../../delegates.h"
|
#include "../../delegates.h"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@ -23,7 +24,7 @@ namespace guiutil {
|
|||||||
|
|
||||||
/// @brief Create element from XML
|
/// @brief Create element from XML
|
||||||
/// @param source XML
|
/// @param source XML
|
||||||
std::shared_ptr<gui::UINode> create(const std::string& source, int env=0);
|
std::shared_ptr<gui::UINode> create(const std::string& source, scriptenv env=0);
|
||||||
|
|
||||||
void alert(
|
void alert(
|
||||||
gui::GUI* gui,
|
gui::GUI* gui,
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "../../frontend/locale/langs.h"
|
#include "../../frontend/locale/langs.h"
|
||||||
#include "../../logic/scripting/scripting.h"
|
#include "../../logic/scripting/scripting.h"
|
||||||
#include "../../logic/scripting/Environment.h"
|
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
#include "../../window/Events.h"
|
#include "../../window/Events.h"
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
|||||||
}
|
}
|
||||||
if (element->has("position-func")) {
|
if (element->has("position-func")) {
|
||||||
auto supplier = scripting::create_vec2_supplier(
|
auto supplier = scripting::create_vec2_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("position-func").getText(),
|
element->attr("position-func").getText(),
|
||||||
reader.getFilename()+".lua"
|
reader.getFilename()+".lua"
|
||||||
);
|
);
|
||||||
@ -111,7 +110,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
|||||||
std::string text = element->attr("onclick").getText();
|
std::string text = element->attr("onclick").getText();
|
||||||
if (!text.empty()) {
|
if (!text.empty()) {
|
||||||
auto callback = scripting::create_runnable(
|
auto callback = scripting::create_runnable(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
text,
|
text,
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -210,7 +209,7 @@ static std::shared_ptr<UINode> readLabel(UiXmlReader& reader, xml::xmlelement el
|
|||||||
}
|
}
|
||||||
if (element->has("supplier")) {
|
if (element->has("supplier")) {
|
||||||
auto supplier = scripting::create_wstring_supplier(
|
auto supplier = scripting::create_wstring_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("supplier").getText(),
|
element->attr("supplier").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -264,7 +263,7 @@ static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
|
|
||||||
if (element->has("consumer")) {
|
if (element->has("consumer")) {
|
||||||
auto consumer = scripting::create_bool_consumer(
|
auto consumer = scripting::create_bool_consumer(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("consumer").getText(),
|
element->attr("consumer").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -273,7 +272,7 @@ static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
|
|
||||||
if (element->has("supplier")) {
|
if (element->has("supplier")) {
|
||||||
auto supplier = scripting::create_bool_supplier(
|
auto supplier = scripting::create_bool_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("supplier").getText(),
|
element->attr("supplier").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -299,7 +298,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
|
|
||||||
if (element->has("consumer")) {
|
if (element->has("consumer")) {
|
||||||
auto consumer = scripting::create_wstring_consumer(
|
auto consumer = scripting::create_wstring_consumer(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("consumer").getText(),
|
element->attr("consumer").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -308,7 +307,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
|
|
||||||
if (element->has("supplier")) {
|
if (element->has("supplier")) {
|
||||||
auto supplier = scripting::create_wstring_supplier(
|
auto supplier = scripting::create_wstring_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("supplier").getText(),
|
element->attr("supplier").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -322,7 +321,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
}
|
}
|
||||||
if (element->has("validator")) {
|
if (element->has("validator")) {
|
||||||
auto validator = scripting::create_wstring_validator(
|
auto validator = scripting::create_wstring_validator(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("validator").getText(),
|
element->attr("validator").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -348,7 +347,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
|||||||
_readUINode(reader, element, *bar);
|
_readUINode(reader, element, *bar);
|
||||||
if (element->has("consumer")) {
|
if (element->has("consumer")) {
|
||||||
auto consumer = scripting::create_number_consumer(
|
auto consumer = scripting::create_number_consumer(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("consumer").getText(),
|
element->attr("consumer").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -356,7 +355,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
|||||||
}
|
}
|
||||||
if (element->has("supplier")) {
|
if (element->has("supplier")) {
|
||||||
auto supplier = scripting::create_number_supplier(
|
auto supplier = scripting::create_number_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment(),
|
||||||
element->attr("supplier").getText(),
|
element->attr("supplier").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
@ -381,7 +380,7 @@ static std::shared_ptr<UINode> readInputBindBox(UiXmlReader& reader, xml::xmlele
|
|||||||
return bindbox;
|
return bindbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiXmlReader::UiXmlReader(const scripting::Environment& env) : env(env) {
|
UiXmlReader::UiXmlReader(const scriptenv& env) : env(env) {
|
||||||
contextStack.push("");
|
contextStack.push("");
|
||||||
add("image", readImage);
|
add("image", readImage);
|
||||||
add("label", readLabel);
|
add("label", readLabel);
|
||||||
@ -460,6 +459,6 @@ const std::string& UiXmlReader::getFilename() const {
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scripting::Environment& UiXmlReader::getEnvironment() const {
|
const scriptenv& UiXmlReader::getEnvironment() const {
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,6 @@
|
|||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "../../coders/xml.h"
|
#include "../../coders/xml.h"
|
||||||
|
|
||||||
namespace scripting {
|
|
||||||
class Environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class UiXmlReader;
|
class UiXmlReader;
|
||||||
|
|
||||||
@ -23,9 +19,9 @@ namespace gui {
|
|||||||
std::unordered_set<std::string> ignored;
|
std::unordered_set<std::string> ignored;
|
||||||
std::stack<std::string> contextStack;
|
std::stack<std::string> contextStack;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
const scripting::Environment& env;
|
const scriptenv& env;
|
||||||
public:
|
public:
|
||||||
UiXmlReader(const scripting::Environment& env);
|
UiXmlReader(const scriptenv& env);
|
||||||
|
|
||||||
void add(const std::string& tag, uinode_reader reader);
|
void add(const std::string& tag, uinode_reader reader);
|
||||||
bool hasReader(const std::string& tag) const;
|
bool hasReader(const std::string& tag) const;
|
||||||
@ -56,7 +52,7 @@ namespace gui {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const std::string& getContext() const;
|
const std::string& getContext() const;
|
||||||
const scripting::Environment& getEnvironment() const;
|
const scriptenv& getEnvironment() const;
|
||||||
const std::string& getFilename() const;
|
const std::string& getFilename() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
#ifndef LOGIC_SCRIPTING_ENVIRONMENT_H_
|
|
||||||
#define LOGIC_SCRIPTING_ENVIRONMENT_H_
|
|
||||||
|
|
||||||
namespace scripting {
|
|
||||||
/// @brief Lua environment wrapper for automatic deletion
|
|
||||||
class Environment {
|
|
||||||
int env;
|
|
||||||
public:
|
|
||||||
Environment(int env);
|
|
||||||
~Environment();
|
|
||||||
|
|
||||||
int getId() const;
|
|
||||||
|
|
||||||
// @brief Release namespace control
|
|
||||||
void release();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // LOGIC_SCRIPTING_ENVIRONMENT_H_
|
|
||||||
@ -348,6 +348,9 @@ int lua::LuaState::createEnvironment(int parent) {
|
|||||||
|
|
||||||
|
|
||||||
void lua::LuaState::removeEnvironment(int id) {
|
void lua::LuaState::removeEnvironment(int id) {
|
||||||
|
if (id == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
setglobal(envName(id));
|
setglobal(envName(id));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -341,7 +341,7 @@ static int l_gui_get_env(lua_State* L) {
|
|||||||
if (doc == nullptr) {
|
if (doc == nullptr) {
|
||||||
luaL_error(L, "document '%s' not found", name);
|
luaL_error(L, "document '%s' not found", name);
|
||||||
}
|
}
|
||||||
lua_getglobal(L, lua::LuaState::envName(doc->getEnvironment()).c_str());
|
lua_getglobal(L, lua::LuaState::envName(*doc->getEnvironment()).c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#include "../../logic/LevelController.h"
|
#include "../../logic/LevelController.h"
|
||||||
#include "../../frontend/UiDocument.h"
|
#include "../../frontend/UiDocument.h"
|
||||||
#include "../../engine.h"
|
#include "../../engine.h"
|
||||||
#include "Environment.h"
|
|
||||||
#include "lua/LuaState.h"
|
#include "lua/LuaState.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
#include "../../util/timeutil.h"
|
#include "../../util/timeutil.h"
|
||||||
@ -38,23 +37,6 @@ const ContentIndices* scripting::indices = nullptr;
|
|||||||
BlocksController* scripting::blocks = nullptr;
|
BlocksController* scripting::blocks = nullptr;
|
||||||
LevelController* scripting::controller = nullptr;
|
LevelController* scripting::controller = nullptr;
|
||||||
|
|
||||||
Environment::Environment(int env) : env(env) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Environment::~Environment() {
|
|
||||||
if (env) {
|
|
||||||
state->removeEnvironment(env);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Environment::getId() const {
|
|
||||||
return env;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Environment::release() {
|
|
||||||
env = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_script(fs::path name) {
|
void load_script(fs::path name) {
|
||||||
auto paths = scripting::engine->getPaths();
|
auto paths = scripting::engine->getPaths();
|
||||||
fs::path file = paths->getResources()/fs::path("scripts")/name;
|
fs::path file = paths->getResources()/fs::path("scripts")/name;
|
||||||
@ -71,11 +53,11 @@ void scripting::initialize(Engine* engine) {
|
|||||||
load_script(fs::path("stdlib.lua"));
|
load_script(fs::path("stdlib.lua"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Environment> scripting::create_environment(int parent) {
|
scriptenv scripting::get_root_environment() {
|
||||||
return std::make_unique<Environment>(state->createEnvironment(parent));
|
return std::make_shared<int>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Environment> scripting::create_pack_environment(const ContentPack& pack) {
|
scriptenv scripting::create_pack_environment(const ContentPack& pack) {
|
||||||
int id = state->createEnvironment(0);
|
int id = state->createEnvironment(0);
|
||||||
state->pushenv(id);
|
state->pushenv(id);
|
||||||
state->pushvalue(-1);
|
state->pushvalue(-1);
|
||||||
@ -83,11 +65,13 @@ std::unique_ptr<Environment> scripting::create_pack_environment(const ContentPac
|
|||||||
state->pushstring(pack.id);
|
state->pushstring(pack.id);
|
||||||
state->setfield("PACK_ID");
|
state->setfield("PACK_ID");
|
||||||
state->pop();
|
state->pop();
|
||||||
return std::make_unique<Environment>(id);
|
return std::shared_ptr<int>(new int(id), [=](int* id) {
|
||||||
|
state->removeEnvironment(*id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Environment> scripting::create_doc_environment(int parent, const std::string& name) {
|
scriptenv scripting::create_doc_environment(scriptenv parent, const std::string& name) {
|
||||||
int id = state->createEnvironment(parent);
|
int id = state->createEnvironment(*parent);
|
||||||
state->pushenv(id);
|
state->pushenv(id);
|
||||||
state->pushvalue(-1);
|
state->pushvalue(-1);
|
||||||
state->setfield("DOC_ENV");
|
state->setfield("DOC_ENV");
|
||||||
@ -104,7 +88,9 @@ std::unique_ptr<Environment> scripting::create_doc_environment(int parent, const
|
|||||||
state->pop();
|
state->pop();
|
||||||
}
|
}
|
||||||
state->pop();
|
state->pop();
|
||||||
return std::make_unique<Environment>(id);
|
return std::shared_ptr<int>(new int(id), [=](int* id) {
|
||||||
|
state->removeEnvironment(*id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::process_post_runnables() {
|
void scripting::process_post_runnables() {
|
||||||
@ -286,7 +272,8 @@ bool scripting::emit_event(const std::string &name, std::function<int(lua::LuaSt
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_block_script(int env, std::string prefix, fs::path file, block_funcs_set& funcsset) {
|
void scripting::load_block_script(scriptenv senv, std::string prefix, fs::path file, block_funcs_set& funcsset) {
|
||||||
|
int env = *senv;
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "script (block) " << file.u8string();
|
logger.info() << "script (block) " << file.u8string();
|
||||||
state->execute(env, src, file.u8string());
|
state->execute(env, src, file.u8string());
|
||||||
@ -299,7 +286,8 @@ void scripting::load_block_script(int env, std::string prefix, fs::path file, bl
|
|||||||
funcsset.onblockstick = register_event(env, "on_blocks_tick", prefix+".blockstick");
|
funcsset.onblockstick = register_event(env, "on_blocks_tick", prefix+".blockstick");
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_item_script(int env, std::string prefix, fs::path file, item_funcs_set& funcsset) {
|
void scripting::load_item_script(scriptenv senv, std::string prefix, fs::path file, item_funcs_set& funcsset) {
|
||||||
|
int env = *senv;
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "script (item) " << file.u8string();
|
logger.info() << "script (item) " << file.u8string();
|
||||||
state->execute(env, src, file.u8string());
|
state->execute(env, src, file.u8string());
|
||||||
@ -310,7 +298,9 @@ void scripting::load_item_script(int env, std::string prefix, fs::path file, ite
|
|||||||
funcsset.on_block_break_by = register_event(env, "on_block_break_by", prefix+".blockbreakby");
|
funcsset.on_block_break_by = register_event(env, "on_block_break_by", prefix+".blockbreakby");
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_world_script(int env, std::string prefix, fs::path file) {
|
void scripting::load_world_script(scriptenv senv, std::string prefix, fs::path file) {
|
||||||
|
int env = *senv;
|
||||||
|
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "loading world script for " << prefix;
|
logger.info() << "loading world script for " << prefix;
|
||||||
|
|
||||||
@ -324,11 +314,12 @@ void scripting::load_world_script(int env, std::string prefix, fs::path file) {
|
|||||||
register_event(env, "on_world_quit", prefix+".worldquit");
|
register_event(env, "on_world_quit", prefix+".worldquit");
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_layout_script(int env, std::string prefix, fs::path file, uidocscript& script) {
|
void scripting::load_layout_script(scriptenv senv, std::string prefix, fs::path file, uidocscript& script) {
|
||||||
|
int env = *senv;
|
||||||
|
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "loading script " << file.u8string();
|
logger.info() << "loading script " << file.u8string();
|
||||||
|
|
||||||
script.environment = env;
|
|
||||||
state->loadbuffer(env, src, file.u8string());
|
state->loadbuffer(env, src, file.u8string());
|
||||||
state->callNoThrow(0);
|
state->callNoThrow(0);
|
||||||
script.onopen = register_event(env, "on_open", prefix+".open");
|
script.onopen = register_event(env, "on_open", prefix+".open");
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "../../typedefs.h"
|
||||||
#include "../../delegates.h"
|
#include "../../delegates.h"
|
||||||
|
|
||||||
#include "lua/LuaState.h"
|
#include "lua/LuaState.h"
|
||||||
@ -33,8 +34,6 @@ namespace scripting {
|
|||||||
extern BlocksController* blocks;
|
extern BlocksController* blocks;
|
||||||
extern LevelController* controller;
|
extern LevelController* controller;
|
||||||
|
|
||||||
class Environment;
|
|
||||||
|
|
||||||
void initialize(Engine* engine);
|
void initialize(Engine* engine);
|
||||||
|
|
||||||
extern bool register_event(int env, const std::string& name, const std::string& id);
|
extern bool register_event(int env, const std::string& name, const std::string& id);
|
||||||
@ -42,9 +41,9 @@ namespace scripting {
|
|||||||
static inline int noargs(lua::LuaState *) { return 0; }
|
static inline int noargs(lua::LuaState *) { return 0; }
|
||||||
extern bool emit_event(const std::string& name, std::function<int(lua::LuaState* state)> args = noargs);
|
extern bool emit_event(const std::string& name, std::function<int(lua::LuaState* state)> args = noargs);
|
||||||
|
|
||||||
std::unique_ptr<Environment> create_environment(int parent=0);
|
scriptenv get_root_environment();
|
||||||
std::unique_ptr<Environment> create_pack_environment(const ContentPack& pack);
|
scriptenv create_pack_environment(const ContentPack& pack);
|
||||||
std::unique_ptr<Environment> create_doc_environment(int parent, const std::string& name);
|
scriptenv create_doc_environment(scriptenv parent, const std::string& name);
|
||||||
|
|
||||||
void process_post_runnables();
|
void process_post_runnables();
|
||||||
|
|
||||||
@ -78,31 +77,31 @@ namespace scripting {
|
|||||||
void on_ui_close(UiDocument* layout, Inventory* inventory);
|
void on_ui_close(UiDocument* layout, Inventory* inventory);
|
||||||
|
|
||||||
/// @brief Load script associated with a Block
|
/// @brief Load script associated with a Block
|
||||||
/// @param env environment id
|
/// @param env environment
|
||||||
/// @param prefix pack id
|
/// @param prefix pack id
|
||||||
/// @param file item script file
|
/// @param file item script file
|
||||||
/// @param funcsset block callbacks set
|
/// @param funcsset block callbacks set
|
||||||
void load_block_script(int env, std::string prefix, fs::path file, block_funcs_set& funcsset);
|
void load_block_script(scriptenv env, std::string prefix, fs::path file, block_funcs_set& funcsset);
|
||||||
|
|
||||||
/// @brief Load script associated with an Item
|
/// @brief Load script associated with an Item
|
||||||
/// @param env environment id
|
/// @param env environment
|
||||||
/// @param prefix pack id
|
/// @param prefix pack id
|
||||||
/// @param file item script file
|
/// @param file item script file
|
||||||
/// @param funcsset item callbacks set
|
/// @param funcsset item callbacks set
|
||||||
void load_item_script(int env, std::string prefix, fs::path file, item_funcs_set& funcsset);
|
void load_item_script(scriptenv env, std::string prefix, fs::path file, item_funcs_set& funcsset);
|
||||||
|
|
||||||
/// @brief Load package-specific world script
|
/// @brief Load package-specific world script
|
||||||
/// @param env environment id
|
/// @param env environment
|
||||||
/// @param packid content-pack id
|
/// @param packid content-pack id
|
||||||
/// @param file script file path
|
/// @param file script file path
|
||||||
void load_world_script(int env, std::string packid, fs::path file);
|
void load_world_script(scriptenv env, std::string packid, fs::path file);
|
||||||
|
|
||||||
/// @brief Load script associated with an UiDocument
|
/// @brief Load script associated with an UiDocument
|
||||||
/// @param env environment id
|
/// @param env environment
|
||||||
/// @param prefix pack id
|
/// @param prefix pack id
|
||||||
/// @param file item script file
|
/// @param file item script file
|
||||||
/// @param script document script info
|
/// @param script document script info
|
||||||
void load_layout_script(int env, std::string prefix, fs::path file, uidocscript& script);
|
void load_layout_script(scriptenv env, std::string prefix, fs::path file, uidocscript& script);
|
||||||
|
|
||||||
/// @brief Finalize lua state. Using scripting after will lead to Lua panic
|
/// @brief Finalize lua state. Using scripting after will lead to Lua panic
|
||||||
void close();
|
void close();
|
||||||
|
|||||||
@ -12,13 +12,13 @@ namespace scripting {
|
|||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
runnable scripting::create_runnable(
|
runnable scripting::create_runnable(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
return [=](){
|
return [=](){
|
||||||
try {
|
try {
|
||||||
state->execute(env, src, file);
|
state->execute(*env, src, file);
|
||||||
} catch (const lua::luaerror& err) {
|
} catch (const lua::luaerror& err) {
|
||||||
std::cerr << err.what() << std::endl;
|
std::cerr << err.what() << std::endl;
|
||||||
}
|
}
|
||||||
@ -26,12 +26,12 @@ runnable scripting::create_runnable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool processCallback(
|
static bool processCallback(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
return state->eval(env, src, file) != 0;
|
return state->eval(*env, src, file) != 0;
|
||||||
} catch (lua::luaerror& err) {
|
} catch (lua::luaerror& err) {
|
||||||
std::cerr << err.what() << std::endl;
|
std::cerr << err.what() << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -39,7 +39,7 @@ static bool processCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
wstringconsumer scripting::create_wstring_consumer(
|
wstringconsumer scripting::create_wstring_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -52,7 +52,7 @@ wstringconsumer scripting::create_wstring_consumer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
wstringsupplier scripting::create_wstring_supplier(
|
wstringsupplier scripting::create_wstring_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -69,7 +69,7 @@ wstringsupplier scripting::create_wstring_supplier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
wstringchecker scripting::create_wstring_validator(
|
wstringchecker scripting::create_wstring_validator(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -84,7 +84,7 @@ wstringchecker scripting::create_wstring_validator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolconsumer scripting::create_bool_consumer(
|
boolconsumer scripting::create_bool_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -97,7 +97,7 @@ boolconsumer scripting::create_bool_consumer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolsupplier scripting::create_bool_supplier(
|
boolsupplier scripting::create_bool_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -114,7 +114,7 @@ boolsupplier scripting::create_bool_supplier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
doubleconsumer scripting::create_number_consumer(
|
doubleconsumer scripting::create_number_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -127,7 +127,7 @@ doubleconsumer scripting::create_number_consumer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
doublesupplier scripting::create_number_supplier(
|
doublesupplier scripting::create_number_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -144,7 +144,7 @@ doublesupplier scripting::create_number_supplier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int_array_consumer scripting::create_int_array_consumer(
|
int_array_consumer scripting::create_int_array_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
@ -159,7 +159,7 @@ int_array_consumer scripting::create_int_array_consumer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec2supplier scripting::create_vec2_supplier(
|
vec2supplier scripting::create_vec2_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -3,65 +3,66 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../../typedefs.h"
|
||||||
#include "../../delegates.h"
|
#include "../../delegates.h"
|
||||||
|
|
||||||
namespace scripting {
|
namespace scripting {
|
||||||
runnable create_runnable(
|
runnable create_runnable(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
wstringconsumer create_wstring_consumer(
|
wstringconsumer create_wstring_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
wstringsupplier create_wstring_supplier(
|
wstringsupplier create_wstring_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
wstringchecker create_wstring_validator(
|
wstringchecker create_wstring_validator(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
boolconsumer create_bool_consumer(
|
boolconsumer create_bool_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
boolsupplier create_bool_supplier(
|
boolsupplier create_bool_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
doubleconsumer create_number_consumer(
|
doubleconsumer create_number_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
doublesupplier create_number_supplier(
|
doublesupplier create_number_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
int_array_consumer create_int_array_consumer(
|
int_array_consumer create_int_array_consumer(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
vec2supplier create_vec2_supplier(
|
vec2supplier create_vec2_supplier(
|
||||||
int env,
|
const scriptenv& env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -42,7 +42,8 @@ void scripting::on_frontend_close() {
|
|||||||
scripting::hud = nullptr;
|
scripting::hud = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::load_hud_script(int env, std::string packid, fs::path file) {
|
void scripting::load_hud_script(scriptenv senv, std::string packid, fs::path file) {
|
||||||
|
int env = *senv;
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
logger.info() << "loading script " << file.u8string();
|
logger.info() << "loading script " << file.u8string();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
#ifndef LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
||||||
#define LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
#define LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
||||||
|
|
||||||
|
#include "../../typedefs.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ namespace scripting {
|
|||||||
* @param packid content-pack id
|
* @param packid content-pack id
|
||||||
* @param file script file path
|
* @param file script file path
|
||||||
*/
|
*/
|
||||||
void load_hud_script(int env, std::string packid, fs::path file);
|
void load_hud_script(scriptenv env, std::string packid, fs::path file);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
#endif // LOGIC_SCRIPTING_SCRIPTING_HUD_H_
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
#ifndef VOX_TYPEDEFS_H
|
#ifndef TYPEDEFS_H_
|
||||||
#define VOX_TYPEDEFS_H
|
#define TYPEDEFS_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
using scriptenv = std::shared_ptr<int>;
|
||||||
|
|
||||||
/// @brief dynamic integer type (64 bit signed integer)
|
/// @brief dynamic integer type (64 bit signed integer)
|
||||||
using integer_t = int64_t;
|
using integer_t = int64_t;
|
||||||
@ -26,4 +28,4 @@ using itemcount_t = uint32_t;
|
|||||||
using blockstate_t = uint16_t;
|
using blockstate_t = uint16_t;
|
||||||
using light_t = uint16_t;
|
using light_t = uint16_t;
|
||||||
|
|
||||||
#endif
|
#endif // TYPEDEFS_H_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user