diff options
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 139 |
1 files changed, 39 insertions, 100 deletions
@@ -30,7 +30,7 @@ local function process_command(meta,data,msg) end end if not msg.texture_name or type(msg.texture_name) ~= "string" then - return + return end local field = {type="image",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,texture_name=minetest.formspec_escape(msg.texture_name)} table.insert(data,field) @@ -45,33 +45,10 @@ local function process_command(meta,data,msg) return end end - local field = {type="field",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label),default=minetest.formspec_escape(msg.default)} - table.insert(data,field) - elseif msg.command == "addpwdfield" then - for _,i in pairs({"X","Y","W","H"}) do - if not msg[i] or type(msg[i]) ~= "number" then - return - end - end - for _,i in pairs({"name","label"}) do - if not msg[i] or type(msg[i]) ~= "string" then - return - end - end - local field = {type="pwdfield",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} - table.insert(data,field) - elseif msg.command == "addtextarea" then - for _,i in pairs({"X","Y","W","H"}) do - if not msg[i] or type(msg[i]) ~= "number" then - return - end - end - for _,i in pairs({"name","label","default"}) do - if not msg[i] or type(msg[i]) ~= "string" then - return - end - end - local field = {type="textarea",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label),default=minetest.formspec_escape(msg.default)} + local fieldname = minetest.formspec_escape(msg.name) + local fieldlabel = minetest.formspec_escape(msg.label) + local fielddefault = minetest.formspec_escape(msg.default) + local field = {type="field",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=fieldname,label=fieldlabel,default=fielddefault} table.insert(data,field) elseif msg.command == "addlabel" then for _,i in pairs({"X","Y"}) do @@ -80,21 +57,10 @@ local function process_command(meta,data,msg) end end if not msg.label or type(msg.label) ~= "string" then - return + return end local field = {type="label",X=msg.X,Y=msg.Y,label=minetest.formspec_escape(msg.label)} table.insert(data,field) - elseif msg.command == "addvertlabel" then - for _,i in pairs({"X","Y"}) do - if not msg[i] or type(msg[i]) ~= "number" then - return - end - end - if not msg.label or type(msg.label) ~= "string" then - return - end - local field = {type="vertlabel",X=msg.X,Y=msg.Y,label=minetest.formspec_escape(msg.label)} - table.insert(data,field) elseif msg.command == "addbutton" then for _,i in pairs({"X","Y","W","H"}) do if not msg[i] or type(msg[i]) ~= "number" then @@ -106,20 +72,9 @@ local function process_command(meta,data,msg) return end end - local field = {type="button",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} - table.insert(data,field) - elseif msg.command == "addbutton_exit" then - for _,i in pairs({"X","Y","W","H"}) do - if not msg[i] or type(msg[i]) ~= "number" then - return - end - end - for _,i in pairs({"name","label"}) do - if not msg[i] or type(msg[i]) ~= "string" then - return - end - end - local field = {type="button_exit",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} + local buttonname = minetest.formspec_escape(msg.name) + local buttonlabel = minetest.formspec_escape(msg.label) + local field = {type="button",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=buttonname,label=buttonlabel} table.insert(data,field) elseif msg.command == "addimage_button" then for _,i in pairs({"X","Y","W","H"}) do @@ -132,20 +87,10 @@ local function process_command(meta,data,msg) return end end - local field = {type="image_button",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,image=minetest.formspec_escape(msg.image),name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} - table.insert(data,field) - elseif msg.command == "addimage_button_exit" then - for _,i in pairs({"X","Y","W","H"}) do - if not msg[i] or type(msg[i]) ~= "number" then - return - end - end - for _,i in pairs({"image","name","label"}) do - if not msg[i] or type(msg[i]) ~= "string" then - return - end - end - local field = {type="image_button_exit",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,image=minetest.formspec_escape(msg.image),name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} + local ibuttonimage = minetest.formspec_escape(msg.image) + local ibuttonname = minetest.formspec_escape(msg.name) + local ibuttonlabel = minetest.formspec_escape(msg.label) + local field = {type="image_button",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,image=ibuttonimage,name=ibuttonname,label=ibuttonlabel} table.insert(data,field) elseif msg.command == "adddropdown" then for _,i in pairs({"X","Y","W","H","selected_id"}) do @@ -233,7 +178,7 @@ end --Interrupt node timer stuff local function getnextinterrupt(interrupts) local nextint = 0 - for k,v in pairs(interrupts) do + for _,v in pairs(interrupts) do if nextint == 0 or v < nextint then nextint = v end @@ -268,7 +213,7 @@ local function setinterrupt(pos,time,iid) end --Load the (mostly unmodified) firmware -local fw = loadfile(minetest.get_modpath("ltc4000e")..DIR_DELIM.."fw.lua") +local fw = loadfile(minetest.get_modpath("ltc4000e").."/fw.lua") local function run(pos,event) --Determine controller type @@ -305,7 +250,7 @@ local function run(pos,event) ts_on_digiline_receive(pos,msg) else --Not an integrated peripheral, so send the message - digiline:receptor_send(pos,cabinet_digiline_rules,channel,msg) + digilines.receptor_send(pos,cabinet_digiline_rules,channel,msg) end end else @@ -315,7 +260,7 @@ local function run(pos,event) ts_on_digiline_receive(pos,msg) else --Not an integrated peripheral, so send the message - digiline:receptor_send(pos,digiline.rules.default,channel,msg) + digilines.receptor_send(pos,digilines.rules.default,channel,msg) end end end @@ -352,7 +297,7 @@ local function oninterrupt(pos) event.iid = i run(pos,event) end - local interrupts = minetest.deserialize(meta:get_string("interrupts")) or {} --Reload as it may have changed + interrupts = minetest.deserialize(meta:get_string("interrupts")) or {} --Reload as it may have changed for _,i in ipairs(current) do if interrupts[i] and interrupts[i] <= os.time() then interrupts[i] = nil @@ -367,7 +312,7 @@ local function oninterrupt(pos) meta:set_string("interrupts",minetest.serialize(interrupts)) end -local function ts_on_receive_fields(pos,formname,fields,sender) +local function ts_on_receive_fields(pos,_,fields,sender) local meta = minetest.get_meta(pos) local playername = sender:get_player_name() local locked = meta:get_int("locked") == 1 @@ -413,14 +358,13 @@ minetest.register_node("ltc4000e:polemount", { node_box = { type = "fixed", fixed = polemount_nodebox - }, + }, selection_box = { type = "fixed", fixed = polemount_nodebox - }, + }, on_receive_fields = ts_on_receive_fields, - digiline = - { + digiline = { receptor = {}, effector = { action = function(pos,_,channel,msg) @@ -498,18 +442,18 @@ minetest.register_node("ltc4000e:nema_bottom", { end end, on_rotate = function(pos,node,user,mode,new_param2) - if not screwdriver then + if not minetest.global_exists("screwdriver") then return false end local ret = screwdriver.rotate_simple(pos,node,user,mode,new_param2) - minetest.after(0,function(pos) + minetest.after(0,function() local newnode = minetest.get_node(pos) local param2 = newnode.param2 pos.y = pos.y + 1 local topnode = minetest.get_node(pos) topnode.param2 = param2 minetest.set_node(pos,topnode) - end,pos) + end) return ret end, on_timer = oninterrupt, @@ -551,17 +495,16 @@ minetest.register_node("ltc4000e:nema_bottom", { node_box = { type = "fixed", fixed = bottom_nodebox - }, + }, selection_box = { type = "fixed", fixed = { {-0.5,-0.5,-0.5,0.5,-0.2,0.5}, {-0.4,-0.2,-0.4,0.4,1.3,0.3}, } - }, + }, on_receive_fields = ts_on_receive_fields, - digiline = - { + digiline = { receptor = {}, wire = { rules = cabinet_digiline_rules, @@ -593,11 +536,11 @@ minetest.register_node("ltc4000e:nema_top", { node_box = { type = "fixed", fixed = top_nodebox - }, + }, selection_box = { type = "fixed", fixed = {0,0,0,0,0,0} - }, + }, groups = {not_in_creative_inventory=1}, sounds = default.node_sound_metal_defaults() }) @@ -661,13 +604,10 @@ minetest.register_node("ltc4000e:nema_bottom_open", { if not puncher:is_player() then return end - local name = puncher:get_player_name() local vpos = vector.new(pos.x,pos.y,pos.z) local backdir = minetest.facedir_to_dir(node.param2) local frontpos = vector.add(vpos,vector.multiply(backdir,-1)) local fronttoppos = vector.add(frontpos,vector.new(0,1,0)) - local frontnode = minetest.get_node(frontpos) - local fronttopnode = minetest.get_node(fronttoppos) minetest.set_node(frontpos,{name="air"}) minetest.set_node(fronttoppos,{name="air"}) node.name = "ltc4000e:nema_bottom" @@ -686,17 +626,16 @@ minetest.register_node("ltc4000e:nema_bottom_open", { node_box = { type = "fixed", fixed = bottom_open_nodebox - }, + }, selection_box = { type = "fixed", fixed = { {-0.5,-0.5,-0.5,0.5,-0.2,0.5}, {-0.4,-0.2,-0.4,0.4,1.3,0.3}, } - }, + }, on_receive_fields = ts_on_receive_fields, - digiline = - { + digiline = { receptor = {}, wire = { rules = cabinet_digiline_rules, @@ -728,11 +667,11 @@ minetest.register_node("ltc4000e:nema_top_open", { node_box = { type = "fixed", fixed = top_open_nodebox - }, + }, selection_box = { type = "fixed", fixed = {0,0,0,0,0,0} - }, + }, groups = {not_in_creative_inventory=1}, sounds = default.node_sound_metal_defaults() }) @@ -752,11 +691,11 @@ minetest.register_node("ltc4000e:door_bottom", { node_box = { type = "fixed", fixed = door_bottom_nodebox - }, + }, selection_box = { type = "fixed", fixed = {0,0,0,0,0,0} - }, + }, groups = {not_in_creative_inventory=1}, sounds = default.node_sound_metal_defaults() }) @@ -776,11 +715,11 @@ minetest.register_node("ltc4000e:door_top", { node_box = { type = "fixed", fixed = door_top_nodebox - }, + }, selection_box = { type = "fixed", fixed = {0,0,0,0,0,0} - }, + }, groups = {not_in_creative_inventory=1}, sounds = default.node_sound_metal_defaults() }) |