Updated pipeworks' textures and mechanisms
@ -126,9 +126,18 @@ end
|
||||
function fs_helpers.cycling_button(meta, base, meta_name, values)
|
||||
local current_value = meta:get_int(meta_name)
|
||||
local new_value = (current_value + 1) % (#values)
|
||||
local text = values[current_value + 1]
|
||||
local val = values[current_value + 1]
|
||||
local text
|
||||
local texture_name = nil
|
||||
--when we get a table, we know the caller wants an image_button
|
||||
if type(val) == "table" then
|
||||
text = val["text"]
|
||||
texture_name = val["texture"]
|
||||
else
|
||||
text = val
|
||||
end
|
||||
local field = "fs_helpers_cycling:"..new_value..":"..meta_name
|
||||
return base..";"..field..";"..minetest.formspec_escape(text).."]"
|
||||
return base..";"..(texture_name and texture_name..";" or "")..field..";"..minetest.formspec_escape(text).."]"
|
||||
end
|
||||
|
||||
---------
|
||||
|
@ -1,53 +1,76 @@
|
||||
|
||||
local filename=minetest.get_worldpath() .. "/teleport_tubes"
|
||||
|
||||
local function read_file()
|
||||
local f = io.open(filename, "r")
|
||||
if f == nil then return {} end
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
if t == "" or t == nil then return {} end
|
||||
return minetest.deserialize(t)
|
||||
local tp_tube_db = nil -- nil forces a read
|
||||
local tp_tube_db_version = 2.0
|
||||
|
||||
local function hash(pos)
|
||||
return string.format("%d", minetest.hash_node_position(pos))
|
||||
end
|
||||
|
||||
local function write_file(tbl)
|
||||
local f = io.open(filename, "w")
|
||||
f:write(minetest.serialize(tbl))
|
||||
f:close()
|
||||
local function save_tube_db()
|
||||
local file, err = io.open(filename, "w")
|
||||
if file then
|
||||
tp_tube_db.version = tp_tube_db_version
|
||||
file:write(minetest.serialize(tp_tube_db))
|
||||
tp_tube_db.version = nil
|
||||
io.close(file)
|
||||
else
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
|
||||
local function update_pos_in_file(pos)
|
||||
local tbl=read_file()
|
||||
for _, val in ipairs(tbl) do
|
||||
if val.x == pos.x and val.y == pos.y and val.z == pos.z then
|
||||
local meta = minetest.get_meta(val)
|
||||
val.channel = meta:get_string("channel")
|
||||
val.cr = meta:get_int("can_receive")
|
||||
local function migrate_tube_db()
|
||||
local tmp_db = {}
|
||||
tp_tube_db.version = nil
|
||||
for key, val in pairs(tp_tube_db) do
|
||||
if(val.channel ~= "") then -- skip unconfigured tubes
|
||||
tmp_db[hash(val)] = val
|
||||
end
|
||||
end
|
||||
tp_tube_db = tmp_db
|
||||
save_tube_db()
|
||||
end
|
||||
|
||||
local function read_tube_db()
|
||||
local file = io.open(filename, "r")
|
||||
if file ~= nil then
|
||||
local file_content = file:read("*all")
|
||||
io.close(file)
|
||||
|
||||
if file_content and file_content ~= "" then
|
||||
tp_tube_db = minetest.deserialize(file_content)
|
||||
if(not tp_tube_db.version or tonumber(tp_tube_db.version) < tp_tube_db_version) then
|
||||
migrate_tube_db()
|
||||
end
|
||||
tp_tube_db.version = nil -- we add it back when saving
|
||||
return tp_tube_db -- we read sucessfully
|
||||
end
|
||||
end
|
||||
write_file(tbl)
|
||||
tp_tube_db = {}
|
||||
return tp_tube_db
|
||||
end
|
||||
|
||||
local function add_tube_in_file(pos,channel, cr)
|
||||
local tbl=read_file()
|
||||
for _,val in ipairs(tbl) do
|
||||
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
|
||||
return
|
||||
end
|
||||
-- updates or adds a tube
|
||||
local function set_tube(pos, channel, can_receive)
|
||||
local tubes = tp_tube_db or read_tube_db()
|
||||
local hash = hash(pos)
|
||||
local tube = tubes[hash]
|
||||
if tube then
|
||||
tube.channel = channel
|
||||
tube.cr = can_receive
|
||||
save_tube_db()
|
||||
return
|
||||
end
|
||||
table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=cr})
|
||||
write_file(tbl)
|
||||
|
||||
-- we haven't found any tp tube to update, so lets add it
|
||||
tp_tube_db[hash] = {x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=can_receive}
|
||||
save_tube_db()
|
||||
end
|
||||
|
||||
local function remove_tube_in_file(pos)
|
||||
local tbl = read_file()
|
||||
local newtbl = {}
|
||||
for _, val in ipairs(tbl) do
|
||||
if val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z then
|
||||
table.insert(newtbl, val)
|
||||
end
|
||||
end
|
||||
write_file(newtbl)
|
||||
local function remove_tube(pos)
|
||||
local tubes = tp_tube_db or read_tube_db()
|
||||
tubes[hash(pos)] = nil
|
||||
save_tube_db()
|
||||
end
|
||||
|
||||
local function read_node_with_vm(pos)
|
||||
@ -58,39 +81,28 @@ local function read_node_with_vm(pos)
|
||||
return minetest.get_name_from_content_id(data[area:index(pos.x, pos.y, pos.z)])
|
||||
end
|
||||
|
||||
local function get_tubes_in_file(pos,channel)
|
||||
local tbl = read_file()
|
||||
local newtbl = {}
|
||||
local changed = false
|
||||
for _, val in ipairs(tbl) do
|
||||
local meta = minetest.get_meta(val)
|
||||
local name = read_node_with_vm(val)
|
||||
local is_loaded = (minetest.get_node_or_nil(val) ~= nil)
|
||||
local is_teleport_tube = minetest.registered_nodes[name] and minetest.registered_nodes[name].is_teleport_tube
|
||||
if is_teleport_tube then
|
||||
if is_loaded and (val.channel ~= meta:get_string("channel") or val.cr ~= meta:get_int("can_receive")) then
|
||||
val.channel = meta:get_string("channel")
|
||||
val.cr = meta:get_int("can_receive")
|
||||
changed = true
|
||||
end
|
||||
if val.cr == 1 and val.channel == channel and (val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z) then
|
||||
table.insert(newtbl, val)
|
||||
end
|
||||
else
|
||||
val.to_remove = true
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
if changed then
|
||||
local updated = {}
|
||||
for _, val in ipairs(tbl) do
|
||||
if not val.to_remove then
|
||||
table.insert(updated, val)
|
||||
local function get_receivers(pos, channel)
|
||||
local tubes = tp_tube_db or read_tube_db()
|
||||
local receivers = {}
|
||||
local dirty = false
|
||||
for key, val in pairs(tubes) do
|
||||
-- skip all non-receivers and the tube that it came from as early as possible, as this is called often
|
||||
if (val.cr == 1 and val.channel == channel and (val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z)) then
|
||||
local is_loaded = (minetest.get_node_or_nil(val) ~= nil)
|
||||
local node_name = is_loaded and minetest.get_node(pos).name or read_node_with_vm(val)
|
||||
|
||||
if minetest.registered_nodes[node_name] and minetest.registered_nodes[node_name].is_teleport_tube then
|
||||
table.insert(receivers, val)
|
||||
else
|
||||
tp_tube_db[key] = nil
|
||||
dirty = true
|
||||
end
|
||||
end
|
||||
write_file(updated)
|
||||
end
|
||||
return newtbl
|
||||
if dirty then
|
||||
save_tube_db()
|
||||
end
|
||||
return receivers
|
||||
end
|
||||
|
||||
local teleport_noctr_textures={"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png",
|
||||
@ -102,11 +114,11 @@ local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_telepo
|
||||
local teleport_short_texture="pipeworks_teleport_tube_short.png"
|
||||
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
|
||||
|
||||
local function set_teleport_tube_formspec(meta)
|
||||
local cr = meta:get_int("can_receive") ~= 0
|
||||
local function set_teleport_tube_formspec(meta, can_receive)
|
||||
local cr = (can_receive ~= 0)
|
||||
meta:set_string("formspec","size[10.5,1;]"..
|
||||
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
|
||||
"button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";"..
|
||||
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
|
||||
"button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";"..
|
||||
(cr and "Send and Receive" or "Send only").."]")
|
||||
end
|
||||
|
||||
@ -118,10 +130,13 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
|
||||
velocity.x = 0
|
||||
velocity.y = 0
|
||||
velocity.z = 0
|
||||
local meta = minetest.get_meta(pos)
|
||||
local channel = meta:get_string("channel")
|
||||
local target = get_tubes_in_file(pos,channel)
|
||||
|
||||
local channel = minetest.get_meta(pos):get_string("channel")
|
||||
if channel == "" then return {} end
|
||||
|
||||
local target = get_receivers(pos, channel)
|
||||
if target[1] == nil then return {} end
|
||||
|
||||
local d = math.random(1,#target)
|
||||
pos.x = target[d].x
|
||||
pos.y = target[d].y
|
||||
@ -131,50 +146,79 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("channel","")
|
||||
meta:set_int("can_receive",1)
|
||||
add_tube_in_file(pos,"")
|
||||
set_teleport_tube_formspec(meta)
|
||||
meta:set_int("can_receive", 1)
|
||||
set_teleport_tube_formspec(meta, 1)
|
||||
end,
|
||||
on_receive_fields = function(pos,formname,fields,sender)
|
||||
if not fields.channel then
|
||||
return -- ignore escaping or clientside manipulation of the form
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
--check for private channels
|
||||
if fields.channel ~= nil then
|
||||
local can_receive = meta:get_int("can_receive")
|
||||
|
||||
-- check for private channels each time before actually changing anything
|
||||
-- to not even allow switching between can_receive states of private channels
|
||||
if fields.channel ~= "" then
|
||||
local sender_name = sender:get_player_name()
|
||||
local name, mode = fields.channel:match("^([^:;]+)([:;])")
|
||||
if name and mode and name ~= sender:get_player_name() then
|
||||
|
||||
if name and mode and name ~= sender_name then
|
||||
--channels starting with '[name]:' can only be used by the named player
|
||||
if mode == ":" then
|
||||
minetest.chat_send_player(sender:get_player_name(), "Sorry, channel '"..fields.channel.."' is reserved for exclusive use by "..name)
|
||||
minetest.chat_send_player(sender_name, "Sorry, channel '"..fields.channel.."' is reserved for exclusive use by "..name)
|
||||
return
|
||||
|
||||
--channels starting with '[name];' can be used by other players, but cannot be received from
|
||||
elseif mode == ";" and (fields.cr1 or (meta:get_int("can_receive") ~= 0 and not fields.cr0)) then
|
||||
minetest.chat_send_player(sender:get_player_name(), "Sorry, receiving from channel '"..fields.channel.."' is reserved for "..name)
|
||||
elseif mode == ";" and (fields.cr1 or (can_receive ~= 0 and not fields.cr0)) then
|
||||
minetest.chat_send_player(sender_name, "Sorry, receiving from channel '"..fields.channel.."' is reserved for "..name)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fields.channel==nil then fields.channel=meta:get_string("channel") end
|
||||
meta:set_string("channel",fields.channel)
|
||||
remove_tube_in_file(pos)
|
||||
if fields.cr0 then meta:set_int("can_receive", 0) end
|
||||
if fields.cr1 then meta:set_int("can_receive", 1) end
|
||||
local cr = meta:get_int("can_receive")
|
||||
add_tube_in_file(pos, fields.channel, meta:get_int("can_receive"))
|
||||
set_teleport_tube_formspec(meta)
|
||||
|
||||
local dirty = false
|
||||
|
||||
-- test if a can_receive button was pressed
|
||||
if fields.cr0 and can_receive ~= 0 then
|
||||
can_receive = 0
|
||||
meta:set_int("can_receive", can_receive)
|
||||
dirty = true
|
||||
elseif fields.cr1 and can_receive ~= 1 then
|
||||
can_receive = 1
|
||||
meta:set_int("can_receive", can_receive)
|
||||
dirty = true
|
||||
end
|
||||
|
||||
-- was the channel changed?
|
||||
local channel = meta:get_string("channel")
|
||||
if fields.channel ~= channel then
|
||||
channel = fields.channel
|
||||
meta:set_string("channel", channel)
|
||||
dirty = true
|
||||
end
|
||||
|
||||
-- save if we changed something, handle the empty channel while we're at it
|
||||
if dirty then
|
||||
if channel ~= "" then
|
||||
set_tube(pos, channel, can_receive)
|
||||
else
|
||||
-- remove empty channel tubes, to not have to search through them
|
||||
remove_tube(pos)
|
||||
end
|
||||
set_teleport_tube_formspec(meta, can_receive)
|
||||
end
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
remove_tube_in_file(pos)
|
||||
end})
|
||||
remove_tube(pos)
|
||||
end
|
||||
})
|
||||
|
||||
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||
mesecon.register_on_mvps_move(function(moved_nodes)
|
||||
for _, n in ipairs(moved_nodes) do
|
||||
if string.find(n.node.name, "pipeworks:teleport_tube") ~= nil then
|
||||
update_pos_in_file(n.pos)
|
||||
local meta = minetest.get_meta(n.pos)
|
||||
set_tube(n.pos, meta:get_string("channel"), meta:get_int("can_receive"))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Before Width: | Height: | Size: 383 B After Width: | Height: | Size: 289 B |
Before Width: | Height: | Size: 600 B After Width: | Height: | Size: 345 B |
Before Width: | Height: | Size: 380 B After Width: | Height: | Size: 293 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 693 B |
Before Width: | Height: | Size: 100 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 100 B After Width: | Height: | Size: 83 B |
BIN
mods/pipeworks/textures/pipeworks_button_off.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
mods/pipeworks/textures/pipeworks_button_on.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 839 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 642 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1005 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 755 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 512 B After Width: | Height: | Size: 275 B |
Before Width: | Height: | Size: 819 B After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 823 B |
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 823 B |
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 823 B |
Before Width: | Height: | Size: 819 B After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 853 B After Width: | Height: | Size: 828 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 892 B |
Before Width: | Height: | Size: 760 B After Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 100 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 699 B After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 628 B After Width: | Height: | Size: 572 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 693 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 651 B After Width: | Height: | Size: 633 B |
Before Width: | Height: | Size: 657 B After Width: | Height: | Size: 637 B |
Before Width: | Height: | Size: 660 B After Width: | Height: | Size: 640 B |
Before Width: | Height: | Size: 607 B After Width: | Height: | Size: 587 B |
Before Width: | Height: | Size: 563 B After Width: | Height: | Size: 544 B |
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 608 B After Width: | Height: | Size: 589 B |
Before Width: | Height: | Size: 601 B After Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 589 B |
Before Width: | Height: | Size: 656 B After Width: | Height: | Size: 637 B |
Before Width: | Height: | Size: 659 B After Width: | Height: | Size: 640 B |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 869 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 873 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 100 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 693 B After Width: | Height: | Size: 664 B |
Before Width: | Height: | Size: 638 B After Width: | Height: | Size: 620 B |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 558 B After Width: | Height: | Size: 248 B |
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 285 B |
Before Width: | Height: | Size: 669 B After Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 727 B After Width: | Height: | Size: 710 B |
Before Width: | Height: | Size: 718 B After Width: | Height: | Size: 701 B |
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 281 B |
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 266 B |
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 692 B After Width: | Height: | Size: 266 B |
Before Width: | Height: | Size: 670 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 867 B |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 119 B |
Before Width: | Height: | Size: 100 B After Width: | Height: | Size: 89 B |
Before Width: | Height: | Size: 164 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 172 B |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 153 B |