mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
test content events names cache
This commit is contained in:
parent
bf7732f68a
commit
0012419651
5 changed files with 34 additions and 12 deletions
|
|
@ -441,7 +441,8 @@ static void load_script(const Content& content, T& def) {
|
|||
def.name,
|
||||
scriptfile,
|
||||
def.scriptFile,
|
||||
def.rt.funcsset
|
||||
def.rt.funcsset,
|
||||
def.rt.eventNames
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ struct ItemFuncsSet {
|
|||
bool on_block_break_by : 1;
|
||||
};
|
||||
|
||||
struct ItemFuncNamesCache {
|
||||
};
|
||||
|
||||
enum class ItemIconType {
|
||||
NONE, // invisible (core:empty) must not be rendered
|
||||
SPRITE, // textured quad: icon is `atlas_name:texture_name`
|
||||
|
|
@ -75,6 +78,8 @@ struct ItemDef {
|
|||
bool emissive = false;
|
||||
|
||||
std::set<int> tags;
|
||||
|
||||
ItemFuncNamesCache eventNames;
|
||||
} rt {};
|
||||
|
||||
ItemDef(const std::string& name);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
#include "scripting.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "scripting_commons.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
|
|
@ -28,6 +25,9 @@
|
|||
#include "world/World.hpp"
|
||||
#include "interfaces/Process.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static debug::Logger logger("scripting");
|
||||
|
|
@ -391,15 +391,15 @@ void scripting::on_blocks_tick(const Block& block, int tps) {
|
|||
}
|
||||
|
||||
void scripting::update_block(const Block& block, const glm::ivec3& pos) {
|
||||
std::string name = block.name + ".update";
|
||||
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
|
||||
lua::emit_event(lua::get_main_state(), block.rt.eventNames.update,
|
||||
[pos](auto L) {
|
||||
return lua::pushivec_stack(L, pos);
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::random_update_block(const Block& block, const glm::ivec3& pos) {
|
||||
std::string name = block.name + ".randupdate";
|
||||
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
|
||||
lua::emit_event(lua::get_main_state(), block.rt.eventNames.randomUpdate,
|
||||
[pos](auto L) {
|
||||
return lua::pushivec_stack(L, pos);
|
||||
});
|
||||
}
|
||||
|
|
@ -660,7 +660,8 @@ void scripting::load_content_script(
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
BlockFuncsSet& funcsset
|
||||
BlockFuncsSet& funcsset,
|
||||
BlockFuncNamesCache& namesCache
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
|
||||
|
|
@ -686,6 +687,9 @@ void scripting::load_content_script(
|
|||
register_event(env, "on_block_present", prefix + ".blockpresent");
|
||||
funcsset.onblockremoved =
|
||||
register_event(env, "on_block_removed", prefix + ".blockremoved");
|
||||
|
||||
namesCache.randomUpdate = prefix + ".update";
|
||||
namesCache.randomUpdate = prefix + ".randupdate";
|
||||
}
|
||||
|
||||
void scripting::load_content_script(
|
||||
|
|
@ -693,7 +697,8 @@ void scripting::load_content_script(
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
ItemFuncsSet& funcsset
|
||||
ItemFuncsSet& funcsset,
|
||||
ItemFuncNamesCache& namesCache
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ struct ItemDef;
|
|||
class Inventory;
|
||||
class UiDocument;
|
||||
struct BlockFuncsSet;
|
||||
struct BlockFuncNamesCache;
|
||||
struct ItemFuncsSet;
|
||||
struct ItemFuncNamesCache;
|
||||
struct WorldFuncsSet;
|
||||
struct UserComponent;
|
||||
struct uidocscript;
|
||||
|
|
@ -168,7 +170,8 @@ namespace scripting {
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
BlockFuncsSet& funcsset
|
||||
BlockFuncsSet& funcsset,
|
||||
BlockFuncNamesCache& namesCache
|
||||
);
|
||||
|
||||
/// @brief Load script associated with an Item
|
||||
|
|
@ -182,7 +185,8 @@ namespace scripting {
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
ItemFuncsSet& funcsset
|
||||
ItemFuncsSet& funcsset,
|
||||
ItemFuncNamesCache& namesCache
|
||||
);
|
||||
|
||||
/// @brief Load component script
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ struct BlockFuncsSet {
|
|||
bool onblockremoved : 1;
|
||||
};
|
||||
|
||||
struct BlockFuncNamesCache {
|
||||
std::string update;
|
||||
std::string randomUpdate;
|
||||
};
|
||||
|
||||
struct CoordSystem {
|
||||
std::array<glm::ivec3, 3> axes;
|
||||
/// @brief Grid 3d position fix offset (for negative vectors)
|
||||
|
|
@ -296,6 +301,8 @@ public:
|
|||
blockid_t surfaceReplacement = 0;
|
||||
|
||||
std::set<int> tags;
|
||||
|
||||
BlockFuncNamesCache eventNames;
|
||||
} rt {};
|
||||
|
||||
Block(const std::string& name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue