Debian Codegraph @

src/game/trackloader.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2011 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D 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 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef TRACKLOADER_HPP
17 #define TRACKLOADER_HPP
18
19 #include <QString>
20 #include <vector>
21
22 #include <MCAssetManager>
23 #include <MCObjectFactory>
24
25 #include "difficultyprofile.hpp"
26 #include "trackobjectfactory.hpp"
27 #include "tracktile.hpp"
28
29 #include "../common/targetnodebase.hpp"
30
31 class TargetNodeBase;
32 class Track;
33 class TrackData;
34 class TrackTileBase;
35 class QDomElement;
36
37 //! A singleton class that handles track loading.
38 //! TODO: This can be shared with the editor or inherit from
39 //! a shared loader.
40 class TrackLoader
41 {
42 public:
43 //! Constructor.
44 TrackLoader();
45
46 //! Add path to search level files for.
47 void addTrackSearchPath(QString path);
48
49 void loadAssets();
50
51 /*! Load all tracks found in the added paths.
52 * Lock/unlock tracks according to the given lap count.
53 * \return Number of track loaded. */
54 int loadTracks(int lapCount, DifficultyProfile::Difficulty difficulty);
55
56 //! Update locked tracks when lap count changes.
57 void updateLockedTracks(int lapCount, DifficultyProfile::Difficulty difficulty);
58
59 //! Get track count.
60 size_t tracks() const;
61
62 //! Get a track of given index.
63 std::shared_ptr<Track> track(size_t index) const;
64
65 static TrackLoader & instance();
66
67 private:
68 //! Load the given track.
69 //! \return Valid data pointer or nullptr if fails.
70 std::unique_ptr<TrackData> loadTrack(QString path);
71
72 void sortTracks();
73
74 //! Read a tile element.
75 void readTile(QDomElement & element, TrackData & newData);
76
77 //! Read an object element.
78 void readObject(QDomElement & element, TrackData & newData);
79
80 //! Read a target node element and push to the given vector.
81 void readTargetNode(QDomElement & element, TrackData & newData, std::vector<TargetNodeBasePtr> & route);
82
83 //! Convert tile type string to a type enum.
84 TrackTile::TileType tileTypeEnumFromString(std::string str);
85
86 MCAssetManager m_assetManager;
87
88 MCObjectFactory m_objectFactory;
89
90 TrackObjectFactory m_trackObjectFactory;
91
92 std::vector<QString> m_paths;
93
94 std::vector<std::shared_ptr<Track>> m_tracks;
95
96 static TrackLoader * m_instance;
97 };
98
99 #endif // TRACKLOADER_HPP