supertux
sector_base.hpp
1 // SuperTux
2 // Copyright (C) 2023 Vankata453
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 #ifndef HEADER_SUPERTUX_SUPERTUX_SECTOR_BASE_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_SECTOR_BASE_HPP
19 
20 #include "supertux/game_object_manager.hpp"
21 
22 #include "squirrel/squirrel_environment.hpp"
23 
24 class Level;
25 class TileSet;
26 
27 namespace Base {
28 
30 class Sector : public GameObjectManager
31 {
32 public:
33  Sector(const std::string& type);
34 
37  virtual void finish_construction(bool editable);
38 
39  virtual void draw(DrawingContext& context) = 0;
40  virtual void update(float dt_sec) = 0;
41 
42  virtual TileSet* get_tileset() const = 0;
43  virtual bool in_worldmap() const = 0;
44 
45  void set_name(const std::string& name) { m_name = name; }
46  const std::string& get_name() const { return m_name; }
47 
48  void set_init_script(const std::string& init_script) { m_init_script = init_script; }
49  void run_script(const std::string& script, const std::string& sourcename);
50 
51 protected:
52  virtual bool before_object_add(GameObject& object) override;
53  virtual void before_object_remove(GameObject& object) override;
54 
55 protected:
56  std::string m_name;
57  std::string m_init_script;
58 
59  std::unique_ptr<SquirrelEnvironment> m_squirrel_environment;
60 
61 private:
62  Sector(const Sector&) = delete;
63  Sector& operator=(const Sector&) = delete;
64 };
65 
66 } // namespace Base
67 
68 #endif
69 
70 /* EOF */
virtual bool before_object_add(GameObject &object) override
Hook that is called before an object is added to the vector.
Definition: sector_base.cpp:45
This class provides basic controlling functions for a sector.
Definition: game_object_manager.hpp:45
virtual void finish_construction(bool editable)
Needs to be called after parsing to finish the construction of the Sector before using it...
Definition: sector_base.cpp:32
A base for sector classes.
Definition: sector_base.hpp:30
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:30
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual void before_object_remove(GameObject &object) override
Hook that is called before an object is removed from the vector.
Definition: sector_base.cpp:52
Definition: sector_base.cpp:22
Definition: tile_set.hpp:44
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42