Beispiel #1
0
def loadGame(saveName):
    """ This function load an xml Save File and starts it"""
    try:
        save = file(os.path.join(parameters.getsavepath(), saveName),'rb')
    except IOError, detail: 
        print "IOError detail=",detail
        sys.exit()
Beispiel #2
0
def loadSaveIndex(saveIndexFile):
    try:
        saveIndex = file(os.path.join(parameters.getsavepath(), saveIndexFile),'rb')
        handler = SaveIndexHandler()
        parser = make_parser()
        parser.setContentHandler(handler)
        parser.parse(saveIndex)
    except:
        print "An error occurred while loading save data. Will discard save data!"
        print sys.exc_info()
        import traceback
        traceback.print_tb(sys.exc_info()[2])
Beispiel #3
0
def saveSaveIndex(saveIndexFile):
    global saves
    f = file(os.path.join(parameters.getsavepath(), saveIndexFile),'w')
    #print 'saved slide ',slide._save(slide._currentslide)
    hd = XMLGenerator(f) # handler's creation
    
    hd.startDocument()
    hd.startElement("SaveIndex", AttributesImpl({}))
    for (key, value) in saves.items():
        attributes = {"age": value.getage(),
                      "image": value.getimage()[0],
                      "date": value.getdate()}
        if value.getimage()[1] is not None:
            attributes["image_archive"] = value.getimage()[1]
        if value.getimage()[2] is not None:
            attributes["image_encryption"] = str(value.getimage()[2])
        hd.startElement("save", AttributesImpl(attributes))
        hd.characters(key)
        hd.endElement("save")
    hd.endElement("SaveIndex")
    hd.endDocument()
    f.close()
Beispiel #4
0
def menusave(i):
    print "save game ",i
    #Open index and search the last
    try:
        tmpfile=open(os.path.join(parameters.getsavepath(), 'index.sav'),'rb')
        data=tmpfile.readlines()
        tmpfile.close()
    except:
        pass
    
    if not os.path.exists(parameters.getsavepath()):
        os.makedirs(parameters.getsavepath())
    
    #Build the save file specific
    name = 'save.'+str(i)
    f = file(os.path.join(parameters.getsavepath(), name),'w')
    #print 'saved slide ',slide._save(slide._currentslide)
    hd = XMLGenerator(f) # handler's creation
    
    hd.startDocument()
    hd.startElement("Save", AttributesImpl({}))
    hd.startElement("age", AttributesImpl({}))
    hd.characters(globals.currentage.getFileName())
    hd.endElement("age")
    hd.startElement("music", AttributesImpl({"name": music.getcurrentStdMusic().getname()}))
    hd.endElement("music")
    hd.startElement("slide", AttributesImpl({}))
    # items in the stack beyond the first item are supposed to be menus, ignore them
    hd.characters(SlideManager.getBaseSlide().getrealname())
    hd.endElement("slide")
    hd.startElement("states", AttributesImpl({}))
    
    import pickle
    import base64
    
    for (k,v) in globals.menuslides.items():
        if (isinstance(v,slide)):
            #We remove the slideload and menu_root
            if (v.getrealname().startswith("slideload")==False and v.getrealname().startswith("menu_root")==False):
                # serialize the state dictionary using Pickle, then encode it in base64 so that it fits well in XML
                state = base64.b64encode(pickle.dumps(v.getAllStateVariables()))
                hd.startElement("state", AttributesImpl({"name": k, "state": state}))
                hd.endElement("state")
    for (k,v) in globals.currentage.getAllSlides().items():
        # serialize the state dictionary using Pickle, then encode it in base64 so that it fits well in XML
        state = base64.b64encode(pickle.dumps(v.getAllStateVariables()))
        hd.startElement("state", AttributesImpl({"name": k, "state": state}))
        hd.endElement("state")
    hd.endElement("states")
    hd.endElement("Save")
    hd.endDocument()
    f.close()
    date = strftime("%a, %d %b %Y %H:%M:%S", localtime())
    currentslideimg = SlideManager.getBaseSlide().getFullFilePath()

    #Build the key of saveIndex
    name = 'save'+str(i)
    #Retrieve the Save object :
    if (globals.saves.has_key(name)):
        mySave=globals.saves[name]
        mySave.setdate(date)
        mySave.setimage(currentslideimg)
        mySave.setage(globals.currentage.getFileName())
    else:
        globals.saves[name] = save(name, globals.currentage.getFileName(), currentslideimg, date)
    globals.saveSaveIndex('saveIndex.xml')
    #We exit the game
    quitgame()