17 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP 18 #define HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP 20 #include "squirrel/exposable_class.hpp" 27 #include "editor/object_settings.hpp" 28 #include "supertux/game_object_component.hpp" 29 #include "util/fade_helper.hpp" 30 #include "util/gettext.hpp" 31 #include "util/uid.hpp" 47 const std::string name;
49 typedef std::vector<GameObjectType> GameObjectTypes;
59 std::vector<std::type_index> types;
63 std::type_index idx(info);
88 static void register_class(ssq::VM& vm);
101 UID get_uid()
const {
return m_uid; }
108 virtual void update(
float dt_sec) = 0;
115 virtual void save(
Writer& writer);
117 virtual std::string get_class_name()
const {
return "game-object"; }
118 virtual std::string get_exposed_class_name()
const override {
return "GameObject"; }
129 virtual std::vector<std::string> get_patches()
const;
130 virtual void update_version();
135 int get_version()
const;
140 int get_latest_version()
const;
145 bool is_up_to_date()
const;
172 virtual GameObjectTypes get_types()
const;
177 int get_type()
const;
179 virtual void after_editor_set();
185 virtual void remove_me() { m_scheduled_for_removal =
true; }
188 bool is_valid()
const {
return !m_scheduled_for_removal; }
198 void set_name(
const std::string& name) { m_name = name; }
203 const std::string& get_name()
const;
205 virtual const std::string get_icon_path()
const {
206 return "images/tiles/auxiliary/notile.png";
217 for(
auto& component : m_components) {
218 if (T* result = dynamic_cast<T*>(component.get())) {
225 void add_component(std::unique_ptr<GameObjectComponent> component) {
226 m_components.emplace_back(std::move(component));
230 auto it = std::find_if(m_components.begin(), m_components.end(),
231 [component](
const std::unique_ptr<GameObjectComponent>& lhs){
232 return lhs.get() == component;
234 if (it != m_components.end()) {
235 m_components.erase(it);
240 virtual void save_state();
241 virtual void check_state();
264 virtual void on_type_change(
int old_type) {}
267 int type_id_to_value(
const std::string&
id)
const;
268 std::string type_value_to_id(
int value)
const;
271 void set_uid(
const UID& uid) { m_uid = uid; }
310 bool m_scheduled_for_removal;
314 std::string m_last_state;
316 std::vector<std::unique_ptr<GameObjectComponent> > m_components;
318 std::vector<ObjectRemoveListener*> m_remove_listeners;
virtual bool is_singleton() const
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: game_object.hpp:149
std::vector< std::unique_ptr< FadeHelper > > m_fade_helpers
Fade Helpers are for easing/fading script functions.
Definition: game_object.hpp:287
virtual void editor_deselect()
The object got deselected.
Definition: game_object.hpp:250
virtual void on_flip(float height)
When level is flipped vertically.
Definition: game_object.hpp:182
virtual void remove_me()
schedules this object to be removed at the end of the frame
Definition: game_object.hpp:185
std::string m_name
a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names b...
Definition: game_object.hpp:280
virtual bool has_object_manager_priority() const
Indicates if the object should be added at the beginning of the object list.
Definition: game_object.hpp:164
Definition: object_remove_listener.hpp:22
This class provides basic controlling functions for a sector.
Definition: game_object_manager.hpp:45
virtual bool has_variable_size() const
Does this object have variable size (secret area trigger, wind, etc.)
Definition: game_object.hpp:153
Definition: object_settings.hpp:39
virtual void editor_update()
Called each frame in the editor, used to keep linked objects together (e.g.
Definition: game_object.hpp:254
virtual bool has_settings() const
Indicates if get_settings() is implemented.
Definition: game_object.hpp:168
Definition: path_object.hpp:28
virtual bool track_state() const
Indicates if the object's state should be tracked.
Definition: game_object.hpp:161
bool m_track_undo
Track the following creation/deletion of this object for undo.
Definition: game_object.hpp:292
virtual void editor_select()
The user clicked on the object in the editor and selected it.
Definition: game_object.hpp:247
bool is_valid() const
returns true if the object is not scheduled to be removed yet
Definition: game_object.hpp:188
int m_type
Type of the GameObject.
Definition: game_object.hpp:284
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Represents a class, which can be exposed to scripting.
Definition: exposable_class.hpp:25
virtual void editor_delete()
The editor requested the deletion of the object.
Definition: game_object.hpp:244
virtual void stop_looping_sounds()
stops all looping sounds
Definition: game_object.hpp:210
virtual void finish_construction()
Called after all objects have been added to the Sector and the Sector is fully constructed.
Definition: game_object.hpp:99
virtual std::string get_display_name() const
Returns the display name of the object, translated to the user's locale.
Definition: game_object.hpp:123
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
virtual void play_looping_sounds()
continues all looping sounds
Definition: game_object.hpp:213
Definition: game_object_component.hpp:20
TypeChange
When the type has been changed from the editor.
Definition: game_object.hpp:263
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual bool is_saveable() const
Indicates if the object will be saved.
Definition: game_object.hpp:157
Definition: game_object.hpp:44
Definition: writer.cpp:23