17 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP 18 #define HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_HPP 23 #include "editor/object_settings.hpp" 24 #include "supertux/game_object_component.hpp" 25 #include "util/gettext.hpp" 26 #include "util/uid.hpp" 61 UID get_uid()
const {
return m_uid; }
68 virtual void update(
float dt_sec) = 0;
76 virtual std::string get_class()
const {
return "game-object"; }
77 virtual std::string get_display_name()
const {
return _(
"Unknown object"); }
96 virtual void after_editor_set() {}
99 bool is_valid()
const {
return !m_scheduled_for_removal; }
112 void set_name(
const std::string& name) {
m_name = name; }
113 const std::string& get_name()
const {
return m_name; }
115 virtual const std::string get_icon_path()
const {
116 return "images/tiles/auxiliary/notile.png";
127 for(
auto& component : m_components) {
128 if (T* result = dynamic_cast<T*>(component.get())) {
135 void add_component(std::unique_ptr<GameObjectComponent> component) {
136 m_components.emplace_back(std::move(component));
140 auto it = std::find_if(m_components.begin(), m_components.end(),
141 [component](
const std::unique_ptr<GameObjectComponent>& lhs){
142 return lhs.get() == component;
144 if (it != m_components.end()) {
145 m_components.erase(it);
163 void set_uid(
const UID& uid) { m_uid = uid; }
176 bool m_scheduled_for_removal;
178 std::vector<std::unique_ptr<GameObjectComponent> > m_components;
180 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:81
Definition: writer.hpp:27
void del_remove_listener(ObjectRemoveListener *listener)
unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed ...
Definition: game_object.cpp:65
virtual void editor_deselect()
The object got deselected.
Definition: game_object.hpp:156
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:168
Definition: object_remove_listener.hpp:22
Definition: game_object_manager.hpp:34
virtual void draw(DrawingContext &context)=0
The GameObject should draw itself onto the provided DrawingContext if this function is called...
virtual bool has_variable_size() const
Does this object have variable size (secret area trigger, wind, etc.)
Definition: game_object.hpp:85
void add_remove_listener(ObjectRemoveListener *listener)
registers a remove listener which will be called if the object gets removed/destroyed ...
Definition: game_object.cpp:59
Definition: object_settings.hpp:35
virtual void editor_update()
Called each frame in the editor, used to keep linked objects together (e.g.
Definition: game_object.hpp:160
void remove_me()
schedules this object to be removed at the end of the frame
Definition: game_object.hpp:102
virtual bool has_settings() const
Indicates if get_settings() is implemented.
Definition: game_object.hpp:93
virtual void editor_select()
The user clicked on the object in the editor and selected it.
Definition: game_object.hpp:153
bool is_valid() const
returns true if the object is not scheduled to be removed yet
Definition: game_object.hpp:99
Base class for all the things that make up Levels' Sectors.
Definition: game_object.hpp:46
virtual void editor_delete()
The editor requested the deletion of the object.
Definition: game_object.hpp:150
virtual void stop_looping_sounds()
stops all looping sounds
Definition: game_object.hpp:120
virtual void update(float dt_sec)=0
This function is called once per frame and allows the object to update it's state.
virtual void finish_construction()
Called after all objects have been added to the Sector and the Sector is fully constructed.
Definition: game_object.hpp:59
virtual void play_looping_sounds()
continues all looping sounds
Definition: game_object.hpp:123
Definition: game_object_component.hpp:20
void save(Writer &writer)
This function saves the object.
Definition: game_object.cpp:74
Definition: reader_mapping.hpp:31
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:89