Skip to content

Commit

Permalink
add update_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 14, 2024
1 parent 501f1b5 commit 4a74e56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions res/content/base/scripts/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function on_hud_open()
end

function on_hud_render()
local pos = gfx.text3d.get_pos(textid)
gfx.text3d.set_pos(textid, {pos[1], pos[2]+time.delta(), pos[3]})
gfx.text3d.update_settings(textid, {
color={math.sin(time.uptime() * 12) * 0.5 + 0.5, 0, 0, 1}
})
end
4 changes: 4 additions & 0 deletions src/graphics/render/TextNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const NotePreset& TextNote::getPreset() const {
return preset;
}

void TextNote::updatePreset(const dv::value& data) {
preset.deserialize(data);
}

void TextNote::setPosition(const glm::vec3& position) {
this->position = position;
}
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/render/TextNote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class TextNote {

const NotePreset& getPreset() const;

void updatePreset(const dv::value& data);

void setPosition(const glm::vec3& position);

const glm::vec3& getPosition() const;
Expand Down
8 changes: 8 additions & 0 deletions src/logic/scripting/lua/libs/libtext3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ static int l_set_pos(lua::State* L) {
return 0;
}

static int l_update_settings(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
note->updatePreset(lua::tovalue(L, 2));
}
return 0;
}

const luaL_Reg text3dlib[] = {
{"show", lua::wrap<l_show>},
{"hide", lua::wrap<l_hide>},
{"get_text", lua::wrap<l_get_text>},
{"set_text", lua::wrap<l_set_text>},
{"get_pos", lua::wrap<l_get_pos>},
{"set_pos", lua::wrap<l_set_pos>},
{"update_settings", lua::wrap<l_update_settings>},
{NULL, NULL}
};

0 comments on commit 4a74e56

Please sign in to comment.