1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-16 23:20:44 +03:00

Gamebook configuration (title and author for now).

This commit is contained in:
Pelle Nilsson 2013-06-10 22:50:06 +02:00
parent 54e03105e7
commit 3421ba7aaa
17 changed files with 45 additions and 25 deletions

3
examples/.gitignore vendored
View file

@ -2,4 +2,5 @@
*.tex
*.html
*.dot
*.debug
*.debug
*.txt

View file

@ -1,3 +1,4 @@
title = Format
* 1 start
This examples tests gamebook formatting, not so much game mechanics or
references. Currently there is nothing here really.

View file

@ -1,3 +1,5 @@
title = Items
author = Pelle Nilsson
* 1 start
Demonstrating how to manage player [collect item]Inventory[/collect].
You start
@ -60,4 +62,4 @@ Otherwise turn to [[won]].
OK. That was fun. Turn to [[won]].
* won
Congratulations, you won.
Congratulations, you won.

View file

@ -74,12 +74,18 @@ def format_gamebook(inputfilenames,
write_book(book, output_format, outputfilename)
def parse_file_to_book(inputfile, book):
before_first_section = True
name = None
number = None
text = ""
tags = None
for line in inputfile.readlines():
if before_first_section:
if '=' in line:
config = line.split('=')
book.configure(config[0].strip(), config[1].strip())
if line.startswith('*'):
before_first_section = False
if name:
add_section_to_book(book, name, text, number)
number = None

View file

@ -8,9 +8,7 @@ class OutputFormat (object):
self.templates = templates
def write_begin(self, book, output):
print >> output, self.format_with_template("begin", {
'max' : book.max
}),
print >> output, self.format_with_template("begin", book.config)
def write_shuffled_sections(self, shuffled_sections, output):
for i, p in enumerate(shuffled_sections.as_list):

View file

@ -37,8 +37,13 @@ class Book:
self.sections = []
self.from_name = {}
self.nr_sections = {}
self.max = 0
self.codewords = set()
self.config = {'max' : 0,
'title' : 'Gamebook',
'author' : ''}
def configure(self, name, value):
self.config[name] = value
def add(self, section):
if section.name in self.from_name:
@ -46,16 +51,16 @@ class Book:
section.name)
self.sections.append(section)
self.from_name[section.name] = section
if len(self.sections) > self.max:
self.max = len(self.sections)
if len(self.sections) > self.config['max']:
self.config['max'] = len(self.sections)
def add_codeword(self, word):
self.codewords.add(word)
def force_section_nr(self, name, nr):
self.nr_sections[nr] = name
if nr > self.max:
self.max = nr
if nr > self.config['max']:
self.config['max'] = nr
def shuffle(self):
as_list = [None]
@ -66,7 +71,7 @@ class Book:
if p in self.from_name:
shuffled.remove(self.from_name[p])
random.shuffle(shuffled)
for nr in range(1, self.max + 1):
for nr in range(1, self.config['max'] + 1):
if (self.nr_sections.has_key(nr)
and self.nr_sections[nr] in self.from_name):
section = self.from_name[self.nr_sections[nr]]

View file

@ -1,2 +1,3 @@
BEGIN DEBUG OUTPUT
Book title: %(title)s
Number of sections: %(max)d

View file

@ -3,7 +3,7 @@
<head>
<meta charset='utf-8'>
#include "viewport"
#include "title"
<title>%(title)s</title>
<script>
#include "script"
</script>

View file

@ -1 +0,0 @@
<title>Gamebook</title>

View file

@ -5,3 +5,6 @@
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\b\fs24 \cf0
\b \qc %(title)s
\b0\

View file

@ -15,13 +15,14 @@
\fi
\fi
#include "title"
\author{}
\title{%(title)s}
\author{%(author)s}
\date{}
\newcounter{sectionnr}
\begin{document}
\thispagestyle{empty}
#include "titlepage"
\clearpage

View file

@ -1 +1,2 @@
\documentclass[A5,twocolumn]{article}
\documentclass[A5,twocolumn]{book}

View file

@ -1 +0,0 @@
\title{Gamebook}

View file

@ -0,0 +1,3 @@
\maketitle
\thispagestyle{empty}

2
templates/txt/begin.txt Normal file
View file

@ -0,0 +1,2 @@
%(title)s

View file

@ -1,2 +1,2 @@
%(nr)
%(nr)d

View file

@ -1,4 +1,4 @@
* TODO [28/59] [47%]
* TODO [31/58] [53%]
- [X] Debug output
- [X] DOT output
- [X] LaTeX output
@ -30,11 +30,9 @@
- [X] Otherwise/else handling for has.
- [X] Redesign otherwise/else to use xor tag on section reference.
- [X] Disable all links after finding an auto link (that is enabled).
- [ ] Default templates. (templates/default?)
- [ ] 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
- [X] Default templates. (templates/default?)
- [X] Book option to set title
- [X] Book option to set author
- [ ] Quote strings to not break formatting.
- [X] Include other templates from a template.
- [ ] Template for book introduction (including rules etc)