Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
package.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
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 <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <map>
20#include <memory>
21#include <string>
22
23#include "engine/asset/asset.h"
24#include "engine/enginelogger.h"
25
26namespace cqsp::asset {
27class AssetLoader;
28class AssetManager;
29
30class Package {
31 public:
32 std::string name;
33 std::string version;
34 std::string title;
35 std::string author;
36
37 template <class T, typename V>
38 T* GetAsset(const V asset) {
39 if (!HasAsset(asset)) {
40 ENGINE_LOG_ERROR("Invalid key {}", asset);
41 return nullptr;
42 }
43 return dynamic_cast<T*>(assets[asset].get());
44 }
45
46 bool HasAsset(const char* asset);
47 bool HasAsset(const std::string& asset);
48
49 auto begin() { return assets.begin(); }
50
51 auto end() { return assets.end(); }
52
53 private:
54 std::map<std::string, std::unique_ptr<Asset>> assets;
55
56 void ClearAssets();
57
58 friend class AssetLoader;
59 friend class AssetManager;
60};
61
62} // namespace cqsp::asset
Definition: assetloader.h:44
Definition: assetmanager.h:46
Definition: package.h:30
auto end()
Definition: package.h:51
auto begin()
Definition: package.h:49
std::string author
Definition: package.h:35
void ClearAssets()
Definition: package.cpp:25
std::string version
Definition: package.h:33
std::string name
Definition: package.h:32
std::string title
Definition: package.h:34
T * GetAsset(const V asset)
Definition: package.h:38
std::map< std::string, std::unique_ptr< Asset > > assets
Definition: package.h:54
bool HasAsset(const char *asset)
Definition: package.cpp:22
#define ENGINE_LOG_ERROR(...)
Definition: enginelogger.h:31
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: asset.h:29