2020-09-13 23:37:55 +01:00
|
|
|
#pragma once
|
2018-09-23 00:47:28 +01:00
|
|
|
#ifndef METATILE_H
|
|
|
|
#define METATILE_H
|
|
|
|
|
|
|
|
#include "tile.h"
|
2022-02-03 23:10:50 +00:00
|
|
|
#include "config.h"
|
2023-12-13 07:30:22 +00:00
|
|
|
#include "bitpacker.h"
|
2018-09-23 00:47:28 +01:00
|
|
|
#include <QImage>
|
2020-09-27 17:17:12 +01:00
|
|
|
#include <QPoint>
|
2019-04-04 06:44:31 +01:00
|
|
|
#include <QString>
|
2018-09-23 00:47:28 +01:00
|
|
|
|
2022-10-27 12:52:07 +01:00
|
|
|
class Project;
|
|
|
|
|
2021-11-23 21:11:07 +00:00
|
|
|
enum {
|
|
|
|
METATILE_LAYER_MIDDLE_TOP,
|
|
|
|
METATILE_LAYER_BOTTOM_MIDDLE,
|
|
|
|
METATILE_LAYER_BOTTOM_TOP,
|
|
|
|
NUM_METATILE_LAYER_TYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ENCOUNTER_NONE,
|
|
|
|
ENCOUNTER_LAND,
|
|
|
|
ENCOUNTER_WATER,
|
|
|
|
NUM_METATILE_ENCOUNTER_TYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TERRAIN_NONE,
|
|
|
|
TERRAIN_GRASS,
|
|
|
|
TERRAIN_WATER,
|
|
|
|
TERRAIN_WATERFALL,
|
|
|
|
NUM_METATILE_TERRAIN_TYPES
|
|
|
|
};
|
|
|
|
|
2018-09-23 00:47:28 +01:00
|
|
|
class Metatile
|
|
|
|
{
|
|
|
|
public:
|
2023-12-13 07:30:22 +00:00
|
|
|
Metatile() = default;
|
2021-02-16 18:22:41 +00:00
|
|
|
Metatile(const Metatile &other) = default;
|
|
|
|
Metatile &operator=(const Metatile &other) = default;
|
2022-10-04 02:28:16 +01:00
|
|
|
Metatile(const int numTiles);
|
2021-02-16 18:22:41 +00:00
|
|
|
|
2023-12-13 07:30:22 +00:00
|
|
|
enum Attr {
|
|
|
|
Behavior,
|
|
|
|
TerrainType,
|
|
|
|
EncounterType,
|
|
|
|
LayerType,
|
|
|
|
Unused, // Preserve bits not used by the other attributes
|
|
|
|
};
|
|
|
|
|
2018-09-23 00:47:28 +01:00
|
|
|
public:
|
2021-02-16 17:14:27 +00:00
|
|
|
QList<Tile> tiles;
|
2018-09-23 00:47:28 +01:00
|
|
|
|
2023-12-13 07:30:22 +00:00
|
|
|
uint32_t getAttributes() const;
|
|
|
|
uint32_t getAttribute(Metatile::Attr attr) const { return this->attributes.value(attr, 0); }
|
2022-10-25 22:51:32 +01:00
|
|
|
void setAttributes(uint32_t data);
|
2022-10-26 09:13:53 +01:00
|
|
|
void setAttributes(uint32_t data, BaseGameVersion version);
|
2023-12-13 07:30:22 +00:00
|
|
|
void setAttribute(Metatile::Attr attr, uint32_t value);
|
|
|
|
|
|
|
|
// For convenience
|
|
|
|
uint32_t behavior() const { return this->getAttribute(Attr::Behavior); }
|
|
|
|
uint32_t terrainType() const { return this->getAttribute(Attr::TerrainType); }
|
|
|
|
uint32_t encounterType() const { return this->getAttribute(Attr::EncounterType); }
|
|
|
|
uint32_t layerType() const { return this->getAttribute(Attr::LayerType); }
|
|
|
|
void setBehavior(int value) { this->setAttribute(Attr::Behavior, static_cast<uint32_t>(value)); }
|
|
|
|
void setTerrainType(int value) { this->setAttribute(Attr::TerrainType, static_cast<uint32_t>(value)); }
|
|
|
|
void setEncounterType(int value) { this->setAttribute(Attr::EncounterType, static_cast<uint32_t>(value)); }
|
|
|
|
void setLayerType(int value) { this->setAttribute(Attr::LayerType, static_cast<uint32_t>(value)); }
|
2022-10-26 07:42:55 +01:00
|
|
|
|
2022-01-04 02:35:15 +00:00
|
|
|
static int getIndexInTileset(int);
|
2020-09-27 17:17:12 +01:00
|
|
|
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
2023-12-13 07:30:22 +00:00
|
|
|
static uint32_t getDefaultAttributesMask(BaseGameVersion version, Metatile::Attr attr);
|
2023-12-16 08:36:26 +00:00
|
|
|
static uint32_t getMaxAttributesMask();
|
2022-10-26 05:14:55 +01:00
|
|
|
static int getDefaultAttributesSize(BaseGameVersion version);
|
2023-12-13 07:30:22 +00:00
|
|
|
static void setLayout(Project*);
|
2023-09-19 19:21:36 +01:00
|
|
|
static QString getMetatileIdString(uint16_t metatileId) {
|
|
|
|
return "0x" + QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper();
|
|
|
|
};
|
|
|
|
static QString getMetatileIdStringList(const QList<uint16_t> metatileIds) {
|
|
|
|
QStringList metatiles;
|
|
|
|
for (auto metatileId : metatileIds)
|
|
|
|
metatiles << Metatile::getMetatileIdString(metatileId);
|
|
|
|
return metatiles.join(",");
|
|
|
|
};
|
2022-10-25 22:51:32 +01:00
|
|
|
|
2023-12-13 07:30:22 +00:00
|
|
|
inline bool operator==(const Metatile &other) {
|
|
|
|
return this->tiles == other.tiles && this->attributes == other.attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const Metatile &other) {
|
|
|
|
return !(operator==(other));
|
|
|
|
}
|
|
|
|
|
2022-10-25 22:51:32 +01:00
|
|
|
private:
|
2023-12-13 07:30:22 +00:00
|
|
|
QMap<Metatile::Attr, uint32_t> attributes;
|
|
|
|
|
2022-10-26 05:14:55 +01:00
|
|
|
static bool doMasksOverlap(QList<uint32_t>);
|
2018-09-23 00:47:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // METATILE_H
|