diff options
Diffstat (limited to 'advtrains/init.lua')
-rw-r--r-- | advtrains/init.lua | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua index 06e456f..cd63104 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -22,9 +22,6 @@ Copyright (C) 2016-2020 Moritz Blei (orwell96) and contributors local lot = os.clock() minetest.log("action", "[advtrains] Loading...") --- There is no need to support 0.4.x anymore given that the compatitability with it is already broken by 1bb1d825f46af3562554c12fba35a31b9f7973ff -attrans = minetest.get_translator ("advtrains") - --advtrains advtrains = {trains={}, player_to_train_mapping={}} @@ -53,6 +50,17 @@ advtrains.TRAIN_MAX_WAGONS = 20 -- ========================================================================== +advtrains.modpath = minetest.get_modpath("advtrains") + +-- Initialize internationalization (using ywang's poconvert) +advtrains.poconvert = dofile(advtrains.modpath.."/poconvert.lua") +advtrains.poconvert.from_flat("advtrains") +-- ask engine for translator instance, this will load the translation files +advtrains.translate = core.get_translator("advtrains") + +-- Get current translator +local S = advtrains.translate + -- Use a global slowdown factor to slow down train movements. Now a setting advtrains.DTIME_LIMIT = tonumber(minetest.settings:get("advtrains_dtime_limit")) or 0.2 advtrains.SAVE_INTERVAL = tonumber(minetest.settings:get("advtrains_save_interval")) or 60 @@ -70,7 +78,7 @@ end local no_action=false local function reload_saves() - atwarn("Restoring saved state in 1 second...") + atwarn(S("Restoring saved state in 1 second...")) no_action=true advtrains.lock_path_inval = false --read last save state and continue, as if server was restarted @@ -81,13 +89,11 @@ local function reload_saves() end minetest.after(1, function() advtrains.load() - atwarn("Reload successful!") + atwarn(S("Reload successful!")) advtrains.ndb.restore_all() end) end -advtrains.modpath = minetest.get_modpath("advtrains") - --Advtrains dump (special treatment of pos and sigd) function atdump(t, intend) local str @@ -181,7 +187,7 @@ function assertt(var, typ) end end -dofile(advtrains.modpath.."/helpers.lua"); +dofile(advtrains.modpath.."/helpers.lua") --dofile(advtrains.modpath.."/debugitems.lua"); advtrains.meseconrules = @@ -202,6 +208,7 @@ advtrains.meseconrules = advtrains.fpath=minetest.get_worldpath().."/advtrains" advtrains.speed = dofile(advtrains.modpath.."/speed.lua") +advtrains.formspec = dofile(advtrains.modpath.."/formspec.lua") advtrains.texture = dofile(advtrains.modpath.."/texture.lua") dofile(advtrains.modpath.."/path.lua") @@ -211,12 +218,12 @@ dofile(advtrains.modpath.."/trackplacer.lua") dofile(advtrains.modpath.."/copytool.lua") dofile(advtrains.modpath.."/wagonprop_tool.lua") dofile(advtrains.modpath.."/tracks.lua") +dofile(advtrains.modpath.."/track_reg_helper.lua") dofile(advtrains.modpath.."/occupation.lua") dofile(advtrains.modpath.."/atc.lua") dofile(advtrains.modpath.."/wagons.lua") dofile(advtrains.modpath.."/protection.lua") -dofile(advtrains.modpath.."/trackdb_legacy.lua") dofile(advtrains.modpath.."/nodedb.lua") dofile(advtrains.modpath.."/couple.lua") @@ -234,6 +241,9 @@ end dofile(advtrains.modpath.."/lzb.lua") +if minetest.settings:get_bool("advtrains_register_debugitems") then + dofile(advtrains.modpath.."/debugitems.lua") +end --load/save @@ -338,7 +348,7 @@ function advtrains.avt_load() end end for wid, _ in pairs(todel) do - atwarn("Removing unused wagon", wid, "from wagon_save table.") + atwarn(S("Removing unused wagon"), wid, S("from wagon_save table.")) advtrains.wagon_save[wid]=nil end else @@ -403,7 +413,7 @@ function advtrains.load_version_4() end end for wid, _ in pairs(todel) do - atwarn("Removing unused wagon", wid, "from wagon_save table.") + atwarn(S("Removing unused wagon"), wid, S("from wagon_save table.")) advtrains.wagon_save[wid]=nil end end @@ -416,6 +426,16 @@ function advtrains.load_version_4() if il_save then advtrains.interlocking.db.load(il_save) end + + -- TODO 2.5.0 backwards compatibility fallback: Store the pre-v2.5.0 save file so that it can be reverted to if needed + local fallback_file = advtrains.fpath.."_interlocking.ls.pre250" + local file = io.open(fallback_file, "rb") + if file then + io.close(file) + else + atwarn("Backing up pre-2.5.0 version of Interlocking save file to",fallback_file," for potential downgrade to older versions") + os.rename(advtrains.fpath.."_interlocking.ls", fallback_file) + end end --== load lines == @@ -475,12 +495,13 @@ advtrains.avt_save = function(remove_players_from_wagons) "atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open", "text_outside", "text_inside", "line", "routingcode", "il_sections", "speed_restriction", "speed_restrictions_t", "is_shunt", - "points_split", "autocouple", "atc_wait_autocouple", "ars_disable", + "path_ori_cp", "autocouple", "atc_wait_autocouple", "ars_disable", + "staticdata", }) --then save it tmp_trains[id]=v else - atwarn("Train",id,"had no wagons left because of some bug. It is being deleted. Wave it goodbye!") + atwarn(S("Train @1 had no wagons left because of some bug. It is being deleted. Wave it goodbye!", id)) advtrains.remove_train(id) end end @@ -561,7 +582,7 @@ advtrains.avt_save = function(remove_players_from_wagons) local succ, err = serialize_lib.save_atomic_multiple(parts_table, advtrains.fpath.."_", callbacks_table) if not succ then - atwarn("Saving failed: "..err) + atwarn(S("Saving failed: @1", err)) else -- store version advtrains.save_component(4, "version") @@ -664,7 +685,7 @@ end function advtrains.save(remove_players_from_wagons) if not init_load then --wait... we haven't loaded yet?! - atwarn("Instructed to save() but load() was never called!") + atwarn(S("Instructed to save() but load() was never called!")) return end @@ -693,7 +714,7 @@ function advtrains.save(remove_players_from_wagons) end minetest.register_on_shutdown(function() if within_mainstep then - atwarn("Crash during advtrains main step - skipping the shutdown save operation to not save inconsistent data!") + atwarn(S("Crash during advtrains main step - skipping the shutdown save operation to not save inconsistent data!")) else advtrains.save() end @@ -705,10 +726,10 @@ end) minetest.register_chatcommand("at_empty_seats", { params = "", -- Short parameter description - description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description + description = S("Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train."), -- Full description privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run func = function(name, param) - atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!") + atwarn(S("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!")) advtrains.save(true) reload_saves() end, @@ -717,60 +738,60 @@ minetest.register_chatcommand("at_empty_seats", minetest.register_chatcommand("at_reroute", { params = "", - description = "Delete all train routes, force them to recalculate", + description = S("Delete all train routes, force them to recalculate"), privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe. func = function(name, param) advtrains.invalidate_all_paths() - return true, "Successfully invalidated train routes" + return true, S("Successfully invalidated train routes") end, }) minetest.register_chatcommand("at_whereis", { params = "<train id>", - description = "Returns the position of the train with the given id", + description = S("Returns the position of the train with the given id"), privs = {train_operator = true}, func = function(name,param) local train = advtrains.trains[param] if not train or not train.last_pos then - return false, "Train "..param.." does not exist or is invalid" + return false, S("Train @1 does not exist or is invalid", param) else - return true, "Train "..param.." is at "..minetest.pos_to_string(train.last_pos) + return true, S("Train @1 is at @2", param, minetest.pos_to_string(train.last_pos)) end end, }) minetest.register_chatcommand("at_tp", { params = "<train id>", - description = "Teleports you to the position of the train with the given id", + description = S("Teleports you to the position of the train with the given id"), privs = {train_operator = true, teleport = true}, func = function(name,param) local train = advtrains.trains[param] if not train or not train.last_pos then - return false, "Train "..param.." does not exist or is invalid" + return false, S("Train @1 does not exist or is invalid", param) else minetest.get_player_by_name(name):set_pos(train.last_pos) - return true, "Teleporting to train "..param + return true, S("Teleporting to train @1", param) end end, }) minetest.register_chatcommand("at_disable_step", { params = "<yes/no>", - description = "Disable the advtrains globalstep temporarily", + description = S("Disable the advtrains globalstep temporarily"), privs = {server=true}, func = function(name, param) if minetest.is_yes(param) then -- disable everything, and turn off saving no_action = true; - atwarn("The advtrains globalstep has been disabled. Trains are not moving, and no data is saved! Run '/at_disable_step no' to enable again!") - return true, "Disabled advtrains successfully" + atwarn(S("The advtrains globalstep has been disabled. Trains are not moving, and no data is saved! Run '/at_disable_step no' to enable again!")) + return true, S("Disabled advtrains successfully") elseif no_action then - atwarn("Re-enabling advtrains globalstep...") + atwarn(S("Re-enabling advtrains globalstep...")) reload_saves() return true else - return false, "Advtrains is already running normally!" + return false, S("Advtrains is already running normally!") end end, }) @@ -778,10 +799,10 @@ minetest.register_chatcommand("at_disable_step", minetest.register_chatcommand("at_status", { params = "", - description = "Print advtrains status info", + description = S("Print advtrains status info"), privs = {train_operator = true}, func = function(name, param) - return true, advtrains.print_concat_table({"Advtrains Status: no_action",no_action,"slowdown",advtrains.global_slowdown,"(log",math.log(advtrains.global_slowdown),")"}) + return true, S("Advtrains Status: no_action @1 slowdown @2 (log @3)", no_action, advtrains.global_slowdown, math.log(advtrains.global_slowdown)) end, }) |