~vbkaisetsu/+junk/renpy-vertical-text

« back to all changes in this revision

Viewing changes to renpy/loadsave.py

  • Committer: Tom
  • Date: 2012-06-19 04:25:04 UTC
  • Revision ID: pytom@bishoujo.us-20120619042504-mvs3w9h72q32t7hn
Document save, load, and rollback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
         file=file, StringIO=cStringIO.StringIO, #@ReservedAssignment
195
195
         mutate_flag=False, wait=None):
196
196
    """
197
 
    Saves the game in the given filename. This will save the game
198
 
    along with a screnshot and the given extra_info, which is just
199
 
    serialized.
 
197
    :doc: loadsave
 
198
    :args: (filename, extra_info='')
 
199
    
 
200
    Saves the game state to a save slot. 
200
201
 
201
 
    It's expected that a screenshot will be taken (with
202
 
    renpy.take_screenshot) before this is called.
 
202
    `filename`
 
203
        A string giving the name of a save slot. Despite the variable name,
 
204
        this corresponds only loosely to filenames.
 
205
    
 
206
    `extra_info`
 
207
        An additional string that should be saved to the save file. Usually,
 
208
        this is the value of :var:`save_name`.
 
209
    
 
210
    :func:`renpy.take_screenshot` should be called before this function.
203
211
    """
204
212
 
205
213
    cache.pop(filename, None)
284
292
 
285
293
def list_saved_games(regexp=r'.'):
286
294
    """
287
 
    This scans the savegames that we know about and returns
288
 
    information about them. It returns a list of tuples, where each
289
 
    tuple represents one savegame and consists of:
290
 
    
291
 
    - The filename of the save.
292
 
    - The extra_info that was passed to renpy.save.
293
 
    - A displayable, the screenshot used to show the game.
294
 
    - The time the game was saved at, seconds since 1/1/1970 UTC.
295
 
    
296
 
    The regexp matches at the start of the filename, and filters the list.
 
295
    :doc: loadsave
 
296
    
 
297
    Lists the save games. For each save game, returns a tuple containing:
 
298
    
 
299
    * The filename of the save.
 
300
    * The extra_info that was passed in.
 
301
    * A displayable that, when displayed, shows the screenshot that was 
 
302
      used when saving the game.
 
303
    * The time the game was stayed at, in seconds since the UNIX epoch.
 
304
 
 
305
    `regexp`
 
306
        A regular expression that is matched against the start of the
 
307
        filename to filter the list.
297
308
    """
298
309
 
299
310
    try:
320
331
 
321
332
def can_load(filename):
322
333
    """
323
 
    Returns true if we can load the given savegame file, False otherwise.
 
334
    :doc: loadsave
 
335
    
 
336
    Returns true if `filename` can be loaded, false otherwise.
324
337
    """
325
338
 
326
339
    try:
333
346
 
334
347
def load(filename):
335
348
    """
336
 
    Loads the game from the given file. This function never returns.
 
349
    :doc: loadsave
 
350
    
 
351
    Loads the game state from `filename`. This function never returns.
337
352
    """
338
353
    
339
354
    zf = zipfile.ZipFile(renpy.config.savedir + "/" + filename + savegame_suffix, "r")
343
358
    log.unfreeze(roots, label="_after_load")
344
359
 
345
360
def rename_save(old, new):
 
361
    """
 
362
    :doc: loadsave
 
363
    
 
364
    Renames a save from `old` to `new`.
 
365
    """
 
366
    
346
367
    unlink_save(new)
347
368
    os.rename(renpy.config.savedir + "/" + old + savegame_suffix, 
348
369
              renpy.config.savedir + "/" + new + savegame_suffix)
351
372
    cache.pop(new, None)
352
373
 
353
374
def unlink_save(filename):
 
375
    """
 
376
    :doc: loadsave
 
377
    
 
378
    Deletes the save with the given `filename`.
 
379
    """
 
380
    
354
381
    if os.path.exists(renpy.config.savedir + "/" + filename + savegame_suffix):
355
382
        os.unlink(renpy.config.savedir + "/" + filename + savegame_suffix)
356
383
 
358
385
        
359
386
 
360
387
def cycle_saves(name, count):
 
388
    """
 
389
    :doc: loadsave
 
390
 
 
391
    Rotates the first `count` saves beginning with `name`.
 
392
    
 
393
    For example, if the name is auto and the count is 10, then 
 
394
    auto-9 will be renamed to auto-9, auto-8 will be renamed to auto-9, 
 
395
    and so on until auto-1 is renamed to auto-2.
 
396
    """
361
397
 
362
398
    for count in range(1, count + 1):
363
399
        if not os.path.exists(renpy.config.savedir + "/" + name + str(count) + savegame_suffix):
407
443
def autosave():
408
444
    global autosave_counter
409
445
 
410
 
    
411
446
    if not renpy.config.autosave_frequency:
412
447
        return 
413
448