From 51659ea5088cbd9d63d22d733036076247cbbd9b Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 3 Nov 2018 19:08:54 +0100 Subject: [PATCH] bugfixes on the way to convert v1 to v2 tubes/shafts --- booking.lua | 16 +++++++------- elevator.lua | 19 +++++++---------- map.lua | 29 ++++++++++++------------- migrate.lua | 56 +++++++++++++++---------------------------------- seat.lua | 2 +- tube.lua | 11 ++-------- tubecrowbar.lua | 5 +++++ 7 files changed, 54 insertions(+), 84 deletions(-) diff --git a/booking.lua b/booking.lua index 95dc32b..4c4fc62 100644 --- a/booking.lua +++ b/booking.lua @@ -32,9 +32,6 @@ local function get_station_list(key_str) distance = hyperloop.distance(local_pos, dest_pos), pos_str = minetest.pos_to_string(dest_pos) } - if #tRes >= 12 then - break - end end table.sort(tRes, function(x,y) return x.distance < y.distance @@ -79,8 +76,12 @@ end -- Form spec for the station list -- param key_str: local station key local function formspec(key_str) - local tRes = {"size[12,10]label[3,0; Wähle dein Ziel :: Select your destination]"} - tRes[2] = "label[1,0.6;Destination]label[3.5,0.6;Distance]label[5,0.6;Position]label[7,0.6;Local Info]" + local tRes = {"size[12,10]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[3,0; Wähle dein Ziel :: Select your destination]"} + tRes[2] = "label[1,0.6;Destination]label[5.4,0.6;Distance]label[7,0.6;Local Info]" for idx,tDest in ipairs(get_station_list(key_str)) do if idx >= 12 then break @@ -88,9 +89,8 @@ local function formspec(key_str) local ypos = 0.5 + idx*0.8 local ypos2 = ypos - 0.2 tRes[#tRes+1] = "button_exit[0,"..ypos2..";1,1;button;"..idx.."]" - tRes[#tRes+1] = "label[1,"..ypos..";"..tDest.name.."]" - tRes[#tRes+1] = "label[3.5,"..ypos..";"..tDest.distance.." m]" - tRes[#tRes+1] = "label[4.7,"..ypos..";"..tDest.pos_str.."]" + tRes[#tRes+1] = "label[1,"..ypos..";"..string.sub(tDest.name,1,28).."]" + tRes[#tRes+1] = "label[5.4,"..ypos..";"..tDest.distance.." m]" tRes[#tRes+1] = "label[7,"..ypos..";"..tDest.info.."]" end return table.concat(tRes) diff --git a/elevator.lua b/elevator.lua index ab5d55e..b836ce9 100644 --- a/elevator.lua +++ b/elevator.lua @@ -41,13 +41,6 @@ local Shaft = tubelib2.Tube:new({ else minetest.set_node(pos, {name = "hyperloop:shaft", param2 = param2}) end - if not hyperloop.convert then - minetest.sound_play({ - name="default_place_node_metal"},{ - gain=1, - max_hear_distance=5, - loop=false}) - end end, }) @@ -55,7 +48,8 @@ hyperloop.Shaft = Shaft minetest.register_node("hyperloop:shaft", { description = "Hyperloop Elevator Shaft", - inventory_image = minetest.inventorycube('hyperloop_tube_open.png', "hyperloop_tube_locked.png", "hyperloop_tube_locked.png"), + inventory_image = minetest.inventorycube('hyperloop_tube_open.png', + "hyperloop_tube_locked.png", "hyperloop_tube_locked.png"), tiles = { -- up, down, right, left, back, front "hyperloop_tube_locked.png^[transformR90]", @@ -131,7 +125,8 @@ end local function remove_artifacts(floors) local tbl = {} for idx,floor in ipairs(floors) do - if floor.pos ~= nil and floor.name ~= nil and floor.up ~= nil and floor.down ~= nil then + if floor.pos ~= nil and floor.name ~= nil + and floor.up ~= nil and floor.down ~= nil then table.insert(tbl, floor) end end @@ -151,7 +146,8 @@ local function get_elevator_list(pos) hyperloop.data.tAllElevators[spos].floors = {} end -- remove invalid entries - hyperloop.data.tAllElevators[spos].floors = remove_artifacts(hyperloop.data.tAllElevators[spos].floors) + hyperloop.data.tAllElevators[spos].floors = + remove_artifacts(hyperloop.data.tAllElevators[spos].floors) return hyperloop.data.tAllElevators[spos].floors end @@ -426,7 +422,8 @@ minetest.register_node("hyperloop:elevator_bottom", { -- store floor_pos (lower car block) as meta data set_floor_pos(pos, pos) local facedir = hyperloop.get_facedir(placer) - add_to_elevator_list(pos, {name="", up=false, down=false, facedir=facedir, pos=pos}) + add_to_elevator_list(pos, {name="", up=false, down=false, + facedir=facedir, pos=pos}) update_elevator(pos) -- formspec local meta = minetest.get_meta(pos) diff --git a/map.lua b/map.lua index 93f51c1..a7b9714 100644 --- a/map.lua +++ b/map.lua @@ -36,22 +36,18 @@ local function station_list_as_string(pos) lStationPositions[spos] = idx end - local tRes = {"label[0,0;ID]label[0.7,0;Dist.]label[1.8,0;Station/Junction]label[4.2,0;Position]".. - "label[5.9,0;State]label[7.9,0;Owner]label[10,0;Conn. with]"} - local state, owner + local tRes = {"label[0,0;ID]label[0.7,0;Dist.]label[1.8,0;Station/Junction]label[5.4,0;Position]".. + "label[7.9,0;Owner]label[10,0;Conn. with]"} + local owner for idx,dataSet in ipairs(sortedList) do - if idx == 18 then + if idx == 23 then break end local ypos = 0.2 + idx * 0.4 - if dataSet.station_name ~= nil then - state = "Station" - elseif dataSet.junction == true then + if dataSet.junction == true then dataSet.station_name = "Junction" - state = "Junction" - else + elseif dataSet.station_name == nil then dataSet.station_name = "" - state = "unfinished" end if dataSet.owner ~= nil then owner = dataSet.owner @@ -60,10 +56,9 @@ local function station_list_as_string(pos) end tRes[#tRes+1] = "label[0,"..ypos..";"..idx.."]" tRes[#tRes+1] = "label[0.7,"..ypos..";"..dataSet.distance.." m]" - tRes[#tRes+1] = "label[1.8,"..ypos..";"..dataSet.station_name.."]" - tRes[#tRes+1] = "label[4.2,"..ypos..";"..minetest.pos_to_string(dataSet.pos).."]" - tRes[#tRes+1] = "label[5.9,"..ypos..";"..state.."]" - tRes[#tRes+1] = "label[7.9,"..ypos..";"..owner.."]" + tRes[#tRes+1] = "label[1.8,"..ypos..";"..string.sub(dataSet.station_name,1,24).."]" + tRes[#tRes+1] = "label[5.4,"..ypos..";"..minetest.pos_to_string(dataSet.pos).."]" + tRes[#tRes+1] = "label[7.9,"..ypos..";"..string.sub(owner,1,14).."]" tRes[#tRes+1] = "label[10,"..ypos..";" --print(idx, #dataSet.routes) for _,route in ipairs(dataSet.routes) do @@ -86,8 +81,10 @@ local function map_on_use(itemstack, user) local player_name = user:get_player_name() local pos = user:get_pos() local sStationList = station_list_as_string(pos) - local formspec = "size[12,10]" .. default.gui_bg .. - default.gui_bg_img .. + local formspec = "size[12,10]" .. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. sStationList .. "button_exit[5,9.5;2,1;close;Close]" diff --git a/migrate.lua b/migrate.lua index 9fcdae8..b8e3a79 100644 --- a/migrate.lua +++ b/migrate.lua @@ -141,24 +141,6 @@ end -- Stations/Junctions -- -Tube:on_convert_tube(function(pos, name, param2) - local dirs = {} - for dir = 1, 6 do - --local npos = Tube:primary_node(pos, dir) - local npos, node = Tube:get_next_node(pos, dir) - if node.name == "hyperloop:tube" or node.name == "hyperloop:tube1" or node.name == "hyperloop:tube2" then - dirs[#dirs+1] = dir - end - end - if #dirs == 1 then - return dirs[1], nil, 1 - elseif #dirs == 2 then - return dirs[1], dirs[2], 2 - else - print("on_convert_tube", dump(dirs)) - end -end) - local function convert_tube_line(pos) -- check all positions for dir = 1, 6 do @@ -174,16 +156,6 @@ end -- -- Elevator shafts -- -Shaft:on_convert_tube(function(pos, name, param2) - if param2 < 30 then - print("param2", param2) - if name == "hyperloop:shaft2" then - return 5, 6, 2 - elseif name == "hyperloop:shaft" then - return 5, 6, 1 - end - end -end) local function convert_shaft_line(pos) -- check lower position @@ -224,14 +196,21 @@ local function convert_station_data(tAllStations) end local function convert_elevator_data(tAllElevators) - for key,item in pairs(tAllElevators) do - if item.pos and Shaft:secondary_node(item.pos) then - hyperloop.data.tAllElevators[key] = item + hyperloop.data.tAllElevators = {} + for pos,item in pairs(tAllElevators) do + local tbl = {} + for _,floor in ipairs(item.floors) do + if floor.pos and Shaft:secondary_node(floor.pos) then + tbl[#tbl+1] = floor + end end + hyperloop.data.tAllElevators[pos] = {floors = tbl} end - for key,item in pairs(tAllElevators) do - if item.pos and Shaft:secondary_node(item.pos) then - convert_shaft_line(item.pos) + for pos,item in pairs(tAllElevators) do + for _,floor in ipairs(item.floors) do + if floor.pos and Shaft:secondary_node(floor.pos) then + convert_shaft_line(floor.pos) + end end end end @@ -247,17 +226,16 @@ function hyperloop.file2table(filename) end local function migrate() + Shaft:add_legacy_node_names({"hyperloop:shaft", "hyperloop:shaft2"}) + Tube:add_legacy_node_names({"hyperloop:tube", "hyperloop:tube1", "hyperloop:tube2"}) local data = hyperloop.file2table("mod_hyperloop.data") if data then hyperloop.convert = true convert_station_data(data.tAllStations) convert_elevator_data(data.tAllElevators) - minetest.safe_file_write(wpath..DIR_DELIM.."mod_hyperloop.data", "") + os.remove(wpath..DIR_DELIM.."mod_hyperloop.data") hyperloop.convert = nil end - - print("NodesWithPeerMeta", dump(NodesWithPeerMeta)) - print("tWifiNodes", dump(tWifiNodes)) end -minetest.after(10, migrate) \ No newline at end of file +minetest.after(5, migrate) \ No newline at end of file diff --git a/seat.lua b/seat.lua index 636b816..20eb881 100644 --- a/seat.lua +++ b/seat.lua @@ -145,7 +145,7 @@ local function on_start_travel(pos, node, clicker) -- close the door at arrival station hyperloop.close_pod_door(tArrival) -- place player on the seat - pos.y = pos.y + 0.5 + pos.y = pos.y - 0.5 clicker:set_pos(pos) -- rotate player to look in move direction clicker:set_look_horizontal(hyperloop.facedir_to_rad(tDeparture.facedir)) diff --git a/tube.lua b/tube.lua index 82c617e..eb89521 100644 --- a/tube.lua +++ b/tube.lua @@ -61,7 +61,7 @@ end local Tube = tubelib2.Tube:new({ allowed_6d_dirs = allowed_6d_dirs, - max_tube_length = 1000, + max_tube_length = 10000, show_infotext = true, primary_node_names = {"hyperloop:tube", "hyperloop:tube2"}, secondary_node_names = {"hyperloop:junction", "hyperloop:station"}, @@ -71,13 +71,6 @@ local Tube = tubelib2.Tube:new({ else minetest.set_node(pos, {name = "hyperloop:tube", param2 = param2}) end - if not hyperloop.convert then - minetest.sound_play({ - name="default_place_node_metal"},{ - gain=1, - max_hear_distance=5, - loop=false}) - end end, }) @@ -167,7 +160,7 @@ function hyperloop.update_routes(pos, called_from_peer, player_name) if player_name then minetest.chat_send_player(player_name, "[Hyperloop] "..S(pos)) end - for dir = 1,4 do -- check all 4 directions + for dir = 1,6 do -- check all 6 directions local npos = Tube:get_connected_node_pos(pos, dir) if Tube:secondary_node(npos) then table.insert(tRoutes, {S(pos), S(npos)}) diff --git a/tubecrowbar.lua b/tubecrowbar.lua index 382b933..fb4d77d 100644 --- a/tubecrowbar.lua +++ b/tubecrowbar.lua @@ -63,6 +63,11 @@ local function remove_tube(itemstack, placer, pointed_thing) else Tube:tool_remove_tube(pos, "default_break_metal") Shaft:tool_remove_tube(pos, "default_break_metal") + minetest.sound_play({ + name="default_place_node_metal"},{ + gain=1, + max_hear_distance=5, + loop=false}) end else tube_crowbar_help(placer)