diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-12 17:33:43 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-12 17:33:43 +0100 |
commit | dc8b47a066ff8b3251ad09d4b490647e3f057d10 (patch) | |
tree | b0953a17adf450e8bff02395f71538472f85e393 /advtrains/advtrains/trainlogic.lua | |
parent | 04d14dc1bf4d7527635652e48493114254750dd3 (diff) | |
download | advtrains-dc8b47a066ff8b3251ad09d4b490647e3f057d10.tar.gz advtrains-dc8b47a066ff8b3251ad09d4b490647e3f057d10.tar.bz2 advtrains-dc8b47a066ff8b3251ad09d4b490647e3f057d10.zip |
Unite all save data (except the track database) into a single save file
Diffstat (limited to 'advtrains/advtrains/trainlogic.lua')
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index 07a48cc..c9c7403 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -39,96 +39,11 @@ advtrains.train_emerg_force=10--for emergency brakes(when going off track) advtrains.audit_interval=10 -advtrains.trains={} -advtrains.wagon_save={} - ---load initially -advtrains.fpath=minetest.get_worldpath().."/advtrains" -local file, err = io.open(advtrains.fpath, "r") -if not file then - local er=err or "Unknown Error" - atprint("Failed loading advtrains save file "..er) -else - local tbl = minetest.deserialize(file:read("*a")) - if type(tbl) == "table" then - advtrains.trains=tbl - end - file:close() -end -advtrains.fpath_ws=minetest.get_worldpath().."/advtrains_wagon_save" -local file, err = io.open(advtrains.fpath_ws, "r") -if not file then - local er=err or "Unknown Error" - atprint("Failed loading advtrains save file "..er) -else - local tbl = minetest.deserialize(file:read("*a")) - if type(tbl) == "table" then - advtrains.wagon_save=tbl - end - file:close() -end - - -advtrains.save = function() - atprint("saving") - advtrains.invalidate_all_paths() - local datastr = minetest.serialize(advtrains.trains) - if not datastr then - minetest.log("error", " Failed to serialize train data!") - return - end - local file, err = io.open(advtrains.fpath, "w") - if err then - return err - end - file:write(datastr) - file:close() - - -- update wagon saves - for _,wagon in pairs(minetest.luaentities) do - if wagon.is_wagon and wagon.initialized then - wagon:get_staticdata() - end - end - --cross out userdata - for w_id, data in pairs(advtrains.wagon_save) do - data.name=nil - data.object=nil - if data.driver then - data.driver_name=data.driver:get_player_name() - data.driver=nil - else - data.driver_name=nil - end - if data.discouple then - data.discouple.object:remove() - data.discouple=nil - end - end - --atprint(dump(advtrains.wagon_save)) - datastr = minetest.serialize(advtrains.wagon_save) - if not datastr then - minetest.log("error", " Failed to serialize train data!") - return - end - file, err = io.open(advtrains.fpath_ws, "w") - if err then - return err - end - file:write(datastr) - file:close() - - advtrains.save_trackdb() - advtrains.atc.save() -end -minetest.register_on_shutdown(advtrains.save) - advtrains.save_and_audit_timer=advtrains.audit_interval minetest.register_globalstep(function(dtime) advtrains.save_and_audit_timer=advtrains.save_and_audit_timer-dtime if advtrains.save_and_audit_timer<=0 then local t=os.clock() - --save advtrains.save() advtrains.save_and_audit_timer=advtrains.audit_interval |