about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-03-02 19:47:19 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-03-02 19:47:19 -0500
commit5b7bf82edb672d5d5dbd8b1de64532aeec695661 (patch)
tree7de8d174a75f06f0f11ed5f3de4e17e8e7912c2c
parent13aab8498a0a2d4494a088f1235a0e80c078bdcf (diff)
downloadlunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.tar.gz
lunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.tar.bz2
lunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.zip
Handled games with no images
For games where no images could be downloaded from Steam, which happens if a game has been removed from the store, the bot will now use a default background. This image is copyright Nintendo.
-rw-r--r--database.cpp41
-rw-r--r--database.h2
-rw-r--r--lunatic.cpp26
-rw-r--r--res/README.md2
-rw-r--r--res/default.pngbin0 -> 1080583 bytes
5 files changed, 61 insertions, 10 deletions
diff --git a/database.cpp b/database.cpp index 953c217..19ba0e0 100644 --- a/database.cpp +++ b/database.cpp
@@ -82,6 +82,47 @@ achievement database::getRandomAchievement() const
82 return result; 82 return result;
83} 83}
84 84
85bool database::doesGameHaveImages(int gameId) const
86{
87 std::string queryString = "SELECT COUNT(*) FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1";
88
89 sqlite3_stmt* ppstmt;
90 if (sqlite3_prepare_v2(
91 ppdb_,
92 queryString.c_str(),
93 queryString.length(),
94 &ppstmt,
95 NULL) != SQLITE_OK)
96 {
97 std::string errorMsg = sqlite3_errmsg(ppdb_);
98 sqlite3_finalize(ppstmt);
99
100 throw std::logic_error(errorMsg);
101 }
102
103 if (sqlite3_bind_int(ppstmt, 1, gameId) != SQLITE_OK)
104 {
105 std::string errorMsg = sqlite3_errmsg(ppdb_);
106 sqlite3_finalize(ppstmt);
107
108 throw std::logic_error(errorMsg);
109 }
110
111 if (sqlite3_step(ppstmt) != SQLITE_ROW)
112 {
113 std::string errorMsg = sqlite3_errmsg(ppdb_);
114 sqlite3_finalize(ppstmt);
115
116 throw std::logic_error(errorMsg);
117 }
118
119 int result = sqlite3_column_int(ppstmt, 0);
120
121 sqlite3_finalize(ppstmt);
122
123 return (result > 0);
124}
125
85std::string database::getRandomImageForGame(int gameId) const 126std::string database::getRandomImageForGame(int gameId) const
86{ 127{
87 std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; 128 std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1";
diff --git a/database.h b/database.h index 9dcb118..50f5b55 100644 --- a/database.h +++ b/database.h
@@ -46,6 +46,8 @@ public:
46 46
47 achievement getRandomAchievement() const; 47 achievement getRandomAchievement() const;
48 48
49 bool doesGameHaveImages(int gameId) const;
50
49 std::string getRandomImageForGame(int gameId) const; 51 std::string getRandomImageForGame(int gameId) const;
50 52
51 did getRandomDidForAchievement(int achievementId) const; 53 did getRandomDidForAchievement(int achievementId) const;
diff --git a/lunatic.cpp b/lunatic.cpp index 291bd09..58a0854 100644 --- a/lunatic.cpp +++ b/lunatic.cpp
@@ -65,9 +65,6 @@ int main(int argc, char** argv)
65 std::cout << "Generating tweet" << std::endl; 65 std::cout << "Generating tweet" << std::endl;
66 66
67 achievement ach = db.getRandomAchievement(); 67 achievement ach = db.getRandomAchievement();
68 std::string imageName = db.getRandomImageForGame(ach.gameId);
69 std::string imagePath = config["images"].as<std::string>()
70 + "/" + imageName;
71 68
72 Magick::Image moonColor; 69 Magick::Image moonColor;
73 moonColor.read("res/" + ach.color + ".png"); 70 moonColor.read("res/" + ach.color + ".png");
@@ -150,14 +147,25 @@ int main(int argc, char** argv)
150 shadow.negate(); 147 shadow.negate();
151 shadow.blur(0, 12); 148 shadow.blur(0, 12);
152 149
153 // Read the game image 150 // Read the game image, using a default if the game has no images
154 Magick::Image image; 151 Magick::Image image;
155 image.read(imagePath);
156 152
157 // Stretch and pixelate it 153 if (db.doesGameHaveImages(ach.gameId))
158 image.transform("1600x900!"); 154 {
159 image.scale("80x45"); 155 std::string imageName = db.getRandomImageForGame(ach.gameId);
160 image.scale("1600x900"); 156 std::string imagePath = config["images"].as<std::string>()
157 + "/" + imageName;
158
159 image.read(imagePath);
160
161 // Stretch and pixelate it
162 image.transform("1600x900!");
163 image.scale("80x45");
164 image.scale("1600x900");
165 } else {
166 image.read("res/default.png");
167 image.transform("1600x900!");
168 }
161 169
162 // Add the generated overlay to it 170 // Add the generated overlay to it
163 image.composite(shadow, 0, 0, Magick::OverCompositeOp); 171 image.composite(shadow, 0, 0, Magick::OverCompositeOp);
diff --git a/res/README.md b/res/README.md index 876f0db..814c2b2 100644 --- a/res/README.md +++ b/res/README.md
@@ -1 +1 @@
The images in this directory are originally from the game Super Mario Odyssey, which is copyrighted by Nintendo. \ No newline at end of file The images in this directory, apart from overlay.png and overlay.psd, are originally from the game Super Mario Odyssey, which is copyrighted by Nintendo. \ No newline at end of file
diff --git a/res/default.png b/res/default.png new file mode 100644 index 0000000..6323270 --- /dev/null +++ b/res/default.png
Binary files differ