porymap/include/core/event.h

108 lines
2.8 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
2018-09-25 01:12:29 +01:00
#ifndef EVENT_H
#define EVENT_H
#include <QString>
#include <QPixmap>
#include <QMap>
#include "orderedjson.h"
using OrderedJson = poryjson::Json;
2018-09-25 01:12:29 +01:00
class EventType
{
public:
static QString Object;
static QString Warp;
static QString Trigger;
static QString WeatherTrigger;
2018-09-25 01:12:29 +01:00
static QString Sign;
static QString HiddenItem;
static QString SecretBase;
static QString HealLocation;
};
class DraggablePixmapItem;
class Project;
2018-09-25 01:12:29 +01:00
class Event
{
public:
Event();
2020-07-09 23:31:35 +01:00
Event(const Event&);
Event(QJsonObject, QString);
2018-09-25 01:12:29 +01:00
public:
int x() const {
2018-09-25 01:12:29 +01:00
return getInt("x");
}
int y() const {
2018-09-25 01:12:29 +01:00
return getInt("y");
}
int elevation() {
return getInt("elevation");
}
void setX(int x) {
put("x", x);
}
void setY(int y) {
put("y", y);
}
QString get(const QString &key) const {
2018-09-25 01:12:29 +01:00
return values.value(key);
}
int getInt(const QString &key) const {
2018-09-25 01:12:29 +01:00
return values.value(key).toInt(nullptr, 0);
}
uint16_t getU16(const QString &key) const {
2018-09-25 01:12:29 +01:00
return values.value(key).toUShort(nullptr, 0);
}
int16_t getS16(const QString &key) const {
return values.value(key).toShort(nullptr, 0);
}
2018-09-25 01:12:29 +01:00
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, Project*);
static Event* createNewObjectEvent(Project*);
2018-09-25 01:12:29 +01:00
static Event* createNewWarpEvent(QString);
static Event* createNewHealLocationEvent(QString);
static Event* createNewTriggerEvent(Project*);
static Event* createNewWeatherTriggerEvent(Project*);
static Event* createNewSignEvent(Project*);
static Event* createNewHiddenItemEvent(Project*);
static Event* createNewSecretBaseEvent(Project*);
2018-09-25 01:12:29 +01:00
OrderedJson::object buildObjectEventJSON();
OrderedJson::object buildWarpEventJSON(const QMap<QString, QString> &);
OrderedJson::object buildTriggerEventJSON();
OrderedJson::object buildWeatherTriggerEventJSON();
OrderedJson::object buildSignEventJSON();
OrderedJson::object buildHiddenItemEventJSON();
OrderedJson::object buildSecretBaseEventJSON();
2019-04-03 00:51:33 +01:00
void setPixmapFromSpritesheet(QImage, int, int, int, bool);
2018-09-25 01:12:29 +01:00
int getPixelX();
int getPixelY();
QMap<QString, bool> getExpectedFields();
void readCustomValues(QJsonObject values);
void addCustomValuesTo(OrderedJson::object *obj);
2019-04-03 00:51:33 +01:00
void setFrameFromMovement(QString);
2018-09-25 01:12:29 +01:00
QMap<QString, QString> values;
QMap<QString, QString> customValues;
2018-09-25 01:12:29 +01:00
QPixmap pixmap;
int spriteWidth;
int spriteHeight;
2019-04-03 00:51:33 +01:00
int frame = 0;
bool hFlip = false;
bool usingSprite;
DraggablePixmapItem *pixmapItem = nullptr;
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
2018-09-25 01:12:29 +01:00
};
#endif // EVENT_H