2020-09-13 23:37:55 +01:00
|
|
|
#pragma once
|
2018-12-28 18:26:18 +00:00
|
|
|
#ifndef REGIONMAP_H
|
|
|
|
#define REGIONMAP_H
|
|
|
|
|
|
|
|
#include "map.h"
|
|
|
|
#include "tilemaptileselector.h"
|
2019-01-09 02:03:54 +00:00
|
|
|
#include "history.h"
|
2018-12-28 18:26:18 +00:00
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QString>
|
2019-01-14 00:27:28 +00:00
|
|
|
#include <QVector>
|
2018-12-28 18:26:18 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
#include <memory>
|
|
|
|
using std::shared_ptr;
|
|
|
|
|
|
|
|
class Project;
|
|
|
|
|
|
|
|
struct LayoutSquare
|
2019-01-05 04:04:14 +00:00
|
|
|
{
|
2022-04-27 01:32:42 +01:00
|
|
|
LayoutSquare() : map_section("MAPSEC_NONE"), x(-1), y(-1), has_map(false) {}
|
2022-03-01 20:32:44 +00:00
|
|
|
QString map_section;
|
2019-01-05 04:04:14 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2022-04-27 01:32:42 +01:00
|
|
|
bool has_map;
|
2019-01-05 04:04:14 +00:00
|
|
|
};
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
struct MapSectionEntry
|
2018-12-28 18:26:18 +00:00
|
|
|
{
|
2022-03-01 20:32:44 +00:00
|
|
|
QString name = "";
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
int width = 1;
|
|
|
|
int height = 1;
|
|
|
|
bool valid = false;
|
2018-12-28 18:26:18 +00:00
|
|
|
};
|
|
|
|
|
2022-04-28 18:21:36 +01:00
|
|
|
class RegionMap : public QObject
|
2018-12-28 18:26:18 +00:00
|
|
|
{
|
2022-04-28 18:21:36 +01:00
|
|
|
Q_OBJECT
|
2018-12-28 18:26:18 +00:00
|
|
|
public:
|
2022-03-01 20:32:44 +00:00
|
|
|
RegionMap() = delete;
|
|
|
|
RegionMap(Project *);
|
2018-12-28 18:26:18 +00:00
|
|
|
|
2022-04-26 22:02:03 +01:00
|
|
|
~RegionMap() {}
|
2019-01-05 04:04:14 +00:00
|
|
|
|
2022-04-26 22:02:03 +01:00
|
|
|
Project *project = nullptr;
|
2019-04-13 02:25:43 +01:00
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
bool loadMapData(poryjson::Json);
|
|
|
|
bool loadTilemap(poryjson::Json);
|
|
|
|
bool loadLayout(poryjson::Json);
|
|
|
|
bool loadEntries();
|
2019-01-15 22:06:18 +00:00
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
void setEntries(tsl::ordered_map<QString, MapSectionEntry> *entries) { this->region_map_entries = entries; }
|
2022-05-06 02:40:13 +01:00
|
|
|
void setEntries(tsl::ordered_map<QString, MapSectionEntry> entries) { *(this->region_map_entries) = entries; }
|
|
|
|
void clearEntries() { this->region_map_entries->clear(); }
|
2022-03-01 20:32:44 +00:00
|
|
|
MapSectionEntry getEntry(QString section);
|
2022-04-27 01:32:42 +01:00
|
|
|
void setEntry(QString section, MapSectionEntry entry);
|
2022-04-27 03:19:36 +01:00
|
|
|
void removeEntry(QString section);
|
2018-12-28 18:26:18 +00:00
|
|
|
|
|
|
|
void save();
|
2022-03-01 20:32:44 +00:00
|
|
|
void saveTilemap();
|
2018-12-28 18:26:18 +00:00
|
|
|
void saveLayout();
|
2019-01-28 18:47:20 +00:00
|
|
|
|
2022-04-28 18:21:36 +01:00
|
|
|
void resizeTilemap(int width, int height, bool update = true);
|
2019-01-28 18:47:20 +00:00
|
|
|
void resetSquare(int index);
|
2019-03-17 16:37:13 +00:00
|
|
|
void clearLayout();
|
|
|
|
void clearImage();
|
2022-04-27 21:00:47 +01:00
|
|
|
void replaceSection(QString oldSection, QString newSection);
|
2022-05-10 20:02:15 +01:00
|
|
|
void swapSections(QString secA, QString secB);
|
2018-12-28 18:26:18 +00:00
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
unsigned getTileId(int index);
|
|
|
|
shared_ptr<TilemapTile> getTile(int index);
|
2019-01-28 18:47:20 +00:00
|
|
|
unsigned getTileId(int x, int y);
|
2022-03-01 20:32:44 +00:00
|
|
|
shared_ptr<TilemapTile> getTile(int x, int y);
|
|
|
|
bool squareHasMap(int index);
|
|
|
|
QString squareMapSection(int index);
|
2022-04-22 21:29:25 +01:00
|
|
|
void setSquareMapSection(int index, QString section);
|
2022-03-01 20:32:44 +00:00
|
|
|
int squareX(int index);
|
|
|
|
int squareY(int index);
|
|
|
|
bool squareInLayout(int x, int y);
|
|
|
|
int firstLayoutIndex() { return this->offset_left + this->offset_top * this->tilemap_width; }
|
|
|
|
|
|
|
|
void setTileId(int index, unsigned id);
|
|
|
|
void setTile(int index, TilemapTile &tile);
|
|
|
|
void setTileData(int index, unsigned id, bool hFlip, bool vFlip, int palette);
|
2019-01-28 18:47:20 +00:00
|
|
|
int getMapSquareIndex(int x, int y);
|
2022-04-28 18:21:36 +01:00
|
|
|
|
|
|
|
QString getAlias() { return this->alias; }
|
|
|
|
poryjson::Json::object config();
|
2022-03-01 20:32:44 +00:00
|
|
|
|
|
|
|
QString palPath();
|
2019-01-28 18:47:20 +00:00
|
|
|
QString pngPath();
|
2022-03-01 20:32:44 +00:00
|
|
|
QString entriesPath() { return this->entries_path; }
|
2018-12-28 18:26:18 +00:00
|
|
|
|
2022-04-22 21:29:25 +01:00
|
|
|
QByteArray getTilemap();
|
|
|
|
void setTilemap(QByteArray newTilemap);
|
|
|
|
|
2022-04-26 22:02:03 +01:00
|
|
|
QList<LayoutSquare> getLayout(QString layer);
|
|
|
|
void setLayout(QString layer, QList<LayoutSquare> layout);
|
|
|
|
|
2022-04-27 21:00:47 +01:00
|
|
|
bool layoutEnabled() { return this->layout_format != LayoutFormat::None; }
|
|
|
|
|
2022-04-27 01:32:42 +01:00
|
|
|
QMap<QString, QList<LayoutSquare>> getAllLayouts();
|
|
|
|
void setAllLayouts(QMap<QString, QList<LayoutSquare>> newLayouts);
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
QStringList getLayers() { return this->layout_layers; }
|
|
|
|
void setLayer(QString layer) { this->current_layer = layer; }
|
|
|
|
QString getLayer() { return this->current_layer; }
|
|
|
|
|
2019-04-13 04:07:00 +01:00
|
|
|
QString fixCase(QString);
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
int padLeft() { return this->offset_left; }
|
|
|
|
int padTop() { return this->offset_top; }
|
|
|
|
int padRight() { return this->tilemap_width - this->layout_width - this->offset_left; }
|
|
|
|
int padBottom() { return this->tilemap_height - this->layout_height - this->offset_top; }
|
|
|
|
|
|
|
|
int tilemapWidth() { return this->tilemap_width; }
|
|
|
|
int tilemapHeight() { return this->tilemap_height; }
|
|
|
|
int tilemapSize() { return this->tilemap_width * this->tilemap_height; }
|
|
|
|
int tilemapBytes();
|
|
|
|
|
2022-04-27 01:32:42 +01:00
|
|
|
int layoutWidth() { return this->layout_width; }
|
|
|
|
int layoutHeight() { return this->layout_height; }
|
|
|
|
void setLayoutDimensions(int width, int height, bool update = true);
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
int tilemapToLayoutIndex(int index);
|
|
|
|
|
|
|
|
TilemapFormat tilemapFormat() { return this->tilemap_format; }
|
|
|
|
|
|
|
|
int pixelWidth() { return this->tilemap_width * 8; }
|
|
|
|
int pixelHeight() { return this->tilemap_height * 8; }
|
|
|
|
|
|
|
|
QString fullPath(QString local);
|
|
|
|
|
2022-04-26 22:02:03 +01:00
|
|
|
void commit(QUndoCommand *command);
|
|
|
|
QUndoStack editHistory;
|
|
|
|
|
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
|
2022-04-28 18:21:36 +01:00
|
|
|
void emitDisplay();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void mapNeedsDisplaying();
|
|
|
|
|
2018-12-28 18:26:18 +00:00
|
|
|
private:
|
2022-04-22 21:29:25 +01:00
|
|
|
// TODO: defaults needed?
|
2022-03-01 20:32:44 +00:00
|
|
|
tsl::ordered_map<QString, MapSectionEntry> *region_map_entries = nullptr;
|
|
|
|
|
2022-04-27 21:00:47 +01:00
|
|
|
QString alias = "";
|
2022-03-01 20:32:44 +00:00
|
|
|
|
|
|
|
int tilemap_width;
|
|
|
|
int tilemap_height;
|
|
|
|
|
|
|
|
int layout_width;
|
|
|
|
int layout_height;
|
|
|
|
|
|
|
|
int offset_left;
|
|
|
|
int offset_top;
|
|
|
|
|
|
|
|
TilemapFormat tilemap_format;
|
|
|
|
|
|
|
|
enum class LayoutFormat { None, Binary, CArray };
|
|
|
|
LayoutFormat layout_format;
|
|
|
|
|
|
|
|
QString tileset_path;
|
|
|
|
QString tilemap_path;
|
|
|
|
QString palette_path = "";
|
|
|
|
|
|
|
|
QString entries_path;
|
|
|
|
QString layout_path;
|
|
|
|
|
|
|
|
QString layout_array_label;
|
|
|
|
bool layout_uses_layers = false;
|
2022-04-22 21:29:25 +01:00
|
|
|
QStringList layout_constants;
|
|
|
|
QString layout_qualifiers;
|
2022-03-01 20:32:44 +00:00
|
|
|
|
2022-04-27 21:00:47 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QVector<shared_ptr<TilemapTile>> tilemap;
|
|
|
|
#else
|
2022-03-01 20:32:44 +00:00
|
|
|
QList<shared_ptr<TilemapTile>> tilemap;
|
2022-04-27 21:00:47 +01:00
|
|
|
#endif
|
2022-03-01 20:32:44 +00:00
|
|
|
|
2022-04-27 21:00:47 +01:00
|
|
|
QStringList layout_layers;
|
2022-03-01 20:32:44 +00:00
|
|
|
QString current_layer;
|
2022-04-27 21:00:47 +01:00
|
|
|
QMap<QString, QList<LayoutSquare>> layouts;
|
2019-01-28 18:47:20 +00:00
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
int get_tilemap_index(int x, int y);
|
|
|
|
int get_layout_index(int x, int y);
|
2018-12-28 18:26:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // REGIONMAP_H
|