Commit 89413b73 authored by aggsol's avatar aggsol 🙉

generate locations list for graph

parent 7851ffa3
Pipeline #26962821 failed with stage
in 3 minutes and 18 seconds
......@@ -102,12 +102,28 @@ namespace
}
return result;
}
std::ostream& writeColor(std::ostream& strm, uint32_t value)
{
uint8_t rgb[3];
rgb[0] = ((value) + 255)/2;
rgb[1] = ((value >> 8) + 255)/2;
rgb[2] = ((value >> 16) + 255)/2;
strm << 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;
return strm;
}
}
namespace bodhi
{
Graph::Graph(const std::string& filename)
Graph::Graph(const std::string& filename, uint32_t colorSeed)
: m_filename(filename)
, m_colorSeed(colorSeed)
{
if(filename.empty())
{
......@@ -118,6 +134,9 @@ Graph::Graph(const std::string& filename)
void Graph::createDotFile(const std::map<int, Section>& sections)
{
std::map<std::string, uint32_t> locationColorMap;
std::ofstream dotfile(m_filename);
if(not dotfile.is_open())
{
......@@ -146,18 +165,14 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
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";
auto location = trimLabel(attr);
// std::cout << "location=" << location << "\n";
const uint32_t value = crc32(attr.c_str(), attr.size(), m_colorSeed);
locationColorMap[location] = value;
dotfile << " " << sectionNum << " [fillcolor=\"#";
writeColor(dotfile, value) << "\"];\n";
continue;
}
......@@ -203,6 +218,21 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
}
}
dotfile << "{ rank = sink; Legend[shape=none, margin=0, label=<\n"
<< "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">\n";
dotfile << "<TR><TD COLSPAN=\"2\"><B>Locations</B></TD></TR>\n";
for(auto& entry: locationColorMap)
{
dotfile << "<TR><TD>" << entry.first << "</TD><TD BGCOLOR=\"#";
writeColor(dotfile, entry.second);
dotfile << "\"></TD></TR>\n";
}
dotfile << "</TABLE>\n";
dotfile << ">]; }\n";
dotfile << "}\n";
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
make && ./gamebook-checker -i ../test/bigfile.adoc -d graph.dot && dot -Tpng ./graph.dot > graph.png
*/
#ifndef BODHI_GRAPH_HPP
#define BODHI_GRAPH_HPP
......@@ -26,11 +28,12 @@ namespace bodhi
class Graph
{
public:
explicit Graph(const std::string& filename);
Graph(const std::string& filename, uint32_t colorSeed);
void createDotFile(const std::map<int, Section>& sections);
private:
std::string m_filename;
uint32_t m_colorSeed;
};
}
......
......@@ -42,17 +42,18 @@ namespace
<< "Example: gamebook-checker -i sections.adoc\n"
<< "\n"
<< "Options:\n"
<< " -i, --input <file> Input file in Asciidoctor format\n"
<< " -o, --output <file> Output file, default is stdout\n"
<< " -s, --seed <number> Shuffle seed, default: 12345\n"
<< " -d, --dot-file <file> Create a dot file named graph.dot\n"
<< " -i, --input <file> Input file in Asciidoctor format\n"
<< " -o, --output <file> Output file, default is stdout\n"
<< " -s, --seed <number> Shuffle seed, default: 12345\n"
<< " -d, --dot-file <file> Create a dot file named <file>\n"
<< " -c, --color-seed <number> Color seed for the generated dot file\n"
<< "\n"
<< "Flags:\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"
<< " -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"
<< std::endl;
......@@ -83,6 +84,7 @@ int main(int argc, char* argv[])
auto dot = args.getOpt<std::string>("d", "dot-file", NONE);
auto verbose = args.getOpt("v", "verbose");
auto noColor = args.getOpt("n", "no-color");
auto colorSeed = args.getOpt<uint32_t>("c", "color-seed", 0);
if(args.arguments().size() > 0)
{
......@@ -188,7 +190,7 @@ int main(int argc, char* argv[])
if(dot != NONE)
{
bodhi::Graph graph(dot);
bodhi::Graph graph(dot, colorSeed);
graph.createDotFile(sections);
return 0;
}
......
......@@ -7,6 +7,7 @@ Lies weiter bei <<_1>>
=== 1
[.start]
[.location-a]
// hier steht ein Kommentar
Es stinkt. So wie es in jeder Station im Sol-Sytem stinkt. Die Filter sind überlastet durch die Mengen an Schweiß und Urin in der Luft. Du wischt dir die dreckigen Hände an deinem Overall ab und betrachtest dein Werk. Eine frische Schweißnaht ziert die Ladeluke der _Bloody Mary 3_. Bei nächsten Druckabfall solltest du nicht wieder die Hälfte deiner Ladung verlieren. Denn eine Frachtversicherung kannst du dir nicht leisten und häufig ist deine Fracht auch nicht ganz legal. Für heute reicht es dir mit Maloche.
......@@ -15,7 +16,7 @@ Willst du in der Sauna entspanne, spinge zu <<_3>>
<<<
=== 2
[.location-a]
Kein freier Tisch in
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
......@@ -24,7 +25,7 @@ Springe zu <<_4>> +
Springe zu <<_6>>
=== 3
[.location-a]
Es ist ruhig in der Sauna.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
......@@ -33,7 +34,7 @@ Springe zu <<_4>> +
Springe zu <<_5>>
=== 4
[.location-b]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
......@@ -42,6 +43,7 @@ Blättere nach <<_5>>
=== 5
[.add-item-key]
[.location-b]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
......
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