13 const core::map::Tile& getTile(
const std::vector<core::map::LayerSet>& levels,
unsigned int level,
14 unsigned int layer,
const sf::Vector2i& pos) {
18 return l.
topLayers()[i].get(pos.x, pos.y);
24 else {
return l.
bottomLayers()[layer].get(pos.x, pos.y); }
27 const core::map::Tile& getTile(
const std::vector<core::map::LayerSet>& levels,
unsigned int level,
28 unsigned int layer,
const glm::u32vec2& pos) {
29 return getTile(levels, level, layer, sf::Vector2i(pos.x, pos.y));
32 void setSingleTile(std::vector<core::map::LayerSet>& levels,
core::map::Tileset& tileset,
33 unsigned int level,
unsigned int layer,
const sf::Vector2i& pos,
39 tile = &l.
topLayers()[i].getRef(pos.x, pos.y);
40 tile->
set(value, isAnim);
45 tile->
set(value, isAnim);
49 tile->
set(value, isAnim);
54 std::vector<bool>& filter) {
57 std::vector<bool>::swap(filter[layer], filter[layer - 1]);
68 std::vector<bool>::swap(filter[layer], filter[layer - 1]);
79 std::vector<bool>::swap(filter[layer], filter[layer - 1]);
86 std::vector<bool>& filter) {
89 std::vector<bool>::swap(filter[layer], filter[layer + 1]);
100 std::vector<bool>::swap(filter[layer], filter[layer + 1]);
102 else if (layer == level.
ysortLayers().size() - 1) {
110 std::vector<bool>::swap(filter[layer], filter[layer + 1]);
117 std::swap(levels[i], levels[i + 1]);
122 std::swap(levels[i], levels[i - 1]);
125 void setNeighbors(
const glm::i32vec2& pos, glm::i32vec2* neighbors) {
126 neighbors[0] = {pos.x - 1, pos.y};
127 neighbors[1] = {pos.x, pos.y - 1};
128 neighbors[2] = {pos.x + 1, pos.y};
129 neighbors[3] = {pos.x, pos.y + 1};
135 const sf::Vector2i& pos,
bool isAnim,
139 bool wasAnim =
false;
140 if (pos.x >= 0 && pos.y >= 0 && pos.x < map.
sizeTiles().x && pos.y < map.
sizeTiles().y) {
141 if (level < map.
levels.size()) {
150 return EditMap::Action::Ptr(
154 EditMap::SetTileAction::SetTileAction(
unsigned int level,
unsigned int layer,
166 if (position.x >= 0 && position.y >= 0 && position.x < map.
sizeTiles().x &&
168 if (level < map.
levels.size()) {
171 setSingleTile(map.
levels, *map.
tileset, level, layer, position, updated, isAnim);
172 map.
setupTile(level, layer, sf::Vector2u(position));
180 if (position.x >= 0 && position.y >= 0 && position.x < map.
sizeTiles().x &&
182 if (level < map.
levels.size()) {
185 setSingleTile(map.
levels, *map.
tileset, level, layer, position, prev, wasAnim);
186 map.
setupTile(level, layer, sf::Vector2u(position));
196 const sf::IntRect& area,
bool isAnim,
202 auto anim = map.
tileset->getAnim(value);
203 if (anim) {
size = sf::Vector2f(anim->getMaxSize()); }
206 auto tile = map.
tileset->getTile(value);
207 if (tile) {
size = sf::Vector2f(tile->getSize()); }
212 bl::ctr::Vector2D<core::map::Tile::IdType> prev;
213 bl::ctr::Vector2D<std::uint8_t> wasAnim;
215 wasAnim.setSize(area.width, area.height, 0);
217 for (
int x = area.left; x < area.left + area.width; ++x) {
218 for (
int y = area.top; y < area.top + area.height; ++y) {
219 const auto& tile = getTile(map.
levels, level, layer, sf::Vector2i{x, y});
220 prev(x - area.left, y - area.top) = tile.
id();
221 wasAnim(x - area.left, y - area.top) = tile.
isAnimation() ? 1 : 0;
232 std::max(1.f, std::floor(
size.x / ts) - 1.f),
233 std::max(1.f, std::floor(
size.y / ts) - 1.f)));
236 EditMap::SetTileAreaAction::SetTileAreaAction(
unsigned int level,
unsigned int layer,
237 const sf::IntRect& area,
238 bl::ctr::Vector2D<core::map::Tile::IdType>&& prev,
239 bl::ctr::Vector2D<std::uint8_t>&& wasAnim,
253 for (
int x = area.left; x < area.left + area.width; x += w) {
254 for (
int y = area.top; y < area.top + area.height; y += h) {
255 setSingleTile(map.
levels, *map.
tileset, level, layer, {x, y}, updated, isAnim);
256 map.
setupTile(level, layer, sf::Vector2u(x, y));
263 for (
int x = area.left; x < area.left + area.width; ++x) {
264 for (
int y = area.top; y < area.top + area.height; ++y) {
270 prev(x - area.left, y - area.top),
271 wasAnim(x - area.left, y - area.top) == 1);
272 map.
setupTile(level, layer, sf::Vector2u(x, y));
281 const sf::Vector2i& pos,
287 bl::ctr::Vector2D<std::uint8_t> visited;
289 visited(pos.x, pos.y) = 1;
291 std::vector<glm::i32vec2> toVisit;
292 toVisit.reserve(estSize);
293 toVisit.emplace_back(glm::i32vec2(pos.x, pos.y));
295 std::vector<FillTile> set;
296 set.reserve(estSize);
298 while (!toVisit.empty()) {
299 const glm::i32vec2 p = toVisit.back();
301 set.emplace_back(sf::Vector2i(p.x, p.y), getTile(map.
levels, level, layer, p));
304 setNeighbors(p, nps);
305 for (
unsigned int i = 0; i < 4; ++i) {
306 const auto& np = nps[i];
307 if (!map.
contains({0, np, bl::tmap::Direction::Up}))
continue;
309 if (visited(np.x, np.y) == 0) {
310 visited(np.x, np.y) = 1;
311 const auto& t = getTile(map.
levels, level, layer, np);
312 if (t.id() == tile.
id() && t.isAnimation() == tile.
isAnimation()) {
313 toVisit.emplace_back(np);
322 EditMap::FillTileAction::FillTileAction(
unsigned int level,
unsigned int layer,
324 std::vector<FillTile>&& set)
332 for (
const auto& p : set) {
333 setSingleTile(map.
levels, *map.
tileset, level, layer, p.position,
id, isAnim);
334 map.
setupTile(level, layer, sf::Vector2u(p.position));
340 for (
const auto& p : set) {
341 setSingleTile(map.
levels, *map.
tileset, level, layer, p.position, p.id, p.isAnim);
342 map.
setupTile(level, layer, sf::Vector2u(p.position));
350 const sf::Vector2i& pos,
354 level, pos, value, map.
levels[level].collisionLayer().get(pos.x, pos.y)));
357 EditMap::SetCollisionAction::SetCollisionAction(
unsigned int level,
const sf::Vector2i& pos,
366 map.
levels[level].collisionLayer().set(pos.x, pos.y, value);
367 map.updateCollisionTileTexture(level, pos.x, pos.y);
372 map.
levels[level].collisionLayer().set(pos.x, pos.y, ogVal);
373 map.updateCollisionTileTexture(level, pos.x, pos.y);
380 const sf::IntRect& area,
383 bl::ctr::Vector2D<core::map::Collision> ogcols;
385 for (
int x = area.left; x < area.left + area.width; ++x) {
386 for (
int y = area.top; y < area.top + area.height; ++y) {
387 ogcols(x - area.left, y - area.top) = map.
levels[level].collisionLayer().get(x, y);
393 EditMap::SetCollisionAreaAction::SetCollisionAreaAction(
395 bl::ctr::Vector2D<core::map::Collision>&& ogcols)
402 for (
int x = area.left; x < area.left + area.width; ++x) {
403 for (
int y = area.top; y < area.top + area.height; ++y) {
404 map.
levels[level].collisionLayer().set(x, y, value);
405 map.updateCollisionTileTexture(level, x, y);
412 for (
int x = area.left; x < area.left + area.width; ++x) {
413 for (
int y = area.top; y < area.top + area.height; ++y) {
414 map.
levels[level].collisionLayer().set(x, y, ogVals(x - area.left, y - area.top));
415 map.updateCollisionTileTexture(level, x, y);
424 const sf::Vector2i& pos,
429 bl::ctr::Vector2D<std::uint8_t> visited;
431 visited(pos.x, pos.y) = 1;
433 std::vector<glm::i32vec2> toVisit;
434 toVisit.reserve(estSize);
435 toVisit.emplace_back(glm::i32vec2(pos.x, pos.y));
437 std::vector<std::pair<sf::Vector2i, core::map::Collision>> set;
438 set.reserve(estSize);
440 while (!toVisit.empty()) {
441 const auto p = toVisit.back();
443 set.emplace_back(sf::Vector2i(p.x, p.y), map.
levels[level].collisionLayer().get(p.x, p.y));
446 setNeighbors(p, nps);
447 for (
unsigned int i = 0; i < 4; ++i) {
448 const auto& np = nps[i];
449 if (!map.
contains({0, np, bl::tmap::Direction::Up}))
continue;
451 if (map.
levels[level].collisionLayer().get(np.x, np.y) == oc &&
452 visited(np.x, np.y) == 0) {
453 visited(np.x, np.y) = 1;
454 toVisit.emplace_back(np);
462 EditMap::FillCollisionAction::FillCollisionAction(
464 std::vector<std::pair<sf::Vector2i, core::map::Collision>>&& set)
470 for (
const auto& p : set) {
471 map.
levels[level].collisionLayer().set(p.first.x, p.first.y, col);
472 map.updateCollisionTileTexture(level, p.first.x, p.first.y);
478 for (
const auto& p : set) {
479 map.
levels[level].collisionLayer().set(p.first.x, p.first.y, p.second);
480 map.updateCollisionTileTexture(level, p.first.x, p.first.y);
488 std::uint8_t value,
const EditMap& map) {
493 EditMap::SetCatchAction::SetCatchAction(
unsigned int level,
const sf::Vector2i& pos,
494 std::uint8_t value, std::uint8_t ogVal)
501 map.
levels[level].catchLayer().set(pos.x, pos.y, value);
502 map.updateCatchTileColor(level, pos.x, pos.y);
507 map.
levels[level].catchLayer().set(pos.x, pos.y, ogVal);
508 map.updateCatchTileColor(level, pos.x, pos.y);
515 const sf::IntRect& area,
516 std::uint8_t value,
const EditMap& map) {
517 bl::ctr::Vector2D<std::uint8_t> ogcols;
518 ogcols.setSize(area.width, area.height, 0);
519 for (
int x = area.left; x < area.left + area.width; ++x) {
520 for (
int y = area.top; y < area.top + area.height; ++y) {
521 ogcols(x - area.left, y - area.top) = map.
levels[level].catchLayer().get(x, y);
527 EditMap::SetCatchAreaAction::SetCatchAreaAction(
unsigned int level,
const sf::IntRect& area,
529 bl::ctr::Vector2D<std::uint8_t>&& ogcols)
536 for (
int x = area.left; x < area.left + area.width; ++x) {
537 for (
int y = area.top; y < area.top + area.height; ++y) {
538 map.
levels[level].catchLayer().set(x, y, value);
539 map.updateCatchTileColor(level, x, y);
546 for (
int x = area.left; x < area.left + area.width; ++x) {
547 for (
int y = area.top; y < area.top + area.height; ++y) {
548 map.
levels[level].catchLayer().set(x, y, ogVals(x - area.left, y - area.top));
549 map.updateCatchTileColor(level, x, y);
558 std::uint8_t
id,
EditMap& map) {
559 const std::uint8_t og = map.
levels[level].catchLayer().get(pos.x, pos.y);
562 bl::ctr::Vector2D<std::uint8_t> visited;
564 visited(pos.x, pos.y) = 1;
566 std::vector<glm::i32vec2> toVisit;
567 toVisit.reserve(estSize);
568 toVisit.emplace_back(glm::i32vec2(pos.x, pos.y));
570 std::vector<std::pair<sf::Vector2i, std::uint8_t>> set;
571 set.reserve(estSize);
573 while (!toVisit.empty()) {
574 const glm::i32vec2 p = toVisit.back();
576 set.emplace_back(sf::Vector2i(p.x, p.y), map.
levels[level].catchLayer().get(p.x, p.y));
579 setNeighbors(p, nps);
580 for (
unsigned int i = 0; i < 4; ++i) {
581 const auto& np = nps[i];
582 if (!map.
contains({0, np, bl::tmap::Direction::Up}))
continue;
584 if (visited(np.x, np.y) == 0 && map.
levels[level].catchLayer().get(np.x, np.y) == og) {
585 visited(np.x, np.y) = 1;
586 toVisit.emplace_back(np);
594 EditMap::FillCatchAction::FillCatchAction(
unsigned int level, std::uint8_t
id,
595 std::vector<std::pair<sf::Vector2i, std::uint8_t>>&& set)
601 for (
const auto& p : set) {
602 map.
levels[level].catchLayer().set(p.first.x, p.first.y,
id);
603 map.updateCatchTileColor(level, p.first.x, p.first.y);
609 for (
const auto& p : set) {
610 map.
levels[level].catchLayer().set(p.first.x, p.first.y, p.second);
611 map.updateCatchTileColor(level, p.first.x, p.first.y);
623 EditMap::SetPlaylistAction::SetPlaylistAction(
const std::string& orig,
const std::string& playlist)
625 , playlist(playlist) {}
643 EditMap::SetNameAction::SetNameAction(
const std::string& orig,
const std::string&
name)
687 EditMap::AppendLayerAction::AppendLayerAction(
unsigned int lv, Location l)
693 std::vector<core::map::TileLayer>* ls =
nullptr;
694 unsigned int offset = 0;
708 const unsigned int i = ls->size();
709 const unsigned int gi = i + offset;
713 std::next(map.
renderLevels.begin(), level)->insertLayer(gi);
714 map.updateAllDepths();
715 map.layerFilter[level].insert(map.layerFilter[level].begin() + gi,
true);
721 std::vector<core::map::TileLayer>* ls =
nullptr;
722 unsigned int offset = 0;
736 const unsigned int i = ls->size() - 1;
737 const unsigned int gi = i + offset;
740 std::next(map.
renderLevels.begin(), level)->removeLayer(gi);
741 map.updateAllDepths();
742 map.layerFilter[level].erase(map.layerFilter[level].begin() + gi);
752 unsigned int ay = layer;
765 EditMap::RemoveLayerAction::RemoveLayerAction(
unsigned int level,
unsigned int layer,
769 , removedLayer(rm) {}
772 unsigned int ay = layer;
774 std::vector<core::map::TileLayer>* set =
nullptr;
784 set->erase(set->begin() + ay);
785 map.layerFilter[level].erase(map.layerFilter[level].begin() + layer);
786 std::next(map.
renderLevels.begin(), level)->removeLayer(layer);
787 map.updateAllDepths();
792 unsigned int ay = layer;
794 std::vector<core::map::TileLayer>* set =
nullptr;
804 set->insert(set->begin() + ay, removedLayer);
805 map.layerFilter[level].insert(map.layerFilter[level].begin() + layer,
true);
806 std::next(map.
renderLevels.begin(), level)->insertLayer(layer);
808 map.updateAllDepths();
819 EditMap::ShiftLayerAction::ShiftLayerAction(
unsigned int level,
unsigned int layer,
bool up)
826 shiftLayerUp(map.
levels[level], layer, *map.
tileset, map.layerFilter[level]);
827 map.swapRenderLayers(level, layer, layer - 1);
830 shiftLayerDown(map.
levels[level], layer, *map.
tileset, map.layerFilter[level]);
831 map.swapRenderLayers(level, layer, layer + 1);
838 unsigned int ay = layer - 1;
839 if (layer == map.
levels[level].bottomLayers().size() - 1 ||
840 layer == map.
levels[level].bottomLayers().size() +
841 map.
levels[level].ysortLayers().size() - 1) {
844 shiftLayerDown(map.
levels[level], ay, *map.
tileset, map.layerFilter[level]);
845 map.swapRenderLayers(level, ay, ay + 1);
848 unsigned int ay = layer + 1;
849 if (layer == map.
levels[level].bottomLayers().size() ||
851 map.
levels[level].bottomLayers().size() + map.
levels[level].ysortLayers().size()) {
854 shiftLayerUp(map.
levels[level], ay, *map.
tileset, map.layerFilter[level]);
855 map.swapRenderLayers(level, ay, ay - 1);
866 EditMap::ShiftLevelAction::ShiftLevelAction(
unsigned int level,
bool up)
873 std::vector<bool>::swap(map.levelFilter[level], map.levelFilter[level - 1]);
874 std::swap(map.layerFilter[level], map.layerFilter[level - 1]);
875 map.swapRenderLevels(level, level - 1);
879 std::vector<bool>::swap(map.levelFilter[level], map.levelFilter[level + 1]);
880 std::swap(map.layerFilter[level], map.layerFilter[level + 1]);
881 map.swapRenderLevels(level, level + 1);
889 std::vector<bool>::swap(map.levelFilter[level], map.levelFilter[level + 1]);
890 std::swap(map.layerFilter[level], map.layerFilter[level + 1]);
891 map.swapRenderLevels(level, level + 1);
895 std::vector<bool>::swap(map.levelFilter[level], map.levelFilter[level - 1]);
896 std::swap(map.layerFilter[level], map.layerFilter[level - 1]);
897 map.swapRenderLevels(level, level - 1);
907 map.levelFilter.push_back(
true);
908 map.layerFilter.emplace_back(5,
true);
909 map.
levels.emplace_back();
912 map.updateAllDepths();
920 map.updateAllDepths();
921 map.levelFilter.pop_back();
922 map.layerFilter.pop_back();
930 const std::string& p) {
934 EditMap::SetScriptAction::SetScriptAction(
bool l,
const std::string& s,
const std::string& p)
952 if (load) {
return "set load script"; }
953 return "set unload script";
960 EditMap::AddEventAction::AddEventAction(
const core::map::Event& e,
unsigned int i)
972 map.removeEventGfx(i);
1005 EditMap::RemoveEventAction::RemoveEventAction(
const core::map::Event& e,
unsigned int i)
1011 map.removeEventGfx(i);
1024 unsigned int id, bl::tmap::Direction dir) {
1028 EditMap::AddSpawnAction::AddSpawnAction(
unsigned int l,
const sf::Vector2i& p,
unsigned int id,
1029 bl::tmap::Direction dir)
1037 core::map::Spawn(
id, bl::tmap::Position(level, glm::i32vec2(pos.x, pos.y), dir));
1039 map.addSpawnGfx(spawn);
1045 map.spawnSprites.erase(
id);
1055 EditMap::RotateSpawnAction::RotateSpawnAction(
unsigned int id)
1061 auto& d = map.
spawns[id].position.direction;
1063 case bl::tmap::Direction::Up:
1064 d = bl::tmap::Direction::Right;
1066 case bl::tmap::Direction::Right:
1067 d = bl::tmap::Direction::Down;
1069 case bl::tmap::Direction::Down:
1070 d = bl::tmap::Direction::Left;
1072 case bl::tmap::Direction::Left:
1074 d = bl::tmap::Direction::Up;
1076 map.updateSpawnRotation(
id);
1083 auto& d = map.
spawns[id].position.direction;
1085 case bl::tmap::Direction::Up:
1086 d = bl::tmap::Direction::Left;
1088 case bl::tmap::Direction::Right:
1089 d = bl::tmap::Direction::Up;
1091 case bl::tmap::Direction::Down:
1092 d = bl::tmap::Direction::Right;
1094 case bl::tmap::Direction::Left:
1096 d = bl::tmap::Direction::Down;
1098 map.updateSpawnRotation(
id);
1109 EditMap::RemoveSpawnAction::RemoveSpawnAction(
unsigned int id,
const core::map::Spawn& spawn)
1115 map.spawnSprites.erase(
id);
1121 map.addSpawnGfx(spawn);
1145 if (c != bl::ecs::InvalidEntity) { map.
systems->
engine().ecs().destroyEntity(c); }
1157 EditMap::EditNpcSpawnAction::EditNpcSpawnAction(
unsigned int i,
1208 const sf::Vector2i& pos,
1214 EditMap::AddOrEditItemAction::AddOrEditItemAction(
unsigned int i,
unsigned int level,
1228 static_cast<std::uint16_t
>(item), map.nextItemId, position, level, visible);
1231 core::map::Item(
static_cast<std::uint16_t
>(item), 0, position, level, visible), map);
1234 map.
itemsField[i].id =
static_cast<std::uint16_t
>(item);
1244 glm::i32vec2(position.x, position.y),
1245 bl::tmap::Direction::Up});
1246 if (ent != bl::ecs::InvalidEntity) { map.
systems->
engine().ecs().destroyEntity(ent); }
1256 return add ?
"spawn item" :
"edit item";
1260 const sf::Vector2i& pos,
1265 EditMap::RemoveItemAction::RemoveItemAction(
unsigned int i,
unsigned int level,
1275 glm::i32vec2(position.x, position.y),
1276 bl::tmap::Direction::Up});
1277 if (ent != bl::ecs::InvalidEntity) { map.
systems->
engine().ecs().destroyEntity(ent); }
1294 EditMap::SetLightAction::SetLightAction(
const sf::Vector2i& pos,
unsigned int radius,
1296 : value(radius, pos)
1317 return spawned ?
"spawn light" :
"edit light";
1324 EditMap::RemoveLightAction::RemoveLightAction(
const core::map::Light& orig)
1363 EditMap::EditCatchRegionAction::EditCatchRegionAction(std::uint8_t i,
1387 EditMap::RemoveCatchRegionAction::RemoveCatchRegionAction(std::uint8_t i,
1393 const std::uint8_t i = index + 1;
1397 if (cleared.empty()) {
1398 for (
unsigned int level = 0; level < map.
levels.size(); ++level) {
1399 for (
unsigned int x = 0; x < map.
levels[level].catchLayer().width(); ++x) {
1400 for (
unsigned int y = 0; y < map.
levels[level].catchLayer().height(); ++y) {
1401 if (map.
levels[level].catchLayer().get(x, y) == i) {
1402 cleared.emplace_back(level, sf::Vector2i(x, y));
1409 for (
const auto& pos : cleared) {
1410 map.
levels[pos.first].catchLayer().set(pos.second.x, pos.second.y, 0);
1413 for (
unsigned int level = 0; level < map.
levels.size(); ++level) {
1414 for (
unsigned int x = 0; x < map.
levels[level].catchLayer().width(); ++x) {
1415 for (
unsigned int y = 0; y < map.
levels[level].catchLayer().height(); ++y) {
1416 const std::uint8_t j = map.
levels[level].catchLayer().get(x, y);
1417 if (j > i) { map.
levels[level].catchLayer().set(x, y, j - 1); }
1426 const std::uint8_t i = index + 1;
1430 for (
unsigned int level = 0; level < map.
levels.size(); ++level) {
1431 for (
unsigned int x = 0; x < map.
levels[level].catchLayer().width(); ++x) {
1432 for (
unsigned int y = 0; y < map.
levels[level].catchLayer().height(); ++y) {
1433 const std::uint8_t j = map.
levels[level].catchLayer().get(x, y);
1434 if (j >= i) { map.
levels[level].catchLayer().set(x, y, j + 1); }
1439 for (
const auto& pos : cleared) {
1440 map.
levels[pos.first].catchLayer().set(pos.second.x, pos.second.y, i);
1453 EditMap::SetAmbientLightAction::SetAmbientLightAction(
bool sun, std::uint8_t upper,
1457 , origSunlight(
lighting.adjustsForSunlight())
1458 , origLower(
lighting.getMinLightLevel())
1460 , origUpper(
lighting.getMaxLightLevel())
1481 t.
name =
"New Town";
1483 map.
towns.emplace_back(std::move(t));
1488 map.
towns.pop_back();
1499 EditMap::EditTownAction::EditTownAction(std::uint8_t i,
const core::map::Town& orig,
1507 return val.name != orig.name;
1511 map.
towns[i] = orig;
1512 return val.name != orig.name;
1522 EditMap::RemoveTownAction::RemoveTownAction(std::uint8_t i,
const core::map::Town& t)
1528 const bool add = tiles.empty();
1529 const std::uint8_t j = i + 1;
1530 for (
int x = 0; x < map.
sizeTiles().x; ++x) {
1531 for (
int y = 0; y < map.
sizeTiles().y; ++y) {
1533 tiles.emplace_back(x, y);
1543 map.
towns.insert(map.
towns.begin() + i, orig);
1544 const std::uint8_t j = i + 1;
1546 for (
int x = 0; x < map.
sizeTiles().x; ++x) {
1547 for (
int y = 0; y < map.
sizeTiles().y; ++y) {
1551 for (
const auto& pos : tiles) { map.
townTiles(pos.x, pos.y) = j; }
1559 std::uint8_t orig) {
1563 EditMap::SetTownTileAction::SetTownTileAction(
const sf::Vector2i& pos, std::uint8_t
id,
1571 map.updateTownTileColor(pos.x, pos.y);
1577 map.updateTownTileColor(pos.x, pos.y);
1584 std::uint8_t
id,
EditMap& map) {
1585 bl::ctr::Vector2D<std::uint8_t> set;
1586 set.setSize(area.width, area.height, 0);
1587 for (
int x = 0; x < area.width; ++x) {
1588 for (
int y = 0; y < area.height; ++y) {
1589 set(x, y) = map.
townTiles(area.left + x, area.top + y);
1595 EditMap::SetTownTileAreaAction::SetTownTileAreaAction(
const sf::IntRect& area, std::uint8_t
id,
1596 bl::ctr::Vector2D<std::uint8_t>&& set)
1602 for (
int x = area.left; x < area.left + area.width; ++x) {
1603 for (
int y = area.top; y < area.top + area.height; ++y) {
1605 map.updateTownTileColor(x, y);
1612 for (
int x = area.left; x < area.left + area.width; ++x) {
1613 for (
int y = area.top; y < area.top + area.height; ++y) {
1614 map.
townTiles(x, y) = orig(x - area.left, y - area.top);
1615 map.updateTownTileColor(x, y);
1625 const std::uint8_t val = map.
townTiles(pos.x, pos.y);
1628 bl::ctr::Vector2D<std::uint8_t> visited;
1630 visited(pos.x, pos.y) = 1;
1632 std::vector<glm::i32vec2> toVisit;
1633 toVisit.reserve(estSize);
1634 toVisit.emplace_back(glm::i32vec2(pos.x, pos.y));
1636 std::vector<std::pair<sf::Vector2i, std::uint8_t>> set;
1637 set.reserve(estSize);
1639 while (!toVisit.empty()) {
1640 const glm::i32vec2 p = toVisit.back();
1642 set.emplace_back(sf::Vector2i(p.x, p.y), map.
townTiles(p.x, p.y));
1644 glm::i32vec2 nps[4];
1645 setNeighbors(p, nps);
1646 for (
unsigned int i = 0; i < 4; ++i) {
1647 if (!map.
contains({0, nps[i], bl::tmap::Direction::Up}))
continue;
1649 if (map.
townTiles(nps[i].x, nps[i].y) == val && visited(nps[i].x, nps[i].y) == 0) {
1650 toVisit.emplace_back(nps[i]);
1651 visited(nps[i].x, nps[i].y) = 1;
1659 EditMap::FillTownTileAction::FillTownTileAction(
1660 std::uint8_t fill, std::vector<std::pair<sf::Vector2i, std::uint8_t>>&& set)
1665 for (
const auto& p : set) {
1666 map.
townTiles(p.first.x, p.first.y) = id;
1667 map.updateTownTileColor(p.first.x, p.first.y);
1673 for (
const auto& p : set) {
1674 map.
townTiles(p.first.x, p.first.y) = p.second;
1675 map.updateTownTileColor(p.first.x, p.first.y);
1688 EditMap::SetLevelTileAction::SetLevelTileAction(
const sf::Vector2i& pos,
1697 map.updateLevelTransitionTexture(pos.x, pos.y);
1703 map.updateLevelTransitionTexture(pos.x, pos.y);
1712 bl::ctr::Vector2D<core::map::LevelTransition> orig;
1713 orig.setSize(area.width, area.height);
1714 for (
int x = area.left; x < area.left + area.width; ++x) {
1715 for (
int y = area.top; y < area.top + area.height; ++y) {
1723 EditMap::SetLevelTileAreaAction::SetLevelTileAreaAction(
1725 bl::ctr::Vector2D<core::map::LevelTransition>&& orig)
1731 for (
int x = area.left; x < area.left + area.width; ++x) {
1732 for (
int y = area.top; y < area.top + area.height; ++y) {
1734 map.updateLevelTransitionTexture(x, y);
1741 for (
int x = area.left; x < area.left + area.width; ++x) {
1742 for (
int y = area.top; y < area.top + area.height; ++y) {
1744 map.updateLevelTransitionTexture(x, y);
1751 return "set level transition area";
Id
Represents an item in its simplist form.
Collision
The different types of collisions in maps.
LevelTransition
Represents a level transition in a map. Level transitions are applied when an entity moves either ont...
All classes and functionality used for implementing the game editor.
Represents a class of catchable peoplemon.
Represents a character to be spawned into a map on load.
Represents an event in a Map. A script that is run on a trigger within a given region.
Basic struct representing a pickup-able item in Map.
Generic map layer class. Can be used for any type of layer.
Encapsulates a set of layers for a given map height. Maps have one LayerSet per height level,...
std::vector< TileLayer > & bottomLayers()
Returns a reference to the bottom tiles in this set.
std::vector< TileLayer > & topLayers()
Returns a reference to the top tiles in this set.
std::vector< TileLayer > & ysortLayers()
Returns a reference to the sorted tiles in this set.
unsigned int layerCount() const
Returns the total number of layers contained.
Represents a renderable light in a Map.
System for handling lighting in Maps. Manages all the lights and performs rendering....
std::uint16_t Handle
Handle representing a light in the map.
void addLight(const Light &light)
Adds a light to the map and to the persistent map file.
void adjustForSunlight(bool adjust)
Set whether or not the light level is adjusted based on time of day. If not adjusting for sunlight th...
void setAmbientLevel(std::uint8_t lowLightLevel, std::uint8_t highLightLevel)
The ambient light band. 0 is full darkness and 255 is full brightness.
void updateLight(Handle handle, const Light &value)
Updates the light with the given handle to the new information.
Handle getClosestLight(const sf::Vector2i &position)
Returns a handle to the light closest to the given position.
static constexpr Handle None
Special handle indicating that no light is referenced.
void removeLight(Handle light)
Remove the given light from the system and optionally persist the removal.
std::vector< Item > itemsField
std::unordered_map< std::uint16_t, Spawn > spawns
std::vector< LayerSet > levels
std::string unloadScriptField
std::vector< Event > eventsField
std::string loadScriptField
Weather::Type weatherField
LightingSystem & lightingSystem()
Returns a reference to the lighting system in this map.
bl::resource::Ref< Tileset > tileset
bool contains(const bl::tmap::Position &position) const
Returns whether or not the map contains the given position.
void setupTile(unsigned int level, unsigned int layer, const sf::Vector2u &pos)
std::vector< Town > towns
bl::ctr::Vector2D< std::uint8_t > townTiles
const sf::Vector2i & sizeTiles() const
Returns the size of the map in tiles.
std::vector< CharacterSpawn > characterField
bl::ctr::Vector2D< LevelTransition > transitionField
void setupLayer(unsigned int level, unsigned int layer)
std::string playlistField
Weather & weatherSystem()
Returns a reference to the weather system in this map.
std::vector< CatchRegion > catchRegionsField
system::Systems * systems
void setupLevel(unsigned int level)
const std::string & name() const
Returns the name of the map.
std::list< RenderLevel > renderLevels
Basic struct representing a spawn in a Map.
Data representation of a tile in a Map TileLayer.
IdType id() const
Returns the id of the image or animation of this tile.
static constexpr IdType Blank
Special id for blank tiles.
bool isAnimation() const
Returns whether this tile is an animation or not.
void set(IdType id, bool anim)
Sets the information of the tile.
Stores the collection of images and animations used by Tiles in a Map.
Represents a town, route, or region within a map. Maps may have many towns. Individual tiles are asso...
@ None
No weather will occur.
void set(Type type, bool immediate=false)
Sets the current weather type.
static int PixelsPerTile()
bool spawnItem(const map::Item &item, map::Map &map)
Spawns an item into the world.
bl::ecs::Entity spawnCharacter(const map::CharacterSpawn &spawn, map::Map &map)
Spawns a trainer or an npc from the given spawn information.
void editorPushLevel()
Called by the editor when a level is added.
bl::ecs::Entity getEntity(const bl::tmap::Position &pos) const
Returns the entity at the given position or InvalidEntity if not found.
void editorPopLevel()
Called by the editor when a level is removed.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Entity & entity()
Returns the entity system.
Position & position()
Returns a reference to the position system.
Wrapper over the core::Map class that is directly usable in a bl::gui::GUI.
std::shared_ptr< EditMap > Ptr
Pointer to an EditMap.
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static EditMap::Action::Ptr create(unsigned int level, unsigned int layer, const sf::Vector2i &pos, bool isAnim, core::map::Tile::IdType value, const EditMap &map)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, unsigned int layer, const sf::IntRect &area, bool isAnim, core::map::Tile::IdType value, const EditMap &map)
virtual bool undo(EditMap &map) override
virtual bool undo(EditMap &map) override
static Action::Ptr create(unsigned int level, unsigned int layer, const sf::Vector2i &pos, core::map::Tile::IdType id, bool isAnim, EditMap &map)
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, const sf::Vector2i &pos, core::map::Collision value, const EditMap &map)
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(unsigned int level, const sf::Vector2i &pos, core::map::Collision col, EditMap &map)
virtual const char * description() const override
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, const sf::IntRect &area, core::map::Collision value, const EditMap &map)
static EditMap::Action::Ptr create(unsigned int level, const sf::Vector2i &pos, std::uint8_t value, const EditMap &map)
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, const sf::IntRect &area, std::uint8_t value, const EditMap &map)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(unsigned int level, const sf::Vector2i &pos, std::uint8_t id, EditMap &map)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
static EditMap::Action::Ptr create(const std::string &playlist, const EditMap &editMap)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static EditMap::Action::Ptr create(const std::string &name, const EditMap &editMap)
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
static EditMap::Action::Ptr create(core::map::Weather::Type type, const EditMap &map)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, Location location)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, unsigned int layer, const EditMap &map)
virtual const char * description() const override
static EditMap::Action::Ptr create(unsigned int level, unsigned int layer, bool up)
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static EditMap::Action::Ptr create(unsigned int level, bool up)
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
static EditMap::Action::Ptr create()
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
static EditMap::Action::Ptr create(bool load, const std::string &s, const std::string &p)
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(const core::map::Event &e, unsigned int i)
virtual bool apply(EditMap &map) override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const core::map::Event &orig, const core::map::Event &val, unsigned int i)
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const core::map::Event &e, unsigned int i)
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(unsigned int lvl, const sf::Vector2i &pos, unsigned int id, bl::tmap::Direction dir)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static Action::Ptr create(unsigned int id)
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(unsigned int id, const core::map::Spawn &spawn)
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
static Action::Ptr create(const core::map::CharacterSpawn &s, unsigned int i)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(unsigned int i, const core::map::CharacterSpawn &orig, const core::map::CharacterSpawn &s)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(const core::map::CharacterSpawn &orig, unsigned int i)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(unsigned int i, unsigned int level, const sf::Vector2i &pos, core::item::Id item, bool visible, const core::map::Item &orig, bool add)
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(unsigned int i, unsigned int level, const sf::Vector2i &pos, const core::map::Item &orig)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(const sf::Vector2i &pos, unsigned int radius, const core::map::Light &orig)
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const core::map::Light &orig)
virtual const char * description() const override
static Action::Ptr create()
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static Action::Ptr create(std::uint8_t index, const core::map::CatchRegion &value, const core::map::CatchRegion &orig)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(std::uint8_t index, const core::map::CatchRegion &orig)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(bool sunlight, std::uint8_t upper, std::uint8_t lower, const core::map::LightingSystem &lighting)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create()
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static Action::Ptr create(std::uint8_t i, const core::map::Town &orig, const core::map::Town &town)
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
static Action::Ptr create(std::uint8_t i, const core::map::Town &orig)
virtual bool apply(EditMap &map) override
virtual const char * description() const override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const sf::Vector2i &pos, std::uint8_t id, std::uint8_t orig)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const sf::IntRect &area, std::uint8_t id, EditMap &map)
virtual bool undo(EditMap &map) override
virtual const char * description() const override
virtual bool apply(EditMap &map) override
static Action::Ptr create(const sf::Vector2i &pos, std::uint8_t id, EditMap &map)
static Action::Ptr create(const sf::Vector2i &pos, core::map::LevelTransition lt, core::map::LevelTransition orig)
virtual const char * description() const override
virtual bool apply(EditMap &map) override
virtual bool undo(EditMap &map) override
virtual bool apply(EditMap &map) override
virtual const char * description() const override
static Action::Ptr create(const sf::IntRect &area, core::map::LevelTransition id, EditMap &map)
virtual bool undo(EditMap &map) override