mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-22 00:26:37 -05:00
Restructure source tree
This commit is contained in:
20
include/core/block.h
Normal file
20
include/core/block.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef BLOCK_H
|
||||
#define BLOCK_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Block
|
||||
{
|
||||
public:
|
||||
Block();
|
||||
Block(uint16_t);
|
||||
Block(const Block&);
|
||||
bool operator ==(Block);
|
||||
bool operator !=(Block);
|
||||
uint16_t tile:10;
|
||||
uint16_t collision:2;
|
||||
uint16_t elevation:4;
|
||||
uint16_t rawValue();
|
||||
};
|
||||
|
||||
#endif // BLOCK_H
|
||||
32
include/core/blockdata.h
Normal file
32
include/core/blockdata.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BLOCKDATA_H
|
||||
#define BLOCKDATA_H
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
|
||||
class Blockdata : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Blockdata(QObject *parent = nullptr);
|
||||
~Blockdata() {
|
||||
if (blocks) delete blocks;
|
||||
}
|
||||
|
||||
public:
|
||||
QList<Block> *blocks = nullptr;
|
||||
void addBlock(uint16_t);
|
||||
void addBlock(Block);
|
||||
QByteArray serialize();
|
||||
void copyFrom(Blockdata*);
|
||||
Blockdata* copy();
|
||||
bool equals(Blockdata *);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // BLOCKDATA_H
|
||||
85
include/core/event.h
Normal file
85
include/core/event.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef EVENT_H
|
||||
#define EVENT_H
|
||||
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
|
||||
class EventType
|
||||
{
|
||||
public:
|
||||
static QString Object;
|
||||
static QString Warp;
|
||||
static QString CoordScript;
|
||||
static QString CoordWeather;
|
||||
static QString Sign;
|
||||
static QString HiddenItem;
|
||||
static QString SecretBase;
|
||||
static QString HealLocation;
|
||||
};
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
Event();
|
||||
public:
|
||||
int x() {
|
||||
return getInt("x");
|
||||
}
|
||||
int y() {
|
||||
return getInt("y");
|
||||
}
|
||||
int elevation() {
|
||||
return getInt("elevation");
|
||||
}
|
||||
void setX(int x) {
|
||||
put("x", x);
|
||||
}
|
||||
void setY(int y) {
|
||||
put("y", y);
|
||||
}
|
||||
QString get(QString key) {
|
||||
return values.value(key);
|
||||
}
|
||||
int getInt(QString key) {
|
||||
return values.value(key).toInt(nullptr, 0);
|
||||
}
|
||||
uint16_t getU16(QString key) {
|
||||
return values.value(key).toUShort(nullptr, 0);
|
||||
}
|
||||
void put(QString key, int value) {
|
||||
put(key, QString("%1").arg(value));
|
||||
}
|
||||
void put(QString key, QString value) {
|
||||
values.insert(key, value);
|
||||
}
|
||||
|
||||
static Event* createNewEvent(QString, QString);
|
||||
static Event* createNewObjectEvent();
|
||||
static Event* createNewWarpEvent(QString);
|
||||
static Event* createNewHealLocationEvent(QString);
|
||||
static Event* createNewCoordScriptEvent();
|
||||
static Event* createNewCoordWeatherEvent();
|
||||
static Event* createNewSignEvent();
|
||||
static Event* createNewHiddenItemEvent();
|
||||
static Event* createNewSecretBaseEvent();
|
||||
|
||||
QString buildObjectEventMacro(int);
|
||||
QString buildWarpEventMacro(QMap<QString, QString>*);
|
||||
QString buildCoordScriptEventMacro();
|
||||
QString buildCoordWeatherEventMacro();
|
||||
QString buildSignEventMacro();
|
||||
QString buildHiddenItemEventMacro();
|
||||
QString buildSecretBaseEventMacro();
|
||||
void setPixmapFromSpritesheet(QImage, int, int);
|
||||
int getPixelX();
|
||||
int getPixelY();
|
||||
|
||||
QMap<QString, QString> values;
|
||||
QPixmap pixmap;
|
||||
int spriteWidth;
|
||||
int spriteHeight;
|
||||
};
|
||||
|
||||
#endif // EVENT_H
|
||||
24
include/core/heallocation.h
Normal file
24
include/core/heallocation.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef HEALLOCATION_H
|
||||
#define HEALLOCATION_H
|
||||
|
||||
#include "event.h"
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
|
||||
class HealLocation {
|
||||
|
||||
public:
|
||||
HealLocation()=default;
|
||||
HealLocation(QString, int, uint16_t, uint16_t);
|
||||
friend QDebug operator<<(QDebug debug, const HealLocation &hl);
|
||||
|
||||
public:
|
||||
//QString group;
|
||||
QString name;
|
||||
int index;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
static HealLocation fromEvent(Event*);
|
||||
};
|
||||
|
||||
#endif // HEALLOCATION_H
|
||||
58
include/core/history.h
Normal file
58
include/core/history.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef HISTORY_H
|
||||
#define HISTORY_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
template <typename T>
|
||||
class History {
|
||||
public:
|
||||
History() { }
|
||||
T back() {
|
||||
if (head > 0) {
|
||||
return history.at(--head);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
T next() {
|
||||
if (head + 1 < history.length()) {
|
||||
return history.at(++head);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void push(T commit) {
|
||||
while (head + 1 < history.length()) {
|
||||
T item = history.last();
|
||||
history.removeLast();
|
||||
delete item;
|
||||
}
|
||||
if (saved > head) {
|
||||
saved = -1;
|
||||
}
|
||||
history.append(commit);
|
||||
head++;
|
||||
}
|
||||
|
||||
T current() {
|
||||
if (head < 0 || history.length() == 0) {
|
||||
return NULL;
|
||||
}
|
||||
return history.at(head);
|
||||
}
|
||||
|
||||
void save() {
|
||||
saved = head;
|
||||
}
|
||||
|
||||
bool isSaved() {
|
||||
return saved == head;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<T> history;
|
||||
int head = -1;
|
||||
int saved = -1;
|
||||
};
|
||||
|
||||
#endif // HISTORY_H
|
||||
15
include/core/historyitem.h
Normal file
15
include/core/historyitem.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef HISTORYITEM_H
|
||||
#define HISTORYITEM_H
|
||||
|
||||
#include "blockdata.h"
|
||||
|
||||
class HistoryItem {
|
||||
public:
|
||||
Blockdata *metatiles;
|
||||
int layoutWidth;
|
||||
int layoutHeight;
|
||||
HistoryItem(Blockdata *metatiles, int layoutWidth, int layoutHeight);
|
||||
~HistoryItem();
|
||||
};
|
||||
|
||||
#endif // HISTORYITEM_H
|
||||
89
include/core/map.h
Normal file
89
include/core/map.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#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 <QDebug>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <math.h>
|
||||
|
||||
class Map : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Map(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
QString name;
|
||||
QString constantName;
|
||||
QString group_num;
|
||||
QString layout_label;
|
||||
QString events_label;
|
||||
QString scripts_label;
|
||||
QString connections_label;
|
||||
QString song;
|
||||
QString layout_id;
|
||||
QString location;
|
||||
QString requiresFlash;
|
||||
QString isFlyable; // TODO: implement this
|
||||
QString weather;
|
||||
QString type;
|
||||
QString unknown;
|
||||
QString show_location;
|
||||
QString battle_scene;
|
||||
MapLayout *layout;
|
||||
bool isPersistedToFile = true;
|
||||
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();
|
||||
QPixmap render(bool ignoreCache);
|
||||
QPixmap renderCollision(bool ignoreCache);
|
||||
bool blockChanged(int, Blockdata*);
|
||||
void cacheBlockdata();
|
||||
void cacheCollision();
|
||||
Block *getBlock(int x, int y);
|
||||
void setBlock(int x, int y, Block block);
|
||||
void _setBlock(int x, int y, Block block);
|
||||
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 undo();
|
||||
void redo();
|
||||
void commit();
|
||||
QList<Event*> getAllEvents();
|
||||
void removeEvent(Event*);
|
||||
void addEvent(Event*);
|
||||
QPixmap renderConnection(MapConnection);
|
||||
QPixmap renderBorder();
|
||||
void setDimensions(int newWidth, int newHeight, bool setNewBlockData = true);
|
||||
void cacheBorder();
|
||||
bool hasUnsavedChanges();
|
||||
|
||||
private:
|
||||
void setNewDimensionsBlockdata(int newWidth, int newHeight);
|
||||
|
||||
signals:
|
||||
void mapChanged(Map *map);
|
||||
void mapNeedsRedrawing();
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
||||
14
include/core/mapconnection.h
Normal file
14
include/core/mapconnection.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MAPCONNECTION_H
|
||||
#define MAPCONNECTION_H
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
|
||||
class MapConnection {
|
||||
public:
|
||||
QString direction;
|
||||
QString offset;
|
||||
QString map_name;
|
||||
};
|
||||
|
||||
#endif // MAPCONNECTION_H
|
||||
41
include/core/maplayout.h
Normal file
41
include/core/maplayout.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef MAPLAYOUT_H
|
||||
#define MAPLAYOUT_H
|
||||
|
||||
#include "blockdata.h"
|
||||
#include "tileset.h"
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
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 = nullptr;
|
||||
Tileset *tileset_secondary = nullptr;
|
||||
Blockdata* blockdata = nullptr;
|
||||
QImage border_image;
|
||||
QPixmap border_pixmap;
|
||||
Blockdata *border = nullptr;
|
||||
Blockdata *cached_blockdata = nullptr;
|
||||
Blockdata *cached_collision = nullptr;
|
||||
Blockdata *cached_border = nullptr;
|
||||
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(), "");
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MAPLAYOUT_H
|
||||
17
include/core/metatile.h
Normal file
17
include/core/metatile.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef METATILE_H
|
||||
#define METATILE_H
|
||||
|
||||
#include "tile.h"
|
||||
#include <QImage>
|
||||
|
||||
class Metatile
|
||||
{
|
||||
public:
|
||||
Metatile();
|
||||
public:
|
||||
QList<Tile> *tiles = nullptr;
|
||||
|
||||
static int getBlockIndex(int);
|
||||
};
|
||||
|
||||
#endif // METATILE_H
|
||||
47
include/core/parseutil.h
Normal file
47
include/core/parseutil.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef PARSEUTIL_H
|
||||
#define PARSEUTIL_H
|
||||
|
||||
#include "heallocation.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
enum TokenType {
|
||||
Number,
|
||||
Operator,
|
||||
};
|
||||
|
||||
class Token {
|
||||
public:
|
||||
Token(QString value = "", QString type = "") {
|
||||
this->value = value;
|
||||
this->type = TokenType::Operator;
|
||||
if (type == "decimal" || type == "hex") {
|
||||
this->type = TokenType::Number;
|
||||
this->operatorPrecedence = -1;
|
||||
} else if (type == "operator") {
|
||||
this->operatorPrecedence = precedenceMap[value];
|
||||
}
|
||||
}
|
||||
static QMap<QString, int> precedenceMap;
|
||||
QString value;
|
||||
TokenType type;
|
||||
int operatorPrecedence; // only relevant for operator tokens
|
||||
};
|
||||
|
||||
class ParseUtil
|
||||
{
|
||||
public:
|
||||
ParseUtil();
|
||||
void strip_comment(QString*);
|
||||
QList<QStringList>* parseAsm(QString);
|
||||
int evaluateDefine(QString, QMap<QString, int>*);
|
||||
QList<HealLocation>* parseHealLocs(QString);
|
||||
private:
|
||||
QList<Token> tokenizeExpression(QString expression, QMap<QString, int>* knownIdentifiers);
|
||||
QList<Token> generatePostfix(QList<Token> tokens);
|
||||
int evaluatePostfix(QList<Token> postfix);
|
||||
};
|
||||
|
||||
#endif // PARSEUTIL_H
|
||||
16
include/core/tile.h
Normal file
16
include/core/tile.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef TILE_H
|
||||
#define TILE_H
|
||||
|
||||
|
||||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile();
|
||||
public:
|
||||
int tile;
|
||||
int xflip;
|
||||
int yflip;
|
||||
int palette;
|
||||
};
|
||||
|
||||
#endif // TILE_H
|
||||
32
include/core/tileset.h
Normal file
32
include/core/tileset.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef TILESET_H
|
||||
#define TILESET_H
|
||||
|
||||
#include "metatile.h"
|
||||
#include "tile.h"
|
||||
#include <QImage>
|
||||
|
||||
class Tileset
|
||||
{
|
||||
public:
|
||||
Tileset();
|
||||
public:
|
||||
QString name;
|
||||
QString is_compressed;
|
||||
QString is_secondary;
|
||||
QString padding;
|
||||
QString tiles_label;
|
||||
QString palettes_label;
|
||||
QString metatiles_label;
|
||||
QString callback_label;
|
||||
QString metatile_attrs_label;
|
||||
|
||||
QList<QImage> *tiles = nullptr;
|
||||
QList<Metatile*> *metatiles = nullptr;
|
||||
QList<QList<QRgb>> *palettes = nullptr;
|
||||
|
||||
static Tileset* getBlockTileset(int, Tileset*, Tileset*);
|
||||
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
||||
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*);
|
||||
};
|
||||
|
||||
#endif // TILESET_H
|
||||
Reference in New Issue
Block a user