diff options
Diffstat (limited to 'advtrains/init.lua')
-rw-r--r-- | advtrains/init.lua | 93 |
1 files changed, 43 insertions, 50 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua index 9019571..91b2b58 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -1,3 +1,4 @@ + --[[ Advanced Trains - Minetest Mod @@ -21,9 +22,6 @@ Copyright (C) 2016-2020 Moritz Blei (orwell96) and contributors local lot = os.clock() minetest.log("action", "[advtrains] Loading...") -local has_itrainmap = minetest.get_modpath("advtrains_itrainmap") -local has_luaautomation = minetest.get_modpath("advtrains_luaautomation") - -- 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") function attrans_formspec(...) @@ -75,7 +73,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 @@ -86,7 +84,7 @@ local function reload_saves() end minetest.after(1, function() advtrains.load() - atwarn("Reload successful!") + atwarn(S("Reload successful!")) advtrains.ndb.restore_all() end) end @@ -155,6 +153,7 @@ end atwarn=function(t, ...) local text=advtrains.print_concat_table({t, ...}) minetest.log("warning", "[advtrains]"..text) + minetest.chat_send_all("[advtrains] -!- "..text) end sid=function(id) if id then return string.sub(id, -6) end end @@ -163,6 +162,7 @@ sid=function(id) if id then return string.sub(id, -6) end end atdebug=function(t, ...) local text=advtrains.print_concat_table({t, ...}) minetest.log("action", "[advtrains]"..text) + minetest.chat_send_all("[advtrains]"..text) end if minetest.settings:get_bool("advtrains_enable_debugging") then @@ -184,7 +184,7 @@ function assertt(var, typ) end end -dofile(advtrains.modpath.."/helpers.lua"); +dofile(advtrains.modpath.."/helpers.lua") --dofile(advtrains.modpath.."/debugitems.lua"); advtrains.meseconrules = @@ -204,6 +204,8 @@ advtrains.meseconrules = advtrains.fpath=minetest.get_worldpath().."/advtrains" +advtrains.poconvert = dofile(advtrains.modpath.."/poconvert.lua") +advtrains.poconvert.from_flat("advtrains") attrans = minetest.get_translator("advtrains") advtrains.speed = dofile(advtrains.modpath.."/speed.lua") @@ -233,7 +235,7 @@ dofile(advtrains.modpath.."/craft_items.lua") dofile(advtrains.modpath.."/log.lua") dofile(advtrains.modpath.."/passive.lua") -if minetest.get_modpath("mesecons") then +if mesecon then dofile(advtrains.modpath.."/p_mesecon_iface.lua") end @@ -347,7 +349,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 @@ -412,7 +414,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 @@ -446,7 +448,7 @@ function advtrains.load_version_4() end --== load luaatc == - if has_luaautomation and atlatc then + if atlatc then local la_save = serialize_lib.load_atomic(advtrains.fpath.."_atlatc.ls") if la_save then atlatc.load(la_save) @@ -495,12 +497,12 @@ advtrains.avt_save = function(remove_players_from_wagons) "text_outside", "text_inside", "line", "routingcode", "il_sections", "speed_restriction", "speed_restrictions_t", "is_shunt", "path_ori_cp", "autocouple", "atc_wait_autocouple", "ars_disable", - "staticdata", "line_status", + "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"),id,S("had no wagons left because of some bug. It is being deleted. Wave it goodbye!")) advtrains.remove_train(id) end end @@ -551,7 +553,7 @@ advtrains.avt_save = function(remove_players_from_wagons) -- save of luaatc local la_save - if has_luaautomation and atlatc then + if atlatc then la_save = atlatc.save() end @@ -581,7 +583,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: ")..err) else -- store version advtrains.save_component(4, "version") @@ -636,10 +638,10 @@ minetest.register_globalstep(function(dtime_mt) end advtrains.mainloop_trainlogic(dtime,advtrains.mainloop_runcnt) - if has_itrainmap and advtrains_itm_mainloop then + if advtrains_itm_mainloop then advtrains_itm_mainloop(dtime) end - if has_luaautomation and atlatc then + if atlatc then --atlatc.mainloop_stepcode(dtime) atlatc.interrupt.mainloop(dtime) end @@ -668,10 +670,10 @@ end) -- first time called in main loop (after the init phase) because luaautomation has to initialize first. function advtrains.load() advtrains.avt_load() --loading advtrains. includes ndb at advtrains.ndb.load_data() - --if minetest.get_modpath("advtrains_luaautomation") and atlatc then + --if atlatc then -- atlatc.load() --includes interrupts --end == No longer loading here. Now part of avt_save() legacy loading. - if has_itrainmap and advtrains_itm_init then + if advtrains_itm_init then advtrains_itm_init() end init_load=true @@ -684,7 +686,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 @@ -700,22 +702,12 @@ function advtrains.save(remove_players_from_wagons) return end - local rwtime - if advtrains.lines ~= nil and advtrains.lines.rwt ~= nil then - local rwt = advtrains.lines.rwt - rwtime = rwt.to_string(rwt.get_time()) - end - local t1 = os.clock() advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data() - if has_luaautomation and atlatc then + if atlatc then atlatc.save() end - local message = "Saved advtrains save files, took "..tostring(math.floor((os.clock()-t1) * 1000)).."ms" - if rwtime ~= nil then - message = message.." rwtime="..rwtime - end - atlog(message) + atlog("Saved advtrains save files, took",math.floor((os.clock()-t1) * 1000),"ms") -- Cleanup actions --TODO very simple yet hacky workaround for the "green signals" bug @@ -723,7 +715,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 @@ -735,10 +727,10 @@ end) minetest.register_chatcommand("at_empty_seats", { params = "", -- Short parameter description - description = attrans("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, @@ -747,60 +739,60 @@ minetest.register_chatcommand("at_empty_seats", minetest.register_chatcommand("at_reroute", { params = "", - description = attrans("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 = attrans("<train id>"), - description = attrans("Returns the position of the train with the given id"), + params = "<train 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 ")..param..S(" does not exist or is invalid") else - return true, "Train "..param.." is at "..minetest.pos_to_string(train.last_pos) + return true, S("Train ")..param..S(" is at ")..minetest.pos_to_string(train.last_pos) end end, }) minetest.register_chatcommand("at_tp", { params = "<train id>", - description = attrans("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 ")..param..S(" does not exist or is invalid") else minetest.get_player_by_name(name):set_pos(train.last_pos) - return true, "Teleporting to train "..param + return true, S("Teleporting to train ")..param end end, }) minetest.register_chatcommand("at_disable_step", { params = "<yes/no>", - description = attrans("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, }) @@ -808,10 +800,10 @@ minetest.register_chatcommand("at_disable_step", minetest.register_chatcommand("at_status", { params = "", - description = attrans("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, advtrains.print_concat_table({S("Advtrains Status: no_action"),no_action,S("slowdown"),advtrains.global_slowdown,S("(log"),math.log(advtrains.global_slowdown),")"}) end, }) @@ -822,3 +814,4 @@ end local tot=(os.clock()-lot)*1000 minetest.log("action", "[advtrains] Loaded in "..tot.."ms") + |