From 5b7bf82edb672d5d5dbd8b1de64532aeec695661 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 2 Mar 2018 19:47:19 -0500 Subject: 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. --- lunatic.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'lunatic.cpp') 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) std::cout << "Generating tweet" << std::endl; achievement ach = db.getRandomAchievement(); - std::string imageName = db.getRandomImageForGame(ach.gameId); - std::string imagePath = config["images"].as() - + "/" + imageName; Magick::Image moonColor; moonColor.read("res/" + ach.color + ".png"); @@ -150,14 +147,25 @@ int main(int argc, char** argv) shadow.negate(); shadow.blur(0, 12); - // Read the game image + // Read the game image, using a default if the game has no images Magick::Image image; - image.read(imagePath); - // Stretch and pixelate it - image.transform("1600x900!"); - image.scale("80x45"); - image.scale("1600x900"); + if (db.doesGameHaveImages(ach.gameId)) + { + std::string imageName = db.getRandomImageForGame(ach.gameId); + std::string imagePath = config["images"].as() + + "/" + imageName; + + image.read(imagePath); + + // Stretch and pixelate it + image.transform("1600x900!"); + image.scale("80x45"); + image.scale("1600x900"); + } else { + image.read("res/default.png"); + image.transform("1600x900!"); + } // Add the generated overlay to it image.composite(shadow, 0, 0, Magick::OverCompositeOp); -- cgit 1.4.1