From d74b530a83f104297c0fa195491e8b80abcc9093 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 14 Nov 2024 10:45:37 +0300 Subject: [PATCH] rename spawn to show & add gfx.text3d.hide(...) --- res/content/base/scripts/hud.lua | 8 ++++---- src/graphics/render/TextsRenderer.cpp | 4 ++++ src/graphics/render/TextsRenderer.hpp | 2 ++ src/logic/scripting/lua/libs/libentity.cpp | 4 ++-- src/logic/scripting/lua/libs/libtext3d.cpp | 10 ++++++++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index 92939b9c..c33cba60 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -25,9 +25,9 @@ function on_hud_open() drop.rigidbody:set_vel(velocity) end) - gfx.text3d.spawn({0.5, 99.5, 0.0015}, "Segmentation fault", { - scale = 0.005, - color = {0, 0, 0, 1}, - displayMode = "static_billboard" + gfx.text3d.show({0.5, 99.5, 0.0015}, "Segmentation fault", { + scale=0.005, + color={0, 0, 0, 1}, + displayMode="static_billboard" }) end diff --git a/src/graphics/render/TextsRenderer.cpp b/src/graphics/render/TextsRenderer.cpp index f6929100..bc6d449a 100644 --- a/src/graphics/render/TextsRenderer.cpp +++ b/src/graphics/render/TextsRenderer.cpp @@ -95,3 +95,7 @@ u64id_t TextsRenderer::add(std::unique_ptr note) { notes[uid] = std::move(note); return uid; } + +void TextsRenderer::remove(u64id_t id) { + notes.erase(id); +} diff --git a/src/graphics/render/TextsRenderer.hpp b/src/graphics/render/TextsRenderer.hpp index d9f64cb4..66b11264 100644 --- a/src/graphics/render/TextsRenderer.hpp +++ b/src/graphics/render/TextsRenderer.hpp @@ -40,4 +40,6 @@ public: ); u64id_t add(std::unique_ptr note); + + void remove(u64id_t id); }; diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp index b6fef820..ba3bd349 100644 --- a/src/logic/scripting/lua/libs/libentity.cpp +++ b/src/logic/scripting/lua/libs/libentity.cpp @@ -53,7 +53,7 @@ static int l_get_def(lua::State* L) { return 0; } -static int l_spawn(lua::State* L) { +static int l_show(lua::State* L) { auto level = controller->getLevel(); auto defname = lua::tostring(L, 1); auto& def = content->entities.require(defname); @@ -213,7 +213,7 @@ const luaL_Reg entitylib[] = { {"def_hitbox", lua::wrap}, {"get_def", lua::wrap}, {"defs_count", lua::wrap}, - {"spawn", lua::wrap}, + {"spawn", lua::wrap}, {"despawn", lua::wrap}, {"get_skeleton", lua::wrap}, {"set_skeleton", lua::wrap}, diff --git a/src/logic/scripting/lua/libs/libtext3d.cpp b/src/logic/scripting/lua/libs/libtext3d.cpp index 932bec13..355cbc54 100644 --- a/src/logic/scripting/lua/libs/libtext3d.cpp +++ b/src/logic/scripting/lua/libs/libtext3d.cpp @@ -8,7 +8,7 @@ using namespace scripting; -static int l_spawn(lua::State* L) { +static int l_show(lua::State* L) { auto position = lua::tovec3(L, 1); auto text = lua::require_wstring(L, 2); auto preset = lua::tovalue(L, 3); @@ -23,7 +23,13 @@ static int l_spawn(lua::State* L) { return lua::pushinteger(L, renderer->texts->add(std::move(note))); } +static int l_hide(lua::State* L) { + renderer->texts->remove(lua::touinteger(L, 1)); + return 0; +} + const luaL_Reg text3dlib[] = { - {"spawn", lua::wrap}, + {"show", lua::wrap}, + {"hide", lua::wrap}, {NULL, NULL} };