载入中...
搜索中...
未找到
PaletteMapAdapter.cpp
浏览该文件的文档.
1#include "map/TileLayer.h"
2#include "procgen/Palette.h"
3
4#include "procgen/Semantic.h"
5
6namespace eve::procgen {
7
8bool PaletteTable::applyToLayer(const Grid2D& grid, const std::string& palette, map::TileLayer* layer,
9 std::string* error) const {
10 if (!layer) {
11 if (error) *error = "applyToLayer: null TileLayer";
12 return false;
13 }
14 const int w = grid.getWidth();
15 const int h = grid.getHeight();
16 if (w <= 0 || h <= 0) {
17 if (error) *error = "applyToLayer: empty grid";
18 return false;
19 }
20 if (layer->getMapWidth() != w || layer->getMapHeight() != h) {
21 layer->resize(w, h);
22 }
23 for (int y = 0; y < h; ++y) {
24 for (int x = 0; x < w; ++x) {
25 layer->setTile(x, y, getGid(palette, grid.getCell(x, y)));
26 }
27 }
28 return true;
29}
30
31} // namespace eve::procgen
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string palette
int h
std::string error
Definition Package.cpp:60
TileLayer * layer
ECS tile layer entity. Script mutates tile GIDs / tileset / draw; TileRenderSystem batch-draws atlas ...
Definition TileLayer.h:32
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
Definition Grid2D.h:36
bool applyToLayer(const Grid2D &grid, const std::string &palette, map::TileLayer *layer, std::string *error) const
Applies to layer.
int getGid(const std::string &palette, const std::string &semantic) const
Returns the gid.
Definition Palette.cpp:11