9bool Grid2D::inBounds(
int x,
int y)
const {
10 return x >= 0 &&
y >= 0 &&
x < width_ &&
y < height_;
17 detail_.assign(
size_t(width_ * height_), 0);
24 if (!inBounds(
x,
y))
return;
30 return int(cells_[
size_t(
y * width_ +
x)]);
34 std::fill(cells_.begin(), cells_.end(), uint32_t(
semantic < 0 ? 0 :
semantic));
38 if (!inBounds(
x,
y))
return;
39 detail_[size_t(
y * width_ +
x)] = uint8_t(
value < 0 ? 0 : (
value > 255 ? 255 :
value));
43 if (!inBounds(
x,
y))
return 0;
44 return int(detail_[
size_t(
y * width_ +
x)]);
50 auto it = meta_.find(
key);
71 o.
gid = uint32_t(gid < 0 ? 0 : gid);
72 objects_.push_back(std::move(o));
76 const std::string &asset,
float x,
float y,
float width,
float height,
79 objects_.back().asset = asset;
81 objects_.back().placementFlags = uint32_t(flags < 0 ? 0 : flags);
87 if (i < 0 || i >=
int(objects_.size()))
return {};
88 return objects_[size_t(i)].name;
91 if (i < 0 || i >=
int(objects_.size()))
return {};
92 return objects_[size_t(i)].type;
95 if (i < 0 || i >=
int(objects_.size()))
return 0.f;
96 return objects_[size_t(i)].x;
99 if (i < 0 || i >=
int(objects_.size()))
return 0.f;
100 return objects_[size_t(i)].y;
103 if (i < 0 || i >=
int(objects_.size()))
return 0.f;
104 return objects_[size_t(i)].width;
107 if (i < 0 || i >=
int(objects_.size()))
return 0.f;
108 return objects_[size_t(i)].height;
111 if (i < 0 || i >=
int(objects_.size()))
return 0;
112 return int(objects_[
size_t(i)].gid);
115 if (i < 0 || i >=
int(objects_.size()))
return {};
116 return objects_[size_t(i)].asset;
119 if (i < 0 || i >=
int(objects_.size()))
return 0.f;
120 return objects_[size_t(i)].rotationDegrees;
123 if (i < 0 || i >=
int(objects_.size()))
return 0;
124 return int(objects_[
size_t(i)].placementFlags);
std::string getObjectAsset(int i) const
Returns the object asset.
void setDetail(int x, int y, int value)
Per-cell detail layer (0..255), parallel to cells. Semantics stay in cells (palette/GID compatible); ...
std::string getObjectType(int i) const
Returns the object type.
void clearObjects()
Clears objects.
int getWidth() const
Returns the width.
float getObjectWidth(int i) const
Returns the object width.
int getDetail(int x, int y) const
Returns the detail.
void resize(int width, int height)
Resize.
float getObjectY(int i) const
Returns the object y.
float getObjectRotation(int i) const
Returns the object rotation.
void fill(int semantic)
Fill.
void setCell(int x, int y, int semantic)
Sets the cell.
void addObject(const std::string &name, const std::string &type, float x, float y, float width, float height, int gid)
Adds object.
int getCell(int x, int y) const
Returns the cell.
int getObjectFlags(int i) const
Returns the object flags.
float getObjectX(int i) const
Returns the object x.
void addObjectAt(const std::string &name, const std::string &type, float x, float y)
Script-friendly: name/type + tile coords.
int getObjectCount() const
Returns the object count.
int getObjectGid(int i) const
Returns the object gid.
float getObjectHeight(int i) const
Returns the object height.
std::string getObjectName(int i) const
Returns the object name.
void setMeta(const std::string &key, const std::string &value)
Sets the meta.
int getHeight() const
Returns the height.
std::string getMeta(const std::string &key, const std::string &defaultValue) const
Returns the meta.
void addAssetObject(const std::string &name, const std::string &role, const std::string &asset, float x, float y, float width, float height, float rotationDegrees, int flags)
Add a placed asset while preserving its semantic role, asset id and orientation.
const char * defaultValue
Named rectangle or asset placement emitted by a procedural generator.