porymap/include/core/map.h

141 lines
4.7 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
2018-09-27 00:30:05 +01:00
#ifndef MAP_H
#define MAP_H
#include "blockdata.h"
#include "mapconnection.h"
#include "maplayout.h"
#include "tileset.h"
#include "events.h"
2018-09-27 00:30:05 +01:00
2020-07-29 20:51:04 +01:00
#include <QUndoStack>
2018-09-27 00:30:05 +01:00
#include <QPixmap>
#include <QObject>
#include <QGraphicsPixmapItem>
#include <math.h>
#define DEFAULT_BORDER_WIDTH 2
#define DEFAULT_BORDER_HEIGHT 2
// Maximum based only on data type (u8) of map border width/height
#define MAX_BORDER_WIDTH 255
#define MAX_BORDER_HEIGHT 255
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
2020-07-29 20:51:04 +01:00
class MapPixmapItem;
class CollisionPixmapItem;
2020-07-29 20:51:04 +01:00
class BorderMetatilesPixmapItem;
2018-09-27 00:30:05 +01:00
class Map : public QObject
{
Q_OBJECT
public:
explicit Map(QObject *parent = nullptr);
~Map();
2018-09-27 00:30:05 +01:00
public:
QString name;
QString constantName;
QString song;
2019-02-01 17:43:25 +00:00
QString layoutId;
2018-09-27 00:30:05 +01:00
QString location;
bool requiresFlash;
2018-09-27 00:30:05 +01:00
QString weather;
QString type;
bool show_location;
bool allowRunning;
bool allowBiking;
bool allowEscaping;
2021-02-18 08:51:44 +00:00
int floorNumber = 0;
2018-09-27 00:30:05 +01:00
QString battle_scene;
QString sharedEventsMap = "";
QString sharedScriptsMap = "";
QStringList scriptsFileLabels;
QMap<QString, QJsonValue> customHeaders;
2018-09-27 00:30:05 +01:00
MapLayout *layout;
bool isPersistedToFile = true;
bool hasUnsavedDataChanges = false;
bool needsLayoutDir = true;
bool needsHealLocation = false;
bool scriptsLoaded = false;
2018-09-27 00:30:05 +01:00
QImage collision_image;
QPixmap collision_pixmap;
QImage image;
QPixmap pixmap;
2023-01-26 20:02:32 +00:00
QMap<Event::Group, QList<Event *>> events;
QList<Event *> ownedEvents; // for memory management
2018-09-27 00:30:05 +01:00
QList<MapConnection*> connections;
QList<int> metatileLayerOrder;
QList<float> metatileLayerOpacity;
2018-09-27 00:30:05 +01:00
void setName(QString mapName);
2023-12-18 07:19:12 +00:00
static QString mapConstantFromName(QString mapName, bool includePrefix = true);
2018-09-27 00:30:05 +01:00
int getWidth();
int getHeight();
int getBorderWidth();
int getBorderHeight();
QPixmap render(bool ignoreCache = false, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
QPixmap renderCollision(bool ignoreCache);
2021-02-14 21:56:23 +00:00
bool mapBlockChanged(int i, const Blockdata &cache);
bool borderBlockChanged(int i, const Blockdata &cache);
2018-09-27 00:30:05 +01:00
void cacheBlockdata();
void cacheCollision();
2021-02-13 21:16:52 +00:00
bool getBlock(int x, int y, Block *out);
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
void setBlockdata(Blockdata blockdata, bool enableScriptCallback = false);
uint16_t getBorderMetatileId(int x, int y);
void setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback = false);
void setBorderBlockData(Blockdata blockdata, 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);
QList<Event *> getAllEvents() const;
QStringList getScriptLabels(Event::Group group = Event::Group::None);
void removeEvent(Event *);
void addEvent(Event *);
bool removeConnection(MapConnection *);
void addConnection(MapConnection *);
2024-08-04 21:08:16 +01:00
QPixmap renderConnection(const QString &, MapLayout *);
2020-05-03 16:00:56 +01:00
QPixmap renderBorder(bool ignoreCache = false);
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
2023-01-17 01:16:25 +00:00
void clearBorderCache();
2018-09-27 00:30:05 +01:00
void cacheBorder();
bool hasUnsavedChanges();
2022-02-08 22:40:07 +00:00
bool isWithinBounds(int x, int y);
bool isWithinBorderBounds(int x, int y);
void openScript(QString label);
QString getScriptsFilePath() const;
2020-07-29 20:51:04 +01:00
MapPixmapItem *mapItem = nullptr;
void setMapItem(MapPixmapItem *item) { mapItem = item; }
CollisionPixmapItem *collisionItem = nullptr;
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
2020-07-29 20:51:04 +01:00
BorderMetatilesPixmapItem *borderItem = nullptr;
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
QUndoStack editHistory;
void modify();
void clean();
2020-07-29 20:51:04 +01:00
2018-09-27 00:30:05 +01:00
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 modified();
2020-10-24 12:45:08 +01:00
void mapDimensionsChanged(const QSize &size);
2018-09-27 00:30:05 +01:00
void mapNeedsRedrawing();
void openScriptRequested(QString label);
void connectionAdded(MapConnection*);
2018-09-27 00:30:05 +01:00
};
#endif // MAP_H