1// SuperTux
2// Copyright (C) 2016 Hume2 <teratux.mail@gmail.com>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "scripting/background.hpp"
18
19#include <physfs.h>
20
21#include "object/background.hpp"
22
23namespace scripting {
24
25void
26Background::set_image(const std::string& image)
27{
28 SCRIPT_GUARD_VOID;
29
30 if (image.empty())
31 {
32 log_info << "No filename / path for background image specified" << std::endl;
33 return;
34 }
35
36 const std::string& default_dir = "images/background/";
37 bool path_valid = true;
38
39 if (!PHYSFS_exists(image.c_str()))
40 path_valid = false;
41
42 object.set_image(path_valid ? image : default_dir + image);
43}
44
45void
46Background::set_images(const std::string& top_image, const std::string& middle_image,
47 const std::string& bottom_image)
48{
49 SCRIPT_GUARD_VOID;
50
51 if (top_image.empty() || middle_image.empty() || bottom_image.empty())
52 {
53 log_info << "No filename / path for background image specified" << std::endl;
54 return;
55 }
56
57 const std::string& default_dir = "images/background/";
58 bool top_image_valid = true, middle_image_valid = true, bottom_image_valid = true;
59
60 if (!PHYSFS_exists(top_image.c_str()))
61 top_image_valid = false;
62
63 if (!PHYSFS_exists(middle_image.c_str()))
64 middle_image_valid = false;
65
66 if (!PHYSFS_exists(bottom_image.c_str()))
67 bottom_image_valid = false;
68
69 object.set_images(top_image_valid ? top_image : default_dir + top_image,
70 middle_image_valid ? middle_image : default_dir + middle_image,
71 bottom_image_valid ? bottom_image : default_dir + bottom_image);
72}
73
74void
75Background::set_speed(float speed)
76{
77 SCRIPT_GUARD_VOID;
78 object.set_speed(speed);
79}
80
81} // namespace scripting
82
83/* EOF */
84