"""
    Copyright 2001-2002 Andrew Jones

    This file is part of Pyzzle.

    Pyzzle is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Pyzzle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Pyzzle; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


"""
import pygame, os, pickle, tempfile, snd, mov, sys
from pygame.locals import *

import nodedata
from nodedata import *

#load_game and save_game functions
#Eventually these functions will be completely selfsufficient, no modification neccary

def save_game():
    
    f = open('savegames/savegame1.sav', 'w')
    pickle.dump(save_data,f)
    
    for i in range(1,len(save_data)):
        pickle.dump(save_data[i].file,f)
        for x in save_data[i].navdata:
            pickle.dump(x,f)
        for y in save_data[i].contains:
            if y == 'custom':
                pickle.dump(save_data[i].custmaps, f)
                pickle.dump(save_data[i].which_cursor, f)
            elif y == 'state':
                pickle.dump(save_data[i].state,f)
            elif y == 'text':
                pickle.dump(save_data[i].text,f)
            elif y == 'image':
                pickle.dump(save_data[i].imagefile,f)
                pickle.dump(save_data[i].imagepos,f)
            elif y == 'alphaimage':
                pickle.dump(save_data[i].imagefile,f)
                pickle.dump(save_data[i].imagepos,f)
                pickle.dump(save_data[i].alphaimage,f)
            elif y == 'movie':
                pickle.dump(save_data[i].moviefile,f)
                pickle.dump(save_data[i].moviepos,f)
            elif y == 'movieloop':
                pickle.dump(save_data[i].moviefile,f)
                pickle.dump(save_data[i].moviepos,f)
    for i in range(1,len(save_data)):
        if save_data[i] == node.currentslide:
            pickle.dump(i,f)
    pickle.dump(snd.currentAmbient,f)
    pickle.dump(snd.getambientvol(),f)
    pickle.dump(snd.currentSound,f)
    
    pickle.dump(node.current_transition,f)

    if movie.mov != None and node.hastype('movie') and movie.isloop:
            pickle.dump(1,f)
            pickle.dump(movie.position,f)
    else:
        pickle.dump(0,f)
        
    
    f.close()
def load_game():
    f = open('savegames/savegame1.sav', 'r')
    nodedata.save_data = pickle.load(f)
    nodedata.action = save_data[0]
    for i in range(1,len(save_data)):
        save_data[i].file = pickle.load(f)
        save_data[i].file
        for x in save_data[i].navdata:
            x = pickle.load(f)
        for y in save_data[i].contains:
            if y == 'custom':
                save_data[i].custmaps = pickle.load(f)
                save_data[i].which_cursor = pickle.load(f)
            elif y == 'state':
                save_data[i].state = pickle.load(f)
            elif y == 'text':
                save_data[i].text  = pickle.load(f)
            elif y == 'image':
                save_data[i].imagefile  = pickle.load(f)
                save_data[i].imagepos  = pickle.load(f)
            elif y == 'alphaimage':
                save_data[i].imagefile = pickle.load(f)
                save_data[i].imagepos = pickle.load(f)
                save_data[i].alphaimage = pickle.load(f)
            elif y == 'movie':
                save_data[i].moviefile = pickle.load(f)
                save_data[i].moviepos = pickle.load(f)
            elif y == 'movieloop':
                save_data[i].moviefile = pickle.load(f)
                save_data[i].moviepos  = pickle.load(f)
        
    i = pickle.load(f)
    sound.playambient(pickle.load(f))
    sound.setambientvol(pickle.load(f))
    snd = pickle.load(f)

    node.current_transition = pickle.load(f)
    if snd != None:
        sound.play(snd,1)
    node.currentslide = save_data[i]
    if pickle.load(f):
        movie.play(pickle.load(f),1,1)
        movie.load = 1
    
        
    f.close()
    
    return node.currentslide


    


