载入中...
搜索中...
未找到
LevelDocument.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Value.h"
8
9#include <memory>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
14namespace eve::level_editing {
15
18
21 std::string id;
22 std::string type;
23 std::string name;
24 float x = 0.f, y = 0.f, width = 0.f, height = 0.f, rotation = 0.f;
25 bool visible = true;
26
27 std::unordered_map<std::string, std::string> properties;
30};
31
33struct LevelLayer {
35 enum class Kind { Tiles, Objects };
36
37 std::string id;
38 std::string name;
40 bool visible = true;
41 bool locked = false;
42 float opacity = 1.f;
43 float offsetX = 0.f, offsetY = 0.f;
44
45 std::unique_ptr<TileBuffer> tiles;
46 std::vector<LevelObject> objects;
47
48 std::unordered_map<std::string, std::string> properties;
51};
52
61public:
63 LevelDocument(int width = 1, int height = 1, float tileWidth = 32.f, float tileHeight = 32.f);
64
65 // std::vector<LevelLayer> holds a unique_ptr member, so the implicit copy
66 // operations were already deleted; a class-level dllexport would nonetheless
67 // instantiate std::vector<LevelLayer>::operator= and hard-error (C2280).
68 // Spell the four out so the export surface stays defined; semantics unchanged.
69 LevelDocument(const LevelDocument&) = delete;
75
77 void resize(int width, int height);
79 int getWidth() const { return width_; }
81 int getHeight() const { return height_; }
83 float getTileWidth() const { return tileWidth_; }
85 float getTileHeight() const { return tileHeight_; }
87 void setTileSize(float width, float height);
89 void setOrientation(const std::string& orientation);
91 const std::string& getOrientation() const { return orientation_; }
92
94 int addTileLayer(const std::string& name);
96 int addObjectLayer(const std::string& name);
98 [[nodiscard]] LevelChange removeLayer(int index);
100 [[nodiscard]] LevelChange moveLayer(int from, int to);
102 int getLayerCount() const { return static_cast<int>(layers_.size()); }
104 const std::string& getLayerName(int index) const;
106 void setLayerName(int index, const std::string& name);
108 const std::string getLayerKind(int index) const;
109
111 [[nodiscard]] eve::OptionalRef<TileBuffer> getTileLayer(int index);
113 [[nodiscard]] eve::OptionalRef<const TileBuffer> getTileLayer(int index) const;
115 [[nodiscard]] eve::OptionalRef<LevelLayer> layer(int index);
117 [[nodiscard]] eve::OptionalRef<const LevelLayer> layer(int index) const;
118
120 int addObject(int layerIndex, const std::string& type, float x, float y);
122 int getObjectCount(int layerIndex) const;
123
125 [[nodiscard]] eve::OptionalRef<LevelObject> object(int layerIndex, int objectIndex);
127 [[nodiscard]] eve::OptionalRef<const LevelObject> object(int layerIndex, int objectIndex) const;
129 [[nodiscard]] LevelChange removeObject(int layerIndex, int objectIndex);
130
132 void setProperty(const std::string& key, const std::string& value);
134 std::string getProperty(const std::string& key, const std::string& fallback = {}) const;
135
136 std::unordered_map<std::string, std::string>& properties() { return properties_; }
137 const std::unordered_map<std::string, std::string>& properties() const { return properties_; }
138
140 std::vector<LevelLayer>& layers() { return layers_; }
142 const std::vector<LevelLayer>& layers() const { return layers_; }
143
144private:
145 friend class LevelFormatCodec;
146 eve::Value::Object extensions_;
147 std::string nextId(const char* prefix);
148 int width_, height_;
149 float tileWidth_, tileHeight_;
150 std::string orientation_ = "orthogonal";
151 unsigned nextId_ = 1;
152
153 std::vector<LevelLayer> layers_;
154 std::unordered_map<std::string, std::string> properties_;
155};
156
157} // namespace eve::level_editing
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string from
Vocabulary aliases for nullable and checked borrowed references.
#define EVENGINE_API_DOMAINS
Definition Export.h:110
std::uint32_t key
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
std::uint32_t height
std::uint32_t width
std::string name
TileLayer * layer
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.