mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-09-27 22:30:22 +02:00
Use on_rotate and ad new rotate function, refactor code
This commit is contained in:
parent
076e861b7d
commit
d7ce9aa806
38
lcd.lua
38
lcd.lua
|
@ -155,27 +155,31 @@ local get_entity = function(pos)
|
|||
return lcd_entity
|
||||
end
|
||||
|
||||
local spawn_entity = function(pos)
|
||||
if not get_entity(pos) then
|
||||
local lcd_info = lcds[minetest.get_node(pos).param2]
|
||||
if not lcd_info then
|
||||
return
|
||||
end
|
||||
local text = minetest.add_entity(vector.add(pos, lcd_info.delta), "digilines_lcd:text")
|
||||
text:set_yaw(lcd_info.yaw or 0)
|
||||
local rotate_text = function(pos, param)
|
||||
local entity = get_entity(pos)
|
||||
if not entity then
|
||||
return
|
||||
end
|
||||
local lcd_info = lcds[param or minetest.get_node(pos).param2]
|
||||
if not lcd_info then
|
||||
return
|
||||
end
|
||||
entity.object:set_pos(vector.add(pos, lcd_info.delta))
|
||||
entity.object:set_yaw(lcd_info.yaw or 0)
|
||||
end
|
||||
|
||||
local prepare_writing = function(pos)
|
||||
local entity = get_entity(pos)
|
||||
if entity then
|
||||
set_texture(entity)
|
||||
local lcd_info = lcds[minetest.get_node(pos).param2]
|
||||
if not lcd_info then
|
||||
return
|
||||
end
|
||||
entity.object:set_pos(vector.add(pos, lcd_info.delta))
|
||||
entity.object:set_yaw(lcd_info.yaw or 0)
|
||||
rotate_text(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local spawn_entity = function(pos)
|
||||
if not get_entity(pos) then
|
||||
local text = minetest.add_entity(pos, "digilines_lcd:text")
|
||||
rotate_text(pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -226,6 +230,12 @@ minetest.register_node("digilines:lcd", {
|
|||
spawn_entity(pos)
|
||||
end
|
||||
end,
|
||||
on_rotate = function(pos, node, user, mode, new_param2)
|
||||
if mode ~= screwdriver.ROTATE_FACE then
|
||||
return false
|
||||
end
|
||||
rotate_text(pos, new_param2)
|
||||
end,
|
||||
on_receive_fields = function(pos, _, fields, sender)
|
||||
local name = sender:get_player_name()
|
||||
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
||||
|
|
Loading…
Reference in New Issue
Block a user