bugfixes on the way to convert v1 to v2 tubes/shafts

This commit is contained in:
Joachim Stolberg 2018-11-03 19:08:54 +01:00
parent 42544af399
commit 51659ea508
7 changed files with 54 additions and 84 deletions

View File

@ -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)

View File

@ -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="<unknown>", up=false, down=false, facedir=facedir, pos=pos})
add_to_elevator_list(pos, {name="<unknown>", up=false, down=false,
facedir=facedir, pos=pos})
update_elevator(pos)
-- formspec
local meta = minetest.get_meta(pos)

29
map.lua
View File

@ -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 = "<no 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]"

View File

@ -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
for key,item in pairs(tAllElevators) do
if item.pos and Shaft:secondary_node(item.pos) then
convert_shaft_line(item.pos)
hyperloop.data.tAllElevators[pos] = {floors = tbl}
end
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)
minetest.after(5, migrate)

View File

@ -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))

View File

@ -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)})

View File

@ -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)