summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.cpp16
-rw-r--r--wizard.cpp17
-rw-r--r--wizard.h18
3 files changed, 27 insertions, 24 deletions
diff --git a/main.cpp b/main.cpp index a0ba7bb..9327c20 100644 --- a/main.cpp +++ b/main.cpp
@@ -4,6 +4,8 @@
4#include <iostream> 4#include <iostream>
5#include <string> 5#include <string>
6 6
7#include "cardset.h"
8#include "imagestore.h"
7#include "wizard.h" 9#include "wizard.h"
8 10
9int main(int argc, char** argv) { 11int main(int argc, char** argv) {
@@ -29,16 +31,18 @@ int main(int argc, char** argv) {
29 "o", "output", "Path to write image output to", true, "", "filename"); 31 "o", "output", "Path to write image output to", true, "", "filename");
30 cmd.add(outputPath); 32 cmd.add(outputPath);
31 33
32 TCLAP::ValueArg<std::string> jsonPath( 34 TCLAP::ValueArg<std::string> textInput("t", "text", "Text to render", true,
33 "j", "json", "Path to write JSON output to", false, "", "filename"); 35 "", "text");
34 cmd.add(jsonPath); 36 cmd.add(textInput);
35 37
36 cmd.parse(argc, argv); 38 cmd.parse(argc, argv);
37 39
38 wizard app(cardsPath.getValue(), cachePath.getValue(), 40 cardset cards(cardsPath.getValue());
39 outputPath.getValue(), jsonPath.getValue(), rng); 41 imagestore images(cachePath.getValue());
40 42
41 app.run(); 43 wizard app(cards, images, textInput.getValue(), rng);
44 Magick::Image result = app.run();
45 result.write(outputPath.getValue());
42 } catch (const TCLAP::ArgException& e) { 46 } catch (const TCLAP::ArgException& e) {
43 std::cerr << "Error: " << e.error() << " for arg " << e.argId() 47 std::cerr << "Error: " << e.error() << " for arg " << e.argId()
44 << std::endl; 48 << std::endl;
diff --git a/wizard.cpp b/wizard.cpp index 4eaefb3..1541fed 100644 --- a/wizard.cpp +++ b/wizard.cpp
@@ -38,13 +38,9 @@ class pix_deleter {
38 38
39using pix_ptr = std::unique_ptr<Pix, pix_deleter>; 39using pix_ptr = std::unique_ptr<Pix, pix_deleter>;
40 40
41wizard::wizard(std::string cardsPath, std::string cachePath, 41wizard::wizard(const cardset& cards, const imagestore& images, std::string text,
42 std::string outputPath, std::string jsonPath, std::mt19937& rng) 42 std::mt19937& rng)
43 : cards_(cardsPath), 43 : cards_(cards), images_(images), text_(text), rng_(rng()) {
44 images_(cachePath),
45 outputPath_(outputPath),
46 jsonPath_(jsonPath),
47 rng_(rng) {
48 std::cout << "Characters: "; 44 std::cout << "Characters: ";
49 45
50 for (char ch : cards_.getCharacters()) { 46 for (char ch : cards_.getCharacters()) {
@@ -54,8 +50,8 @@ wizard::wizard(std::string cardsPath, std::string cachePath,
54 std::cout << std::endl; 50 std::cout << std::endl;
55} 51}
56 52
57void wizard::run() { 53Magick::Image wizard::run() {
58 std::string text = "what the heck, it's just some gay guy"; 54 std::string text = text_; //"what the heck, it's just some gay guy";
59 // getline(std::cin, text); 55 // getline(std::cin, text);
60 if (text.back() == '\r') { 56 if (text.back() == '\r') {
61 text.pop_back(); 57 text.pop_back();
@@ -252,5 +248,6 @@ void wizard::run() {
252 } 248 }
253 249
254 endImage.magick("PNG"); 250 endImage.magick("PNG");
255 endImage.write(outputPath_); 251
252 return endImage;
256} 253}
diff --git a/wizard.h b/wizard.h index 9b27143..a02197b 100644 --- a/wizard.h +++ b/wizard.h
@@ -1,6 +1,8 @@
1#ifndef WIZARD_H_1014B13E 1#ifndef WIZARD_H_1014B13E
2#define WIZARD_H_1014B13E 2#define WIZARD_H_1014B13E
3 3
4#include <Magick++.h>
5
4#include <random> 6#include <random>
5#include <string> 7#include <string>
6 8
@@ -9,17 +11,17 @@
9 11
10class wizard { 12class wizard {
11 public: 13 public:
12 wizard(std::string cardsPath, std::string cachePath, std::string outputPath, 14 wizard(const cardset& cards, const imagestore& images, std::string text,
13 std::string jsonPath, std::mt19937& rng); 15 std::mt19937& rng);
14 16
15 void run(); 17 Magick::Image run();
16 18
17 private: 19 private:
18 cardset cards_; 20 const cardset& cards_;
19 imagestore images_; 21 const imagestore& images_;
20 std::string outputPath_; 22 std::string text_;
21 std::string jsonPath_; 23
22 std::mt19937& rng_; 24 std::mt19937 rng_;
23}; 25};
24 26
25#endif /* end of include guard: WIZARD_H_1014B13E */ 27#endif /* end of include guard: WIZARD_H_1014B13E */