1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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 "supertux/game_object.hpp"
18
19#include <algorithm>
20
21#include "supertux/object_remove_listener.hpp"
22#include "util/reader_mapping.hpp"
23#include "util/writer.hpp"
24#include "video/color.hpp"
25
26GameObject::GameObject() :
27 m_name(),
28 m_uid(),
29 m_scheduled_for_removal(false),
30 m_components(),
31 m_remove_listeners()
32{
33}
34
35GameObject::GameObject(const std::string& name) :
36 m_name(name),
37 m_uid(),
38 m_scheduled_for_removal(false),
39 m_components(),
40 m_remove_listeners()
41{
42}
43
44GameObject::GameObject(const ReaderMapping& reader) :
45 GameObject()
46{
47 reader.get("name", m_name, "");
48}
49
50GameObject::~GameObject()
51{
52 for (const auto& entry : m_remove_listeners) {
53 entry->object_removed(this);
54 }
55 m_remove_listeners.clear();
56}
57
58void
59GameObject::add_remove_listener(ObjectRemoveListener* listener)
60{
61 m_remove_listeners.push_back(listener);
62}
63
64void
65GameObject::del_remove_listener(ObjectRemoveListener* listener)
66{
67 m_remove_listeners.erase(std::remove(m_remove_listeners.begin(),
68 m_remove_listeners.end(),
69 listener),
70 m_remove_listeners.end());
71}
72
73void
74GameObject::save(Writer& writer)
75{
76 auto settings = get_settings();
77 for (const auto& option_ptr : settings.get_options())
78 {
79 const auto& option = *option_ptr;
80 option.save(writer);
81 }
82}
83
84ObjectSettings
85GameObject::get_settings()
86{
87 ObjectSettings result(get_display_name());
88 result.add_text(_("Name"), &m_name, "name", std::string());
89 return result;
90}
91
92/* EOF */
93