feature: bone model overriding
This commit is contained in:
@@ -20,6 +20,7 @@ enum class BlockInteraction {
|
||||
placing
|
||||
};
|
||||
|
||||
/// @brief Player argument is nullable
|
||||
using on_block_interaction = std::function<void(
|
||||
Player*, glm::ivec3, const Block*, BlockInteraction type
|
||||
)>;
|
||||
@@ -76,6 +77,7 @@ public:
|
||||
BlockInteraction type
|
||||
);
|
||||
|
||||
/// @brief Add block interaction callback
|
||||
void listenBlockInteraction(const on_block_interaction& callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,25 @@ static int l_get_model(lua::State* L) {
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
auto* rigConfig = skeleton.config;
|
||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
||||
return lua::pushstring(L, rigConfig->getNodes()[index]->getModelName());
|
||||
const auto& modelOverride = skeleton.modelOverrides[index];
|
||||
if (!modelOverride.model) {
|
||||
return lua::pushstring(L, modelOverride.name);
|
||||
}
|
||||
return lua::pushstring(L, rigConfig->getNodes()[index]->model.name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_model(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
||||
auto& modelOverride = skeleton.modelOverrides[index];
|
||||
if (lua::isnoneornil(L, 3)) {
|
||||
modelOverride = {"", nullptr, true};
|
||||
} else {
|
||||
modelOverride = {lua::require_string(L, 3), nullptr, true};
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -96,6 +114,7 @@ static int l_set_visible(lua::State* L) {
|
||||
|
||||
const luaL_Reg skeletonlib [] = {
|
||||
{"get_model", lua::wrap<l_get_model>},
|
||||
{"set_model", lua::wrap<l_set_model>},
|
||||
{"get_matrix", lua::wrap<l_get_matrix>},
|
||||
{"set_matrix", lua::wrap<l_set_matrix>},
|
||||
{"get_texture", lua::wrap<l_get_texture>},
|
||||
|
||||
Reference in New Issue
Block a user