------------------- Система сохранений ----------------------------

dump = require "dump"


SAVEFILE = sys.appdir('existenz_hare')..'/save.dmp'
SAVESOUNDSTATE = sys.appdir('existenz_hare')..'/sound.dmp'

if debugmode then print('Сохранение осуществляется в файл '..SAVEFILE) end

-- Сохранить
function savetofile()

local savetable = {}

savetable.i = pl.i
savetable.j = pl.j
savetable.EVENTS = EVENTS

savetable.oldSceneName = oldSceneName
savetable.activeSceneName = activeSceneName
savetable.activeObjectName = activeObjectName
savetable.activeMapName = activeMapName
savetable.lsite = lsite

savetable.inv = {}
for i = 1, #inventory.obj do
    table.insert(savetable.inv, inventory.obj[i].nam)
    end--for


dump.save(SAVEFILE, savetable)
dump.save(SAVESOUNDSTATE, {MUSIC_ON, SOUND_ON})
end -- func

-- Загрузить
function loadfromfile()

local savetable = dump.load(SAVEFILE)

pl.i = savetable.i
pl.j = savetable.j
EVENTS = savetable.EVENTS
oldSceneName = savetable.oldSceneName
activeSceneName = savetable.activeSceneName
activeObjectName = savetable.activeObjectName
activeMapName = savetable.activeMapName
lsite = savetable.lsite

for i = 1, #savetable.inv do
    take(savetable.inv[i])
    end--for

setMap(activeMapName)
setScene 'Экран игры'
end -- func


-- Проверить, есть ли сейв
function saveexist()
local f = io.open(SAVEFILE, 'r')
if f then
    f:close()
    return true
    else 
    return false
    end --if
end --func
SAVEEXIST = saveexist()
