R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
MapData.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** MapData.hpp - Component storing map/level information
6*/
7
8#pragma once
9
10#include <string>
11#include "IComponent.hpp"
12
13namespace ecs {
24 class MapData : public IComponent {
25 public:
31 : _mapId(""),
32 _name(""),
33 _scrollSpeed(0.0f),
37 _spawnScript(""),
38 _duration(0.0f),
39 _nextMapId(""),
40 _elapsedTime(0.0f),
41 _isCompleted(false) {}
42
50 MapData(const std::string &mapId, float scrollSpeed, const std::string &backgroundSprite,
51 const std::string &spawnScript)
52 : _mapId(mapId),
53 _name(""),
54 _scrollSpeed(scrollSpeed),
55 _backgroundSprite(backgroundSprite),
58 _spawnScript(spawnScript),
59 _duration(0.0f),
60 _nextMapId(""),
61 _elapsedTime(0.0f),
62 _isCompleted(false) {}
63
76 MapData(const std::string &mapId, const std::string &name, float scrollSpeed,
77 const std::string &backgroundSprite, const std::string &spawnScript, float duration,
78 const std::string &nextMapId, const std::string &parallaxBackground = "",
79 float parallaxSpeedFactor = 0.5f)
80 : _mapId(mapId),
81 _name(name),
82 _scrollSpeed(scrollSpeed),
83 _backgroundSprite(backgroundSprite),
84 _parallaxBackgroundSprite(parallaxBackground),
85 _parallaxSpeedFactor(parallaxSpeedFactor),
86 _spawnScript(spawnScript),
87 _duration(duration),
88 _nextMapId(nextMapId),
89 _elapsedTime(0.0f),
90 _isCompleted(false) {}
91
92 ~MapData() override = default;
93
94 // ===== Getters =====
95
100 const std::string &getMapId() const { return _mapId; }
101
106 const std::string &getName() const { return _name; }
107
112 float getScrollSpeed() const { return _scrollSpeed; }
113
118 const std::string &getBackgroundSprite() const { return _backgroundSprite; }
119
124 const std::string &getParallaxBackgroundSprite() const { return _parallaxBackgroundSprite; }
125
131
136 const std::string &getSpawnScript() const { return _spawnScript; }
137
142 float getDuration() const { return _duration; }
143
148 const std::string &getNextMapId() const { return _nextMapId; }
149
154 float getElapsedTime() const { return _elapsedTime; }
155
160 bool isCompleted() const { return _isCompleted; }
161
162 // ===== Setters =====
163
168 void setMapId(const std::string &mapId) { _mapId = mapId; }
169
174 void setName(const std::string &name) { _name = name; }
175
180 void setScrollSpeed(float speed) { _scrollSpeed = speed; }
181
186 void setBackgroundSprite(const std::string &sprite) { _backgroundSprite = sprite; }
187
192 void setParallaxBackgroundSprite(const std::string &sprite) { _parallaxBackgroundSprite = sprite; }
193
198 void setParallaxSpeedFactor(float factor) { _parallaxSpeedFactor = factor; }
199
204 void setSpawnScript(const std::string &script) { _spawnScript = script; }
205
210 void setDuration(float duration) { _duration = duration; }
211
216 void setNextMapId(const std::string &nextMapId) { _nextMapId = nextMapId; }
217
222 void updateElapsedTime(float deltaTime) { _elapsedTime += deltaTime; }
223
227 void markCompleted() { _isCompleted = true; }
228
232 void reset() {
233 _elapsedTime = 0.0f;
234 _isCompleted = false;
235 }
236
241 ComponentType getType() const override { return getComponentType<MapData>(); }
242
243 private:
244 std::string _mapId;
245 std::string _name;
247 std::string _backgroundSprite;
248 std::string
251 std::string _spawnScript;
252 float _duration;
253 std::string _nextMapId;
256 };
257
258} // namespace ecs
Base interface for all ECS components.
Component storing information about the current map/level.
Definition MapData.hpp:24
float _parallaxSpeedFactor
Speed factor for parallax layer (0.5 = half speed)
Definition MapData.hpp:250
float _scrollSpeed
Horizontal scroll speed (px/s)
Definition MapData.hpp:246
std::string _backgroundSprite
Background asset path.
Definition MapData.hpp:247
const std::string & getNextMapId() const
Get the next map ID.
Definition MapData.hpp:148
std::string _name
Display name.
Definition MapData.hpp:245
void setScrollSpeed(float speed)
Set the scroll speed.
Definition MapData.hpp:180
float getParallaxSpeedFactor() const
Get the parallax speed factor.
Definition MapData.hpp:130
void setBackgroundSprite(const std::string &sprite)
Set the background sprite.
Definition MapData.hpp:186
const std::string & getMapId() const
Get the map unique identifier.
Definition MapData.hpp:100
bool isCompleted() const
Check if the map is completed.
Definition MapData.hpp:160
ComponentType getType() const override
Get the component type ID.
Definition MapData.hpp:241
MapData(const std::string &mapId, const std::string &name, float scrollSpeed, const std::string &backgroundSprite, const std::string &spawnScript, float duration, const std::string &nextMapId, const std::string &parallaxBackground="", float parallaxSpeedFactor=0.5f)
Full constructor with all parameters.
Definition MapData.hpp:76
~MapData() override=default
void reset()
Reset the map state (elapsed time and completion).
Definition MapData.hpp:232
const std::string & getBackgroundSprite() const
Get the background sprite path.
Definition MapData.hpp:118
float _duration
Map duration in seconds (0 = infinite)
Definition MapData.hpp:252
std::string _mapId
Unique map identifier.
Definition MapData.hpp:244
void setSpawnScript(const std::string &script)
Set the spawn script.
Definition MapData.hpp:204
std::string _nextMapId
Next map to load after completion.
Definition MapData.hpp:253
void setParallaxSpeedFactor(float factor)
Set the parallax speed factor.
Definition MapData.hpp:198
float _elapsedTime
Time spent on this map.
Definition MapData.hpp:254
void setNextMapId(const std::string &nextMapId)
Set the next map ID.
Definition MapData.hpp:216
std::string _parallaxBackgroundSprite
Parallax layer asset path (rendered on top, scrolls slower)
Definition MapData.hpp:249
bool _isCompleted
Completion flag.
Definition MapData.hpp:255
float getScrollSpeed() const
Get the scroll speed.
Definition MapData.hpp:112
void setMapId(const std::string &mapId)
Set the map ID.
Definition MapData.hpp:168
MapData()
Default constructor. Initializes with empty map data.
Definition MapData.hpp:30
void setParallaxBackgroundSprite(const std::string &sprite)
Set the parallax background sprite.
Definition MapData.hpp:192
float getElapsedTime() const
Get the elapsed time on this map.
Definition MapData.hpp:154
void setDuration(float duration)
Set the map duration.
Definition MapData.hpp:210
void setName(const std::string &name)
Set the map name.
Definition MapData.hpp:174
const std::string & getSpawnScript() const
Get the spawn script path.
Definition MapData.hpp:136
float getDuration() const
Get the map duration.
Definition MapData.hpp:142
MapData(const std::string &mapId, float scrollSpeed, const std::string &backgroundSprite, const std::string &spawnScript)
Constructor with basic parameters.
Definition MapData.hpp:50
std::string _spawnScript
Lua script for spawn logic.
Definition MapData.hpp:251
const std::string & getParallaxBackgroundSprite() const
Get the parallax background sprite path.
Definition MapData.hpp:124
const std::string & getName() const
Get the map display name.
Definition MapData.hpp:106
void updateElapsedTime(float deltaTime)
Update the elapsed time.
Definition MapData.hpp:222
void markCompleted()
Mark the map as completed.
Definition MapData.hpp:227
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::size_t ComponentType
Type alias for component identification.