示例#1
0
def menuenter():
    
    if globals.playerinventory != None:
        globals.playerinventory.update(visible = 0, enabled = 0)
    
    if globals.currentage is None or SlideManager.getBaseSlide().gettype() == 'menu':
        # The save menu should not be reachable when no age has been played
        menumain.detachhotspotById('save')
    else:
        menumain.attachhotspot((500, 460, 200, 40), 'grab', {'dest' : 'savemenu','zip':0, 'push':1},'save')
        
    musicmain.playmusic()
示例#2
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()