From d96ca765b12779665b44828cfdf6b9291b7aa34f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Mon, 29 Sep 2025 09:17:36 +0200 Subject: [PATCH] wip --- display_api/display.lua | 47 ++-- ontime_clocks/common.lua | 14 +- ontime_clocks/design/needles.svg | 214 ++++++++++++++++++ ontime_clocks/nodes.lua | 86 ++++++- .../textures/ontime_clocks_black_pixel.png | Bin 0 -> 4302 bytes .../ontime_clocks_needle_hours_3x3.png | Bin 0 -> 184 bytes .../ontime_clocks_needle_hours_5x5.png | Bin 0 -> 191 bytes .../ontime_clocks_needle_minutes_3x3.png | Bin 0 -> 183 bytes .../ontime_clocks_needle_minutes_5x5.png | Bin 0 -> 189 bytes 9 files changed, 330 insertions(+), 31 deletions(-) create mode 100644 ontime_clocks/design/needles.svg create mode 100644 ontime_clocks/textures/ontime_clocks_black_pixel.png create mode 100644 ontime_clocks/textures/ontime_clocks_needle_hours_3x3.png create mode 100644 ontime_clocks/textures/ontime_clocks_needle_hours_5x5.png create mode 100644 ontime_clocks/textures/ontime_clocks_needle_minutes_3x3.png create mode 100644 ontime_clocks/textures/ontime_clocks_needle_minutes_5x5.png diff --git a/display_api/display.lua b/display_api/display.lua index c329dd7..a676d6d 100644 --- a/display_api/display.lua +++ b/display_api/display.lua @@ -147,7 +147,9 @@ function display_api.update_entities(pos) end for _, objref in pairs(get_display_objrefs(pos, true)) do - local edef = ndef.display_entities[objref:get_luaentity().name] + local entity = objref:get_luaentity() + local edef = ndef.display_entities[entity.name] + local oprop = objref:get_properties() local depth = clip_pos_prop(edef.depth) local right = clip_pos_prop(edef.right) local top = clip_pos_prop(edef.top) @@ -160,9 +162,9 @@ function display_api.update_entities(pos) if objref.set_rotation then objref:set_rotation({ - x = ov.rotation.x*math.pi/2, - y = ov.rotation.y*math.pi/2 + (edef.yaw or 0), - z = ov.rotation.z*math.pi/2, + x = ov.rotation.x * math.pi / 2 + (entity.rotation and entity.rotation.x or 0), + y = ov.rotation.y * math.pi / 2 + (entity.rotation and entity.rotation.y or 0) + (edef.yaw or 0), + z = ov.rotation.z * math.pi / 2 + (entity.rotation and entity.rotation.z or 0), }) else if ov.rotation.x ~=0 or ov.rotation.y ~= 0 then @@ -276,24 +278,27 @@ end --- Creates display entity with some fields and the on_activate callback function display_api.register_display_entity(entity_name) - if not minetest.registered_entities[entity_name] then - minetest.register_entity(':'..entity_name, { - initial_properties = { - collisionbox = {0, 0, 0, 0, 0, 0}, - visual = "upright_sprite", - textures = {}, - collide_with_objects = false, - pointable = false - }, - on_activate = display_api.on_activate, - get_staticdata = function(self) - return minetest.serialize({ nodepos = self.nodepos }) - end, - on_blast = function(self, damage) - return false, false, {} - end, - }) + + if minetest.registered_entities[entity_name] then + return end + + minetest.register_entity(':'..entity_name, { + initial_properties = { + collisionbox = {0, 0, 0, 0, 0, 0}, + visual = "upright_sprite", + textures = {}, + collide_with_objects = false, + pointable = false, + }, + on_activate = display_api.on_activate, + get_staticdata = function(self) + return minetest.serialize({ nodepos = self.nodepos }) + end, + on_blast = function(self, damage) + return false, false, {} + end, + }) end minetest.register_lbm({ diff --git a/ontime_clocks/common.lua b/ontime_clocks/common.lua index 2c7639f..23fa248 100644 --- a/ontime_clocks/common.lua +++ b/ontime_clocks/common.lua @@ -18,9 +18,13 @@ along with ontime_clocks. If not, see . --]] --- Entity for time display +-- Entity for time display of most of clocks display_api.register_display_entity("ontime_clocks:display") +-- Entities for two needles of large clocks +display_api.register_display_entity("ontime_clocks:hours_needle") +display_api.register_display_entity("ontime_clocks:minutes_needle") + function ontime_clocks.get_h24() return math.floor(minetest.get_timeofday()*24)%24 end @@ -59,3 +63,11 @@ function ontime_clocks.get_needles_properties(color, size, hour, minute) } end +function ontime_clocks.get_roll_h12() + print(minetest.get_timeofday()) + return minetest.get_timeofday() * math.pi / 12 +end + +function ontime_clocks.get_roll_m() + return 0 +end diff --git a/ontime_clocks/design/needles.svg b/ontime_clocks/design/needles.svg new file mode 100644 index 0000000..53577cc --- /dev/null +++ b/ontime_clocks/design/needles.svg @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ontime_clocks/nodes.lua b/ontime_clocks/nodes.lua index afa28fe..2ce6d45 100644 --- a/ontime_clocks/nodes.lua +++ b/ontime_clocks/nodes.lua @@ -46,7 +46,7 @@ minetest.register_node("ontime_clocks:green_digital", { wall_top = {-7/16, 0.5, -7/32, 7/16, 13/32, 3/16} }, tiles = {"ontime_clocks_digital.png"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -83,7 +83,7 @@ minetest.register_node("ontime_clocks:red_digital", { wall_top = {-7/16, 0.5, -7/32, 7/16, 13/32, 3/16} }, tiles = {"ontime_clocks_digital.png"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -119,7 +119,7 @@ minetest.register_node("ontime_clocks:white", { wall_top = { -7/16, 0.5, -7/16, 7/16, 7/16, 7/16}, }, tiles = {"ontime_clocks_white.png"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -156,7 +156,7 @@ minetest.register_node("ontime_clocks:frameless_black", { wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } }, tiles = {"ontime_clocks_frameless.png"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -193,7 +193,7 @@ minetest.register_node("ontime_clocks:frameless_gold", { wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } }, tiles = {"ontime_clocks_frameless.png^[colorize:#FF0"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -230,7 +230,7 @@ minetest.register_node("ontime_clocks:frameless_white", { wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } }, tiles = {"ontime_clocks_frameless.png^[colorize:#FFF"}, - groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, + groups = {ontime_clocks_tick=1, oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1, handy = 1}, _mcl_hardness = 0.8, _mcl_blast_resistance = 1, is_ground_content = false, @@ -252,13 +252,81 @@ minetest.register_node("ontime_clocks:frameless_white", { }) +minetest.register_node("ontime_clocks:large_clock_black", { + description = S("Frameless large black clock"), + inventory_image = "ontime_clocks_frameless_inventory.png^[colorize:#FFF", + wield_image = "ontime_clocks_frameless_inventory.png^[colorize:#FFF", + paramtype = "light", + paramtype2 = "wallmounted", + drawtype = "nodebox", + use_texture_alpha = "clip", + node_box = { + type = "wallmounted", + wall_side = { -0.5, -7/16, -7/16, -0.45, 7/16, 7/16 }, + wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }, + wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } + }, + tiles = {"ontime_clocks_frameless_inventory.png"}, + groups = {ontime_clocks_tick = 1, oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_api = 1, handy = 1}, + _mcl_hardness = 0.8, + _mcl_blast_resistance = 1, + is_ground_content = false, + display_entities = { + ["ontime_clocks:hours_needle"] = { + depth = 15/32, + on_display_update = function(pos, objref) + objref:set_properties({ + textures={"ontime_clocks_needle_hours_5x5.png"}, + visual_size = {x=1, y=5}, + }) + print( minetest.get_timeofday() ) + objref:get_luaentity()["rotation"] = { z = math.floor(minetest.get_timeofday() * 24) / 6 * math.pi } + end + }, + ["ontime_clocks:minutes_needle"] = { + depth = 14/32, + on_display_update = function(pos, objref) + objref:set_properties({ + textures={"ontime_clocks_needle_minutes_5x5.png"}, + visual_size = {x=1, y=5}, + }) + objref:get_luaentity()["rotation"] = { z = math.floor(minetest.get_timeofday() * 288) / 6 * math.pi } + end + }, + }, + on_place = display_api.on_place, + on_construct = clock_on_construct, + on_destruct = display_api.on_destruct, + on_blast = display_api.on_blast, + on_rotate = display_api.on_rotate, + on_timer = clock_on_timer, +}) + +function flatten(from, to) + local mt = getmetatable(from) + if mt ~= nil then + flatten(mt, to) + end + for k, v in pairs(from) do + to[k] = v + end +end + +function dump(title, table) + print("=== " .. title .. " ===", table) + local t = {} + flatten(table, t) + for k,v in pairs(t) do + print(k, "=>", v) + end +end + minetest.register_lbm({ name = "ontime_clocks:nodetimer_init", - nodenames = {"ontime_clocks:green_digital", "ontime_clocks:red_digital", "ontime_clocks:white", - "ontime_clocks:frameless_black", "ontime_clocks:frameless_gold", "ontime_clocks:frameless_white"}, + nodenames = {"group:ontime_clocks_tick"}, run_at_every_load = false, action = function(pos) local timer = minetest.get_node_timer(pos) - timer:start(5) + timer:start(1) end }) diff --git a/ontime_clocks/textures/ontime_clocks_black_pixel.png b/ontime_clocks/textures/ontime_clocks_black_pixel.png new file mode 100644 index 0000000000000000000000000000000000000000..4f85ea239f3c07173d10530ea3e37808d6e61e0d GIT binary patch literal 4302 zcmeHKeQXnD7{3X!u`fVC7a4FIiW9ir^{!ppv)veLX$$M9TQfl*?0Wa!cCc%^-mNVo z5)d(hC`{uAgz!BB7*GhBz(klZ6*q8bf`AALQ$fR*3aAY5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{C zZI_GpXa%E@=gejjwgRAG{j$v@&KmuGJe#Ei+639PnB%R`fi4FHCCY|DUK!*Oas}H{ z;|k5v3iV|7Sfb@XtpX$rCoOmzitxC|a%@GK-c z4#PIiV7&M9*H(-B=>kQ2o%D#`Ub=ee>JbAyQts`pUb=e3K#!DryX$|WE4lMJ1p@G2 zP!wL4>YNEL!;6;aE$}(+-o2~cy6*e%VPw}b=p?~E#c4-gdT_W4PWp#j(`5un8LU1D z$m%s2P?)H=J&weS{WAxR?UV3njtE7`ZhM|D=^L)JFM{+z9{6E?!xkt-+>S!~j)|qu F{{t^++3ElQ literal 0 HcmV?d00001 diff --git a/ontime_clocks/textures/ontime_clocks_needle_hours_3x3.png b/ontime_clocks/textures/ontime_clocks_needle_hours_3x3.png new file mode 100644 index 0000000000000000000000000000000000000000..31f16bbe50860a6cb0832d123439130eabcd229b GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^0zhoR!3HG1@KjgzF7ps^>p=fS?83{1OTy}Hz)uA literal 0 HcmV?d00001 diff --git a/ontime_clocks/textures/ontime_clocks_needle_hours_5x5.png b/ontime_clocks/textures/ontime_clocks_needle_hours_5x5.png new file mode 100644 index 0000000000000000000000000000000000000000..52efd681365afc74e9d0a4c7fb791c556f8ef473 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^0ze$V!3JWj{>lraI14-?iy0XB4ude`@%$AjKtah8 z*NBqf{Irtt#G+J&^73-M%)IR4%EIU@{*ft(eC+k_e9@r@NU>BmGbPp!z!&l6QEWQm?3Nz3Sl*H ZH}cPY!!`S>r@Jjk#M9N!Wt~$(69DD{I(h&A literal 0 HcmV?d00001 diff --git a/ontime_clocks/textures/ontime_clocks_needle_minutes_3x3.png b/ontime_clocks/textures/ontime_clocks_needle_minutes_3x3.png new file mode 100644 index 0000000000000000000000000000000000000000..eb360bb9493f3755328956d36779860fdfc702b3 GIT binary patch literal 183 zcmeAS@N?(olHy`uVBq!ia0vp^0zhoR!3HG1@KjgCe5HtTjfBTx$i!w;U0%$WH#U^YX6=#A_= UuFRa~`9dH8Pgg&ebxsLQ09{QrjQ{`u literal 0 HcmV?d00001 diff --git a/ontime_clocks/textures/ontime_clocks_needle_minutes_5x5.png b/ontime_clocks/textures/ontime_clocks_needle_minutes_5x5.png new file mode 100644 index 0000000000000000000000000000000000000000..d716e41919bfd3ee08289267a6394e4c75bb44bf GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^0ze$V!3JWj{>lraI14-?iy0XB4ude`@%$AjKtah8 z*NBqf{Irtt#G+J&^73-M%)IR4xrBdOFg?@#5@*WTAY^T9qQ}iQvSTGcbP0l+XkKKe{?e literal 0 HcmV?d00001