Merge pull request #50 from huderlem/layouts
Support new map organization
This commit is contained in:
commit
9c2cf84983
7 changed files with 341 additions and 428 deletions
14
editor.cpp
14
editor.cpp
|
@ -349,14 +349,14 @@ void Editor::displayMap() {
|
||||||
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
||||||
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
||||||
|
|
||||||
map_item->draw();
|
map_item->draw(true);
|
||||||
scene->addItem(map_item);
|
scene->addItem(map_item);
|
||||||
|
|
||||||
collision_item = new CollisionPixmapItem(map);
|
collision_item = new CollisionPixmapItem(map);
|
||||||
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
||||||
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
||||||
|
|
||||||
collision_item->draw();
|
collision_item->draw(true);
|
||||||
scene->addItem(collision_item);
|
scene->addItem(collision_item);
|
||||||
|
|
||||||
events_group = new EventGroup;
|
events_group = new EventGroup;
|
||||||
|
@ -1077,9 +1077,9 @@ void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapPixmapItem::draw() {
|
void MapPixmapItem::draw(bool ignoreCache) {
|
||||||
if (map) {
|
if (map) {
|
||||||
setPixmap(map->render());
|
setPixmap(map->render(ignoreCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,7 +1104,7 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
|
||||||
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
|
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
|
||||||
map->clearHoveredTile();
|
map->clearHoveredTile();
|
||||||
} else {
|
} else {
|
||||||
int tile = map->blockdata->blocks->at(blockIndex).tile;
|
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
||||||
map->hoveredTileChanged(x, y, tile);
|
map->hoveredTileChanged(x, y, tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1141,9 +1141,9 @@ void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::draw() {
|
void CollisionPixmapItem::draw(bool ignoreCache) {
|
||||||
if (map) {
|
if (map) {
|
||||||
setPixmap(map->renderCollision());
|
setPixmap(map->renderCollision(ignoreCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
editor.h
4
editor.h
|
@ -237,7 +237,7 @@ public:
|
||||||
virtual void select(QGraphicsSceneMouseEvent*);
|
virtual void select(QGraphicsSceneMouseEvent*);
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
virtual void draw();
|
virtual void draw(bool ignoreCache = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCurHoveredTile(QPointF pos);
|
void updateCurHoveredTile(QPointF pos);
|
||||||
|
@ -266,7 +266,7 @@ public:
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
virtual void draw();
|
virtual void draw(bool ignoreCache = false);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
||||||
|
|
|
@ -285,8 +285,8 @@ void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
||||||
|
|
||||||
void MainWindow::loadDataStructures() {
|
void MainWindow::loadDataStructures() {
|
||||||
Project *project = editor->project;
|
Project *project = editor->project;
|
||||||
project->readMapAttributesTable();
|
project->readMapLayoutsTable();
|
||||||
project->readAllMapAttributes();
|
project->readAllMapLayouts();
|
||||||
project->readItemNames();
|
project->readItemNames();
|
||||||
project->readFlagNames();
|
project->readFlagNames();
|
||||||
project->readVarNames();
|
project->readVarNames();
|
||||||
|
@ -761,6 +761,7 @@ void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onMapChanged(Map *map) {
|
void MainWindow::onMapChanged(Map *map) {
|
||||||
|
map->layout->has_unsaved_changes = true;
|
||||||
updateMapList();
|
updateMapList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
145
map.cpp
145
map.cpp
|
@ -8,10 +8,6 @@
|
||||||
|
|
||||||
Map::Map(QObject *parent) : QObject(parent)
|
Map::Map(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
blockdata = new Blockdata;
|
|
||||||
cached_blockdata = new Blockdata;
|
|
||||||
cached_collision = new Blockdata;
|
|
||||||
cached_border = new Blockdata;
|
|
||||||
paint_tile_index = 1;
|
paint_tile_index = 1;
|
||||||
paint_collision = 0;
|
paint_collision = 0;
|
||||||
paint_elevation = 3;
|
paint_elevation = 3;
|
||||||
|
@ -36,29 +32,29 @@ QString Map::mapConstantFromName(QString mapName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::getWidth() {
|
int Map::getWidth() {
|
||||||
return width.toInt(nullptr, 0);
|
return layout->width.toInt(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::getHeight() {
|
int Map::getHeight() {
|
||||||
return height.toInt(nullptr, 0);
|
return layout->height.toInt(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset* Map::getBlockTileset(int metatile_index) {
|
Tileset* Map::getBlockTileset(int metatile_index) {
|
||||||
int primary_size = 0x200;//tileset_primary->metatiles->length();
|
int primary_size = 0x200;
|
||||||
if (metatile_index < primary_size) {
|
if (metatile_index < primary_size) {
|
||||||
return tileset_primary;
|
return layout->tileset_primary;
|
||||||
} else {
|
} else {
|
||||||
return tileset_secondary;
|
return layout->tileset_secondary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QList<QRgb>> Map::getBlockPalettes(int metatile_index) {
|
QList<QList<QRgb>> Map::getBlockPalettes(int metatile_index) {
|
||||||
QList<QList<QRgb>> palettes;
|
QList<QList<QRgb>> palettes;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
palettes.append(tileset_primary->palettes->at(i));
|
palettes.append(layout->tileset_primary->palettes->at(i));
|
||||||
}
|
}
|
||||||
for (int i = 6; i < tileset_secondary->palettes->length(); i++) {
|
for (int i = 6; i < layout->tileset_secondary->palettes->length(); i++) {
|
||||||
palettes.append(tileset_secondary->palettes->at(i));
|
palettes.append(layout->tileset_secondary->palettes->at(i));
|
||||||
}
|
}
|
||||||
return palettes;
|
return palettes;
|
||||||
}
|
}
|
||||||
|
@ -73,18 +69,18 @@ int Map::getBlockIndex(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::getSelectedBlockIndex(int index) {
|
int Map::getSelectedBlockIndex(int index) {
|
||||||
if (index < tileset_primary->metatiles->length()) {
|
if (index < layout->tileset_primary->metatiles->length()) {
|
||||||
return index;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return 0x200 + (index - tileset_primary->metatiles->length());
|
return 0x200 + (index - layout->tileset_primary->metatiles->length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Map::getDisplayedBlockIndex(int index) {
|
int Map::getDisplayedBlockIndex(int index) {
|
||||||
if (index < tileset_primary->metatiles->length()) {
|
if (index < layout->tileset_primary->metatiles->length()) {
|
||||||
return index;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return index - 0x200 + tileset_primary->metatiles->length();
|
return index - 0x200 + layout->tileset_primary->metatiles->length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,58 +201,58 @@ bool Map::blockChanged(int i, Blockdata *cache) {
|
||||||
if (cache == NULL || cache == nullptr) {
|
if (cache == NULL || cache == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (blockdata == NULL || blockdata == nullptr) {
|
if (layout->blockdata == NULL || layout->blockdata == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (cache->blocks == NULL || cache->blocks == nullptr) {
|
if (cache->blocks == NULL || cache->blocks == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (blockdata->blocks == NULL || blockdata->blocks == nullptr) {
|
if (layout->blockdata->blocks == NULL || layout->blockdata->blocks == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (cache->blocks->length() <= i) {
|
if (cache->blocks->length() <= i) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (blockdata->blocks->length() <= i) {
|
if (layout->blockdata->blocks->length() <= i) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return blockdata->blocks->value(i) != cache->blocks->value(i);
|
return layout->blockdata->blocks->value(i) != cache->blocks->value(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheBorder() {
|
void Map::cacheBorder() {
|
||||||
if (cached_border) delete cached_border;
|
if (layout->cached_border) delete layout->cached_border;
|
||||||
cached_border = new Blockdata;
|
layout->cached_border = new Blockdata;
|
||||||
if (border && border->blocks) {
|
if (layout->border && layout->border->blocks) {
|
||||||
for (int i = 0; i < border->blocks->length(); i++) {
|
for (int i = 0; i < layout->border->blocks->length(); i++) {
|
||||||
Block block = border->blocks->value(i);
|
Block block = layout->border->blocks->value(i);
|
||||||
cached_border->blocks->append(block);
|
layout->cached_border->blocks->append(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheBlockdata() {
|
void Map::cacheBlockdata() {
|
||||||
if (cached_blockdata) delete cached_blockdata;
|
if (layout->cached_blockdata) delete layout->cached_blockdata;
|
||||||
cached_blockdata = new Blockdata;
|
layout->cached_blockdata = new Blockdata;
|
||||||
if (blockdata && blockdata->blocks) {
|
if (layout->blockdata && layout->blockdata->blocks) {
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
||||||
Block block = blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
cached_blockdata->blocks->append(block);
|
layout->cached_blockdata->blocks->append(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheCollision() {
|
void Map::cacheCollision() {
|
||||||
if (cached_collision) delete cached_collision;
|
if (layout->cached_collision) delete layout->cached_collision;
|
||||||
cached_collision = new Blockdata;
|
layout->cached_collision = new Blockdata;
|
||||||
if (blockdata && blockdata->blocks) {
|
if (layout->blockdata && layout->blockdata->blocks) {
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
||||||
Block block = blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
cached_collision->blocks->append(block);
|
layout->cached_collision->blocks->append(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderCollision() {
|
QPixmap Map::renderCollision(bool ignoreCache) {
|
||||||
bool changed_any = false;
|
bool changed_any = false;
|
||||||
int width_ = getWidth();
|
int width_ = getWidth();
|
||||||
int height_ = getHeight();
|
int height_ = getHeight();
|
||||||
|
@ -268,17 +264,17 @@ QPixmap Map::renderCollision() {
|
||||||
collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
if (!(blockdata && blockdata->blocks && width_ && height_)) {
|
if (!(layout->blockdata && layout->blockdata->blocks && width_ && height_)) {
|
||||||
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
||||||
return collision_pixmap;
|
return collision_pixmap;
|
||||||
}
|
}
|
||||||
QPainter painter(&collision_image);
|
QPainter painter(&collision_image);
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
||||||
if (cached_collision && !blockChanged(i, cached_collision)) {
|
if (!ignoreCache && layout->cached_collision && !blockChanged(i, layout->cached_collision)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
QImage metatile_image = getMetatileImage(block.tile);
|
QImage metatile_image = getMetatileImage(block.tile);
|
||||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||||
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
||||||
|
@ -324,7 +320,7 @@ QPixmap Map::renderCollision() {
|
||||||
return collision_pixmap;
|
return collision_pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::render() {
|
QPixmap Map::render(bool ignoreCache = false) {
|
||||||
bool changed_any = false;
|
bool changed_any = false;
|
||||||
int width_ = getWidth();
|
int width_ = getWidth();
|
||||||
int height_ = getHeight();
|
int height_ = getHeight();
|
||||||
|
@ -336,18 +332,18 @@ QPixmap Map::render() {
|
||||||
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
if (!(blockdata && blockdata->blocks && width_ && height_)) {
|
if (!(layout->blockdata && layout->blockdata->blocks && width_ && height_)) {
|
||||||
pixmap = pixmap.fromImage(image);
|
pixmap = pixmap.fromImage(image);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, cached_blockdata)) {
|
if (!ignoreCache && !blockChanged(i, layout->cached_blockdata)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
QImage metatile_image = getMetatileImage(block.tile);
|
QImage metatile_image = getMetatileImage(block.tile);
|
||||||
int map_y = width_ ? i / width_ : 0;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = width_ ? i % width_ : 0;
|
int map_x = width_ ? i % width_ : 0;
|
||||||
|
@ -366,21 +362,21 @@ QPixmap Map::renderBorder() {
|
||||||
bool changed_any = false;
|
bool changed_any = false;
|
||||||
int width_ = 2;
|
int width_ = 2;
|
||||||
int height_ = 2;
|
int height_ = 2;
|
||||||
if (border_image.isNull()) {
|
if (layout->border_image.isNull()) {
|
||||||
border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
if (!(border && border->blocks)) {
|
if (!(layout->border && layout->border->blocks)) {
|
||||||
border_pixmap = border_pixmap.fromImage(border_image);
|
layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image);
|
||||||
return border_pixmap;
|
return layout->border_pixmap;
|
||||||
}
|
}
|
||||||
QPainter painter(&border_image);
|
QPainter painter(&layout->border_image);
|
||||||
for (int i = 0; i < border->blocks->length(); i++) {
|
for (int i = 0; i < layout->border->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, cached_border)) {
|
if (!blockChanged(i, layout->cached_border)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = border->blocks->value(i);
|
Block block = layout->border->blocks->value(i);
|
||||||
QImage metatile_image = getMetatileImage(block.tile);
|
QImage metatile_image = getMetatileImage(block.tile);
|
||||||
int map_y = i / width_;
|
int map_y = i / width_;
|
||||||
int map_x = i % width_;
|
int map_x = i % width_;
|
||||||
|
@ -389,9 +385,9 @@ QPixmap Map::renderBorder() {
|
||||||
painter.end();
|
painter.end();
|
||||||
if (changed_any) {
|
if (changed_any) {
|
||||||
cacheBorder();
|
cacheBorder();
|
||||||
border_pixmap = border_pixmap.fromImage(border_image);
|
layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image);
|
||||||
}
|
}
|
||||||
return border_pixmap;
|
return layout->border_pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderConnection(Connection connection) {
|
QPixmap Map::renderConnection(Connection connection) {
|
||||||
|
@ -482,11 +478,12 @@ void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, Q
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderMetatiles() {
|
QPixmap Map::renderMetatiles() {
|
||||||
if (!tileset_primary || !tileset_primary->metatiles || !tileset_secondary || !tileset_secondary->metatiles) {
|
if (!layout->tileset_primary || !layout->tileset_primary->metatiles
|
||||||
|
|| !layout->tileset_secondary || !layout->tileset_secondary->metatiles) {
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
int primary_length = tileset_primary->metatiles->length();
|
int primary_length = layout->tileset_primary->metatiles->length();
|
||||||
int length_ = primary_length + tileset_secondary->metatiles->length();
|
int length_ = primary_length + layout->tileset_secondary->metatiles->length();
|
||||||
int width_ = 8;
|
int width_ = 8;
|
||||||
int height_ = length_ / width_;
|
int height_ = length_ / width_;
|
||||||
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
|
@ -510,11 +507,11 @@ QPixmap Map::renderMetatiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block* Map::getBlock(int x, int y) {
|
Block* Map::getBlock(int x, int y) {
|
||||||
if (blockdata && blockdata->blocks) {
|
if (layout->blockdata && layout->blockdata->blocks) {
|
||||||
if (x >= 0 && x < getWidth())
|
if (x >= 0 && x < getWidth())
|
||||||
if (y >= 0 && y < getHeight()) {
|
if (y >= 0 && y < getHeight()) {
|
||||||
int i = y * getWidth() + x;
|
int i = y * getWidth() + x;
|
||||||
return new Block(blockdata->blocks->value(i));
|
return new Block(layout->blockdata->blocks->value(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -522,8 +519,8 @@ Block* Map::getBlock(int x, int y) {
|
||||||
|
|
||||||
void Map::_setBlock(int x, int y, Block block) {
|
void Map::_setBlock(int x, int y, Block block) {
|
||||||
int i = y * getWidth() + x;
|
int i = y * getWidth() + x;
|
||||||
if (blockdata && blockdata->blocks) {
|
if (layout->blockdata && layout->blockdata->blocks) {
|
||||||
blockdata->blocks->replace(i, block);
|
layout->blockdata->blocks->replace(i, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,29 +657,29 @@ void Map::_floodFillCollisionElevation(int x, int y, uint collision, uint elevat
|
||||||
|
|
||||||
|
|
||||||
void Map::undo() {
|
void Map::undo() {
|
||||||
if (blockdata) {
|
if (layout->blockdata) {
|
||||||
Blockdata *commit = history.back();
|
Blockdata *commit = history.back();
|
||||||
if (commit != NULL) {
|
if (commit != NULL) {
|
||||||
blockdata->copyFrom(commit);
|
layout->blockdata->copyFrom(commit);
|
||||||
emit mapChanged(this);
|
emit mapChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::redo() {
|
void Map::redo() {
|
||||||
if (blockdata) {
|
if (layout->blockdata) {
|
||||||
Blockdata *commit = history.next();
|
Blockdata *commit = history.next();
|
||||||
if (commit != NULL) {
|
if (commit != NULL) {
|
||||||
blockdata->copyFrom(commit);
|
layout->blockdata->copyFrom(commit);
|
||||||
emit mapChanged(this);
|
emit mapChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::commit() {
|
void Map::commit() {
|
||||||
if (blockdata) {
|
if (layout->blockdata) {
|
||||||
if (!blockdata->equals(history.current())) {
|
if (!layout->blockdata->equals(history.current())) {
|
||||||
Blockdata* commit = blockdata->copy();
|
Blockdata* commit = layout->blockdata->copy();
|
||||||
history.push(commit);
|
history.push(commit);
|
||||||
emit mapChanged(this);
|
emit mapChanged(this);
|
||||||
}
|
}
|
||||||
|
@ -752,7 +749,7 @@ void Map::addEvent(Event *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::hasUnsavedChanges() {
|
bool Map::hasUnsavedChanges() {
|
||||||
return !history.isSaved() || !isPersistedToFile;
|
return !history.isSaved() || !isPersistedToFile || layout->has_unsaved_changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredTileChanged(int x, int y, int block) {
|
void Map::hoveredTileChanged(int x, int y, int block) {
|
||||||
|
|
64
map.h
64
map.h
|
@ -68,6 +68,37 @@ public:
|
||||||
QString map_name;
|
QString map_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MapLayout {
|
||||||
|
public:
|
||||||
|
MapLayout() {}
|
||||||
|
int index;
|
||||||
|
QString name;
|
||||||
|
QString label;
|
||||||
|
QString width;
|
||||||
|
QString height;
|
||||||
|
QString border_label;
|
||||||
|
QString border_path;
|
||||||
|
QString blockdata_label;
|
||||||
|
QString blockdata_path;
|
||||||
|
QString tileset_primary_label;
|
||||||
|
QString tileset_secondary_label;
|
||||||
|
Tileset *tileset_primary = NULL;
|
||||||
|
Tileset *tileset_secondary = NULL;
|
||||||
|
Blockdata* blockdata = NULL;
|
||||||
|
QImage border_image;
|
||||||
|
QPixmap border_pixmap;
|
||||||
|
Blockdata *border = NULL;
|
||||||
|
Blockdata *cached_blockdata = NULL;
|
||||||
|
Blockdata *cached_collision = NULL;
|
||||||
|
Blockdata *cached_border = NULL;
|
||||||
|
bool has_unsaved_changes = false;
|
||||||
|
public:
|
||||||
|
static QString getNameFromLabel(QString label) {
|
||||||
|
// ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
|
||||||
|
return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Map : public QObject
|
class Map : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -78,12 +109,12 @@ public:
|
||||||
QString name;
|
QString name;
|
||||||
QString constantName;
|
QString constantName;
|
||||||
QString group_num;
|
QString group_num;
|
||||||
QString attributes_label;
|
QString layout_label;
|
||||||
QString events_label;
|
QString events_label;
|
||||||
QString scripts_label;
|
QString scripts_label;
|
||||||
QString connections_label;
|
QString connections_label;
|
||||||
QString song;
|
QString song;
|
||||||
QString index;
|
QString layout_id;
|
||||||
QString location;
|
QString location;
|
||||||
QString visibility;
|
QString visibility;
|
||||||
QString weather;
|
QString weather;
|
||||||
|
@ -91,18 +122,7 @@ public:
|
||||||
QString unknown;
|
QString unknown;
|
||||||
QString show_location;
|
QString show_location;
|
||||||
QString battle_scene;
|
QString battle_scene;
|
||||||
|
MapLayout *layout;
|
||||||
QString width;
|
|
||||||
QString height;
|
|
||||||
QString border_label;
|
|
||||||
QString blockdata_label;
|
|
||||||
QString tileset_primary_label;
|
|
||||||
QString tileset_secondary_label;
|
|
||||||
|
|
||||||
Tileset *tileset_primary = NULL;
|
|
||||||
Tileset *tileset_secondary = NULL;
|
|
||||||
|
|
||||||
Blockdata* blockdata = NULL;
|
|
||||||
|
|
||||||
bool isPersistedToFile = true;
|
bool isPersistedToFile = true;
|
||||||
|
|
||||||
|
@ -112,16 +132,16 @@ public:
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
Tileset* getBlockTileset(int);
|
Tileset* getBlockTileset(int);
|
||||||
int getBlockIndex(int index);
|
int getBlockIndex(int layout_id);
|
||||||
int getSelectedBlockIndex(int index);
|
int getSelectedBlockIndex(int layout_id);
|
||||||
int getDisplayedBlockIndex(int index);
|
int getDisplayedBlockIndex(int layout_id);
|
||||||
Metatile* getMetatile(int);
|
Metatile* getMetatile(int);
|
||||||
QImage getMetatileImage(int);
|
QImage getMetatileImage(int);
|
||||||
QImage getMetatileTile(int);
|
QImage getMetatileTile(int);
|
||||||
QPixmap render();
|
QPixmap render(bool ignoreCache);
|
||||||
QPixmap renderMetatiles();
|
QPixmap renderMetatiles();
|
||||||
|
|
||||||
QPixmap renderCollision();
|
QPixmap renderCollision(bool ignoreCache);
|
||||||
QImage collision_image;
|
QImage collision_image;
|
||||||
QPixmap collision_pixmap;
|
QPixmap collision_pixmap;
|
||||||
QImage getCollisionMetatileImage(Block);
|
QImage getCollisionMetatileImage(Block);
|
||||||
|
@ -134,9 +154,7 @@ public:
|
||||||
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
|
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
|
||||||
|
|
||||||
bool blockChanged(int, Blockdata*);
|
bool blockChanged(int, Blockdata*);
|
||||||
Blockdata* cached_blockdata = NULL;
|
|
||||||
void cacheBlockdata();
|
void cacheBlockdata();
|
||||||
Blockdata* cached_collision = NULL;
|
|
||||||
void cacheCollision();
|
void cacheCollision();
|
||||||
QImage image;
|
QImage image;
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
@ -185,10 +203,6 @@ public:
|
||||||
QList<QGraphicsPixmapItem*> connection_items;
|
QList<QGraphicsPixmapItem*> connection_items;
|
||||||
QPixmap renderConnection(Connection);
|
QPixmap renderConnection(Connection);
|
||||||
|
|
||||||
QImage border_image;
|
|
||||||
QPixmap border_pixmap;
|
|
||||||
Blockdata *border = NULL;
|
|
||||||
Blockdata *cached_border = NULL;
|
|
||||||
QPixmap renderBorder();
|
QPixmap renderBorder();
|
||||||
void cacheBorder();
|
void cacheBorder();
|
||||||
|
|
||||||
|
|
508
project.cpp
508
project.cpp
|
@ -49,10 +49,7 @@ Map* Project::loadMap(QString map_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
readMapHeader(map);
|
readMapHeader(map);
|
||||||
readMapAttributes(map);
|
readMapLayout(map);
|
||||||
getTilesets(map);
|
|
||||||
loadBlockdata(map);
|
|
||||||
loadMapBorder(map);
|
|
||||||
readMapEvents(map);
|
readMapEvents(map);
|
||||||
loadMapConnections(map);
|
loadMapConnections(map);
|
||||||
map->commit();
|
map->commit();
|
||||||
|
@ -136,9 +133,12 @@ QStringList* Project::getLabelValues(QList<QStringList> *list, QString label) {
|
||||||
QStringList params = list->value(i);
|
QStringList params = list->value(i);
|
||||||
QString macro = params.value(0);
|
QString macro = params.value(0);
|
||||||
// Ignore .align
|
// Ignore .align
|
||||||
if (macro == ".align") {
|
if (macro == ".align")
|
||||||
|
continue;
|
||||||
|
if (macro == ".ifdef")
|
||||||
|
continue;
|
||||||
|
if (macro == ".ifndef")
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
for (int j = 1; j < params.length(); j++) {
|
for (int j = 1; j < params.length(); j++) {
|
||||||
values->append(params.value(j));
|
values->append(params.value(j));
|
||||||
}
|
}
|
||||||
|
@ -159,12 +159,12 @@ void Project::readMapHeader(Map* map) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
|
QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
|
||||||
map->attributes_label = header->value(0);
|
map->layout_label = header->value(0);
|
||||||
map->events_label = header->value(1);
|
map->events_label = header->value(1);
|
||||||
map->scripts_label = header->value(2);
|
map->scripts_label = header->value(2);
|
||||||
map->connections_label = header->value(3);
|
map->connections_label = header->value(3);
|
||||||
map->song = header->value(4);
|
map->song = header->value(4);
|
||||||
map->index = header->value(5);
|
map->layout_id = header->value(5);
|
||||||
map->location = header->value(6);
|
map->location = header->value(6);
|
||||||
map->visibility = header->value(7);
|
map->visibility = header->value(7);
|
||||||
map->weather = header->value(8);
|
map->weather = header->value(8);
|
||||||
|
@ -175,12 +175,12 @@ void Project::readMapHeader(Map* map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::setNewMapHeader(Map* map, int mapIndex) {
|
void Project::setNewMapHeader(Map* map, int mapIndex) {
|
||||||
map->attributes_label = QString("%1_MapAttributes").arg(map->name);
|
map->layout_label = QString("%1_Layout").arg(map->name);
|
||||||
map->events_label = QString("%1_MapEvents").arg(map->name);;
|
map->events_label = QString("%1_MapEvents").arg(map->name);;
|
||||||
map->scripts_label = QString("%1_MapScripts").arg(map->name);;
|
map->scripts_label = QString("%1_MapScripts").arg(map->name);;
|
||||||
map->connections_label = "0x0";
|
map->connections_label = "0x0";
|
||||||
map->song = "BGM_DAN02";
|
map->song = "MUS_DAN02";
|
||||||
map->index = QString("%1").arg(mapIndex);
|
map->layout_id = QString("%1").arg(mapIndex);
|
||||||
map->location = "0";
|
map->location = "0";
|
||||||
map->visibility = "0";
|
map->visibility = "0";
|
||||||
map->weather = "2";
|
map->weather = "2";
|
||||||
|
@ -195,7 +195,7 @@ void Project::saveMapHeader(Map *map) {
|
||||||
QString header_path = root + "/data/maps/" + label + "/header.inc";
|
QString header_path = root + "/data/maps/" + label + "/header.inc";
|
||||||
QString text = "";
|
QString text = "";
|
||||||
text += QString("%1::\n").arg(label);
|
text += QString("%1::\n").arg(label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
text += QString("\t.4byte %1\n").arg(map->layout_label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->events_label);
|
text += QString("\t.4byte %1\n").arg(map->events_label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ void Project::saveMapHeader(Map *map) {
|
||||||
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
||||||
|
|
||||||
text += QString("\t.2byte %1\n").arg(map->song);
|
text += QString("\t.2byte %1\n").arg(map->song);
|
||||||
text += QString("\t.2byte %1\n").arg(map->index);
|
text += QString("\t.2byte %1\n").arg(map->layout_id);
|
||||||
text += QString("\t.byte %1\n").arg(map->location);
|
text += QString("\t.byte %1\n").arg(map->location);
|
||||||
text += QString("\t.byte %1\n").arg(map->visibility);
|
text += QString("\t.byte %1\n").arg(map->visibility);
|
||||||
text += QString("\t.byte %1\n").arg(map->weather);
|
text += QString("\t.byte %1\n").arg(map->weather);
|
||||||
|
@ -260,269 +260,180 @@ void Project::updateMapsWithConnections(Map *map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapAttributesTable() {
|
void Project::readMapLayoutsTable() {
|
||||||
int curMapIndex = 1;
|
int curIndex = 1;
|
||||||
QString attributesText = readTextFile(getMapAttributesTableFilepath());
|
QString layoutsText = readTextFile(getMapLayoutsTableFilepath());
|
||||||
QList<QStringList>* values = parseAsm(attributesText);
|
QList<QStringList>* values = parseAsm(layoutsText);
|
||||||
bool inAttributePointers = false;
|
bool inLayoutPointers = false;
|
||||||
for (int i = 0; i < values->length(); i++) {
|
for (int i = 0; i < values->length(); i++) {
|
||||||
QStringList params = values->value(i);
|
QStringList params = values->value(i);
|
||||||
QString macro = params.value(0);
|
QString macro = params.value(0);
|
||||||
if (macro == ".label") {
|
if (macro == ".label") {
|
||||||
if (inAttributePointers) {
|
if (inLayoutPointers) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (params.value(1) == "gMapAttributes") {
|
if (params.value(1) == "gMapLayouts") {
|
||||||
inAttributePointers = true;
|
inLayoutPointers = true;
|
||||||
}
|
}
|
||||||
} else if (macro == ".4byte" && inAttributePointers) {
|
} else if (macro == ".4byte" && inLayoutPointers) {
|
||||||
QString mapName = params.value(1);
|
QString layoutName = params.value(1);
|
||||||
if (!mapName.contains("UnknownMapAttributes")) {
|
mapLayoutsTable.append(layoutName);
|
||||||
// Strip off "_MapAttributes" from the label if it's a real map label.
|
|
||||||
mapName = mapName.remove(mapName.length() - 14, 14);
|
|
||||||
}
|
|
||||||
mapAttributesTable.insert(curMapIndex, mapName);
|
|
||||||
curMapIndex++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep copy
|
// Deep copy
|
||||||
mapAttributesTableMaster = mapAttributesTable;
|
mapLayoutsTableMaster = mapLayoutsTable;
|
||||||
mapAttributesTableMaster.detach();
|
mapLayoutsTableMaster.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapAttributesTable() {
|
void Project::saveMapLayoutsTable() {
|
||||||
QString text = "";
|
QString text = "";
|
||||||
text += QString("\t.align 2\n");
|
text += QString("\t.align 2\n");
|
||||||
text += QString("gMapAttributes::\n");
|
text += QString("gMapLayouts::\n");
|
||||||
for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
for (QString layoutName : mapLayoutsTableMaster) {
|
||||||
int mapIndex = i + 1;
|
text += QString("\t.4byte %1\n").arg(layoutName);
|
||||||
QString mapName = mapAttributesTableMaster.value(mapIndex);
|
|
||||||
if (!mapName.contains("UnknownMapAttributes")) {
|
|
||||||
text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
|
|
||||||
} else {
|
|
||||||
text += QString("\t.4byte %1\n").arg(mapName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
saveTextFile(getMapAttributesTableFilepath(), text);
|
saveTextFile(getMapLayoutsTableFilepath(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getMapAttributesTableFilepath() {
|
QString Project::getMapLayoutsTableFilepath() {
|
||||||
return QString("%1/data/maps/attributes_table.inc").arg(root);
|
return QString("%1/data/layouts_table.inc").arg(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapAttributes(Map* map) {
|
QStringList* Project::readLayoutValues(QString layoutLabel) {
|
||||||
|
ParseUtil *parser = new ParseUtil;
|
||||||
|
|
||||||
|
QString layoutText = readTextFile(getMapLayoutFilepath(layoutLabel));
|
||||||
|
if (layoutText.isNull()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList *layoutValues = getLabelValues(parser->parseAsm(layoutText), layoutLabel);
|
||||||
|
QString borderLabel = layoutValues->value(2);
|
||||||
|
QString blockdataLabel = layoutValues->value(3);
|
||||||
|
QStringList *borderValues = getLabelValues(parser->parseAsm(layoutText), borderLabel);
|
||||||
|
QString borderPath = borderValues->value(0).replace("\"", "");
|
||||||
|
layoutValues->append(borderPath);
|
||||||
|
QStringList *blockdataValues = getLabelValues(parser->parseAsm(layoutText), blockdataLabel);
|
||||||
|
QString blockdataPath = blockdataValues->value(0).replace("\"", "");
|
||||||
|
layoutValues->append(blockdataPath);
|
||||||
|
|
||||||
|
if (layoutValues->size() != 8) {
|
||||||
|
qDebug() << "Error: Unexpected number of properties in layout '" << layoutLabel << "'";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return layoutValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::readMapLayout(Map* map) {
|
||||||
if (!map->isPersistedToFile) {
|
if (!map->isPersistedToFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseUtil *parser = new ParseUtil;
|
MapLayout *layout;
|
||||||
|
if (!mapLayouts.contains(map->layout_label)) {
|
||||||
|
QStringList *layoutValues = readLayoutValues(map->layout->label);
|
||||||
|
if (layoutValues == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString assets_text = readTextFile(getMapAssetsFilepath());
|
layout = new MapLayout();
|
||||||
if (assets_text.isNull()) {
|
mapLayouts.insert(map->layout_label, layout);
|
||||||
return;
|
layout->name = MapLayout::getNameFromLabel(map->layout_label);
|
||||||
|
layout->label = map->layout_label;
|
||||||
|
layout->width = layoutValues->value(0);
|
||||||
|
layout->height = layoutValues->value(1);
|
||||||
|
layout->border_label = layoutValues->value(2);
|
||||||
|
layout->blockdata_label = layoutValues->value(3);
|
||||||
|
layout->tileset_primary_label = layoutValues->value(4);
|
||||||
|
layout->tileset_secondary_label = layoutValues->value(5);
|
||||||
|
layout->border_path = layoutValues->value(6);
|
||||||
|
layout->blockdata_path = layoutValues->value(7);
|
||||||
|
map->layout = layout;
|
||||||
|
} else {
|
||||||
|
map->layout = mapLayouts[map->layout_label];
|
||||||
}
|
}
|
||||||
QStringList *attributes = getLabelValues(parser->parseAsm(assets_text), map->attributes_label);
|
|
||||||
map->width = attributes->value(0);
|
getTilesets(map);
|
||||||
map->height = attributes->value(1);
|
loadBlockdata(map);
|
||||||
map->border_label = attributes->value(2);
|
loadMapBorder(map);
|
||||||
map->blockdata_label = attributes->value(3);
|
|
||||||
map->tileset_primary_label = attributes->value(4);
|
|
||||||
map->tileset_secondary_label = attributes->value(5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readAllMapAttributes() {
|
void Project::readAllMapLayouts() {
|
||||||
mapAttributes.clear();
|
mapLayouts.clear();
|
||||||
|
|
||||||
ParseUtil *parser = new ParseUtil;
|
for (int i = 0; i < mapLayoutsTable.size(); i++) {
|
||||||
QString assets_text = readTextFile(getMapAssetsFilepath());
|
QString layoutLabel = mapLayoutsTable[i];
|
||||||
if (assets_text.isNull()) {
|
QStringList *layoutValues = readLayoutValues(layoutLabel);
|
||||||
return;
|
if (layoutValues == NULL) {
|
||||||
}
|
return;
|
||||||
|
|
||||||
QList<QStringList> *commands = parser->parseAsm(assets_text);
|
|
||||||
|
|
||||||
// Assume the _assets.inc file is grouped consistently in the order of:
|
|
||||||
// 1. <map_name>_MapBorder
|
|
||||||
// 2. <map_name>_MapBlockdata
|
|
||||||
// 3. <map_name>_MapAttributes
|
|
||||||
int i = 0;
|
|
||||||
while (i < commands->length()) {
|
|
||||||
// Read MapBorder assets.
|
|
||||||
QStringList borderParams = commands->value(i++);
|
|
||||||
bool isUnknownMapBorder = borderParams.value(1).startsWith("UnknownMapBorder_");
|
|
||||||
if (borderParams.value(0) != ".label" || (!borderParams.value(1).endsWith("_MapBorder") && !isUnknownMapBorder)) {
|
|
||||||
qDebug() << QString("Expected MapBorder label, but found %1").arg(borderParams.value(1));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QString borderLabel = borderParams.value(1);
|
|
||||||
QString mapName;
|
|
||||||
if (!isUnknownMapBorder) {
|
|
||||||
mapName = borderLabel.remove(borderLabel.length() - 10, 10);
|
|
||||||
} else {
|
|
||||||
// Unknown map name has to match the MapAttributes label.
|
|
||||||
mapName = borderLabel.replace("Border", "Attributes");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mapAttributes[mapName].insert("border_label", borderParams.value(1));
|
MapLayout *layout = new MapLayout();
|
||||||
borderParams = commands->value(i++);
|
layout->name = MapLayout::getNameFromLabel(layoutLabel);
|
||||||
mapAttributes[mapName].insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
layout->label = layoutLabel;
|
||||||
|
layout->index = i;
|
||||||
// Read MapBlockData assets.
|
layout->width = layoutValues->value(0);
|
||||||
QStringList blockDataParams = commands->value(i++);
|
layout->height = layoutValues->value(1);
|
||||||
bool isUnknownMapBlockdata = blockDataParams.value(1).startsWith("UnknownMapBlockdata_");
|
layout->border_label = layoutValues->value(2);
|
||||||
if (blockDataParams.value(0) != ".label" || (!blockDataParams.value(1).endsWith("_MapBlockdata") && !isUnknownMapBlockdata)) {
|
layout->blockdata_label = layoutValues->value(3);
|
||||||
qDebug() << QString("Expected MapBlockdata label, but found %1").arg(blockDataParams.value(1));
|
layout->tileset_primary_label = layoutValues->value(4);
|
||||||
continue;
|
layout->tileset_secondary_label = layoutValues->value(5);
|
||||||
}
|
layout->border_path = layoutValues->value(6);
|
||||||
QString blockDataLabel = blockDataParams.value(1);
|
layout->blockdata_path = layoutValues->value(7);
|
||||||
mapAttributes[mapName].insert("blockdata_label", blockDataLabel);
|
mapLayouts.insert(layoutLabel, layout);
|
||||||
blockDataParams = commands->value(i++);
|
|
||||||
mapAttributes[mapName].insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
|
||||||
|
|
||||||
// Read MapAttributes assets.
|
|
||||||
i++; // skip .align
|
|
||||||
// Maps can share MapAttributes, so gather a list of them.
|
|
||||||
QStringList attributeMapLabels;
|
|
||||||
QStringList attributesParams;
|
|
||||||
QStringList* sharedAttrMaps = new QStringList;
|
|
||||||
while (i < commands->length()) {
|
|
||||||
attributesParams = commands->value(i);
|
|
||||||
if (attributesParams.value(0) != ".label") {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
QString attrLabel = attributesParams.value(1);
|
|
||||||
attributeMapLabels.append(attrLabel);
|
|
||||||
sharedAttrMaps->append(attrLabel);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the map attributes to each of the shared maps.
|
|
||||||
QString attrWidth = commands->value(i++).value(1);
|
|
||||||
QString attrHeight = commands->value(i++).value(1);
|
|
||||||
QString attrBorderLabel = commands->value(i++).value(1);
|
|
||||||
QString attrBlockdataLabel = commands->value(i++).value(1);
|
|
||||||
QString attrTilesetPrimary = commands->value(i++).value(1);
|
|
||||||
QString attrTilesetSecondary = commands->value(i++).value(1);
|
|
||||||
for (QString attributeMapLabel: attributeMapLabels) {
|
|
||||||
QString altMapName = attributeMapLabel;
|
|
||||||
if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
|
||||||
altMapName.remove(altMapName.length() - 14, 14);
|
|
||||||
}
|
|
||||||
if (!mapAttributes.contains(altMapName)) {
|
|
||||||
mapAttributes.insert(altMapName, QMap<QString, QString>());
|
|
||||||
}
|
|
||||||
mapAttributes[altMapName].insert("attributes_label", attributeMapLabel);
|
|
||||||
mapAttributes[altMapName].insert("width", attrWidth);
|
|
||||||
mapAttributes[altMapName].insert("height", attrHeight);
|
|
||||||
mapAttributes[altMapName].insert("border_label", attrBorderLabel);
|
|
||||||
mapAttributes[altMapName].insert("blockdata_label", attrBlockdataLabel);
|
|
||||||
mapAttributes[altMapName].insert("tileset_primary", attrTilesetPrimary);
|
|
||||||
mapAttributes[altMapName].insert("tileset_secondary", attrTilesetSecondary);
|
|
||||||
|
|
||||||
if (sharedAttrMaps->length() > 1) {
|
|
||||||
mapAttributes[altMapName].insert("shared_attr_maps", sharedAttrMaps->join(":"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep copy
|
// Deep copy
|
||||||
mapAttributesMaster = mapAttributes;
|
mapLayoutsMaster = mapLayouts;
|
||||||
mapAttributesMaster.detach();
|
mapLayoutsMaster.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveAllMapAttributes() {
|
void Project::saveAllMapLayouts() {
|
||||||
QString text = "";
|
for (QString layoutName : mapLayoutsTableMaster) {
|
||||||
for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
MapLayout *layout = mapLayouts.value(layoutName);
|
||||||
int mapIndex = i + 1;
|
QString text = QString("%1::\n").arg(layout->border_label);
|
||||||
QString mapName = mapAttributesTableMaster.value(mapIndex);
|
text += QString("\t.incbin \"%1\"\n").arg(layout->border_path);
|
||||||
QMap<QString, QString> attrs = mapAttributesMaster.value(mapName);
|
|
||||||
|
|
||||||
// Find the map attributes object that contains the border data.
|
|
||||||
QMap<QString, QString> attrsWithBorder;
|
|
||||||
if (attrs.contains("border_filepath")) {
|
|
||||||
attrsWithBorder = attrs;
|
|
||||||
} else {
|
|
||||||
QStringList labels = attrs.value("shared_attr_maps").split(":");
|
|
||||||
for (QString label : labels) {
|
|
||||||
label.remove(label.length() - 14, 14);
|
|
||||||
if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("border_filepath")) {
|
|
||||||
attrsWithBorder = mapAttributesMaster.value(label);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!attrsWithBorder.isEmpty()) {
|
|
||||||
text += QString("%1::\n").arg(attrsWithBorder.value("border_label"));
|
|
||||||
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("border_filepath"));
|
|
||||||
text += QString("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the map attributes object that contains the blockdata.
|
|
||||||
QMap<QString, QString> attrsWithBlockdata;
|
|
||||||
if (attrs.contains("blockdata_filepath")) {
|
|
||||||
attrsWithBlockdata = attrs;
|
|
||||||
} else {
|
|
||||||
QStringList labels = attrs["shared_attr_maps"].split(":");
|
|
||||||
for (QString label : labels) {
|
|
||||||
label.remove(label.length() - 14, 14);
|
|
||||||
if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("blockdata_filepath")) {
|
|
||||||
attrsWithBlockdata = mapAttributesMaster.value(label);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!attrsWithBlockdata.isEmpty()) {
|
|
||||||
text += QString("%1::\n").arg(attrsWithBlockdata.value("blockdata_label"));
|
|
||||||
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("blockdata_filepath"));
|
|
||||||
text += QString("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
text += QString("\t.align 2\n");
|
|
||||||
if (attrs.contains("shared_attr_maps")) {
|
|
||||||
QStringList labels = attrs.value("shared_attr_maps").split(":");
|
|
||||||
for (QString label : labels) {
|
|
||||||
text += QString("%1::\n").arg(label);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
text += QString("%1::\n").arg(attrs.value("attributes_label"));
|
|
||||||
}
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("width"));
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("height"));
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("border_label"));
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("blockdata_label"));
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("tileset_primary"));
|
|
||||||
text += QString("\t.4byte %1\n").arg(attrs.value("tileset_secondary"));
|
|
||||||
text += QString("\n");
|
text += QString("\n");
|
||||||
|
text += QString("%1::\n").arg(layout->blockdata_label);
|
||||||
|
text += QString("\t.incbin \"%1\"\n").arg(layout->blockdata_path);
|
||||||
|
text += QString("\n");
|
||||||
|
text += QString("\t.align 2\n");
|
||||||
|
text += QString("%1::\n").arg(layoutName);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->width);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->height);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->border_label);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->blockdata_label);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->tileset_primary_label);
|
||||||
|
text += QString("\t.4byte %1\n").arg(layout->tileset_secondary_label);
|
||||||
|
text += QString("\n");
|
||||||
|
saveTextFile(getMapLayoutFilepath(layout->label), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTextFile(getMapAssetsFilepath(), text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getMapAssetsFilepath() {
|
QString Project::getMapLayoutFilepath(QString layoutLabel) {
|
||||||
return root + "/data/maps/_assets.inc";
|
return QString("%1/data/layouts/%2/layout.inc").arg(root).arg(MapLayout::getNameFromLabel(layoutLabel));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::setNewMapAttributes(Map* map) {
|
void Project::setNewMapLayout(Map* map) {
|
||||||
map->width = "20";
|
MapLayout *layout = new MapLayout();
|
||||||
map->height = "20";
|
layout->label = QString("%1_Layout").arg(map->name);
|
||||||
map->border_label = QString("%1_MapBorder").arg(map->name);
|
layout->name = MapLayout::getNameFromLabel(layout->label);
|
||||||
map->blockdata_label = QString("%1_MapBlockdata").arg(map->name);
|
layout->width = "20";
|
||||||
map->tileset_primary_label = "gTileset_General";
|
layout->height = "20";
|
||||||
map->tileset_secondary_label = "gTileset_Petalburg";
|
layout->border_label = QString("%1_MapBorder").arg(map->name);
|
||||||
|
layout->border_path = QString("data/layouts/%1/border.bin").arg(map->name);
|
||||||
|
layout->blockdata_label = QString("%1_MapBlockdata").arg(map->name);
|
||||||
|
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(map->name);
|
||||||
|
layout->tileset_primary_label = "gTileset_General";
|
||||||
|
layout->tileset_secondary_label = "gTileset_Petalburg";
|
||||||
|
map->layout = layout;
|
||||||
|
map->layout_label = layout->label;
|
||||||
|
|
||||||
// Insert new entry into the global map attributes.
|
// Insert new entry into the global map layouts.
|
||||||
QMap<QString, QString> attrs;
|
mapLayouts.insert(layout->label, layout);
|
||||||
attrs.insert("border_label", QString("%1_MapBorder").arg(map->name));
|
mapLayoutsTable.append(layout->label);
|
||||||
attrs.insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
|
|
||||||
attrs.insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
|
|
||||||
attrs.insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
|
|
||||||
attrs.insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
|
|
||||||
attrs.insert("width", map->width);
|
|
||||||
attrs.insert("height", map->height);
|
|
||||||
attrs.insert("tileset_primary", map->tileset_primary_label);
|
|
||||||
attrs.insert("tileset_secondary", map->tileset_secondary_label);
|
|
||||||
mapAttributes.insert(map->name, attrs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapGroupsTable() {
|
void Project::saveMapGroupsTable() {
|
||||||
|
@ -544,7 +455,7 @@ void Project::saveMapGroupsTable() {
|
||||||
text += QString("\t.4byte gMapGroup%1\n").arg(i);
|
text += QString("\t.4byte gMapGroup%1\n").arg(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTextFile(root + "/data/maps/_groups.inc", text);
|
saveTextFile(root + "/data/maps/groups.inc", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapConstantsHeader() {
|
void Project::saveMapConstantsHeader() {
|
||||||
|
@ -585,8 +496,12 @@ void Project::saveMapConstantsHeader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::getTilesets(Map* map) {
|
void Project::getTilesets(Map* map) {
|
||||||
map->tileset_primary = getTileset(map->tileset_primary_label);
|
if (map->layout->has_unsaved_changes) {
|
||||||
map->tileset_secondary = getTileset(map->tileset_secondary_label);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
map->layout->tileset_primary = getTileset(map->layout->tileset_primary_label);
|
||||||
|
map->layout->tileset_secondary = getTileset(map->layout->tileset_secondary_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset* Project::loadTileset(QString label) {
|
Tileset* Project::loadTileset(QString label) {
|
||||||
|
@ -611,37 +526,13 @@ Tileset* Project::loadTileset(QString label) {
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getBlockdataPath(Map* map) {
|
|
||||||
QString text = readTextFile(getMapAssetsFilepath());
|
|
||||||
QStringList *values = getLabelValues(parseAsm(text), map->blockdata_label);
|
|
||||||
QString path;
|
|
||||||
if (!values->isEmpty()) {
|
|
||||||
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
||||||
} else {
|
|
||||||
path = root + "/data/maps/" + map->name + "/map.bin";
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Project::getMapBorderPath(Map *map) {
|
|
||||||
QString text = readTextFile(getMapAssetsFilepath());
|
|
||||||
QStringList *values = getLabelValues(parseAsm(text), map->border_label);
|
|
||||||
QString path;
|
|
||||||
if (!values->isEmpty()) {
|
|
||||||
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
||||||
} else {
|
|
||||||
path = root + "/data/maps/" + map->name + "/border.bin";
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Project::loadBlockdata(Map* map) {
|
void Project::loadBlockdata(Map* map) {
|
||||||
if (!map->isPersistedToFile) {
|
if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = getBlockdataPath(map);
|
QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
|
||||||
map->blockdata = readBlockdata(path);
|
map->layout->blockdata = readBlockdata(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::setNewMapBlockdata(Map* map) {
|
void Project::setNewMapBlockdata(Map* map) {
|
||||||
|
@ -649,16 +540,16 @@ void Project::setNewMapBlockdata(Map* map) {
|
||||||
for (int i = 0; i < map->getWidth() * map->getHeight(); i++) {
|
for (int i = 0; i < map->getWidth() * map->getHeight(); i++) {
|
||||||
blockdata->addBlock(qint16(0x3001));
|
blockdata->addBlock(qint16(0x3001));
|
||||||
}
|
}
|
||||||
map->blockdata = blockdata;
|
map->layout->blockdata = blockdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::loadMapBorder(Map *map) {
|
void Project::loadMapBorder(Map *map) {
|
||||||
if (!map->isPersistedToFile) {
|
if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = getMapBorderPath(map);
|
QString path = QString("%1/%2").arg(root).arg(map->layout->border_path);
|
||||||
map->border = readBlockdata(path);
|
map->layout->border = readBlockdata(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::setNewMapBorder(Map *map) {
|
void Project::setNewMapBorder(Map *map) {
|
||||||
|
@ -667,17 +558,17 @@ void Project::setNewMapBorder(Map *map) {
|
||||||
blockdata->addBlock(qint16(0x01D5));
|
blockdata->addBlock(qint16(0x01D5));
|
||||||
blockdata->addBlock(qint16(0x01DC));
|
blockdata->addBlock(qint16(0x01DC));
|
||||||
blockdata->addBlock(qint16(0x01DD));
|
blockdata->addBlock(qint16(0x01DD));
|
||||||
map->border = blockdata;
|
map->layout->border = blockdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapBorder(Map *map) {
|
void Project::saveMapBorder(Map *map) {
|
||||||
QString path = getMapBorderPath(map);
|
QString path = QString("%1/%2").arg(root).arg(map->layout->border_path);
|
||||||
writeBlockdata(path, map->border);
|
writeBlockdata(path, map->layout->border);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveBlockdata(Map* map) {
|
void Project::saveBlockdata(Map* map) {
|
||||||
QString path = getBlockdataPath(map);
|
QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
|
||||||
writeBlockdata(path, map->blockdata);
|
writeBlockdata(path, map->layout->blockdata);
|
||||||
map->history.save();
|
map->history.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,6 +577,8 @@ void Project::writeBlockdata(QString path, Blockdata *blockdata) {
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
QByteArray data = blockdata->serialize();
|
QByteArray data = blockdata->serialize();
|
||||||
file.write(data);
|
file.write(data);
|
||||||
|
} else {
|
||||||
|
qDebug() << "Failed to open blockdata file for writing: '" << path << "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,26 +599,35 @@ void Project::saveMap(Map *map) {
|
||||||
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: In the future, these files needs more structure to allow for proper parsing/saving.
|
QString newLayoutDir = QString(root + "/data/layouts/%1").arg(map->name);
|
||||||
// Create file data/scripts/maps/<map_name>.inc
|
if (!QDir::root().mkdir(newLayoutDir)) {
|
||||||
QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
|
qDebug() << "Error: failed to create directory for new layout. " << newLayoutDir;
|
||||||
saveTextFile(root + "/data/scripts/maps/" + map->name + ".inc", text);
|
}
|
||||||
|
|
||||||
// Create file data/text/maps/<map_name>.inc
|
// TODO: In the future, these files needs more structure to allow for proper parsing/saving.
|
||||||
saveTextFile(root + "/data/text/maps/" + map->name + ".inc", "\n");
|
// Create file data/maps/<map_name>/scripts.inc
|
||||||
|
QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
|
||||||
|
saveTextFile(root + "/data/maps/" + map->name + "/scripts.inc", text);
|
||||||
|
|
||||||
|
// Create file data/maps/<map_name>/text.inc
|
||||||
|
saveTextFile(root + "/data/maps/" + map->name + "/text.inc", "\n");
|
||||||
|
|
||||||
// Simply append to data/event_scripts.s.
|
// Simply append to data/event_scripts.s.
|
||||||
text = QString("\n\t.include \"data/scripts/maps/%1.inc\"\n").arg(map->name);
|
text = QString("\n\t.include \"data/maps/%1/scripts.inc\"\n").arg(map->name);
|
||||||
text += QString("\t.include \"data/text/maps/%1.inc\"\n").arg(map->name);
|
text += QString("\t.include \"data/maps/%1/text.inc\"\n").arg(map->name);
|
||||||
appendTextFile(root + "/data/event_scripts.s", text);
|
appendTextFile(root + "/data/event_scripts.s", text);
|
||||||
|
|
||||||
// Simply append to data/map_events.s.
|
// Simply append to data/map_events.s.
|
||||||
text = QString("\n\t.include \"data/maps/events/%1.inc\"\n").arg(map->name);
|
text = QString("\n\t.include \"data/maps/%1/events.inc\"\n").arg(map->name);
|
||||||
appendTextFile(root + "/data/map_events.s", text);
|
appendTextFile(root + "/data/map_events.s", text);
|
||||||
|
|
||||||
// Simply append to data/maps/headers.inc.
|
// Simply append to data/maps/headers.inc.
|
||||||
text = QString("\t.include \"data/maps/%1/header.inc\"\n").arg(map->name);
|
text = QString("\t.include \"data/maps/%1/header.inc\"\n").arg(map->name);
|
||||||
appendTextFile(root + "/data/maps/headers.inc", text);
|
appendTextFile(root + "/data/maps/headers.inc", text);
|
||||||
|
|
||||||
|
// Simply append to data/layouts.inc.
|
||||||
|
text = QString("\t.include \"data/layouts/%1/layout.inc\"\n").arg(map->layout->name);
|
||||||
|
appendTextFile(root + "/data/layouts.inc", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMapBorder(map);
|
saveMapBorder(map);
|
||||||
|
@ -735,25 +637,27 @@ void Project::saveMap(Map *map) {
|
||||||
saveMapEvents(map);
|
saveMapEvents(map);
|
||||||
|
|
||||||
// Update global data structures with current map data.
|
// Update global data structures with current map data.
|
||||||
updateMapAttributes(map);
|
updateMapLayout(map);
|
||||||
|
|
||||||
map->isPersistedToFile = true;
|
map->isPersistedToFile = true;
|
||||||
|
map->layout->has_unsaved_changes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::updateMapAttributes(Map* map) {
|
void Project::updateMapLayout(Map* map) {
|
||||||
if (!mapAttributesTableMaster.contains(map->index.toInt())) {
|
if (!mapLayoutsTableMaster.contains(map->layout_label)) {
|
||||||
mapAttributesTableMaster.insert(map->index.toInt(), map->name);
|
mapLayoutsTableMaster.append(map->layout_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep copy
|
// Deep copy
|
||||||
QMap<QString, QString> attrs = mapAttributes.value(map->name);
|
MapLayout *layout = mapLayouts.value(map->layout_label);
|
||||||
attrs.detach();
|
MapLayout *newLayout = new MapLayout();
|
||||||
mapAttributesMaster.insert(map->name, attrs);
|
*newLayout = *layout;
|
||||||
|
mapLayoutsMaster.insert(map->layout_label, newLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveAllDataStructures() {
|
void Project::saveAllDataStructures() {
|
||||||
saveMapAttributesTable();
|
saveMapLayoutsTable();
|
||||||
saveAllMapAttributes();
|
saveAllMapLayouts();
|
||||||
saveMapGroupsTable();
|
saveMapGroupsTable();
|
||||||
saveMapConstantsHeader();
|
saveMapConstantsHeader();
|
||||||
saveMapsWithConnections();
|
saveMapsWithConnections();
|
||||||
|
@ -828,7 +732,6 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
tileset->tiles = tiles;
|
tileset->tiles = tiles;
|
||||||
|
|
||||||
// metatiles
|
// metatiles
|
||||||
//qDebug() << metatiles_path;
|
|
||||||
QFile metatiles_file(metatiles_path);
|
QFile metatiles_file(metatiles_path);
|
||||||
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray data = metatiles_file.readAll();
|
QByteArray data = metatiles_file.readAll();
|
||||||
|
@ -895,9 +798,9 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
for (int j = 0; j < 16; j++) {
|
for (int j = 0; j < 16; j++) {
|
||||||
palette.append(qRgb(j * 16, j * 16, j * 16));
|
palette.append(qRgb(j * 16, j * 16, j * 16));
|
||||||
}
|
}
|
||||||
qDebug() << QString("Could not open '%1'").arg(path);
|
qDebug() << QString("Could not open palette path '%1'").arg(path);
|
||||||
}
|
}
|
||||||
//qDebug() << path;
|
|
||||||
palettes->append(palette);
|
palettes->append(palette);
|
||||||
}
|
}
|
||||||
tileset->palettes = palettes;
|
tileset->palettes = palettes;
|
||||||
|
@ -905,7 +808,6 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
|
|
||||||
Blockdata* Project::readBlockdata(QString path) {
|
Blockdata* Project::readBlockdata(QString path) {
|
||||||
Blockdata *blockdata = new Blockdata;
|
Blockdata *blockdata = new Blockdata;
|
||||||
//qDebug() << path;
|
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray data = file.readAll();
|
QByteArray data = file.readAll();
|
||||||
|
@ -913,7 +815,10 @@ Blockdata* Project::readBlockdata(QString path) {
|
||||||
uint16_t word = (data[i] & 0xff) + ((data[i + 1] & 0xff) << 8);
|
uint16_t word = (data[i] & 0xff) + ((data[i + 1] & 0xff) << 8);
|
||||||
blockdata->addBlock(word);
|
blockdata->addBlock(word);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Failed to open blockdata path '" << path << "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
return blockdata;
|
return blockdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,7 +881,7 @@ void Project::deleteFile(QString path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapGroups() {
|
void Project::readMapGroups() {
|
||||||
QString text = readTextFile(root + "/data/maps/_groups.inc");
|
QString text = readTextFile(root + "/data/maps/groups.inc");
|
||||||
if (text.isNull()) {
|
if (text.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1039,9 +944,6 @@ void Project::readMapGroups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
int mapIndex = mapAttributesTable.count() + 1;
|
|
||||||
mapAttributesTable.insert(mapIndex, mapName);
|
|
||||||
|
|
||||||
// Setup new map in memory, but don't write to file until map is actually saved later.
|
// Setup new map in memory, but don't write to file until map is actually saved later.
|
||||||
mapNames->append(mapName);
|
mapNames->append(mapName);
|
||||||
map_groups->insert(mapName, groupNum);
|
map_groups->insert(mapName, groupNum);
|
||||||
|
@ -1052,8 +954,8 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
map->setName(mapName);
|
map->setName(mapName);
|
||||||
mapConstantsToMapNames->insert(map->constantName, map->name);
|
mapConstantsToMapNames->insert(map->constantName, map->name);
|
||||||
mapNamesToMapConstants->insert(map->name, map->constantName);
|
mapNamesToMapConstants->insert(map->name, map->constantName);
|
||||||
setNewMapHeader(map, mapIndex);
|
setNewMapHeader(map, mapLayoutsTable.size() + 1);
|
||||||
setNewMapAttributes(map);
|
setNewMapLayout(map);
|
||||||
getTilesets(map);
|
getTilesets(map);
|
||||||
setNewMapBlockdata(map);
|
setNewMapBlockdata(map);
|
||||||
setNewMapBorder(map);
|
setNewMapBorder(map);
|
||||||
|
@ -1200,7 +1102,7 @@ QStringList Project::getSongNames() {
|
||||||
QString text = readTextFile(root + "/include/constants/songs.h");
|
QString text = readTextFile(root + "/include/constants/songs.h");
|
||||||
if (!text.isNull()) {
|
if (!text.isNull()) {
|
||||||
QStringList songDefinePrefixes;
|
QStringList songDefinePrefixes;
|
||||||
songDefinePrefixes << "SE_" << "BGM_";
|
songDefinePrefixes << "SE_" << "MUS_";
|
||||||
QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
|
QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
|
||||||
names = songDefines.keys();
|
names = songDefines.keys();
|
||||||
}
|
}
|
||||||
|
@ -1283,7 +1185,7 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapEvents(Map *map) {
|
void Project::saveMapEvents(Map *map) {
|
||||||
QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
|
||||||
QString text = "";
|
QString text = "";
|
||||||
|
|
||||||
if (map->events["object"].length() > 0) {
|
if (map->events["object"].length() > 0) {
|
||||||
|
@ -1397,7 +1299,7 @@ void Project::readMapEvents(Map *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lazy
|
// lazy
|
||||||
QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
|
||||||
QString text = readTextFile(path);
|
QString text = readTextFile(path);
|
||||||
if (text.isNull()) {
|
if (text.isNull()) {
|
||||||
return;
|
return;
|
||||||
|
|
29
project.h
29
project.h
|
@ -19,10 +19,10 @@ public:
|
||||||
QStringList *mapNames = NULL;
|
QStringList *mapNames = NULL;
|
||||||
QMap<QString, QString>* mapConstantsToMapNames;
|
QMap<QString, QString>* mapConstantsToMapNames;
|
||||||
QMap<QString, QString>* mapNamesToMapConstants;
|
QMap<QString, QString>* mapNamesToMapConstants;
|
||||||
QMap<int, QString> mapAttributesTable;
|
QList<QString> mapLayoutsTable;
|
||||||
QMap<int, QString> mapAttributesTableMaster;
|
QList<QString> mapLayoutsTableMaster;
|
||||||
QMap<QString, QMap<QString, QString>> mapAttributes;
|
QMap<QString, MapLayout*> mapLayouts;
|
||||||
QMap<QString, QMap<QString, QString>> mapAttributesMaster;
|
QMap<QString, MapLayout*> mapLayoutsMaster;
|
||||||
QStringList *itemNames = NULL;
|
QStringList *itemNames = NULL;
|
||||||
QStringList *flagNames = NULL;
|
QStringList *flagNames = NULL;
|
||||||
QStringList *varNames = NULL;
|
QStringList *varNames = NULL;
|
||||||
|
@ -52,21 +52,21 @@ public:
|
||||||
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
||||||
QStringList* getLabelValues(QList<QStringList>*, QString);
|
QStringList* getLabelValues(QList<QStringList>*, QString);
|
||||||
void readMapHeader(Map*);
|
void readMapHeader(Map*);
|
||||||
void readMapAttributesTable();
|
void readMapLayoutsTable();
|
||||||
void readAllMapAttributes();
|
void readAllMapLayouts();
|
||||||
void readMapAttributes(Map*);
|
QStringList* readLayoutValues(QString layoutName);
|
||||||
|
void readMapLayout(Map*);
|
||||||
void readMapsWithConnections();
|
void readMapsWithConnections();
|
||||||
void getTilesets(Map*);
|
void getTilesets(Map*);
|
||||||
void loadTilesetAssets(Tileset*);
|
void loadTilesetAssets(Tileset*);
|
||||||
|
|
||||||
QString getBlockdataPath(Map*);
|
|
||||||
void saveBlockdata(Map*);
|
void saveBlockdata(Map*);
|
||||||
void saveMapBorder(Map*);
|
void saveMapBorder(Map*);
|
||||||
void writeBlockdata(QString, Blockdata*);
|
void writeBlockdata(QString, Blockdata*);
|
||||||
void saveAllMaps();
|
void saveAllMaps();
|
||||||
void saveMap(Map*);
|
void saveMap(Map*);
|
||||||
void saveAllDataStructures();
|
void saveAllDataStructures();
|
||||||
void saveAllMapAttributes();
|
void saveAllMapLayouts();
|
||||||
void saveMapGroupsTable();
|
void saveMapGroupsTable();
|
||||||
void saveMapConstantsHeader();
|
void saveMapConstantsHeader();
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ public:
|
||||||
void loadMapConnections(Map *map);
|
void loadMapConnections(Map *map);
|
||||||
|
|
||||||
void loadMapBorder(Map *map);
|
void loadMapBorder(Map *map);
|
||||||
QString getMapBorderPath(Map *map);
|
|
||||||
|
|
||||||
void saveMapEvents(Map *map);
|
void saveMapEvents(Map *map);
|
||||||
|
|
||||||
|
@ -97,19 +96,19 @@ public:
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||||
private:
|
private:
|
||||||
QString getMapAttributesTableFilepath();
|
QString getMapLayoutsTableFilepath();
|
||||||
QString getMapAssetsFilepath();
|
QString getMapLayoutFilepath(QString);
|
||||||
void saveMapHeader(Map*);
|
void saveMapHeader(Map*);
|
||||||
void saveMapConnections(Map*);
|
void saveMapConnections(Map*);
|
||||||
void updateMapsWithConnections(Map*);
|
void updateMapsWithConnections(Map*);
|
||||||
void saveMapsWithConnections();
|
void saveMapsWithConnections();
|
||||||
void saveMapAttributesTable();
|
void saveMapLayoutsTable();
|
||||||
void updateMapAttributes(Map* map);
|
void updateMapLayout(Map*);
|
||||||
void readCDefinesSorted(QString, QStringList, QStringList*);
|
void readCDefinesSorted(QString, QStringList, QStringList*);
|
||||||
void readCDefinesSorted(QString, QStringList, QStringList*, QString, int);
|
void readCDefinesSorted(QString, QStringList, QStringList*, QString, int);
|
||||||
|
|
||||||
void setNewMapHeader(Map* map, int mapIndex);
|
void setNewMapHeader(Map* map, int mapIndex);
|
||||||
void setNewMapAttributes(Map* map);
|
void setNewMapLayout(Map* map);
|
||||||
void setNewMapBlockdata(Map* map);
|
void setNewMapBlockdata(Map* map);
|
||||||
void setNewMapBorder(Map *map);
|
void setNewMapBorder(Map *map);
|
||||||
void setNewMapEvents(Map *map);
|
void setNewMapEvents(Map *map);
|
||||||
|
|
Loading…
Reference in a new issue