mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-28 20:55:13 +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
|
title = Format
|
||||||
|
id = format2
|
||||||
starttext = Adventure begins in section 1.
|
starttext = Adventure begins in section 1.
|
||||||
hideintrotext = HIDE THE INTRO
|
hideintrotext = HIDE THE INTRO
|
||||||
showintrotext = SHOW THE INTRO
|
showintrotext = SHOW THE INTRO
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
|
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
|
'id' : 'codewords',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
'started' : false,
|
'started' : false,
|
||||||
'currentSection' : -1,
|
'currentSection' : -1,
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,7 +132,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -148,6 +150,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
|
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
|
'id' : 'format2',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
'started' : false,
|
'started' : false,
|
||||||
'currentSection' : -1,
|
'currentSection' : -1,
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,7 +132,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -148,6 +150,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
|
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
|
'id' : 'items',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
'started' : false,
|
'started' : false,
|
||||||
'currentSection' : -1,
|
'currentSection' : -1,
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,7 +132,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -148,6 +150,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
|
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
|
'id' : 'references',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
'started' : false,
|
'started' : false,
|
||||||
'currentSection' : -1,
|
'currentSection' : -1,
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,7 +132,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -148,6 +150,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
|
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
|
'id' : 'unreachable',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
'started' : false,
|
'started' : false,
|
||||||
'currentSection' : -1,
|
'currentSection' : -1,
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -130,7 +132,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -148,6 +150,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
|
@ -71,7 +71,7 @@ def format_gamebook(inputfilenames,
|
||||||
verify,
|
verify,
|
||||||
shuffle):
|
shuffle):
|
||||||
output_format = make_output(outputfilename, templatedirs)
|
output_format = make_output(outputfilename, templatedirs)
|
||||||
book = sections.Book()
|
book = sections.Book(make_bookid(outputfilename))
|
||||||
for inputfilename in inputfilenames:
|
for inputfilename in inputfilenames:
|
||||||
parse_file_to_book(open(inputfilename, 'r'), book)
|
parse_file_to_book(open(inputfilename, 'r'), book)
|
||||||
if import_default_map_file:
|
if import_default_map_file:
|
||||||
|
@ -80,6 +80,9 @@ def format_gamebook(inputfilenames,
|
||||||
verifygamebook.verify(book)
|
verifygamebook.verify(book)
|
||||||
write_book(book, shuffle, output_format, outputfilename)
|
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):
|
def parse_file_to_book(inputfile, book):
|
||||||
before_first_section = True
|
before_first_section = True
|
||||||
name = None
|
name = None
|
||||||
|
|
|
@ -51,12 +51,12 @@ class ShuffledSections:
|
||||||
for nr in nr_sections:
|
for nr in nr_sections:
|
||||||
self.name_to_nr[nr_sections[nr]] = nr
|
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'])
|
'showintrotext', 'resumetext'])
|
||||||
INT_BOOK_CONFIG = set(['max'])
|
INT_BOOK_CONFIG = set(['max'])
|
||||||
|
|
||||||
class Book:
|
class Book:
|
||||||
def __init__(self):
|
def __init__(self, bookid="gamebook"):
|
||||||
self.sections = []
|
self.sections = []
|
||||||
self.introsections = []
|
self.introsections = []
|
||||||
self.from_name = {}
|
self.from_name = {}
|
||||||
|
@ -68,7 +68,8 @@ class Book:
|
||||||
'starttext' : 'Turn to 1 to begin.',
|
'starttext' : 'Turn to 1 to begin.',
|
||||||
'hideintrotext' : '(hide instructions)',
|
'hideintrotext' : '(hide instructions)',
|
||||||
'showintrotext' : '(show instructions)',
|
'showintrotext' : '(show instructions)',
|
||||||
'resumetext' : 'Resume saved game.'}
|
'resumetext' : 'Resume saved game.',
|
||||||
|
'id' : bookid}
|
||||||
|
|
||||||
def configure(self, name, value):
|
def configure(self, name, value):
|
||||||
if name in INT_BOOK_CONFIG:
|
if name in INT_BOOK_CONFIG:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'id' : '%(id)s',
|
||||||
|
|
||||||
'player' : {
|
'player' : {
|
||||||
#include "playerscript"
|
#include "playerscript"
|
||||||
#include "extra-playerscript"
|
#include "extra-playerscript"
|
||||||
|
@ -45,7 +47,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'saveGame' : function() {
|
'saveGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
window.localStorage.setItem('savedGamebookPlayer',
|
window.localStorage.setItem(this.getSavedGameName(),
|
||||||
this.player.getState());
|
this.player.getState());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -53,7 +55,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'hasSavedGame' : function() {
|
'hasSavedGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
||||||
return window.localStorage.getItem('savedGamebookPlayer');
|
return window.localStorage.getItem(this.getSavedGameName());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@
|
||||||
//FIXME move out from gamebook object
|
//FIXME move out from gamebook object
|
||||||
'loadGame' : function() {
|
'loadGame' : function() {
|
||||||
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
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.player.setState(state);
|
||||||
this.turnTo(this.player.currentSection);
|
this.turnTo(this.player.currentSection);
|
||||||
this.updateCollectionsView();
|
this.updateCollectionsView();
|
||||||
|
@ -71,6 +73,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getSavedGameName' : function() {
|
||||||
|
return 'savedGamebookPlayer-' + this.id;
|
||||||
|
},
|
||||||
|
|
||||||
'hideIntroSections' : function() {
|
'hideIntroSections' : function() {
|
||||||
this.addClassToClass('introsection', 'nodisplay');
|
this.addClassToClass('introsection', 'nodisplay');
|
||||||
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
this.removeClassFromClass('displayintrolink', 'nodisplay');
|
||||||
|
|
Loading…
Reference in a new issue