mesecons wireless: Fixed crash, fixed formspecs for 0.4.10+ clients

master
Pitriss 2014-11-27 07:52:18 +01:00
parent b23157bd78
commit 7f41140650
1 changed files with 27 additions and 13 deletions

View File

@ -1,6 +1,17 @@
local wireless_filename=minetest.get_worldpath() .. "/wireless"
local formspec = "size[9,1.5]" ..
"field[0.3,0;9,2;channel;Channel;${channel}]"..
"button_exit[7,0;2,3;save;Save]"
local function formspec_handling (fields)
if fields.save == nil then
return true
else
return false
end
end
local function read_file()
local f = io.open(wireless_filename, "r")
if f==nil then return {} end
@ -64,11 +75,12 @@ minetest.register_node("mesecons_wireless:emitter", {
tiles = {"mesecons_wireless_emitter.png"},
walkable = true,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("channel","")
meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
meta:set_string("formspec", formspec)
end,
on_receive_fields = function(pos,formname,fields,sender)
if formspec_handling(fields) == true then return end
local meta = minetest.env:get_meta(pos)
meta:set_string("channel",fields.channel)
end,
@ -79,21 +91,21 @@ minetest.register_node("mesecons_wireless:emitter", {
effector =
{
action_on = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local channel = meta:get_string("channel")
local w = get_wireless_receivers(channel)
for _,i in ipairs(w) do
mesecon:receptor_on(i)
mesecon:swap_node(i, "mesecons_wireless:receiver_on")
minetest.swap_node(i, {name = "mesecons_wireless:receiver_on"})
end
end,
action_off = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local channel = meta:get_string("channel")
local w = get_wireless_receivers(channel)
for _,i in ipairs(w) do
mesecon:receptor_off(i)
mesecon:swap_node(i, "mesecons_wireless:receiver")
minetest.swap_node(i, {name = "mesecons_wireless:receiver"})
end
end,
}
@ -107,13 +119,14 @@ minetest.register_node("mesecons_wireless:receiver", {
tiles = {"mesecons_wireless_receiver.png"},
walkable = true,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("channel","")
meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
meta:set_string("formspec", formspec)
add_wireless_receiver(pos,"")
end,
on_receive_fields = function(pos,formname,fields,sender)
local meta = minetest.env:get_meta(pos)
if formspec_handling(fields) == true then return end
local meta = minetest.get_meta(pos)
meta:set_string("channel",fields.channel)
remove_wireless_receiver(pos)
add_wireless_receiver(pos,fields.channel)
@ -139,13 +152,14 @@ minetest.register_node("mesecons_wireless:receiver_on", {
tiles = {"mesecons_wireless_receiver_on.png"},
walkable = true,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("channel","")
meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
meta:set_string("formspec", formspec)
add_wireless_receiver(pos,"")
end,
on_receive_fields = function(pos,formname,fields,sender)
local meta = minetest.env:get_meta(pos)
if formspec_handling(fields) == true then return end
local meta = minetest.get_meta(pos)
meta:set_string("channel",fields.channel)
remove_wireless_receiver(pos)
add_wireless_receiver(pos,fields.channel)