mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-14 03:45:35 -05:00
Merge pull request #485 from GriffinRichards/metatile-attr
Allow reorganization of metatile attributes
This commit is contained in:
@@ -36,6 +36,7 @@ protected:
|
||||
virtual void setUnreadKeys() = 0;
|
||||
bool getConfigBool(QString key, QString value);
|
||||
int getConfigInteger(QString key, QString value, int min, int max, int defaultValue);
|
||||
long getConfigLong(QString key, QString value, long min, long max, long defaultValue);
|
||||
};
|
||||
|
||||
class PorymapConfig: public KeyValueConfigBase
|
||||
@@ -268,6 +269,12 @@ public:
|
||||
bool getTilesetsHaveCallback();
|
||||
void setTilesetsHaveIsCompressed(bool has);
|
||||
bool getTilesetsHaveIsCompressed();
|
||||
int getMetatileAttributesSize();
|
||||
uint32_t getMetatileBehaviorMask();
|
||||
uint32_t getMetatileTerrainTypeMask();
|
||||
uint32_t getMetatileEncounterTypeMask();
|
||||
uint32_t getMetatileLayerTypeMask();
|
||||
bool getMapAllowFlagsEnabled();
|
||||
protected:
|
||||
virtual QString getConfigFilepath() override;
|
||||
virtual void parseConfigKeyValue(QString key, QString value) override;
|
||||
@@ -299,6 +306,12 @@ private:
|
||||
bool prefabImportPrompted;
|
||||
bool tilesetsHaveCallback;
|
||||
bool tilesetsHaveIsCompressed;
|
||||
int metatileAttributesSize;
|
||||
uint32_t metatileBehaviorMask;
|
||||
uint32_t metatileTerrainTypeMask;
|
||||
uint32_t metatileEncounterTypeMask;
|
||||
uint32_t metatileLayerTypeMask;
|
||||
bool enableMapAllowFlags;
|
||||
};
|
||||
|
||||
extern ProjectConfig projectConfig;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QPoint>
|
||||
#include <QString>
|
||||
|
||||
class Project;
|
||||
|
||||
enum {
|
||||
METATILE_LAYER_MIDDLE_TOP,
|
||||
METATILE_LAYER_BOTTOM_MIDDLE,
|
||||
@@ -30,6 +32,29 @@ enum {
|
||||
NUM_METATILE_TERRAIN_TYPES
|
||||
};
|
||||
|
||||
class MetatileAttr
|
||||
{
|
||||
public:
|
||||
MetatileAttr();
|
||||
MetatileAttr(uint32_t mask, int shift);
|
||||
|
||||
public:
|
||||
uint32_t mask;
|
||||
int shift;
|
||||
|
||||
// Given the raw value for all attributes of a metatile
|
||||
// Returns the extracted value for this attribute
|
||||
uint32_t fromRaw(uint32_t raw) const { return (raw & this->mask) >> this->shift; }
|
||||
|
||||
// Given a value for this attribute
|
||||
// Returns the raw value to OR together with the other attributes
|
||||
uint32_t toRaw(uint32_t value) const { return (value << this->shift) & this->mask; }
|
||||
|
||||
// Given an arbitrary value to set for an attribute
|
||||
// Returns a bounded value for that attribute
|
||||
uint32_t getClamped(int value) const { return static_cast<uint32_t>(value) & (this->mask >> this->shift); }
|
||||
};
|
||||
|
||||
class Metatile
|
||||
{
|
||||
public:
|
||||
@@ -40,19 +65,54 @@ public:
|
||||
|
||||
public:
|
||||
QList<Tile> tiles;
|
||||
uint16_t behavior; // 8 bits RSE, 9 bits FRLG
|
||||
uint8_t layerType;
|
||||
uint8_t encounterType; // FRLG only
|
||||
uint8_t terrainType; // FRLG only
|
||||
uint32_t behavior;
|
||||
uint32_t terrainType;
|
||||
uint32_t encounterType;
|
||||
uint32_t layerType;
|
||||
uint32_t unusedAttributes;
|
||||
QString label;
|
||||
|
||||
uint32_t getAttributes();
|
||||
void setAttributes(uint32_t data);
|
||||
void setAttributes(uint32_t data, BaseGameVersion version);
|
||||
uint32_t getAttributes(BaseGameVersion version);
|
||||
|
||||
void setBehavior(int value) { this->behavior = behaviorAttr.getClamped(value); }
|
||||
void setTerrainType(int value) { this->terrainType = terrainTypeAttr.getClamped(value); }
|
||||
void setEncounterType(int value) { this->encounterType = encounterTypeAttr.getClamped(value); }
|
||||
void setLayerType(int value) { this->layerType = layerTypeAttr.getClamped(value); }
|
||||
|
||||
static uint32_t getBehaviorMask() { return behaviorAttr.mask; }
|
||||
static uint32_t getTerrainTypeMask() { return terrainTypeAttr.mask; }
|
||||
static uint32_t getEncounterTypeMask() { return encounterTypeAttr.mask; }
|
||||
static uint32_t getLayerTypeMask() { return layerTypeAttr.mask; }
|
||||
static uint32_t getBehaviorMask(BaseGameVersion version);
|
||||
static uint32_t getTerrainTypeMask(BaseGameVersion version);
|
||||
static uint32_t getEncounterTypeMask(BaseGameVersion version);
|
||||
static uint32_t getLayerTypeMask(BaseGameVersion version);
|
||||
|
||||
static int getIndexInTileset(int);
|
||||
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
||||
static int getAttributesSize(BaseGameVersion version);
|
||||
static int getDefaultAttributesSize(BaseGameVersion version);
|
||||
static void setCustomLayout(Project*);
|
||||
|
||||
private:
|
||||
// Stores how each attribute should be laid out for all metatiles, according to the user's config
|
||||
static MetatileAttr behaviorAttr;
|
||||
static MetatileAttr terrainTypeAttr;
|
||||
static MetatileAttr encounterTypeAttr;
|
||||
static MetatileAttr layerTypeAttr;
|
||||
|
||||
static uint32_t unusedAttrMask;
|
||||
|
||||
// Stores how each attribute should be laid out for all metatiles, according to the vanilla games
|
||||
// Used to set default config values and import maps with AdvanceMap
|
||||
static const QHash<QString, MetatileAttr> defaultLayoutFRLG;
|
||||
static const QHash<QString, MetatileAttr> defaultLayoutRSE;
|
||||
static const QHash<BaseGameVersion, const QHash<QString, MetatileAttr>*> defaultLayouts;
|
||||
|
||||
static void setCustomAttributeLayout(MetatileAttr *, uint32_t, uint32_t);
|
||||
static bool isMaskTooSmall(MetatileAttr *, int);
|
||||
static bool doMasksOverlap(QList<uint32_t>);
|
||||
};
|
||||
|
||||
inline bool operator==(const Metatile &a, const Metatile &b) {
|
||||
|
||||
@@ -231,7 +231,6 @@ public:
|
||||
private:
|
||||
void updateMapLayout(Map*);
|
||||
|
||||
void setNewMapHeader(Map* map, int mapIndex);
|
||||
void setNewMapBlockdata(Map* map);
|
||||
void setNewMapBorder(Map *map);
|
||||
void setNewMapEvents(Map *map);
|
||||
|
||||
@@ -111,9 +111,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void initUi();
|
||||
void setMetatileBehaviors();
|
||||
void setMetatileLayersUi();
|
||||
void setVersionSpecificUi();
|
||||
void setAttributesUi();
|
||||
void setMetatileLabelValidator();
|
||||
void initMetatileSelector();
|
||||
void initTileSelector();
|
||||
|
||||
Reference in New Issue
Block a user