mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-16 23:20:44 +03:00
Examples structure. New examples. Verification stub. Tags parsing.
This commit is contained in:
parent
4dc609c1a2
commit
84243fafa8
26
Makefile
26
Makefile
|
@ -1,29 +1,37 @@
|
|||
all: test.rtf test.pdf test.html test.debug test.png
|
||||
examples=$(wildcard examples/*.gamebook)
|
||||
|
||||
all: $(examples:.gamebook=.rtf) \
|
||||
$(examples:.gamebook=.pdf) \
|
||||
$(examples:.gamebook=.html) \
|
||||
$(examples:.gamebook=.debug) \
|
||||
$(examples:.gamebook=.png)
|
||||
|
||||
%.rtf: %.gamebook formatgamebook.py
|
||||
./formatgamebook.py $< $@
|
||||
./formatgamebook.py --verify $< $@
|
||||
|
||||
%.html: %.gamebook formatgamebook.py
|
||||
./formatgamebook.py $< $@
|
||||
./formatgamebook.py --verify $< $@
|
||||
|
||||
%.tex: %.gamebook formatgamebook.py
|
||||
./formatgamebook.py $< $@
|
||||
./formatgamebook.py --verify $< $@
|
||||
|
||||
%.dot: %.gamebook formatgamebook.py
|
||||
./formatgamebook.py $< $@
|
||||
./formatgamebook.py --verify $< $@
|
||||
|
||||
%.debug: %.gamebook formatgamebook.py
|
||||
./formatgamebook.py $< $@
|
||||
./formatgamebook.py --verify $< $@
|
||||
|
||||
%.pdf: %.tex
|
||||
pdflatex $< && pdflatex $<
|
||||
cd $(dir $<) && pdflatex $(notdir $<) && pdflatex $(notdir $<)
|
||||
|
||||
%.png: %.dot
|
||||
dot -Tpng $< > $@
|
||||
|
||||
clean:
|
||||
$(RM) *.rtf *.html *.tex *.debug *.pdf *~ *.pyc *.dot \
|
||||
*.aux *.toc *.png
|
||||
$(RM) examples/*.rtf examples/*.html examples/*.tex \
|
||||
examples/*.debug examples/*.pdf *~ examples/*~ *.pyc \
|
||||
examples/*.dot examples/*.aux examples/*.toc examples/*.png \
|
||||
examples/*.map
|
||||
|
||||
fixmes:
|
||||
grep FIXME *.py
|
||||
|
|
5
examples/.gitignore
vendored
Normal file
5
examples/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
*.rtf
|
||||
*.tex
|
||||
*.html
|
||||
*.dot
|
||||
*.debug
|
2
examples/codewords.gamebook
Normal file
2
examples/codewords.gamebook
Normal file
|
@ -0,0 +1,2 @@
|
|||
* 1 start
|
||||
Demonstrating how codewords (AKA sightings) can be used.
|
2
examples/items.gamebook
Normal file
2
examples/items.gamebook
Normal file
|
@ -0,0 +1,2 @@
|
|||
* 1 start
|
||||
Demonstrating how to manage player inventory.
|
14
examples/references.gamebook
Normal file
14
examples/references.gamebook
Normal file
|
@ -0,0 +1,14 @@
|
|||
* 1 start
|
||||
This is where the adventure begins. You can go on to the
|
||||
next section, see %(next)s or try the other instead, see %(other)s.
|
||||
|
||||
* next
|
||||
This is the next section. Go on to the end at %(end)s.
|
||||
|
||||
* other
|
||||
This is another section. You can try the next section now,
|
||||
see %(next)s, or go on to the end, see %(end)s.
|
||||
|
||||
* end
|
||||
The end.
|
||||
|
16
examples/unreachable.gamebook
Normal file
16
examples/unreachable.gamebook
Normal file
|
@ -0,0 +1,16 @@
|
|||
* 1 start
|
||||
It starts here. You can get to %(here)s.
|
||||
|
||||
* here
|
||||
You can get here. Congratulations!
|
||||
|
||||
* nothere
|
||||
You can not get here. Verification
|
||||
should warn you about that, if enabled (with the --verify option).
|
||||
|
||||
* nothereeither :dummy:
|
||||
You can not get here either, but because it is tagged as
|
||||
dummy there will be no warning generated.
|
||||
|
||||
* seconddummy :dummy:
|
||||
Another dummy section that is also ignored.
|
|
@ -35,13 +35,15 @@ import json
|
|||
|
||||
import sections
|
||||
import templates
|
||||
import verifygamebook
|
||||
from output import OutputFormat
|
||||
|
||||
USAGE = "usage: %prog [options] inputfile(s)... outputfile"
|
||||
|
||||
def of(extension, name):
|
||||
return {'extension' : extension,
|
||||
'name' : name}
|
||||
'name' : name,
|
||||
}
|
||||
|
||||
OUTPUT_FORMATS = [
|
||||
of('tex', 'LaTeX'),
|
||||
|
@ -58,26 +60,38 @@ def make_supported_formats_list_string():
|
|||
def format_gamebook(inputfilenames,
|
||||
outputfilename,
|
||||
import_default_map_file,
|
||||
templatedirs):
|
||||
templatedirs,
|
||||
verify):
|
||||
output_format = make_output(outputfilename, templatedirs)
|
||||
book = sections.Book()
|
||||
for inputfilename in inputfilenames:
|
||||
parse_file_to_book(open(inputfilename, 'r'), book)
|
||||
if import_default_map_file:
|
||||
import_default_nr_map(outputfilename, book)
|
||||
if verify:
|
||||
verifygamebook.verify(book)
|
||||
write_book(book, output_format, outputfilename)
|
||||
|
||||
def parse_file_to_book(inputfile, book):
|
||||
name = None
|
||||
number = None
|
||||
text = ""
|
||||
tags = None
|
||||
for line in inputfile.readlines():
|
||||
if line.startswith('*'):
|
||||
if name:
|
||||
add_section_to_book(book, name, text, number)
|
||||
number = None
|
||||
text = ""
|
||||
heading = line[1:].strip().split(' ')
|
||||
heading = [h.strip() for h in line[1:].strip().split()]
|
||||
if len(heading) > 1 and heading[-1].startswith(':'):
|
||||
if not heading[-1].endswith(':'):
|
||||
raise Exception('Section heading tags syntax error: %s' %
|
||||
heading)
|
||||
tags = [t.strip() for t in heading[-1][1:-1].split(':')]
|
||||
heading = heading[:-1]
|
||||
else:
|
||||
tags = None
|
||||
if len(heading) == 1:
|
||||
name = heading[0]
|
||||
elif len(heading) == 2:
|
||||
|
@ -88,10 +102,13 @@ def parse_file_to_book(inputfile, book):
|
|||
else:
|
||||
text = text + " " + line.strip()
|
||||
if name:
|
||||
add_section_to_book(book, name, text, number)
|
||||
add_section_to_book(book, name, text, number, tags)
|
||||
|
||||
def add_section_to_book(book, name, text, number=None):
|
||||
book.add(sections.Section(name, text))
|
||||
def add_section_to_book(book, name, text, number=None, tags=None):
|
||||
section = sections.Section(name, text)
|
||||
if tags:
|
||||
section.set_tags(tags)
|
||||
book.add(section)
|
||||
if number:
|
||||
book.force_section_nr(name, number)
|
||||
|
||||
|
@ -141,6 +158,8 @@ if __name__ == '__main__':
|
|||
help='ignore default map file')
|
||||
ap.add_argument('-t', '--template', metavar='D', dest='templatedirs',
|
||||
action='append', help='add custom template dir')
|
||||
ap.add_argument('-y', '--verify', action='store_true',
|
||||
help='verify gamebook structure')
|
||||
args = ap.parse_args()
|
||||
templatedirs = ['templates',
|
||||
os.path.join(os.path.dirname(sys.argv[0]), 'templates')]
|
||||
|
@ -150,5 +169,5 @@ if __name__ == '__main__':
|
|||
format_gamebook(args.inputfiles,
|
||||
args.outputfile,
|
||||
args.import_default_map_file,
|
||||
templatedirs)
|
||||
|
||||
templatedirs,
|
||||
args.verify)
|
||||
|
|
|
@ -5,9 +5,14 @@ class Section:
|
|||
def __init__(self, name, text):
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.tags = set()
|
||||
|
||||
def set_tags(self, tags):
|
||||
self.tags = set(tags)
|
||||
|
||||
def __repr__(self):
|
||||
return "Section(%s, %s)" % (repr(self.name), repr(self.text))
|
||||
return "Section(%s, %s, %s)" % (repr(self.name), repr(self.text),
|
||||
repr(self.tags))
|
||||
|
||||
def format(self, references):
|
||||
return self.text % references
|
||||
|
|
17
todo.org
17
todo.org
|
@ -12,6 +12,7 @@
|
|||
- [X] Add section links in LaTeX output.
|
||||
- [X] Prettier LaTeX output
|
||||
Look at how some existing gamebooks are formatted.
|
||||
- [ ] Verify gamebook for debug and dot outputs
|
||||
- [ ] Inventory pick up items
|
||||
- [ ] Codewords set
|
||||
- [ ] Check if has inventory item
|
||||
|
@ -20,11 +21,23 @@
|
|||
- [ ] Optionally remove inventory item to make a choice
|
||||
- [ ] More formatting possibilities in sections
|
||||
Look at existing gamebooks to get ideas.
|
||||
- [ ] Command-line flag to set max section number to use
|
||||
- [ ] Book option to set max section number to use
|
||||
- [ ] Book option to set pdf layout (page size and number of columns)
|
||||
- [ ] Book option to set title
|
||||
- [ ] Book option to set author
|
||||
- [ ] Book option to set date
|
||||
- [ ] Template for book introduction (including rules etc)
|
||||
- [ ] Some way to insert character sheet in book introduction
|
||||
- [ ] Some way to insert dice at bottom of pages for LaTeX
|
||||
- [ ] Some way to insert optional random numbers table at end of book
|
||||
- [ ] Possibility to make predictable random numbers and shuffling for testing
|
||||
- [ ] Test generate examples and compare to expected output in all formats
|
||||
- [ ] Unit tests (finally...)
|
||||
- [ ] Inserting images
|
||||
- [ ] Dummy sections
|
||||
- [ ] Counters (life, money, whatever) create and set
|
||||
- [ ] Counters increase/decrease
|
||||
- [ ] Counters check
|
||||
- [ ] Document Gamebook format
|
||||
- [ ] Debug HTML output
|
||||
- [ ] Playable HTML (javascript) output
|
||||
- [ ] Higher level text-language for Gamebooks
|
||||
|
|
43
verifygamebook.py
Normal file
43
verifygamebook.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
"""
|
||||
Copyright (c) 2013, Pelle Nilsson
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
def verify(book):
|
||||
pass
|
||||
|
||||
def v(name, ok, details=""):
|
||||
if not ok:
|
||||
print >> sys.stderr, name, "ERROR (" + details + ")"
|
||||
sys.exit(1)
|
||||
|
||||
def w(name, ok, details=""):
|
||||
if not ok:
|
||||
print >> sys.stderr, name, "WARNING (" + details + ")"
|
Loading…
Reference in a new issue