aboutsummaryrefslogtreecommitdiff
path: root/ch_core/markers.lua
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2025-05-27 21:17:10 +0200
committerorwell <orwell@bleipb.de>2025-05-27 21:17:10 +0200
commit3470687be0af7254aca478ead1e9c72757edf070 (patch)
tree41781361c979cfda61a924d7471978037d68005e /ch_core/markers.lua
parent8506dd2825b715293138976a5ad1fa11a46206a7 (diff)
downloadadvtrains-cesky-hvozd.tar.gz
advtrains-cesky-hvozd.tar.bz2
advtrains-cesky-hvozd.zip
Add CH dependencies temporarily.cesky-hvozd
Before merge to master should remove them again and split out util functions (e.g. formspec lib)
Diffstat (limited to 'ch_core/markers.lua')
-rw-r--r--ch_core/markers.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/ch_core/markers.lua b/ch_core/markers.lua
new file mode 100644
index 0000000..4f8d34e
--- /dev/null
+++ b/ch_core/markers.lua
@@ -0,0 +1,49 @@
+ch_core.open_submod("markers", {})
+
+local texture = "ch_core_chessboard.png^[makealpha:255,255,255^[opacity:240"
+
+local function remove_object(self)
+ self.object:remove()
+end
+local function remove_object_after(self, delay)
+ if delay > 0 then
+ minetest.after(delay, remove_object, self)
+ else
+ remove_object(self)
+ end
+end
+local function remove_object_after_timeout(self, shift)
+ remove_object_after(self, (self.timeout or shift) - shift)
+end
+local function on_activate(self, staticdata, dtime_s)
+ minetest.after(1, remove_object_after_timeout, self, 1)
+end
+
+local def = {
+ initial_properties = {
+ physical = false,
+ pointable = false,
+ visual = "cube",
+ textures = {texture, texture, texture, texture, texture, texture},
+ use_texture_alpha = true,
+ backface_culling = false,
+ static_save = false,
+ shaded = false,
+ },
+ on_activate = on_activate,
+}
+minetest.register_entity("ch_core:markers", def)
+
+function ch_core.show_aabb(coords, timeout)
+ local size = vector.new(coords[4] - coords[1], coords[5] - coords[2], coords[6] - coords[3])
+ local center = vector.new(
+ 0.5 * (coords[4] + coords[1]) - 0.5,
+ 0.5 * (coords[5] + coords[2]) - 0.5,
+ 0.5 * (coords[6] + coords[3]) - 0.5)
+ local obj = minetest.add_entity(center, "ch_core:markers")
+ obj:set_properties{visual_size = size}
+ obj:get_luaentity().timeout = timeout or 16
+ return obj
+end
+
+ch_core.close_submod("markers")