forked from mtcontrib/digiterms
First working version
This commit is contained in:
parent
f0b979f1f9
commit
56ba26d4f6
66
functions.lua
Normal file
66
functions.lua
Normal file
@ -0,0 +1,66 @@
|
||||
--[[
|
||||
digimons mod for Minetest - Digiline monitors using Display API / Font API
|
||||
(c) Pierre-Yves Rollo
|
||||
|
||||
This file is part of digimons.
|
||||
|
||||
signs is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
signs is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with signs. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
digimons.columns = 30
|
||||
|
||||
local function get_lines(pos)
|
||||
local lines = {}
|
||||
local meta = minetest.get_meta(pos)
|
||||
local text = meta:get_string("display_text")
|
||||
local pos = 1
|
||||
repeat
|
||||
local found = text:find("\n", pos) or #text + 1
|
||||
lines[#lines+1] = text:sub(pos, found - 1)
|
||||
pos = found + 1
|
||||
until (pos > (#text + 1))
|
||||
return lines
|
||||
end
|
||||
|
||||
local function set_lines(pos, lines)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("display_text", table.concat(lines, "\n"))
|
||||
end
|
||||
|
||||
local function push_line(lines, line, maxlines)
|
||||
for index = 1, (maxlines - 1) do
|
||||
lines[index] = lines[index + 1] or ""
|
||||
end
|
||||
lines[maxlines] = line
|
||||
end
|
||||
|
||||
local function push_text(lines, text, maxlines, maxcolumns)
|
||||
local pos = 1
|
||||
repeat
|
||||
local found = text:find("\n", pos) or #text + 1
|
||||
local line = text:sub(pos, found - 1)
|
||||
for index = 1, math.ceil(line:len() / maxcolumns) do
|
||||
local part = line:sub((index-1)*maxcolumns+1, index*maxcolumns)
|
||||
push_line(lines, part, maxlines)
|
||||
end
|
||||
pos = found + 1
|
||||
until (pos > (#text + 1))
|
||||
end
|
||||
|
||||
function digimons.push_text_on_screen(pos, text)
|
||||
local lines = get_lines(pos)
|
||||
push_text(lines, text, 6, 20)
|
||||
set_lines(pos, lines)
|
||||
display_api.update_entities(pos)
|
||||
end
|
1
init.lua
1
init.lua
@ -23,6 +23,7 @@ digimons.name = minetest.get_current_modname()
|
||||
digimons.path = minetest.get_modpath(digimons.name)
|
||||
|
||||
dofile(digimons.path.."/font_mozart.lua")
|
||||
dofile(digimons.path.."/functions.lua")
|
||||
dofile(digimons.path.."/nodes.lua")
|
||||
--dofile(digimons.path.."/crafts.lua")
|
||||
|
||||
|
63
nodes.lua
63
nodes.lua
@ -31,7 +31,6 @@ minetest.register_node('digimons:cathodic_amber_monitor', {
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
|
||||
{-8/16, 8/16, -8/16, 8/16, 7/16, -7/16},
|
||||
{-8/16, -8/16, -8/16, 8/16, -5/16, -7/16},
|
||||
{-8/16, 7/16, -8/16, -7/16, -5/16, -7/16},
|
||||
@ -45,53 +44,43 @@ minetest.register_node('digimons:cathodic_amber_monitor', {
|
||||
on_display_update = font_api.on_display_update,
|
||||
depth = -7/16 - display_api.entity_spacing,
|
||||
top = -1/16,
|
||||
aspect_ratio = 0.4, maxlines = 6,
|
||||
size = { x = 12/16, y = 10/16 },
|
||||
color = "#FFA000", font = "mozart", halign="left", valing="top",
|
||||
aspect_ratio = 0.5, maxlines = 6,
|
||||
size = { x = 23/32, y = 10/16 },
|
||||
color = "#FFA000", font_name = "mozart", halign="left", valing="top",
|
||||
},
|
||||
},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
minetest.rotate_node(itemstack, placer, pointed_thing)
|
||||
return display_api.on_place(itemstack, placer, pointed_thing)
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
--[==[ meta:set_string("formspec", string.format([=[
|
||||
size[6,4]%s%s%s
|
||||
textarea[0.5,0.7;5.5,2;display_text;%s;${display_text}]
|
||||
button[1,3;2,1;font;%s]
|
||||
button_exit[3,3;2,1;ok;%s]]=],
|
||||
default.gui_bg, default.gui_bg_img, default.gui_slots,
|
||||
F("Displayed text (3 lines max)"),
|
||||
F("Font"), F("Write")))
|
||||
]==]
|
||||
on_construct = function(pos)
|
||||
minetest.get_meta(pos):set_string("formspec",
|
||||
"field[channel;Channel;${channel}]")
|
||||
display_api.on_construct(pos)
|
||||
end,
|
||||
on_rightclick = function(pos, node, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("display_text", [[0123456789012345678901234567890
|
||||
?SYNTAX ERROR
|
||||
READY
|
||||
>
|
||||
>
|
||||
>
|
||||
>]])
|
||||
display_api.update_entities(pos)
|
||||
end,
|
||||
on_destruct = display_api.on_destruct,
|
||||
on_rotate = display_api.on_rotate,
|
||||
on_receive_fields = function(pos, formname, fields, player)
|
||||
if not minetest.is_protected(pos, player:get_player_name()) then
|
||||
local meta = minetest.get_meta(pos)
|
||||
if fields.ok or fields.font then
|
||||
meta:set_string("display_text", fields.display_text)
|
||||
meta:set_string("infotext", "\""..fields.display_text.."\"")
|
||||
display_api.update_entities(pos)
|
||||
end
|
||||
if fields.font then
|
||||
font_api.show_font_list(player, pos)
|
||||
end
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return
|
||||
end
|
||||
|
||||
if (fields.channel) then
|
||||
minetest.get_meta(pos):set_string("channel", fields.channel)
|
||||
end
|
||||
end,
|
||||
on_punch = display_api.update_entities,
|
||||
digiline = {
|
||||
receptor = {},
|
||||
effector = {
|
||||
action = function(pos, _, channel, msg)
|
||||
if channel ~= minetest.get_meta(pos):get_string("channel") then
|
||||
return
|
||||
end
|
||||
digimons.push_text_on_screen(pos, msg)
|
||||
end,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user