mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-26 03:41:04 +03:00
Gamebook id to allow saved games from different games in browser.
Default id is basename of file without extension. Override id by setting book config, as seen in format.gamebook.
This commit is contained in:
parent
cf8f805255
commit
1fac366e19
|
@ -1,4 +1,5 @@
|
|||
title = Format
|
||||
id = format2
|
||||
starttext = Adventure begins in section 1.
|
||||
hideintrotext = HIDE THE INTRO
|
||||
showintrotext = SHOW THE INTRO
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
|
||||
var gamebook = {
|
||||
'id' : 'codewords',
|
||||
|
||||
'player' : {
|
||||
'started' : false,
|
||||
'currentSection' : -1,
|
||||
|
@ -122,7 +124,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -130,7 +132,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -148,6 +150,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
|
||||
var gamebook = {
|
||||
'id' : 'format2',
|
||||
|
||||
'player' : {
|
||||
'started' : false,
|
||||
'currentSection' : -1,
|
||||
|
@ -122,7 +124,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -130,7 +132,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -148,6 +150,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
|
||||
var gamebook = {
|
||||
'id' : 'items',
|
||||
|
||||
'player' : {
|
||||
'started' : false,
|
||||
'currentSection' : -1,
|
||||
|
@ -122,7 +124,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -130,7 +132,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -148,6 +150,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
|
||||
var gamebook = {
|
||||
'id' : 'references',
|
||||
|
||||
'player' : {
|
||||
'started' : false,
|
||||
'currentSection' : -1,
|
||||
|
@ -122,7 +124,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -130,7 +132,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -148,6 +150,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
|
||||
var gamebook = {
|
||||
'id' : 'unreachable',
|
||||
|
||||
'player' : {
|
||||
'started' : false,
|
||||
'currentSection' : -1,
|
||||
|
@ -122,7 +124,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -130,7 +132,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,7 +141,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -148,6 +150,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
|
@ -71,7 +71,7 @@ def format_gamebook(inputfilenames,
|
|||
verify,
|
||||
shuffle):
|
||||
output_format = make_output(outputfilename, templatedirs)
|
||||
book = sections.Book()
|
||||
book = sections.Book(make_bookid(outputfilename))
|
||||
for inputfilename in inputfilenames:
|
||||
parse_file_to_book(open(inputfilename, 'r'), book)
|
||||
if import_default_map_file:
|
||||
|
@ -80,6 +80,9 @@ def format_gamebook(inputfilenames,
|
|||
verifygamebook.verify(book)
|
||||
write_book(book, shuffle, output_format, outputfilename)
|
||||
|
||||
def make_bookid(filename):
|
||||
return os.path.splitext(os.path.basename(filename))[0]
|
||||
|
||||
def parse_file_to_book(inputfile, book):
|
||||
before_first_section = True
|
||||
name = None
|
||||
|
|
|
@ -51,12 +51,12 @@ class ShuffledSections:
|
|||
for nr in nr_sections:
|
||||
self.name_to_nr[nr_sections[nr]] = nr
|
||||
|
||||
STR_BOOK_CONFIG = set(['title', 'author', 'starttext', 'hideintrotext',
|
||||
STR_BOOK_CONFIG = set(['id', 'title', 'author', 'starttext', 'hideintrotext',
|
||||
'showintrotext', 'resumetext'])
|
||||
INT_BOOK_CONFIG = set(['max'])
|
||||
|
||||
class Book:
|
||||
def __init__(self):
|
||||
def __init__(self, bookid="gamebook"):
|
||||
self.sections = []
|
||||
self.introsections = []
|
||||
self.from_name = {}
|
||||
|
@ -68,7 +68,8 @@ class Book:
|
|||
'starttext' : 'Turn to 1 to begin.',
|
||||
'hideintrotext' : '(hide instructions)',
|
||||
'showintrotext' : '(show instructions)',
|
||||
'resumetext' : 'Resume saved game.'}
|
||||
'resumetext' : 'Resume saved game.',
|
||||
'id' : bookid}
|
||||
|
||||
def configure(self, name, value):
|
||||
if name in INT_BOOK_CONFIG:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'id' : '%(id)s',
|
||||
|
||||
'player' : {
|
||||
#include "playerscript"
|
||||
#include "extra-playerscript"
|
||||
|
@ -45,7 +47,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'saveGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
window.localStorage.setItem('savedGamebookPlayer',
|
||||
window.localStorage.setItem(this.getSavedGameName(),
|
||||
this.player.getState());
|
||||
}
|
||||
},
|
||||
|
@ -53,7 +55,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'hasSavedGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
return window.localStorage.getItem('savedGamebookPlayer');
|
||||
return window.localStorage.getItem(this.getSavedGameName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -62,7 +64,7 @@
|
|||
//FIXME move out from gamebook object
|
||||
'loadGame' : function() {
|
||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||
var state = window.localStorage.getItem('savedGamebookPlayer');
|
||||
var state = window.localStorage.getItem(this.getSavedGameName());
|
||||
this.player.setState(state);
|
||||
this.turnTo(this.player.currentSection);
|
||||
this.updateCollectionsView();
|
||||
|
@ -71,6 +73,10 @@
|
|||
}
|
||||
},
|
||||
|
||||
'getSavedGameName' : function() {
|
||||
return 'savedGamebookPlayer-' + this.id;
|
||||
},
|
||||
|
||||
'hideIntroSections' : function() {
|
||||
this.addClassToClass('introsection', 'nodisplay');
|
||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||
|
|
Loading…
Reference in a new issue