载入中...
搜索中...
未找到
LevelDocument.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
4
5
7#include "common/Value.h"
9
10#include <memory>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace eve::level_editing {
16
19
22 std::string id;
23 std::string type;
24 std::string name;
25 float x = 0.f, y = 0.f, width = 0.f, height = 0.f, rotation = 0.f;
26 bool visible = true;
27
28 std::unordered_map<std::string, std::string> properties;
31};
32
34struct LevelLayer {
36 enum class Kind { Tiles, Objects };
37
38 std::string id;
39 std::string name;
41 bool visible = true;
42 bool locked = false;
43 float opacity = 1.f;
44 float offsetX = 0.f, offsetY = 0.f;
45
46 std::unique_ptr<TileBuffer> tiles;
47 std::vector<LevelObject> objects;
48
49 std::unordered_map<std::string, std::string> properties;
52};
53
62public:
64 LevelDocument(int width = 1, int height = 1, float tileWidth = 32.f, float tileHeight = 32.f);
65
66 // std::vector<LevelLayer> holds a unique_ptr member, so the implicit copy
67 // operations were already deleted; a class-level dllexport would nonetheless
68 // instantiate std::vector<LevelLayer>::operator= and hard-error (C2280).
69 // Spell the four out so the export surface stays defined; semantics unchanged.
70 LevelDocument(const LevelDocument&) = delete;
76
78 void resize(int width, int height);
80 int getWidth() const { return width_; }
82 int getHeight() const { return height_; }
84 float getTileWidth() const { return tileWidth_; }
86 float getTileHeight() const { return tileHeight_; }
88 void setTileSize(float width, float height);
90 void setOrientation(const std::string& orientation);
92 const std::string& getOrientation() const { return orientation_; }
93
95 int addTileLayer(const std::string& name);
97 int addObjectLayer(const std::string& name);
99 [[nodiscard]] LevelChange removeLayer(int index);
101 [[nodiscard]] LevelChange moveLayer(int from, int to);
103 int getLayerCount() const { return static_cast<int>(layers_.size()); }
105 const std::string& getLayerName(int index) const;
107 void setLayerName(int index, const std::string& name);
109 const std::string getLayerKind(int index) const;
110
112 [[nodiscard]] eve::OptionalRef<TileBuffer> getTileLayer(int index);
114 [[nodiscard]] eve::OptionalRef<const TileBuffer> getTileLayer(int index) const;
116 [[nodiscard]] eve::OptionalRef<LevelLayer> layer(int index);
118 [[nodiscard]] eve::OptionalRef<const LevelLayer> layer(int index) const;
119
121 int addObject(int layerIndex, const std::string& type, float x, float y);
123 int getObjectCount(int layerIndex) const;
124
126 [[nodiscard]] eve::OptionalRef<LevelObject> object(int layerIndex, int objectIndex);
128 [[nodiscard]] eve::OptionalRef<const LevelObject> object(int layerIndex, int objectIndex) const;
130 [[nodiscard]] LevelChange removeObject(int layerIndex, int objectIndex);
131
133 void setProperty(const std::string& key, const std::string& value);
135 std::string getProperty(const std::string& key, const std::string& fallback = {}) const;
136
137 std::unordered_map<std::string, std::string>& properties() { return properties_; }
138 const std::unordered_map<std::string, std::string>& properties() const { return properties_; }
139
141 std::vector<LevelLayer>& layers() { return layers_; }
143 const std::vector<LevelLayer>& layers() const { return layers_; }
144
145private:
146 friend class LevelFormatCodec;
147 eve::Value::Object extensions_;
148 std::string nextId(const char* prefix);
149 int width_, height_;
150 float tileWidth_, tileHeight_;
151 std::string orientation_ = "orthogonal";
152 unsigned nextId_ = 1;
153
154 std::vector<LevelLayer> layers_;
155 std::unordered_map<std::string, std::string> properties_;
156};
157
158} // namespace eve::level_editing
double y
double x
Vocabulary aliases for nullable and checked borrowed references.
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_DOMAINS
Definition Export.h:110
std::uint32_t height
std::uint32_t width
std::string to
std::string from
TileLayer * layer
Object::Ptr value
Share string attribute map operations through the Windows Foundation DLL.
Json object
uint32_t index
Owning, renderer-independent dynamic values.
std::map< std::string, Value > Object
Definition Value.h:34
Format-neutral, editable top-down level model.
int getLayerCount() const
Returns the layer count.
float getTileWidth() const
Returns the tile width.
LevelDocument(LevelDocument &&)=default
Level document.
const std::string & getOrientation() const
Returns the orientation.
int getHeight() const
Returns the height.
LevelDocument & operator=(const LevelDocument &)=delete
LevelDocument & operator=(LevelDocument &&)=default
Operator =.
std::vector< LevelLayer > & layers()
Layers.
float getTileHeight() const
Returns the tile height.
const std::vector< LevelLayer > & layers() const
Layers.
LevelDocument(const LevelDocument &)=delete
std::unordered_map< std::string, std::string > & properties()
const std::unordered_map< std::string, std::string > & properties() const
int getWidth() const
Returns the width.
LevelChange
Whether a requested level mutation changed authoritative document state.
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
A tile or object layer in a LevelDocument.
std::unique_ptr< TileBuffer > tiles
std::unordered_map< std::string, std::string > properties
std::vector< LevelObject > objects
eve::Value::Object extensions
Owned format fields not represented above; codec excludes authoritative fields.
One freely extensible object placed in a top-down level.
std::unordered_map< std::string, std::string > properties
eve::Value::Object extensions
Owned format fields not represented above; codec excludes authoritative fields.