aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_line_automation')
-rw-r--r--advtrains_line_automation/line_editor.lua65
-rw-r--r--advtrains_line_automation/line_functions.lua26
-rw-r--r--advtrains_line_automation/structs.md2
3 files changed, 69 insertions, 24 deletions
diff --git a/advtrains_line_automation/line_editor.lua b/advtrains_line_automation/line_editor.lua
index 26157be..9ab2b06 100644
--- a/advtrains_line_automation/line_editor.lua
+++ b/advtrains_line_automation/line_editor.lua
@@ -142,7 +142,7 @@ local function get_formspec(custom_state)
pinfo.role == "admin" or selection_index == 1 or
pinfo.player_name == custom_state.linevars[selection_index - 1].owner
- if has_rights_to_open_variant then
+ if has_rights_to_open_variant and selection_index ~= 1 then
table.insert(formspec, "button[10.5,0.3;3.5,0.75;delete;smazat variantu]")
end
table.insert(formspec, "button_exit[18.75,0.3;0.75,0.75;close;X]"..
@@ -157,6 +157,9 @@ local function get_formspec(custom_state)
table.insert(formspec, F(custom_state.owner).."]"..
"checkbox[11.25,7.25;disable_linevar;vypnout;"..custom_state.disable_linevar.."]")
+ if custom_state.message ~= "" then
+ table.insert(formspec, "label[0.5,8.25;"..F(custom_state.message).."]")
+ end
if pinfo.role ~= "new" then
if has_rights_to_open_variant then
if selection_index > 1 then
@@ -324,8 +327,10 @@ local function custom_state_set_selection_index(custom_state, new_selection_inde
custom_state.owner = custom_state.player_name
custom_state.disable_linevar = "false"
end
+ custom_state.owner = ch_core.prihlasovaci_na_zobrazovaci(custom_state.owner)
custom_state.compiled_linevar = nil
custom_state.evl_scroll = 0
+ custom_state.message = ""
end
local function num_transform(s)
@@ -459,7 +464,7 @@ local function custom_state_compile_linevar(custom_state)
custom_state.compiled_linevar = {
name = line.."/"..stops[1].stn.."/"..rc,
line = line,
- owner = owner,
+ owner = ch_core.jmeno_na_prihlasovaci(owner),
stops = stops,
}
if train_name ~= "" then
@@ -539,13 +544,15 @@ local function formspec_callback(custom_state, player, formname, fields)
local success, errmsg = custom_state_compile_linevar(custom_state)
if success then
-- TODO: zkontrolovat práva a možnost přepsání i zde!
- ch_core.systemovy_kanal(pinfo.player_name, "Úspěšně ověřeno. Varianta linky může být uložena.")
+ custom_state.message = color_green.."Úspěšně ověřeno. Varianta linky může být uložena."
else
- ch_core.systemovy_kanal(pinfo.player_name, "Ověření selhalo: "..(errmsg or "Neznámý důvod"))
+ custom_state.message = color_red.."Ověření selhalo: "..(errmsg or "Neznámý důvod")
end
update_formspec = true
else
-- pokusit se uložit...
+ custom_state.message = ""
+
local selection_index = custom_state.selection_index or 1
local selected_linevar, selected_linevar_def, selected_linevar_station
local to_linevar, to_linevar_def, to_linevar_station
@@ -622,12 +629,12 @@ local function formspec_callback(custom_state, player, formname, fields)
end
if success then
- ch_core.systemovy_kanal(pinfo.player_name, "Varianta linky '"..new_linevar.."' úspěšně uložena.")
+ custom_state.message = color_green.."Varianta linky '"..new_linevar.."' úspěšně uložena."
custom_state_refresh_linevars(custom_state, new_linevar)
- update_formspec = true
else
- ch_core.systemovy_kanal(pinfo.player_name, "Ukládání selhalo: "..(errmsg or "Neznámá chyba."))
+ custom_state.message = color_red.."Ukládání selhalo: "..(errmsg or "Neznámá chyba.")
end
+ update_formspec = true
end
elseif fields.delete then
@@ -638,7 +645,7 @@ local function formspec_callback(custom_state, player, formname, fields)
end
local selection_index = custom_state.selection_index or 1
local selected_linevar, selected_linevar_def, selected_linevar_station
- if custom_state.selection_index > 1 and custom_state.linevars[selection_index - 1] ~= nil then
+ if selection_index > 1 and custom_state.linevars[selection_index - 1] ~= nil then
selected_linevar_def, selected_linevar_station = try_get_linevar_def(custom_state.linevars[selection_index - 1].name)
if selected_linevar_def ~= nil then
selected_linevar = selected_linevar_def.name
@@ -651,17 +658,17 @@ local function formspec_callback(custom_state, player, formname, fields)
errmsg = "Nedostatečná práva k variantě linky '"..selected_linevar.."'."
end
if success then
- ch_core.systemovy_kanal(pinfo.player_name, "Varianta linky '"..selected_linevar.."' úspěšně smazána.")
+ custom_state.message = "Varianta linky '"..selected_linevar.."' úspěšně smazána."
custom_state_refresh_linevars(custom_state)
- update_formspec = true
+ custom_state_set_selection_index(custom_state, 1)
else
- ch_core.systemovy_kanal(pinfo.player_name, "Mazání selhalo: "..(errmsg or "Neznámá chyba."))
+ custom_state.message = "Mazání selhalo: "..(errmsg or "Neznámá chyba.")
end
+ update_formspec = true
end
elseif fields.last_passages then
local selected_linevar_def = try_get_linevar_def(custom_state.linevars[(custom_state.selection_index or 1) - 1].name)
if selected_linevar_def ~= nil then
- print("DEBUG: selected_linevar_def: "..dump2(selected_linevar_def))
assert(selected_linevar_def.name)
show_last_passages_formspec(player, selected_linevar_def, assert(selected_linevar_def.name))
return
@@ -678,6 +685,7 @@ local function show_editor_formspec(player, linevar_to_select)
local custom_state = {
player_name = assert(player:get_player_name()),
evl_scroll = 0,
+ message = "",
}
if not custom_state_refresh_linevars(custom_state, linevar_to_select) then
custom_state_set_selection_index(custom_state, 1)
@@ -704,18 +712,39 @@ show_last_passages_formspec = function(player, linevar_def, selected_linevar)
local passages, stops = get_last_passages(linevar_def)
local max_time = {}
if passages ~= nil then
- for i = 1, 10 do
- if passages[i] == nil then
- passages[i] = {}
+ for j = 1, 10 do
+ max_time[j] = 0
+ if passages[j] == nil then
+ passages[j] = {}
+ end
+ end
+ -- stání na výchozí zastávce:
+ table.insert(formspec, ",,STÁNÍ NA V.Z.:")
+ for j = 1, 10 do
+ local wait = passages[j].wait
+ if wait ~= nil then
+ table.insert(formspec, ","..wait.." s")
+ else
+ table.insert(formspec, ",-")
+ end
+ end
+ -- odjezd z výchozí zastávky:
+ table.insert(formspec, ","..F(stops[1][1])..","..F(stops[1][2]).." (odj.)")
+ for j = 1, 10 do
+ local time = assert(passages[j][1])
+ table.insert(formspec, ",("..time..")")
+ if max_time[j] < time then
+ max_time[j] = time
end
end
- for i = 1, #stops do -- i = index zastávky
+ -- odjezdy z ostatních zasŧávek:
+ for i = 2, #stops do -- i = index zastávky
table.insert(formspec, ","..F(stops[i][1])..","..F(stops[i][2]))
for j = 1, 10 do -- j = index jízdy
local time = passages[j][i]
if time ~= nil then
- table.insert(formspec, ","..time)
- if max_time[j] == nil or max_time[j] < time then
+ table.insert(formspec, ","..(time - passages[j][1]))
+ if max_time[j] < time then
max_time[j] = time
end
else
diff --git a/advtrains_line_automation/line_functions.lua b/advtrains_line_automation/line_functions.lua
index 941bc4c..deb4ef7 100644
--- a/advtrains_line_automation/line_functions.lua
+++ b/advtrains_line_automation/line_functions.lua
@@ -20,12 +20,17 @@ local simple_modes = {
}
local current_passages = {--[[
- [train_id] = {[1] = rwtime, ..., [n] = rwtime (časy *odjezdu*, kromě koncových zastávek, kde jde o čas příjezdu)}
+ [train_id] = {
+ [1] = rwtime,
+ ...,
+ [n] = rwtime (časy *odjezdu*, kromě koncových zastávek, kde jde o čas příjezdu)
+ wait = int or nil (původně naplánovaná doba čekání na výchozí zastávce)
+ }
]]}
local last_passages = {--[[
[linevar] = {
- [1..10] = {[1] = rwtime, ...} -- jízdy seřazeny od nejstarší (1) po nejnovější (až 10) podle odjezdu z výchozí zastávky
+ [1..10] = {[1] = rwtime, ..., wait} -- jízdy seřazeny od nejstarší (1) po nejnovější (až 10) podle odjezdu z výchozí zastávky
}
]]}
@@ -596,6 +601,7 @@ function al.on_train_enter(pos, train_id, train, index)
debug_print("Vlak "..train_id.." zastavil na "..stn.." a odjede za "..wait.." sekund ("..planned_departure..").")
-- print("DEBUG: planned departure: "..planned_departure.." = "..rwtime.." + "..wait)
stdata.last_dep = planned_departure -- naplánovaný čas odjezdu
+ stdata.last_wait = wait -- naplánovaná doba čekání
ls.standing_at = pe
if linevar_def == nil or next_index == nil or (linevar_def.stops[next_index].mode or MODE_NORMAL) ~= MODE_HIDDEN then
-- zrušit stop_request, pokud jsme nezastavili na skryté zastávce:
@@ -728,6 +734,9 @@ function al.on_train_leave(pos, train_id, train, index)
if ls.linevar_index == 1 then
-- odjezd z výchozí zastávky:
local new_passage = {rwtime}
+ if stdata.last_wait ~= nil then
+ new_passage.wait = stdata.last_wait
+ end
current_passages[train_id] = new_passage
local passages_by_linevar = last_passages[ls.linevar]
if passages_by_linevar == nil then
@@ -775,7 +784,7 @@ end
Vrací:
a) pokud linevar existuje a má průjezdy:
passages, stops:
- {{[1] = rwtime, ...}...}, {"kód", "název"}...}
+ {{[1] = rwtime, ..., wait = int or nil}...}, {"kód", "název"}...}
b) jinak:
nil, nil
]]
@@ -838,7 +847,6 @@ end
local function get_train_position(line_status, linevar_def, rwtime)
if line_status ~= nil then
local last_pos_info = get_last_pos(line_status)
- print("DEBUG: last_pos_info = "..dump2({last_pos_info}))
local last_pos = last_pos_info.last_pos
if last_pos ~= nil then
local result = "„"..get_station_name(last_pos.stn).."“"
@@ -864,6 +872,7 @@ local def = {
local result = {}
if not param:match("/") then
local rwtime = rwt.to_secs(rwt.get_time())
+ local results = {}
for train_id, train in pairs(advtrains.trains) do
local ls, linevar_def = al.get_line_status(train)
if linevar_def ~= nil and (param == "" or ls.linevar:sub(1, #param + 1) == param.."/") then
@@ -872,10 +881,15 @@ local def = {
if direction_index ~= nil then
direction = get_station_name(direction_stop.stn)
end
- local s = "("..train_id..") ["..linevar_def.line.."] směr „"..direction.."“, poloha: "..get_train_position(ls, linevar_def, rwtime)
- table.insert(result, s)
+ local s = "("..train_id..") ["..linevar_def.line.."] směr „"..direction.."“, poloha: "..
+ get_train_position(ls, linevar_def, rwtime)
+ table.insert(results, {key = linevar_def.name.."/"..ls.linevar_index, value = s})
end
end
+ table.sort(results, function(a, b) return a.key < b.key end)
+ for i, v in ipairs(results) do
+ result[i] = v.value
+ end
end
if #result == 0 then
return false, "Nenalezen žádný odpovídající vlak."
diff --git a/advtrains_line_automation/structs.md b/advtrains_line_automation/structs.md
index f5e97fe..1fedcf9 100644
--- a/advtrains_line_automation/structs.md
+++ b/advtrains_line_automation/structs.md
@@ -93,6 +93,8 @@ stop = {
-- žel. čas posledního odjezdu jakéhokoliv zastavivšího vlaku z této zastávkové koleje;
-- používá se v kombinaci s intervalem
last_dep = int or nil,
+ -- původně naplánovaná doba stání vlaku vztahující se k last_dep
+ last_wait = int or nil,
}
local current_passages = {--[[