Commit 5c29572d authored by aggsol's avatar aggsol 🙉

color graph nodes by location

parent a168c605
......@@ -19,8 +19,41 @@ Subset of Asciidoc.
### Book
### Sections
* Sections are numbered
* 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
### Graph
The gamecheck tool can create a grpah from the sections where every node is a section.
### Metadata
Annotation sections with tags. Example:
```
[[section-1]
=== 1
[.TODO.combat]
[.my-tag.another-tag]
[.location-crypta]
```
Tags of sections helps to debug and naviagte the story quickliy with the generated graph. Generic annotations will be used as labels for nodes.
|Tag |Apperance |Comment |
|-------------|------------------|--------------------------------------------------|
|.combat |Hexagon Node |Section has combat |
|.TODO |Node filled red |Mark section as unfinished |
|.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 |
## 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
......@@ -19,11 +19,42 @@
#include "Graph.hpp"
#include <array>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
namespace
{
// Crc32.cpp
// Copyright (c) 2011-2016 Stephan Brumme. All rights reserved.
// see http://create.stephan-brumme.com/disclaimer.html
//
/// compute CRC32 (half-byte algorithm)
uint32_t crc32(const void* data, size_t length, uint32_t previousCrc32)
{
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
// const uint8_t* current = (const uint8_t*) data;
const uint8_t* current = static_cast<const uint8_t*>(data);
/// look-up table for half-byte, same as crc32Lookup[0][16*i]
static const uint32_t Crc32Lookup16[16] =
{
0x00000000,0x1DB71064,0x3B6E20C8,0x26D930AC,0x76DC4190,0x6B6B51F4,0x4DB26158,0x5005713C,
0xEDB88320,0xF00F9344,0xD6D6A3E8,0xCB61B38C,0x9B64C2B0,0x86D3D2D4,0xA00AE278,0xBDBDF21C
};
while (length-- != 0)
{
crc = Crc32Lookup16[(crc ^ *current ) & 0x0F] ^ (crc >> 4);
crc = Crc32Lookup16[(crc ^ (*current >> 4)) & 0x0F] ^ (crc >> 4);
current++;
}
return ~crc; // same as crc ^ 0xFFFFFFFF
}
std::array<std::string, 7> s_skipLabels = {
"fixed",
"TODO",
......@@ -47,10 +78,11 @@ namespace
return false;
}
std::array<std::string, 3> s_suffixes = {
std::array<std::string, 4> s_suffixes = {
"add-item-",
"add-weapon-",
"codeword-"
"codeword-",
"location-"
};
std::string trimLabel(const std::string& l)
......@@ -85,13 +117,30 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
for(auto& s: sections)
{
int sectionNum = s.second.m_number;
const int sectionNum = s.second.m_number;
std::ostringstream label;
label << " " << sectionNum << " [xlabel=<<font color=\"#1111ee\" point-size=\"8\">";
unsigned counter = 0;
for(auto& attr: s.second.m_classes)
{
if(attr.find("location-") != std::string::npos)
{
std::cout << "location=" << attr << "\n";
uint32_t value = crc32(attr.c_str(), attr.size(), 0);
uint8_t rgb[3];
rgb[0] = ((value) + 255)/2;
rgb[1] = ((value >> 8) + 255)/2;
rgb[2] = ((value >> 16) + 255)/2;
dotfile << " " << sectionNum << " [fillcolor=\"#"
<< std::hex << std::setfill('0')
<< std::setw(2) << static_cast<int>(rgb[0])
<< std::setw(2) << static_cast<int>(rgb[1])
<< std::setw(2) << static_cast<int>(rgb[2])
<< std::dec << "\"];\n";
continue;
}
if(attr == "TODO")
{
dotfile << " " << sectionNum << " [fillcolor=red];\n";
......@@ -100,7 +149,7 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
if(attr == "Combat" || attr == "combat")
{
dotfile << " " << sectionNum << " [fillcolor=yellow];\n";
dotfile << " " << sectionNum << " [shape=hexagon];\n";
continue;
}
......@@ -122,6 +171,7 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
label << trimLabel(attr);
counter++;
}
label << "</font>>];\n";
auto labelStr = label.str();
if(counter > 0)
......
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