FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_tilemap.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_TILEMAP_HPP_INCLUDED
18#define _FGE_C_TILEMAP_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_scene.hpp"
22#include "FastEngine/C_tilelayer.hpp"
23#include "FastEngine/C_tileset.hpp"
24
25#define FGE_TILEMAP_PLAN_STEP 2
26
27namespace fge
28{
29
30struct FGE_API TileMap : public std::enable_shared_from_this<TileMap>
31{
32private:
33 TileMap() = default;
34
35public:
36 using TileSetList = std::vector<std::shared_ptr<TileSet>>;
37 using TileLayerList = std::vector<std::shared_ptr<BaseLayer>>;
38
39 TileLayerList _layers;
40 TileSetList _tileSets;
41 std::vector<ObjectDataWeak> _generatedObjects;
42
43 void clear();
44
45 [[nodiscard]] TileLayerList::value_type* findLayerName(std::string_view name);
46 [[nodiscard]] TileLayerList::value_type const* findLayerName(std::string_view name) const;
47
48 bool loadFromFile(std::filesystem::path const& path);
49 void save(nlohmann::json& jsonObject) const;
50 void load(nlohmann::json& jsonObject, std::filesystem::path const& filePath);
51 void generateObjects(fge::Scene& scene, fge::ObjectPlan basePlan = FGE_SCENE_PLAN_DEFAULT);
52
53 [[nodiscard]] ObjectDataShared retrieveGeneratedTilelayerObject(std::string_view layerName) const;
54
55 inline static std::shared_ptr<TileMap> create() { return std::shared_ptr<TileMap>(new TileMap()); }
56};
57
58} // namespace fge
59
60#endif // _FGE_C_TILEMAP_HPP_INCLUDED
A scene contain a collection of object and handle them.
Definition C_scene.hpp:465