inventory script, modules

This commit is contained in:
MihailRis
2024-02-11 17:38:30 +03:00
parent bb1743105d
commit 8e529eb63b
22 changed files with 274 additions and 163 deletions
+1
View File
@@ -16,6 +16,7 @@ lua::LuaState::LuaState() {
luaopen_math(L);
luaopen_string(L);
luaopen_table(L);
luaopen_debug(L);
std::cout << LUA_VERSION << std::endl;
# ifdef LUAJIT_VERSION
+17 -4
View File
@@ -60,8 +60,8 @@ void scripting::initialize(Engine* engine) {
runnable scripting::create_runnable(
int env,
const std::string& file,
const std::string& src
const std::string& src,
const std::string& file
) {
return [=](){
state->execute(env, src, file);
@@ -170,7 +170,7 @@ void scripting::on_block_broken(Player* player, const Block* block, int x, int y
}
bool scripting::on_block_interact(Player* player, const Block* block, int x, int y, int z) {
std::string name = block->name+".oninteract";
std::string name = block->name+".interact";
if (state->getglobal(name)) {
state->pushivec3(x, y, z);
state->pushinteger(1); // playerid placeholder
@@ -205,8 +205,21 @@ bool scripting::on_item_break_block(Player* player, const ItemDef* item, int x,
return false;
}
void scripting::on_ui_open(UiDocument* layout, Inventory* inventory) {
std::string name = layout->getId()+".open";
if (state->getglobal(name)) {
state->callNoThrow(0);
}
}
void scripting::on_ui_close(UiDocument* layout, Inventory* inventory) {
std::string name = layout->getId()+".close";
if (state->getglobal(name)) {
state->callNoThrow(0);
}
}
bool register_event(int env, const std::string& name, const std::string& id) {
std::cout << "register " << name << " -> " << id << std::endl;
if (state->pushenv(env) == 0) {
state->pushglobals();
}
+6 -2
View File
@@ -14,6 +14,8 @@ class Level;
class Block;
class Player;
class ItemDef;
class Inventory;
class UiDocument;
struct block_funcs_set;
struct item_funcs_set;
struct uidocscript;
@@ -39,8 +41,8 @@ namespace scripting {
runnable create_runnable(
int env,
const std::string& filename,
const std::string& source
const std::string& src,
const std::string& file="<string>"
);
wstringconsumer create_wstring_consumer(
@@ -62,6 +64,8 @@ namespace scripting {
bool on_block_interact(Player* player, const Block* block, int x, int y, int z);
bool on_item_use_on_block(Player* player, const ItemDef* item, int x, int y, int z);
bool on_item_break_block(Player* player, const ItemDef* item, int x, int y, int z);
void on_ui_open(UiDocument* layout, Inventory* inventory);
void on_ui_close(UiDocument* layout, Inventory* inventory);
void load_block_script(int env, std::string prefix, fs::path file, block_funcs_set& funcsset);
void load_item_script(int env, std::string prefix, fs::path file, item_funcs_set& funcsset);
void load_world_script(int env, std::string prefix, fs::path file);