porymap/include/core/map.h

104 lines
3.2 KiB
C
Raw Normal View History

2018-09-27 00:30:05 +01:00
#ifndef MAP_H
#define MAP_H
#include "blockdata.h"
#include "history.h"
#include "historyitem.h"
#include "mapconnection.h"
#include "maplayout.h"
#include "tileset.h"
#include "event.h"
#include <QPixmap>
#include <QObject>
#include <QGraphicsPixmapItem>
#include <math.h>
#define DEFAULT_BORDER_WIDTH 2
#define DEFAULT_BORDER_HEIGHT 2
2020-04-05 05:03:36 +01:00
// Number of metatiles to draw out from edge of map. Could allow modification of this in the future.
2020-03-14 07:44:55 +00:00
// porymap will reflect changes to it, but the value is hard-coded in the projects at the moment
2020-04-05 05:03:36 +01:00
#define BORDER_DISTANCE 7
2020-03-14 07:44:55 +00:00
2018-09-27 00:30:05 +01:00
class Map : public QObject
{
Q_OBJECT
public:
explicit Map(QObject *parent = nullptr);
public:
QString name;
QString constantName;
QString group_num;
QString song;
2019-02-01 17:43:25 +00:00
QString layoutId;
2018-09-27 00:30:05 +01:00
QString location;
QString requiresFlash;
QString isFlyable;
2018-09-27 00:30:05 +01:00
QString weather;
QString type;
QString show_location;
QString allowRunning;
QString allowBiking;
QString allowEscapeRope;
int floorNumber;
2018-09-27 00:30:05 +01:00
QString battle_scene;
QString sharedEventsMap = "";
QString sharedScriptsMap = "";
QMap<QString, QString> customHeaders;
2018-09-27 00:30:05 +01:00
MapLayout *layout;
bool isPersistedToFile = true;
bool needsLayoutDir = true;
2018-09-27 00:30:05 +01:00
QImage collision_image;
QPixmap collision_pixmap;
QImage image;
QPixmap pixmap;
History<HistoryItem*> metatileHistory;
QMap<QString, QList<Event*>> events;
QList<MapConnection*> connections;
void setName(QString mapName);
static QString mapConstantFromName(QString mapName);
static QString objectEventsLabelFromName(QString mapName);
static QString warpEventsLabelFromName(QString mapName);
static QString coordEventsLabelFromName(QString mapName);
static QString bgEventsLabelFromName(QString mapName);
int getWidth();
int getHeight();
int getBorderWidth();
int getBorderHeight();
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
QPixmap renderCollision(qreal opacity, bool ignoreCache);
2020-03-14 07:44:55 +00:00
bool mapBlockChanged(int i, Blockdata * cache);
bool borderBlockChanged(int i, Blockdata * cache);
2018-09-27 00:30:05 +01:00
void cacheBlockdata();
void cacheCollision();
Block *getBlock(int x, int y);
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
2018-09-27 00:30:05 +01:00
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
2018-09-27 00:30:05 +01:00
void undo();
void redo();
void commit();
QList<Event*> getAllEvents();
void removeEvent(Event*);
void addEvent(Event*);
QPixmap renderConnection(MapConnection, MapLayout *);
2020-05-03 16:00:56 +01:00
QPixmap renderBorder(bool ignoreCache = false);
2020-03-14 07:44:55 +00:00
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
2018-09-27 00:30:05 +01:00
void cacheBorder();
bool hasUnsavedChanges();
private:
void setNewDimensionsBlockdata(int newWidth, int newHeight);
2020-03-14 07:44:55 +00:00
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
2018-09-27 00:30:05 +01:00
signals:
void mapChanged(Map *map);
void mapNeedsRedrawing();
};
#endif // MAP_H