Commit 5c0ff568 authored by aggsol's avatar aggsol 🙉

wip example, better readme

parent 356b6c88
......@@ -9,13 +9,50 @@ Helper tool for gamebooks written in Asciidoc
1. Shuffle of sections, verify shuffle
2. Better test cases
## Build
### Requirements
1. C++ compiler
2. Asciidoctor (to generate the book)
3. Graphiz dot (to generate graphs)
Clone the repo and enter the repo folder.
```
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
```
### Run the example
Check the sections
```
$ ./gamebook-checker --input ../example/sections.adoc
```
Generate a graph
```
$ ./gamebook-checker --dot --input ../example/sections.adoc
$ dot -Tpng graph.dot > shuffled.png
```
## Format
Subset of Asciidoc.
### Book
A book is composed from several files. The actual story with sections is in a file names `sections.adoc`. The content files are referenced from `book.adoc` Example structure:
```
book.adoc
-> intro.adoc
-> rules.adoc
-> sections.adoc
-> appendix.adoc
```
### Sections
......@@ -23,11 +60,11 @@ Subset of Asciidoc.
* Section 0 is optional and can be used as prologue
* Section 1 is always the start
* All sections (exept 0) must be in one file `sections.adoc`
* You get warning for missing or unreferences sections
* You get a warning for missing or unreferenced sections
### Graph
The gamecheck tool can create a grpah from the sections where every node is a section.
The gamecheck tool can create a graph from the sections where every node is a section. The nodes differenty by shape and color. The Color is generated from the location data. Also images are tagged to their nodes.
### Metadata
......@@ -49,7 +86,18 @@ Tags of sections helps to debug and naviagte the story quickliy with the generat
|.location-xyz|Set a fillcolor |Color is random but the same for one location |
|.fixed |Box node |Section will no be shuffled, fixed section number |
## How to Build the Book
* Use a Makfile
* Asciidoctor to create HTML and docbook format
* Pandoc to create DOCS from HTML
* Calibre to create ePub and Mobi from HTML
## Best Practices
1. Plan throroughly before start writing
2. Shuffle sections at the very end before the last edit and starting to layout
\ No newline at end of file
1. Plan thoroughly before start writing
2. Shuffle sections at the very end before the last edit and starting to layout
3. Fix plot holes asap
4. Write related sections together
## Shuffle Sections
\ No newline at end of file
== Appendix
It's over! Anything extra goes here.
\ No newline at end of file
My First Gamebook
=================
:Revision: 1.0.0
:Author: Mrs. Gamebook Writer
:Email: you|@example.com
:doctype: book
include::intro.adoc[]
include::rules.adoc[]
include::sections.adoc[]
include::appendix.adoc[]
== Intro
This is my first gamebook.
== Prologue
You enter the castle.
Turn to <<section-1>>
\ No newline at end of file
== Rules
The are just a few easy rules
. Always follow the rules
. There no exceptions
. If in doubt roll a dice
\ No newline at end of file
[[section-1]]
=== 1
The castle is well lit and cozy warm. But there is nobody her!
Do you want to go to the kitchen, turn to <<section-2>> +
Do you want to enter the throne room, turn to <<section-3>>
[[section-2]]
=== 2
[.location-kitchen]
The cook is missing and there is no food left. You are still very hungry.
Do you want to enter the throne room, turn to <<section-3>>
[[section-3]]
=== 3
[.location-throneroom]
You sit on the throne room. You are now the king!
Happy End!
\ No newline at end of file
......@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Parser.hpp"
#include "rang.hpp"
#include <cassert>
#include <istream>
#include <sstream>
......@@ -113,7 +113,9 @@ bool Parser::parse(std::map<int, Section>& sections)
}
catch(const std::exception& ex)
{
std::cerr << "Error in line " << m_lineCounter << " : " << ex.what() << "\n";
std::cerr << rang::fg::red
<< "Error in line " << m_lineCounter << " : " << ex.what() << "\n"
<< rang::fg::reset;
return true;
}
m_lineCounter++;
......
......@@ -20,6 +20,7 @@
#include "Helpers.hpp"
#include "Parser.hpp"
#include "Shuffle.hpp"
#include "rang.hpp"
#include <cassert>
#include <iostream>
......@@ -49,6 +50,7 @@ namespace
<< " -d, --dot-file Create a dot file named graph.dot\n"
<< " -h, --help Show this help text\n"
<< " -m, --mix-sections Shuffle the sections\n"
<< " -n, --no-color Disable colored output\n"
<< " -v, --verbose Show additional information\n"
<< " --version Show version\n"
......@@ -97,35 +99,6 @@ namespace
strm << l << "\n";
}
}
// for(auto& s: sections)
// {
// assert(s.first == s.second.m_number);
// int shuffled = resultMapping.at(s.first);
// strm << "[[section-" << shuffled << "]]\n"
// << "== " << shuffled << "\n";
// std::string line;
// for(auto& l: s.second.m_lines)
// {
// line = l;
// for(auto& c: s.second.m_children)
// {
// std::string before = "<<section-";
// before += std::to_string(c);
// before += ">>";
// std::string after = "<<section-";
// after += std::to_string(resultMapping.at(c));
// after += ">>";
// line = bodhi::replaceSubStr(line, before, after);
// }
// strm << line << "\n";
// }
// }
}
}
......@@ -150,10 +123,18 @@ int main(int argc, char* argv[])
auto mix = args.getOpt("m", "mix-sections");
auto dot = args.getOpt("d", "dot-file");
auto verbose = args.getOpt("v", "verbose");
auto noColor = args.getOpt("n", "no-color");
if(noColor)
{
rang::setControlMode(rang::control::Off);
}
if(mix && dot)
{
std::cerr << "Error : Cannot combine --mix-sections and --dot-file\n";
std::cerr << rang::fg::red
<< "Error : Cannot combine --mix-sections and --dot-file\n"
<< rang::fg::reset;
return 101;
}
......@@ -180,13 +161,14 @@ int main(int argc, char* argv[])
}
else
{
std::cerr << "Error : Missing section: " << child
<< " linked from section: " << s.first << "\n";
std::cerr << rang::fg::red
<< "Error : Missing section: " << child
<< " linked from section: " << s.first << "\n"
<< rang::fg::reset;
}
}
// Append empty lines for section padding
// std::cout << "last line='" << s.second.m_lines.back() << "'\n";
// Append empty line for section padding
if(s.second.m_lines.back() != "")
{
s.second.m_lines.push_back("");
......@@ -201,13 +183,17 @@ int main(int argc, char* argv[])
{
if(s.first - last != 1)
{
std::cerr << "Error : Missing section(s) " << last+1 << "-" << s.first-1 << "\n";
std::cerr << rang::fg::yellow
<< "Warning: Missing section(s) " << last+1 << "-" << s.first-1 << "\n"
<< rang::fg::reset;
}
if(s.second.m_parents.size() == 0)
{
assert(s.first == s.second.m_number);
std::cerr << "Error : No reference to section: " << s.first << "\n";
std::cerr << rang::fg::yellow
<< "Warning: No reference to section: " << s.first << "\n"
<< rang::fg::reset;
}
}
last = s.first;
......@@ -256,7 +242,10 @@ int main(int argc, char* argv[])
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << "\n"
std::cerr << rang::fg::red
<< ex.what()
<< rang::fg::reset
<< "\n"
<< "Try -h/--help\n";
}
return 0;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment