mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-09-25 13:20:25 +02:00
Rework behavior, more code cleanup
This commit is contained in:
parent
551835dd27
commit
bbfcc5149a
27
lcd.lua
27
lcd.lua
|
@ -119,6 +119,7 @@ local reset_meta = function(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local clearscreen = function(pos)
|
local clearscreen = function(pos)
|
||||||
|
minetest.chat_send_all("clearing screen at "..minetest.pos_to_string(pos))
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, o in ipairs(objects) do
|
for _, o in ipairs(objects) do
|
||||||
local o_entity = o:get_luaentity()
|
local o_entity = o:get_luaentity()
|
||||||
|
@ -138,7 +139,7 @@ local set_texture = function(ent)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local prepare_writing = function(pos)
|
local get_entity = function(pos)
|
||||||
local lcd_entity
|
local lcd_entity
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, o in ipairs(objects) do
|
for _, o in ipairs(objects) do
|
||||||
|
@ -152,7 +153,11 @@ local prepare_writing = function(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not lcd_entity then
|
return lcd_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
local spawn_entity = function(pos)
|
||||||
|
if not get_entity(pos) then
|
||||||
local lcd_info = lcds[minetest.get_node(pos).param2]
|
local lcd_info = lcds[minetest.get_node(pos).param2]
|
||||||
if not lcd_info then
|
if not lcd_info then
|
||||||
return
|
return
|
||||||
|
@ -161,8 +166,12 @@ local prepare_writing = function(pos)
|
||||||
text:set_yaw(lcd_info.yaw or 0)
|
text:set_yaw(lcd_info.yaw or 0)
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
end
|
||||||
set_texture(lcd_entity)
|
|
||||||
|
local prepare_writing = function(pos)
|
||||||
|
if get_entity(pos) then
|
||||||
|
set_texture(get_entity(pos))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_digiline_receive = function(pos, _, channel, msg)
|
local on_digiline_receive = function(pos, _, channel, msg)
|
||||||
|
@ -197,15 +206,21 @@ minetest.register_node("digilines:lcd", {
|
||||||
node_box = lcd_box,
|
node_box = lcd_box,
|
||||||
selection_box = lcd_box,
|
selection_box = lcd_box,
|
||||||
groups = {choppy = 3, dig_immediate = 2},
|
groups = {choppy = 3, dig_immediate = 2},
|
||||||
after_place_node = function (pos)
|
after_place_node = function(pos)
|
||||||
local param2 = minetest.get_node(pos).param2
|
local param2 = minetest.get_node(pos).param2
|
||||||
if param2 == 0 or param2 == 1 then
|
if param2 == 0 or param2 == 1 then
|
||||||
minetest.add_node(pos, {name = "digilines:lcd", param2 = 3})
|
minetest.add_node(pos, {name = "digilines:lcd", param2 = 3})
|
||||||
end
|
end
|
||||||
|
spawn_entity(pos)
|
||||||
prepare_writing(pos)
|
prepare_writing(pos)
|
||||||
end,
|
end,
|
||||||
on_construct = reset_meta,
|
on_construct = reset_meta,
|
||||||
on_destruct = clearscreen,
|
on_destruct = clearscreen,
|
||||||
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
if puncher:is_player() and minetest.get_player_by_name(puncher:get_player_name()) then
|
||||||
|
spawn_entity(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
on_receive_fields = function(pos, _, fields, sender)
|
on_receive_fields = function(pos, _, fields, sender)
|
||||||
local name = sender:get_player_name()
|
local name = sender:get_player_name()
|
||||||
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
||||||
|
@ -229,7 +244,7 @@ minetest.register_lbm({
|
||||||
name = "digilines:replace_text",
|
name = "digilines:replace_text",
|
||||||
nodenames = {"digilines:lcd"},
|
nodenames = {"digilines:lcd"},
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
action = prepare_writing,
|
action = spawn_entity,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_entity(":digilines_lcd:text", {
|
minetest.register_entity(":digilines_lcd:text", {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user