diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3a054b..3aa0d5ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Added - Add ability to export map timelapse animated GIFs with `File -> Export Map Timelapse Image...`. +### Changed +- New events will be placed in the center of the current view of the map. + ### Fixed - Fix tileset palette editor crash that could occur when switching maps or tilesets with it open. diff --git a/docsrc/manual/settings-and-options.rst b/docsrc/manual/settings-and-options.rst index 5a4968e3..a3e7d48e 100644 --- a/docsrc/manual/settings-and-options.rst +++ b/docsrc/manual/settings-and-options.rst @@ -44,6 +44,7 @@ determined by this file. ``enable_heal_location_respawn_data``, 1 if ``pokefirered``, project, yes, Adds ``Respawn Map`` and ``Respawn NPC`` to Heal Location events ``enable_object_event_in_connection``, 1 if ``pokefirered``, project, yes, Adds ``In Connection`` to Object events ``enable_floor_number``, 1 if ``pokefirered``, project, yes, Adds ``Floor Number`` to map headers + ``create_map_text_file``, 1 if not ``pokeemerald``, project, yes, A ``text.inc`` or ``text.pory`` file will be created for any new map ``enable_triple_layer_metatiles``, 0, project, yes, Enables triple-layer metatiles (See https://github.com/pret/pokeemerald/wiki/Triple-layer-metatiles) ``custom_scripts``, , project, yes, A list of script files to load into the scripting engine diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index f752e85d..8b4a5dd4 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2649,6 +2649,8 @@ Help + + @@ -2944,6 +2946,16 @@ Export Map Timelapse Image... + + + Open Log File + + + + + Open Config Folder + + diff --git a/forms/newmappopup.ui b/forms/newmappopup.ui index 213b7ceb..32369f57 100644 --- a/forms/newmappopup.ui +++ b/forms/newmappopup.ui @@ -210,13 +210,30 @@ + + + Song + + + + + + + <html><head/><body><p>The default background music for this map.</p></body></html> + + + true + + + + Can Fly To - + <html><head/><body><p>Whether to add a heal location to the new map.</p></body></html> @@ -226,14 +243,14 @@ - + Show Location Name - + <html><head/><body><p>Whether or not to display the location name when the player enters the map.</p></body></html> @@ -243,14 +260,14 @@ - + Allow Running - + <html><head/><body><p>Allows the player to use Running Shoes</p></body></html> @@ -260,14 +277,14 @@ - + Allow Biking - + <html><head/><body><p>Allows the player to use a Bike</p></body></html> @@ -277,14 +294,14 @@ - + Allow Dig & Escape Rope - + <html><head/><body><p>Allows the player to use Dig or Escape Rope</p></body></html> @@ -294,14 +311,14 @@ - + Floor Number - + <html><head/><body><p>Floor number to be used for maps with elevators.</p></body></html> diff --git a/include/config.h b/include/config.h index e9264d15..a0841a53 100644 --- a/include/config.h +++ b/include/config.h @@ -15,7 +15,7 @@ enum MapSortOrder { Layout = 2, }; -class KeyValueConfigBase : public QObject +class KeyValueConfigBase { public: void save(); @@ -38,7 +38,6 @@ public: } virtual void reset() override { this->recentProject = ""; - this->recentMap = ""; this->mapSortOrder = MapSortOrder::Group; this->prettyCursors = true; this->collisionOpacity = 50; @@ -52,7 +51,6 @@ public: this->textEditorGotoLine = ""; } void setRecentProject(QString project); - void setRecentMap(QString map); void setMapSortOrder(MapSortOrder order); void setPrettyCursors(bool enabled); void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray); @@ -69,7 +67,6 @@ public: void setTextEditorOpenFolder(const QString &command); void setTextEditorGotoLine(const QString &command); QString getRecentProject(); - QString getRecentMap(); MapSortOrder getMapSortOrder(); bool getPrettyCursors(); QMap getMainGeometry(); @@ -93,7 +90,6 @@ protected: virtual void setUnreadKeys() override {}; private: QString recentProject; - QString recentMap; QString stringFromByteArray(QByteArray); QByteArray bytesFromString(QString); MapSortOrder mapSortOrder; @@ -136,6 +132,7 @@ public: } virtual void reset() override { this->baseGameVersion = BaseGameVersion::pokeemerald; + this->recentMap = QString(); this->useEncounterJson = true; this->useCustomBorderSize = false; this->enableEventWeatherTrigger = true; @@ -145,12 +142,15 @@ public: this->enableHealLocationRespawnData = false; this->enableObjectEventInConnection = false; this->enableFloorNumber = false; + this->createMapTextFile = false; this->enableTripleLayerMetatiles = false; this->customScripts.clear(); this->readKeys.clear(); } void setBaseGameVersion(BaseGameVersion baseGameVersion); BaseGameVersion getBaseGameVersion(); + void setRecentMap(const QString &map); + QString getRecentMap(); void setEncounterJsonActive(bool active); bool getEncounterJsonActive(); void setUsePoryScript(bool usePoryScript); @@ -173,6 +173,8 @@ public: bool getObjectEventInConnectionEnabled(); void setFloorNumberEnabled(bool enable); bool getFloorNumberEnabled(); + void setCreateMapTextFileEnabled(bool enable); + bool getCreateMapTextFileEnabled(); void setTripleLayerMetatilesEnabled(bool enable); bool getTripleLayerMetatilesEnabled(); void setCustomScripts(QList scripts); @@ -186,6 +188,7 @@ protected: private: BaseGameVersion baseGameVersion; QString projectDir; + QString recentMap; bool useEncounterJson; bool usePoryScript; bool useCustomBorderSize; @@ -196,6 +199,7 @@ private: bool enableHealLocationRespawnData; bool enableObjectEventInConnection; bool enableFloorNumber; + bool createMapTextFile; bool enableTripleLayerMetatiles; QList customScripts; QStringList readKeys; diff --git a/include/core/block.h b/include/core/block.h index 6a787265..9bb1877f 100644 --- a/include/core/block.h +++ b/include/core/block.h @@ -10,13 +10,14 @@ public: Block(); Block(uint16_t); Block(uint16_t tile, uint16_t collision, uint16_t elevation); - Block(const Block&); - bool operator ==(Block); - bool operator !=(Block); + Block(const Block &); + Block &operator=(const Block &); + bool operator ==(Block) const; + bool operator !=(Block) const; uint16_t tile:10; uint16_t collision:2; uint16_t elevation:4; - uint16_t rawValue(); + uint16_t rawValue() const; }; #endif // BLOCK_H diff --git a/include/core/blockdata.h b/include/core/blockdata.h index a8e29d36..a1e45b63 100644 --- a/include/core/blockdata.h +++ b/include/core/blockdata.h @@ -4,31 +4,13 @@ #include "block.h" -#include #include #include -class Blockdata : public QObject +class Blockdata : public QVector { - Q_OBJECT public: - explicit Blockdata(QObject *parent = nullptr); - ~Blockdata() { - if (blocks) delete blocks; - } - -public: - QVector *blocks = nullptr; - void addBlock(uint16_t); - void addBlock(Block); - QByteArray serialize(); - void copyFrom(Blockdata*); - Blockdata* copy(); - bool equals(Blockdata *); - -signals: - -public slots: + QByteArray serialize() const; }; #endif // BLOCKDATA_H diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 8ff606f0..9b96ea3c 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -2,6 +2,8 @@ #ifndef EDITCOMMANDS_H #define EDITCOMMANDS_H +#include "blockdata.h" + #include #include @@ -41,9 +43,8 @@ enum CommandId { class PaintMetatile : public QUndoCommand { public: PaintMetatile(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent = nullptr); - virtual ~PaintMetatile(); void undo() override; void redo() override; @@ -54,8 +55,8 @@ public: private: Map *map; - Blockdata *newMetatiles; - Blockdata *oldMetatiles; + Blockdata newMetatiles; + Blockdata oldMetatiles; unsigned actionId; }; @@ -67,7 +68,7 @@ private: class PaintCollision : public PaintMetatile { public: PaintCollision(Map *map, - Blockdata *oldCollision, Blockdata *newCollision, + const Blockdata &oldCollision, const Blockdata &newCollision, unsigned actionId, QUndoCommand *parent = nullptr) : PaintMetatile(map, oldCollision, newCollision, actionId, parent) { setText("Paint Collision"); @@ -82,9 +83,8 @@ public: class PaintBorder : public QUndoCommand { public: PaintBorder(Map *map, - Blockdata *oldBorder, Blockdata *newBorder, + const Blockdata &oldBorder, const Blockdata &newBorder, unsigned actionId, QUndoCommand *parent = nullptr); - ~PaintBorder(); void undo() override; void redo() override; @@ -95,8 +95,8 @@ public: private: Map *map; - Blockdata *newBorder; - Blockdata *oldBorder; + Blockdata newBorder; + Blockdata oldBorder; unsigned actionId; }; @@ -108,7 +108,7 @@ private: class BucketFillMetatile : public PaintMetatile { public: BucketFillMetatile(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent = nullptr) : PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) { setText("Bucket Fill Metatiles"); @@ -124,7 +124,7 @@ public: class BucketFillCollision : public PaintCollision { public: BucketFillCollision(Map *map, - Blockdata *oldCollision, Blockdata *newCollision, + const Blockdata &oldCollision, const Blockdata &newCollision, QUndoCommand *parent = nullptr) : PaintCollision(map, oldCollision, newCollision, -1, parent) { setText("Flood Fill Collision"); @@ -141,7 +141,7 @@ public: class MagicFillMetatile : public PaintMetatile { public: MagicFillMetatile(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent = nullptr) : PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) { setText("Magic Fill Metatiles"); @@ -156,7 +156,7 @@ public: class MagicFillCollision : public PaintCollision { public: MagicFillCollision(Map *map, - Blockdata *oldCollision, Blockdata *newCollision, + const Blockdata &oldCollision, const Blockdata &newCollision, QUndoCommand *parent = nullptr) : PaintCollision(map, oldCollision, newCollision, -1, parent) { setText("Magic Fill Collision"); @@ -172,9 +172,8 @@ public: class ShiftMetatiles : public QUndoCommand { public: ShiftMetatiles(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent = nullptr); - ~ShiftMetatiles(); void undo() override; void redo() override; @@ -185,8 +184,8 @@ public: private: Map *map; - Blockdata *newMetatiles; - Blockdata *oldMetatiles; + Blockdata newMetatiles; + Blockdata oldMetatiles; unsigned actionId; }; @@ -197,11 +196,10 @@ private: class ResizeMap : public QUndoCommand { public: ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, - Blockdata *oldBorder, Blockdata *newBorder, + const Blockdata &oldBorder, const Blockdata &newBorder, QUndoCommand *parent = nullptr); - ~ResizeMap(); void undo() override; void redo() override; @@ -222,11 +220,11 @@ private: int newBorderWidth; int newBorderHeight; - Blockdata *newMetatiles; - Blockdata *oldMetatiles; + Blockdata newMetatiles; + Blockdata oldMetatiles; - Blockdata *newBorder; - Blockdata *oldBorder; + Blockdata newBorder; + Blockdata oldBorder; }; @@ -238,7 +236,6 @@ public: EventMove(QList events, int deltaX, int deltaY, unsigned actionId, QUndoCommand *parent = nullptr); - ~EventMove(); void undo() override; void redo() override; @@ -262,7 +259,6 @@ public: EventShift(QList events, int deltaX, int deltaY, unsigned actionId, QUndoCommand *parent = nullptr); - ~EventShift(); int id() const override; private: QList events; @@ -276,7 +272,6 @@ class EventCreate : public QUndoCommand { public: EventCreate(Editor *editor, Map *map, Event *event, QUndoCommand *parent = nullptr); - ~EventCreate(); void undo() override; void redo() override; @@ -299,7 +294,6 @@ public: EventDelete(Editor *editor, Map *map, QList selectedEvents, Event *nextSelectedEvent, QUndoCommand *parent = nullptr); - ~EventDelete(); void undo() override; void redo() override; @@ -321,7 +315,6 @@ class EventDuplicate : public QUndoCommand { public: EventDuplicate(Editor *editor, Map *map, QList selectedEvents, QUndoCommand *parent = nullptr); - ~EventDuplicate(); void undo() override; void redo() override; @@ -343,9 +336,8 @@ class ScriptEditMap : public QUndoCommand { public: ScriptEditMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QUndoCommand *parent = nullptr); - ~ScriptEditMap(); void undo() override; void redo() override; @@ -356,8 +348,8 @@ public: private: Map *map; - Blockdata *newMetatiles; - Blockdata *oldMetatiles; + Blockdata newMetatiles; + Blockdata oldMetatiles; int oldMapWidth; int oldMapHeight; diff --git a/include/core/event.h b/include/core/event.h index 4a6e7c4a..6ee59ac5 100644 --- a/include/core/event.h +++ b/include/core/event.h @@ -77,7 +77,7 @@ public: static Event* createNewSecretBaseEvent(Project*); OrderedJson::object buildObjectEventJSON(); - OrderedJson::object buildWarpEventJSON(QMap*); + OrderedJson::object buildWarpEventJSON(const QMap &); OrderedJson::object buildTriggerEventJSON(); OrderedJson::object buildWeatherTriggerEventJSON(); OrderedJson::object buildSignEventJSON(); diff --git a/include/core/map.h b/include/core/map.h index 7052802a..66017ae0 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -47,7 +47,7 @@ public: QString allowRunning; QString allowBiking; QString allowEscapeRope; - int floorNumber; + int floorNumber = 0; QString battle_scene; QString sharedEventsMap = ""; QString sharedScriptsMap = ""; @@ -75,11 +75,11 @@ public: int getBorderHeight(); QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr); QPixmap renderCollision(qreal opacity, bool ignoreCache); - bool mapBlockChanged(int i, Blockdata * cache); - bool borderBlockChanged(int i, Blockdata * cache); + bool mapBlockChanged(int i, const Blockdata &cache); + bool borderBlockChanged(int i, const Blockdata &cache); void cacheBlockdata(); void cacheCollision(); - Block *getBlock(int x, int y); + bool getBlock(int x, int y, Block *out); void setBlock(int x, int y, Block block, bool enableScriptCallback = false); void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); diff --git a/include/core/maplayout.h b/include/core/maplayout.h index d04fbab5..38bb3f23 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -24,15 +24,15 @@ public: QString tileset_secondary_label; Tileset *tileset_primary = nullptr; Tileset *tileset_secondary = nullptr; - Blockdata *blockdata = nullptr; + Blockdata blockdata; QImage border_image; QPixmap border_pixmap; - Blockdata *border = nullptr; - Blockdata *cached_blockdata = nullptr; - Blockdata *cached_collision = nullptr; - Blockdata *cached_border = nullptr; + Blockdata border; + Blockdata cached_blockdata; + Blockdata cached_collision; + Blockdata cached_border; struct { - Blockdata *blocks = nullptr; + Blockdata blocks; QSize dimensions; } lastCommitMapBlocks; // to track map changes }; diff --git a/include/core/metatile.h b/include/core/metatile.h index c016ae7c..5b9bb813 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -11,16 +11,17 @@ class Metatile { public: Metatile(); + Metatile(const Metatile &other) = default; + Metatile &operator=(const Metatile &other) = default; + public: - QList *tiles = nullptr; + QList tiles; uint16_t behavior; // 8 bits RSE, 9 bits FRLG uint8_t layerType; uint8_t encounterType; // FRLG only uint8_t terrainType; // FRLG only QString label; - Metatile *copy(); - void copyInPlace(Metatile*); static int getBlockIndex(int); static QPoint coordFromPixmapCoord(const QPointF &pixelCoord); }; diff --git a/include/core/metatileparser.h b/include/core/metatileparser.h index 7bf0b096..b85e5b36 100644 --- a/include/core/metatileparser.h +++ b/include/core/metatileparser.h @@ -4,13 +4,9 @@ #include "metatile.h" #include -#include -class MetatileParser -{ -public: - MetatileParser(); - QList *parse(QString filepath, bool *error, bool primaryTileset); -}; +namespace MetatileParser { + QList parse(QString filepath, bool *error, bool primaryTileset); +} #endif // METATILEPARSER_H diff --git a/include/core/paletteutil.h b/include/core/paletteutil.h index abc1700a..ce221026 100644 --- a/include/core/paletteutil.h +++ b/include/core/paletteutil.h @@ -4,22 +4,10 @@ #include #include -#include -class PaletteUtil -{ -public: - PaletteUtil(); +namespace PaletteUtil { QList parse(QString filepath, bool *error); void writeJASC(QString filepath, QVector colors, int offset, int nColors); -private: - QList parsePal(QString filepath, bool *error); - QList parseJASC(QString filepath, bool *error); - QList parseAdvanceMapPal(QString filepath, bool *error); - QList parseAdobeColorTable(QString filepath, bool *error); - QList parseTileLayerPro(QString filepath, bool *error); - QList parseAdvancePaletteEditor(QString filepath, bool *error); - int clampColorValue(int value); -}; +} #endif // PALETTEUTIL_H diff --git a/include/core/parseutil.h b/include/core/parseutil.h index 17a1cf4c..009e07c3 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -39,21 +39,21 @@ public: class ParseUtil { public: - ParseUtil(); - void set_root(QString); - static QString readTextFile(QString); - void strip_comment(QString*); - QList* parseAsm(QString); - int evaluateDefine(QString, QMap*); - QStringList readCArray(QString text, QString label); - QMap readNamedIndexCArray(QString text, QString label); - QString readCIncbin(QString text, QString label); - QMap readCDefines(QString filename, QStringList prefixes, QMap = QMap()); - void readCDefinesSorted(QString, QStringList, QStringList*, QMap = QMap()); - QList* getLabelMacros(QList*, QString); - QStringList* getLabelValues(QList*, QString); - bool tryParseJsonFile(QJsonDocument *out, QString filepath); - bool ensureFieldsExist(QJsonObject obj, QList fields); + ParseUtil() { }; + void set_root(const QString &dir); + static QString readTextFile(const QString &path); + static int textFileLineCount(const QString &path); + QList parseAsm(const QString &filename); + int evaluateDefine(const QString&, const QMap&); + QStringList readCArray(const QString &text, const QString &label); + QMap readNamedIndexCArray(const QString &text, const QString &label); + QString readCIncbin(const QString &text, const QString &label); + QMap readCDefines(const QString &filename, const QStringList &prefixes, QMap = { }); + QStringList readCDefinesSorted(const QString&, const QStringList&, const QMap& = { }); + QList getLabelMacros(const QList&, const QString&); + QStringList getLabelValues(const QList&, const QString&); + bool tryParseJsonFile(QJsonDocument *out, const QString &filepath); + bool ensureFieldsExist(const QJsonObject &obj, const QList &fields); // Returns the 1-indexed line number for the definition of scriptLabel in the scripts file at filePath. // Returns 0 if a definition for scriptLabel cannot be found. @@ -63,9 +63,9 @@ public: static QStringList getGlobalScriptLabels(const QString &filePath); static QStringList getGlobalRawScriptLabels(QString text); static QStringList getGlobalPoryScriptLabels(QString text); - static QString &removeStringLiterals(QString &text); - static QString &removeLineComments(QString &text, const QString &commentSymbol); - static QString &removeLineComments(QString &text, const QStringList &commentSymbols); + static QString removeStringLiterals(QString text); + static QString removeLineComments(QString text, const QString &commentSymbol); + static QString removeLineComments(QString text, const QStringList &commentSymbols); static QStringList splitShellCommand(QStringView command); @@ -73,10 +73,10 @@ private: QString root; QString text; QString file; - QList tokenizeExpression(QString expression, QMap* knownIdentifiers); - QList generatePostfix(QList tokens); - int evaluatePostfix(QList postfix); - void error(QString message, QString expression); + QList tokenizeExpression(QString expression, const QMap &knownIdentifiers); + QList generatePostfix(const QList &tokens); + int evaluatePostfix(const QList &postfix); + void error(const QString &message, const QString &expression); static const QRegularExpression re_incScriptLabel; static const QRegularExpression re_globalIncScriptLabel; diff --git a/include/core/regionmap.h b/include/core/regionmap.h index a24ae1ea..03059266 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -79,15 +79,11 @@ public: QString city_map_name; }; -class RegionMap : public QObject +class RegionMap { - Q_OBJECT - public: RegionMap() = default; - ~RegionMap() {}; - Project *project = nullptr; QVector map_squares; diff --git a/include/core/tile.h b/include/core/tile.h index e2b1ec4d..dfcb7117 100644 --- a/include/core/tile.h +++ b/include/core/tile.h @@ -6,8 +6,20 @@ class Tile { public: - Tile() {} - Tile(int tile, bool xflip, bool yflip, int palette); + Tile() : + tile(0), + xflip(false), + yflip(false), + palette(0) + { } + + Tile(int tile, bool xflip, bool yflip, int palette) : + tile(tile), + xflip(xflip), + yflip(yflip), + palette(palette) + { } + public: int tile; bool xflip; diff --git a/include/core/tileset.h b/include/core/tileset.h index c6349cfe..9a02aefc 100644 --- a/include/core/tileset.h +++ b/include/core/tileset.h @@ -9,7 +9,10 @@ class Tileset { public: - Tileset(); + Tileset() = default; + Tileset(const Tileset &other); + Tileset &operator=(const Tileset &other); + public: QString name; QString is_compressed; @@ -24,14 +27,12 @@ public: QString metatile_attrs_path; QString tilesImagePath; QImage tilesImage; - QList palettePaths; + QStringList palettePaths; - QList *tiles = nullptr; - QList *metatiles = nullptr; - QList> *palettes = nullptr; - QList> *palettePreviews = nullptr; - - Tileset* copy(); + QList tiles; + QList metatiles; + QList> palettes; + QList> palettePreviews; static Tileset* getBlockTileset(int, Tileset*, Tileset*); static Metatile* getMetatile(int, Tileset*, Tileset*); diff --git a/include/editor.h b/include/editor.h index e876a3ca..2b70a6f6 100644 --- a/include/editor.h +++ b/include/editor.h @@ -60,7 +60,6 @@ public: void displayCurrentMetatilesSelection(); void redrawCurrentMetatilesSelection(); void displayMovementPermissionSelector(); - void displayElevationMetatiles(); void displayMapEvents(); void displayMapConnections(); void displayMapBorder(); @@ -75,7 +74,6 @@ public: void setEditingObjects(); void setEditingConnections(); void setMapEditingButtonsEnabled(bool enabled); - void clearWildMonTabWidgets(); void setCurrentConnectionDirection(QString curDirection); void updateCurrentConnectionDirection(QString curDirection); void setConnectionsVisibility(bool visible); @@ -99,7 +97,6 @@ public: void selectMapEvent(DraggablePixmapItem *object); void selectMapEvent(DraggablePixmapItem *object, bool toggle); DraggablePixmapItem *addNewEvent(QString event_type); - Event* createNewEvent(QString event_type); void deleteEvent(Event *); void updateSelectedEvents(); void duplicateSelectedEvents(); @@ -143,8 +140,6 @@ public: qreal collisionOpacity = 0.5; void objectsView_onMousePress(QMouseEvent *event); - void objectsView_onMouseMove(QMouseEvent *event); - void objectsView_onMouseRelease(QMouseEvent *event); int getBorderDrawDistance(int dimension); @@ -154,6 +149,7 @@ public: void shouldReselectEvents(); void scaleMapView(int); + void openInTextEditor(const QString &path, int lineNum = 0) const; public slots: void openMapScripts() const; @@ -177,18 +173,9 @@ private: void updateMirroredConnectionMap(MapConnection*, QString); void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false); void updateEncounterFields(EncounterFields newFields); - Event* createNewObjectEvent(); - Event* createNewWarpEvent(); - Event* createNewHealLocationEvent(); - Event* createNewTriggerEvent(); - Event* createNewWeatherTriggerEvent(); - Event* createNewSignEvent(); - Event* createNewHiddenItemEvent(); - Event* createNewSecretBaseEvent(); QString getMovementPermissionText(uint16_t collision, uint16_t elevation); QString getMetatileDisplayMessage(uint16_t metatileId); bool eventLimitReached(Map *, QString); - void openInTextEditor(const QString &path, int lineNum = 0) const; bool startDetachedProcess(const QString &command, const QString &workingDirectory = QString(), qint64 *pid = nullptr) const; diff --git a/include/mainwindow.h b/include/mainwindow.h index 3d09c5e7..63d430a7 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -77,8 +77,8 @@ public: Q_INVOKABLE void setPrimaryTilesetPalettes(QList>> palettes); Q_INVOKABLE void setSecondaryTilesetPalette(int paletteIndex, QList> colors); Q_INVOKABLE void setSecondaryTilesetPalettes(QList>> palettes); - QJSValue getTilesetPalette(QList> *palettes, int paletteIndex); - QJSValue getTilesetPalettes(QList> *palettes); + QJSValue getTilesetPalette(const QList> &palettes, int paletteIndex); + QJSValue getTilesetPalettes(const QList> &palettes); Q_INVOKABLE QJSValue getPrimaryTilesetPalette(int paletteIndex); Q_INVOKABLE QJSValue getPrimaryTilesetPalettes(); Q_INVOKABLE QJSValue getSecondaryTilesetPalette(int paletteIndex); @@ -222,6 +222,8 @@ private slots: void on_toolButton_ExpandAll_clicked(); void on_toolButton_CollapseAll_clicked(); void on_actionAbout_Porymap_triggered(); + void on_actionOpen_Log_File_triggered(); + void on_actionOpen_Config_Folder_triggered(); void on_pushButton_AddCustomHeaderField_clicked(); void on_pushButton_DeleteCustomHeaderField_clicked(); void on_tableWidget_CustomHeaderFields_cellChanged(int row, int column); @@ -236,14 +238,14 @@ private slots: private: Ui::MainWindow *ui; - QLabel *label_MapRulerStatus; - TilesetEditor *tilesetEditor = nullptr; - RegionMapEditor *regionMapEditor = nullptr; - ShortcutsEditor *shortcutsEditor = nullptr; - MapImageExporter *mapImageExporter = nullptr; + QLabel *label_MapRulerStatus = nullptr; + QPointer tilesetEditor = nullptr; + QPointer regionMapEditor = nullptr; + QPointer shortcutsEditor = nullptr; + QPointer mapImageExporter = nullptr; + QPointer newmapprompt = nullptr; + QPointer preferenceEditor = nullptr; FilterChildrenProxyModel *mapListProxyModel; - NewMapPopup *newmapprompt = nullptr; - PreferenceEditor *preferenceEditor = nullptr; QStandardItemModel *mapListModel; QList *mapGroupItemsList; QMap mapListIndexes; diff --git a/include/project.h b/include/project.h index 14e24939..b8620fc4 100644 --- a/include/project.h +++ b/include/project.h @@ -31,35 +31,37 @@ public: Project(const Project &) = delete; Project & operator = (const Project &) = delete; + inline QWidget *parentWidget() const { return static_cast(parent()); } + public: QString root; - QStringList *groupNames = nullptr; - QMap *mapGroups; + QStringList groupNames; + QMap mapGroups; QList groupedMapNames; - QStringList *mapNames = nullptr; + QStringList mapNames; QMap miscConstants; QList healLocations; - QMap* mapConstantsToMapNames; - QMap* mapNamesToMapConstants; - QList mapLayoutsTable; - QList mapLayoutsTableMaster; + QMap mapConstantsToMapNames; + QMap mapNamesToMapConstants; + QStringList mapLayoutsTable; + QStringList mapLayoutsTableMaster; QString layoutsLabel; QMap mapLayouts; QMap mapLayoutsMaster; - QMap *mapSecToMapHoverName; + QMap mapSecToMapHoverName; QMap mapSectionNameToValue; QMap mapSectionValueToName; - QStringList *itemNames = nullptr; - QStringList *flagNames = nullptr; - QStringList *varNames = nullptr; - QStringList *movementTypes = nullptr; - QStringList *mapTypes = nullptr; - QStringList *mapBattleScenes = nullptr; - QStringList *weatherNames = nullptr; - QStringList *coordEventWeatherNames = nullptr; - QStringList *secretBaseIds = nullptr; - QStringList *bgEventFacingDirections = nullptr; - QStringList *trainerTypes = nullptr; + QStringList itemNames; + QStringList flagNames; + QStringList varNames; + QStringList movementTypes; + QStringList mapTypes; + QStringList mapBattleScenes; + QStringList weatherNames; + QStringList coordEventWeatherNames; + QStringList secretBaseIds; + QStringList bgEventFacingDirections; + QStringList trainerTypes; QStringList eventScriptLabels; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; @@ -83,16 +85,16 @@ public: DataQualifiers getDataQualifiers(QString, QString); QMap dataQualifiers; - QMap *mapCache; + QMap mapCache; Map* loadMap(QString); Map* getMap(QString); - QMap *tilesetCache = nullptr; + QMap tilesetCache; Tileset* loadTileset(QString, Tileset *tileset = nullptr); Tileset* getTileset(QString, bool forceLoad = false); QMap tilesetLabels; - Blockdata* readBlockdata(QString); + Blockdata readBlockdata(QString); bool loadBlockdata(Map*); void saveTextFile(QString path, QString text); @@ -100,7 +102,6 @@ public: void deleteFile(QString path); bool readMapGroups(); - Map* addNewMapToGroup(QString mapName, int groupNum); Map* addNewMapToGroup(QString, int, Map*, bool); QString getNewMapName(); QString getProjectTitle(); @@ -130,7 +131,7 @@ public: void saveLayoutBlockdata(Map*); void saveLayoutBorder(Map*); - void writeBlockdata(QString, Blockdata*); + void writeBlockdata(QString, const Blockdata &); void saveAllMaps(); void saveMap(Map*); void saveAllDataStructures(); @@ -222,7 +223,6 @@ private: static int default_map_size; static int max_object_events; - QWidget *parent; QStringListModel *eventScriptLabelModel = nullptr; QCompleter *eventScriptLabelCompleter = nullptr; diff --git a/include/ui/currentselectedmetatilespixmapitem.h b/include/ui/currentselectedmetatilespixmapitem.h index 0bc8e0e3..76c52d55 100644 --- a/include/ui/currentselectedmetatilespixmapitem.h +++ b/include/ui/currentselectedmetatilespixmapitem.h @@ -5,8 +5,7 @@ #include "metatileselector.h" #include -class CurrentSelectedMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem { - Q_OBJECT +class CurrentSelectedMetatilesPixmapItem : public QGraphicsPixmapItem { public: CurrentSelectedMetatilesPixmapItem(Map *map, MetatileSelector *metatileSelector) { this->map = map; diff --git a/include/ui/draggablepixmapitem.h b/include/ui/draggablepixmapitem.h index 4bbdf982..a836ea23 100644 --- a/include/ui/draggablepixmapitem.h +++ b/include/ui/draggablepixmapitem.h @@ -33,7 +33,8 @@ public: int last_y; void updatePosition(); - void move(int x, int y); + void move(int dx, int dy); + void moveTo(const QPoint &pos); void emitPositionChanged(); void updatePixmap(); void bind(QComboBox *combo, QString key); diff --git a/include/ui/newmappopup.h b/include/ui/newmappopup.h index c573b16e..c77470ca 100644 --- a/include/ui/newmappopup.h +++ b/include/ui/newmappopup.h @@ -33,6 +33,7 @@ private: Project *project; void setDefaultValues(int, QString); bool checkNewMapDimensions(); + bool checkNewMapGroup(); private slots: void on_pushButton_NewMap_Accept_clicked(); diff --git a/porymap.pro b/porymap.pro index 1c3b2fac..91763837 100644 --- a/porymap.pro +++ b/porymap.pro @@ -25,7 +25,6 @@ SOURCES += src/core/block.cpp \ src/core/metatileparser.cpp \ src/core/paletteutil.cpp \ src/core/parseutil.cpp \ - src/core/tile.cpp \ src/core/tileset.cpp \ src/core/regionmap.cpp \ src/core/wildmoninfo.cpp \ diff --git a/src/config.cpp b/src/config.cpp index 5ef3723f..1d0d55bf 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -109,8 +109,6 @@ QString PorymapConfig::getConfigFilepath() { void PorymapConfig::parseConfigKeyValue(QString key, QString value) { if (key == "recent_project") { this->recentProject = value; - } else if (key == "recent_map") { - this->recentMap = value; } else if (key == "pretty_cursors") { bool ok; this->prettyCursors = value.toInt(&ok); @@ -202,7 +200,6 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { QMap PorymapConfig::getKeyValueMap() { QMap map; map.insert("recent_project", this->recentProject); - map.insert("recent_map", this->recentMap); map.insert("pretty_cursors", this->prettyCursors ? "1" : "0"); map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder)); map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry)); @@ -250,11 +247,6 @@ void PorymapConfig::setRecentProject(QString project) { this->save(); } -void PorymapConfig::setRecentMap(QString map) { - this->recentMap = map; - this->save(); -} - void PorymapConfig::setMapSortOrder(MapSortOrder order) { this->mapSortOrder = order; this->save(); @@ -339,10 +331,6 @@ QString PorymapConfig::getRecentProject() { return this->recentProject; } -QString PorymapConfig::getRecentMap() { - return this->recentMap; -} - MapSortOrder PorymapConfig::getMapSortOrder() { return this->mapSortOrder; } @@ -453,6 +441,8 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { this->baseGameVersion = BaseGameVersion::pokeemerald; logWarn(QString("Invalid config value for base_game_version: '%1'. Must be 'pokeruby', 'pokefirered' or 'pokeemerald'.").arg(value)); } + } else if (key == "recent_map") { + this->recentMap = value; } else if (key == "use_encounter_json") { bool ok; this->useEncounterJson = value.toInt(&ok); @@ -513,6 +503,12 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { if (!ok) { logWarn(QString("Invalid config value for enable_floor_number: '%1'. Must be 0 or 1.").arg(value)); } + } else if (key == "create_map_text_file") { + bool ok; + this->createMapTextFile = value.toInt(&ok); + if (!ok) { + logWarn(QString("Invalid config value for create_map_text_file: '%1'. Must be 0 or 1.").arg(value)); + } } else if (key == "enable_triple_layer_metatiles") { bool ok; this->enableTripleLayerMetatiles = value.toInt(&ok); @@ -545,11 +541,13 @@ void ProjectConfig::setUnreadKeys() { if (!readKeys.contains("enable_heal_location_respawn_data")) this->enableHealLocationRespawnData = isPokefirered; if (!readKeys.contains("enable_object_event_in_connection")) this->enableObjectEventInConnection = isPokefirered; if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered; + if (!readKeys.contains("create_map_text_file")) this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald); } QMap ProjectConfig::getKeyValueMap() { QMap map; map.insert("base_game_version", baseGameVersionMap.value(this->baseGameVersion)); + map.insert("recent_map", this->recentMap); map.insert("use_encounter_json", QString::number(this->useEncounterJson)); map.insert("use_poryscript", QString::number(this->usePoryScript)); map.insert("use_custom_border_size", QString::number(this->useCustomBorderSize)); @@ -560,6 +558,7 @@ QMap ProjectConfig::getKeyValueMap() { map.insert("enable_heal_location_respawn_data", QString::number(this->enableHealLocationRespawnData)); map.insert("enable_object_event_in_connection", QString::number(this->enableObjectEventInConnection)); map.insert("enable_floor_number", QString::number(this->enableFloorNumber)); + map.insert("create_map_text_file", QString::number(this->createMapTextFile)); map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles)); map.insert("custom_scripts", this->customScripts.join(",")); return map; @@ -584,7 +583,7 @@ void ProjectConfig::onNewConfigFileCreated() { form.addRow(new QLabel("Game Version"), baseGameVersionComboBox); QDialogButtonBox buttonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog); - connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); form.addRow(&buttonBox); if (dialog.exec() == QDialog::Accepted) { @@ -600,6 +599,7 @@ void ProjectConfig::onNewConfigFileCreated() { this->enableHealLocationRespawnData = isPokefirered; this->enableObjectEventInConnection = isPokefirered; this->enableFloorNumber = isPokefirered; + this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald); this->useEncounterJson = true; this->usePoryScript = false; this->enableTripleLayerMetatiles = false; @@ -623,6 +623,15 @@ BaseGameVersion ProjectConfig::getBaseGameVersion() { return this->baseGameVersion; } +void ProjectConfig::setRecentMap(const QString &map) { + this->recentMap = map; + this->save(); +} + +QString ProjectConfig::getRecentMap() { + return this->recentMap; +} + void ProjectConfig::setEncounterJsonActive(bool active) { this->useEncounterJson = active; this->save(); @@ -713,6 +722,15 @@ bool ProjectConfig::getFloorNumberEnabled() { return this->enableFloorNumber; } +void ProjectConfig::setCreateMapTextFileEnabled(bool enable) { + this->createMapTextFile = enable; + this->save(); +} + +bool ProjectConfig::getCreateMapTextFileEnabled() { + return this->createMapTextFile; +} + void ProjectConfig::setTripleLayerMetatilesEnabled(bool enable) { this->enableTripleLayerMetatiles = enable; this->save(); diff --git a/src/core/block.cpp b/src/core/block.cpp index 2a6b057d..680384fd 100644 --- a/src/core/block.cpp +++ b/src/core/block.cpp @@ -1,38 +1,43 @@ #include "block.h" -Block::Block() : tile(0), collision(0), elevation(0) { +Block::Block() : tile(0), collision(0), elevation(0) { } + +Block::Block(uint16_t tile, uint16_t collision, uint16_t elevation) : + tile(tile), + collision(collision), + elevation(elevation) +{ } + +Block::Block(uint16_t word) : + tile(word & 0x3ff), + collision((word >> 10) & 0x3), + elevation((word >> 12) & 0xf) +{ } + +Block::Block(const Block &other) : + tile(other.tile), + collision(other.collision), + elevation(other.elevation) +{ } + +Block &Block::operator=(const Block &other) { + tile = other.tile; + collision = other.collision; + elevation = other.elevation; + return *this; } -Block::Block(uint16_t tile, uint16_t collision, uint16_t elevation) { - this->tile = tile; - this->collision = collision; - this->elevation = elevation; -} - -Block::Block(uint16_t word) -{ - tile = word & 0x3ff; - collision = (word >> 10) & 0x3; - elevation = (word >> 12) & 0xf; -} - -Block::Block(const Block &block) { - tile = block.tile; - collision = block.collision; - elevation = block.elevation; -} - -uint16_t Block::rawValue() { +uint16_t Block::rawValue() const { return static_cast( (tile & 0x3ff) + ((collision & 0x3) << 10) + ((elevation & 0xf) << 12)); } -bool Block::operator ==(Block other) { +bool Block::operator ==(Block other) const { return (tile == other.tile) && (collision == other.collision) && (elevation == other.elevation); } -bool Block::operator !=(Block other) { +bool Block::operator !=(Block other) const { return !(operator ==(other)); } diff --git a/src/core/blockdata.cpp b/src/core/blockdata.cpp index 77239add..5fcd4e32 100644 --- a/src/core/blockdata.cpp +++ b/src/core/blockdata.cpp @@ -1,54 +1,11 @@ #include "blockdata.h" -Blockdata::Blockdata(QObject *parent) : QObject(parent) -{ - blocks = new QVector; -} - -void Blockdata::addBlock(uint16_t word) { - Block block(word); - blocks->append(block); -} - -void Blockdata::addBlock(Block block) { - blocks->append(block); -} - -QByteArray Blockdata::serialize() { +QByteArray Blockdata::serialize() const { QByteArray data; - for (int i = 0; i < blocks->length(); i++) { - Block block = blocks->value(i); + for (const auto &block : *this) { uint16_t word = block.rawValue(); data.append(static_cast(word & 0xff)); data.append(static_cast((word >> 8) & 0xff)); } return data; } - -void Blockdata::copyFrom(Blockdata* other) { - blocks->clear(); - for (int i = 0; i < other->blocks->length(); i++) { - addBlock(other->blocks->value(i)); - } -} - -Blockdata* Blockdata::copy() { - Blockdata* blockdata = new Blockdata; - blockdata->copyFrom(this); - return blockdata; -} - -bool Blockdata::equals(Blockdata *other) { - if (!other) { - return false; - } - if (blocks->length() != other->blocks->length()) { - return false; - } - for (int i = 0; i < blocks->length(); i++) { - if (blocks->value(i) != other->blocks->value(i)) { - return false; - } - } - return true; -} diff --git a/src/core/editcommands.cpp b/src/core/editcommands.cpp index 05ecc22a..e7a3d300 100644 --- a/src/core/editcommands.cpp +++ b/src/core/editcommands.cpp @@ -31,8 +31,9 @@ void renderMapBlocks(Map *map, bool ignoreCache = false) { map->mapItem->draw(ignoreCache); map->collisionItem->draw(ignoreCache); } + PaintMetatile::PaintMetatile(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) { setText("Paint Metatiles"); @@ -43,21 +44,14 @@ PaintMetatile::PaintMetatile(Map *map, this->actionId = actionId; } -PaintMetatile::~PaintMetatile() { - if (newMetatiles) delete newMetatiles; - if (oldMetatiles) delete oldMetatiles; -} - void PaintMetatile::redo() { QUndoCommand::redo(); if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(newMetatiles); - } + map->layout->blockdata = newMetatiles; - map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata); + map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata; renderMapBlocks(map); } @@ -65,11 +59,9 @@ void PaintMetatile::redo() { void PaintMetatile::undo() { if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(oldMetatiles); - } + map->layout->blockdata = oldMetatiles; - map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata); + map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata; renderMapBlocks(map); @@ -79,13 +71,13 @@ void PaintMetatile::undo() { bool PaintMetatile::mergeWith(const QUndoCommand *command) { const PaintMetatile *other = static_cast(command); - if (this->map != other->map) + if (map != other->map) return false; if (actionId != other->actionId) return false; - this->newMetatiles->copyFrom(other->newMetatiles); + newMetatiles = other->newMetatiles; return true; } @@ -95,7 +87,7 @@ bool PaintMetatile::mergeWith(const QUndoCommand *command) { ******************************************************************************/ PaintBorder::PaintBorder(Map *map, - Blockdata *oldBorder, Blockdata *newBorder, + const Blockdata &oldBorder, const Blockdata &newBorder, unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) { setText("Paint Border"); @@ -106,19 +98,12 @@ PaintBorder::PaintBorder(Map *map, this->actionId = actionId; } -PaintBorder::~PaintBorder() { - if (newBorder) delete newBorder; - if (oldBorder) delete oldBorder; -} - void PaintBorder::redo() { QUndoCommand::redo(); if (!map) return; - if (map->layout->border) { - map->layout->border->copyFrom(newBorder); - } + map->layout->border = newBorder; map->borderItem->draw(); } @@ -126,9 +111,7 @@ void PaintBorder::redo() { void PaintBorder::undo() { if (!map) return; - if (map->layout->border) { - map->layout->border->copyFrom(oldBorder); - } + map->layout->border = oldBorder; map->borderItem->draw(); @@ -140,7 +123,7 @@ void PaintBorder::undo() { ******************************************************************************/ ShiftMetatiles::ShiftMetatiles(Map *map, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) { setText("Shift Metatiles"); @@ -151,21 +134,14 @@ ShiftMetatiles::ShiftMetatiles(Map *map, this->actionId = actionId; } -ShiftMetatiles::~ShiftMetatiles() { - if (newMetatiles) delete newMetatiles; - if (oldMetatiles) delete oldMetatiles; -} - void ShiftMetatiles::redo() { QUndoCommand::redo(); if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(newMetatiles); - } + map->layout->blockdata = newMetatiles; - map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata); + map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata; renderMapBlocks(map, true); } @@ -173,11 +149,9 @@ void ShiftMetatiles::redo() { void ShiftMetatiles::undo() { if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(oldMetatiles); - } + map->layout->blockdata = oldMetatiles; - map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata); + map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata; renderMapBlocks(map, true); @@ -193,7 +167,7 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) { if (actionId != other->actionId) return false; - this->newMetatiles->copyFrom(other->newMetatiles); + this->newMetatiles = other->newMetatiles; return true; } @@ -203,9 +177,9 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) { ******************************************************************************/ ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, - Blockdata *oldBorder, Blockdata *newBorder, + const Blockdata &oldBorder, const Blockdata &newBorder, QUndoCommand *parent) : QUndoCommand(parent) { setText("Resize Map"); @@ -230,25 +204,16 @@ ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions, this->newBorder = newBorder; } -ResizeMap::~ResizeMap() { - if (newMetatiles) delete newMetatiles; - if (oldMetatiles) delete oldMetatiles; -} - void ResizeMap::redo() { QUndoCommand::redo(); if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(newMetatiles); - map->setDimensions(newMapWidth, newMapHeight, false); - } + map->layout->blockdata = newMetatiles; + map->setDimensions(newMapWidth, newMapHeight, false); - if (map->layout->border) { - map->layout->border->copyFrom(newBorder); - map->setBorderDimensions(newBorderWidth, newBorderHeight, false); - } + map->layout->border = newBorder; + map->setBorderDimensions(newBorderWidth, newBorderHeight, false); map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight()); @@ -258,15 +223,11 @@ void ResizeMap::redo() { void ResizeMap::undo() { if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(oldMetatiles); - map->setDimensions(oldMapWidth, oldMapHeight, false); - } + map->layout->blockdata = oldMetatiles; + map->setDimensions(oldMapWidth, oldMapHeight, false); - if (map->layout->border) { - map->layout->border->copyFrom(oldBorder); - map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false); - } + map->layout->border = oldBorder; + map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false); map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight()); @@ -292,8 +253,6 @@ EventMove::EventMove(QList events, this->actionId = actionId; } -EventMove::~EventMove() {} - void EventMove::redo() { QUndoCommand::redo(); @@ -340,8 +299,6 @@ EventShift::EventShift(QList events, setText("Shift Events"); } -EventShift::~EventShift() {} - int EventShift::id() const { return CommandId::ID_EventShift | getEventTypeMask(events); } @@ -360,13 +317,11 @@ EventCreate::EventCreate(Editor *editor, Map *map, Event *event, this->event = event; } -EventCreate::~EventCreate() {} - void EventCreate::redo() { QUndoCommand::redo(); map->addEvent(event); - + editor->project->loadEventPixmaps(map->getAllEvents()); editor->addMapEvent(event); @@ -412,8 +367,6 @@ EventDelete::EventDelete(Editor *editor, Map *map, this->nextSelectedEvent = nextSelectedEvent; } -EventDelete::~EventDelete() {} - void EventDelete::redo() { QUndoCommand::redo(); @@ -435,7 +388,7 @@ void EventDelete::redo() { void EventDelete::undo() { for (Event *event : selectedEvents) { map->addEvent(event); - + editor->project->loadEventPixmaps(map->getAllEvents()); editor->addMapEvent(event); } @@ -469,8 +422,6 @@ EventDuplicate::EventDuplicate(Editor *editor, Map *map, this->selectedEvents = selectedEvents; } -EventDuplicate::~EventDuplicate() {} - void EventDuplicate::redo() { QUndoCommand::redo(); @@ -517,7 +468,7 @@ int EventDuplicate::id() const { ScriptEditMap::ScriptEditMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions, - Blockdata *oldMetatiles, Blockdata *newMetatiles, + const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QUndoCommand *parent) : QUndoCommand(parent) { setText("Script Edit Map"); @@ -532,24 +483,17 @@ ScriptEditMap::ScriptEditMap(Map *map, this->newMapHeight = newMapDimensions.height(); } -ScriptEditMap::~ScriptEditMap() { - if (newMetatiles) delete newMetatiles; - if (oldMetatiles) delete oldMetatiles; -} - void ScriptEditMap::redo() { QUndoCommand::redo(); if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(newMetatiles); - if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) { - map->setDimensions(newMapWidth, newMapHeight, false); - } + map->layout->blockdata = newMetatiles; + if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) { + map->setDimensions(newMapWidth, newMapHeight, false); } - map->layout->lastCommitMapBlocks.blocks->copyFrom(newMetatiles); + map->layout->lastCommitMapBlocks.blocks = newMetatiles; map->layout->lastCommitMapBlocks.dimensions = QSize(newMapWidth, newMapHeight); renderMapBlocks(map); @@ -558,14 +502,12 @@ void ScriptEditMap::redo() { void ScriptEditMap::undo() { if (!map) return; - if (map->layout->blockdata) { - map->layout->blockdata->copyFrom(oldMetatiles); - if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) { - map->setDimensions(oldMapWidth, oldMapHeight, false); - } + map->layout->blockdata = oldMetatiles; + if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) { + map->setDimensions(oldMapWidth, oldMapHeight, false); } - map->layout->lastCommitMapBlocks.blocks->copyFrom(oldMetatiles); + map->layout->lastCommitMapBlocks.blocks = oldMetatiles; map->layout->lastCommitMapBlocks.dimensions = QSize(oldMapWidth, oldMapHeight); renderMapBlocks(map); diff --git a/src/core/event.cpp b/src/core/event.cpp index 754a3ab9..ea8e078f 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -12,29 +12,25 @@ QString EventType::HiddenItem = "event_hidden_item"; QString EventType::SecretBase = "event_secret_base"; QString EventType::HealLocation = "event_heal_location"; -Event::Event() -{ - this->spriteWidth = 16; - this->spriteHeight = 16; - this->usingSprite = false; -} +Event::Event() : + spriteWidth(16), + spriteHeight(16), + usingSprite(false) +{ } -Event::Event(const Event& toCopy) -{ - Event(); - this->values = toCopy.values; - this->customValues = toCopy.customValues; - this->pixmap = toCopy.pixmap; - this->spriteWidth = toCopy.spriteWidth; - this->spriteHeight = toCopy.spriteHeight; - this->frame = toCopy.frame; - this->hFlip = toCopy.hFlip; - this->usingSprite = toCopy.usingSprite; -} +Event::Event(const Event& toCopy) : + values(toCopy.values), + customValues(toCopy.customValues), + pixmap(toCopy.pixmap), + spriteWidth(toCopy.spriteWidth), + spriteHeight(toCopy.spriteHeight), + frame(toCopy.frame), + hFlip(toCopy.hFlip), + usingSprite(toCopy.usingSprite) +{ } -Event::Event(QJsonObject obj, QString type) +Event::Event(QJsonObject obj, QString type) : Event() { - Event(); this->put("event_type", type); this->readCustomValues(obj); } @@ -75,7 +71,7 @@ Event* Event::createNewObjectEvent(Project *project) event->put("event_group_type", "object_event_group"); event->put("event_type", EventType::Object); event->put("sprite", project->getEventObjGfxConstants().keys().first()); - event->put("movement_type", project->movementTypes->first()); + event->put("movement_type", project->movementTypes.first()); if (projectConfig.getObjectEventInConnectionEnabled()) { event->put("in_connection", false); } @@ -84,7 +80,7 @@ Event* Event::createNewObjectEvent(Project *project) event->put("script_label", "NULL"); event->put("event_flag", "0"); event->put("replacement", "0"); - event->put("trainer_type", project->trainerTypes->value(0, "0")); + event->put("trainer_type", project->trainerTypes.value(0, "0")); event->put("sight_radius_tree_id", 0); event->put("elevation", 3); return event; @@ -122,7 +118,7 @@ Event* Event::createNewTriggerEvent(Project *project) event->put("event_group_type", "coord_event_group"); event->put("event_type", EventType::Trigger); event->put("script_label", "NULL"); - event->put("script_var", project->varNames->first()); + event->put("script_var", project->varNames.first()); event->put("script_var_value", "0"); event->put("elevation", 0); return event; @@ -133,7 +129,7 @@ Event* Event::createNewWeatherTriggerEvent(Project *project) Event *event = new Event; event->put("event_group_type", "coord_event_group"); event->put("event_type", EventType::WeatherTrigger); - event->put("weather", project->coordEventWeatherNames->first()); + event->put("weather", project->coordEventWeatherNames.first()); event->put("elevation", 0); return event; } @@ -143,7 +139,7 @@ Event* Event::createNewSignEvent(Project *project) Event *event = new Event; event->put("event_group_type", "bg_event_group"); event->put("event_type", EventType::Sign); - event->put("player_facing_direction", project->bgEventFacingDirections->first()); + event->put("player_facing_direction", project->bgEventFacingDirections.first()); event->put("script_label", "NULL"); event->put("elevation", 0); return event; @@ -154,8 +150,8 @@ Event* Event::createNewHiddenItemEvent(Project *project) Event *event = new Event; event->put("event_group_type", "bg_event_group"); event->put("event_type", EventType::HiddenItem); - event->put("item", project->itemNames->first()); - event->put("flag", project->flagNames->first()); + event->put("item", project->itemNames.first()); + event->put("flag", project->flagNames.first()); event->put("elevation", 3); if (projectConfig.getHiddenItemQuantityEnabled()) { event->put("quantity", 1); @@ -171,7 +167,7 @@ Event* Event::createNewSecretBaseEvent(Project *project) Event *event = new Event; event->put("event_group_type", "bg_event_group"); event->put("event_type", EventType::SecretBase); - event->put("secret_base_id", project->secretBaseIds->first()); + event->put("secret_base_id", project->secretBaseIds.first()); event->put("elevation", 0); return event; } @@ -325,13 +321,13 @@ OrderedJson::object Event::buildObjectEventJSON() return eventObj; } -OrderedJson::object Event::buildWarpEventJSON(QMap *mapNamesToMapConstants) +OrderedJson::object Event::buildWarpEventJSON(const QMap &mapNamesToMapConstants) { OrderedJson::object warpObj; warpObj["x"] = this->getU16("x"); warpObj["y"] = this->getU16("y"); warpObj["elevation"] = this->getInt("elevation"); - warpObj["dest_map"] = mapNamesToMapConstants->value(this->get("destination_map_name")); + warpObj["dest_map"] = mapNamesToMapConstants.value(this->get("destination_map_name")); warpObj["dest_warp_id"] = this->getInt("destination_warp"); this->addCustomValuesTo(&warpObj); diff --git a/src/core/map.cpp b/src/core/map.cpp index 14da4650..3d839ecc 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -78,96 +78,61 @@ int Map::getBorderHeight() { return layout->border_height.toInt(nullptr, 0); } -bool Map::mapBlockChanged(int i, Blockdata * cache) { - if (!cache) +bool Map::mapBlockChanged(int i, const Blockdata &cache) { + if (cache.length() <= i) return true; - if (!layout->blockdata) - return true; - if (!cache->blocks) - return true; - if (!layout->blockdata->blocks) - return true; - if (cache->blocks->length() <= i) - return true; - if (layout->blockdata->blocks->length() <= i) + if (layout->blockdata.length() <= i) return true; - return layout->blockdata->blocks->value(i) != cache->blocks->value(i); + return layout->blockdata.at(i) != cache.at(i); } -bool Map::borderBlockChanged(int i, Blockdata * cache) { - if (!cache) +bool Map::borderBlockChanged(int i, const Blockdata &cache) { + if (cache.length() <= i) return true; - if (!layout->border) - return true; - if (!cache->blocks) - return true; - if (!layout->border->blocks) - return true; - if (cache->blocks->length() <= i) - return true; - if (layout->border->blocks->length() <= i) + if (layout->border.length() <= i) return true; - return layout->border->blocks->value(i) != cache->blocks->value(i); + return layout->border.at(i) != cache.at(i); } void Map::cacheBorder() { - if (layout->cached_border) delete layout->cached_border; - layout->cached_border = new Blockdata; - if (layout->border && layout->border->blocks) { - for (int i = 0; i < layout->border->blocks->length(); i++) { - Block block = layout->border->blocks->value(i); - layout->cached_border->blocks->append(block); - } - } + layout->cached_border.clear(); + for (const auto &block : layout->border) + layout->cached_border.append(block); } void Map::cacheBlockdata() { - if (layout->cached_blockdata) delete layout->cached_blockdata; - layout->cached_blockdata = new Blockdata; - if (layout->blockdata && layout->blockdata->blocks) { - for (int i = 0; i < layout->blockdata->blocks->length(); i++) { - Block block = layout->blockdata->blocks->value(i); - layout->cached_blockdata->blocks->append(block); - } - } + layout->cached_blockdata.clear(); + for (const auto &block : layout->blockdata) + layout->cached_blockdata.append(block); } void Map::cacheCollision() { - if (layout->cached_collision) delete layout->cached_collision; - layout->cached_collision = new Blockdata; - if (layout->blockdata && layout->blockdata->blocks) { - for (int i = 0; i < layout->blockdata->blocks->length(); i++) { - Block block = layout->blockdata->blocks->value(i); - layout->cached_collision->blocks->append(block); - } - } + layout->cached_collision.clear(); + for (const auto &block : layout->blockdata) + layout->cached_collision.append(block); } QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) { bool changed_any = false; int width_ = getWidth(); int height_ = getHeight(); - if ( - collision_image.isNull() - || collision_image.width() != width_ * 16 - || collision_image.height() != height_ * 16 - ) { + if (collision_image.isNull() || collision_image.width() != width_ * 16 || collision_image.height() != height_ * 16) { collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888); changed_any = true; } - if (!(layout->blockdata && layout->blockdata->blocks && width_ && height_)) { + if (layout->blockdata.isEmpty() || !width_ || !height_) { collision_pixmap = collision_pixmap.fromImage(collision_image); return collision_pixmap; } QPainter painter(&collision_image); - for (int i = 0; i < layout->blockdata->blocks->length(); i++) { - if (!ignoreCache && layout->cached_collision && !mapBlockChanged(i, layout->cached_collision)) { + for (int i = 0; i < layout->blockdata.length(); i++) { + if (!ignoreCache && !mapBlockChanged(i, layout->cached_collision)) { continue; } changed_any = true; - Block block = layout->blockdata->blocks->value(i); + Block block = layout->blockdata.at(i); QImage metatile_image = getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity); QImage collision_metatile_image = getCollisionMetatileImage(block); int map_y = width_ ? i / width_ : 0; @@ -192,26 +157,22 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) { bool changed_any = false; int width_ = getWidth(); int height_ = getHeight(); - if ( - image.isNull() - || image.width() != width_ * 16 - || image.height() != height_ * 16 - ) { + if (image.isNull() || image.width() != width_ * 16 || image.height() != height_ * 16) { image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888); changed_any = true; } - if (!(layout->blockdata && layout->blockdata->blocks && width_ && height_)) { + if (layout->blockdata.isEmpty() || !width_ || !height_) { pixmap = pixmap.fromImage(image); return pixmap; } QPainter painter(&image); - for (int i = 0; i < layout->blockdata->blocks->length(); i++) { + for (int i = 0; i < layout->blockdata.length(); i++) { if (!ignoreCache && !mapBlockChanged(i, layout->cached_blockdata)) { continue; } changed_any = true; - Block block = layout->blockdata->blocks->value(i); + Block block = layout->blockdata.at(i); QImage metatile_image = getMetatileImage( block.tile, fromLayout ? fromLayout->tileset_primary : layout->tileset_primary, @@ -245,18 +206,18 @@ QPixmap Map::renderBorder(bool ignoreCache) { layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888); border_resized = true; } - if (!(layout->border && layout->border->blocks)) { + if (layout->border.isEmpty()) { layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image); return layout->border_pixmap; } QPainter painter(&layout->border_image); - for (int i = 0; i < layout->border->blocks->length(); i++) { + for (int i = 0; i < layout->border.length(); i++) { if (!ignoreCache && (!border_resized && !borderBlockChanged(i, layout->cached_border))) { continue; } changed_any = true; - Block block = layout->border->blocks->value(i); + Block block = layout->border.at(i); uint16_t tile = block.tile; QImage metatile_image = getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity); int map_y = width_ ? i / width_ : 0; @@ -310,38 +271,38 @@ void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) { int oldWidth = getWidth(); int oldHeight = getHeight(); - Blockdata* newBlockData = new Blockdata; + Blockdata newBlockdata; for (int y = 0; y < newHeight; y++) for (int x = 0; x < newWidth; x++) { if (x < oldWidth && y < oldHeight) { int index = y * oldWidth + x; - newBlockData->addBlock(layout->blockdata->blocks->value(index)); + newBlockdata.append(layout->blockdata.value(index)); } else { - newBlockData->addBlock(0); + newBlockdata.append(0); } } - layout->blockdata->copyFrom(newBlockData); + layout->blockdata = newBlockdata; } void Map::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) { int oldWidth = getBorderWidth(); int oldHeight = getBorderHeight(); - Blockdata* newBlockData = new Blockdata; + Blockdata newBlockdata; for (int y = 0; y < newHeight; y++) for (int x = 0; x < newWidth; x++) { if (x < oldWidth && y < oldHeight) { int index = y * oldWidth + x; - newBlockData->addBlock(layout->border->blocks->value(index)); + newBlockdata.append(layout->border.value(index)); } else { - newBlockData->addBlock(0); + newBlockdata.append(0); } } - layout->border->copyFrom(newBlockData); + layout->border = newBlockdata; } void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) { @@ -367,21 +328,20 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata) emit mapChanged(this); } -Block* Map::getBlock(int x, int y) { - if (layout->blockdata && layout->blockdata->blocks) { - if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) { - int i = y * getWidth() + x; - return new Block(layout->blockdata->blocks->value(i)); - } +bool Map::getBlock(int x, int y, Block *out) { + if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) { + int i = y * getWidth() + x; + *out = layout->blockdata.value(i); + return true; } - return nullptr; + return false; } void Map::setBlock(int x, int y, Block block, bool enableScriptCallback) { int i = y * getWidth() + x; - if (layout->blockdata && layout->blockdata->blocks && i < layout->blockdata->blocks->size()) { - Block prevBlock = layout->blockdata->blocks->value(i); - layout->blockdata->blocks->replace(i, block); + if (i < layout->blockdata.size()) { + Block prevBlock = layout->blockdata.at(i); + layout->blockdata.replace(i, block); if (enableScriptCallback) { Scripting::cb_MetatileChanged(x, y, prevBlock, block); } @@ -392,58 +352,57 @@ void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_ QList todo; todo.append(QPoint(x, y)); while (todo.length()) { - QPoint point = todo.takeAt(0); - x = point.x(); - y = point.y(); - Block *block = getBlock(x, y); - if (!block) { - continue; - } + QPoint point = todo.takeAt(0); + x = point.x(); + y = point.y(); + Block block; + if (!getBlock(x, y, &block)) { + continue; + } - uint old_coll = block->collision; - uint old_elev = block->elevation; - if (old_coll == collision && old_elev == elevation) { - continue; - } + uint old_coll = block.collision; + uint old_elev = block.elevation; + if (old_coll == collision && old_elev == elevation) { + continue; + } - block->collision = collision; - block->elevation = elevation; - setBlock(x, y, *block, true); - if ((block = getBlock(x + 1, y)) && block->collision == old_coll && block->elevation == old_elev) { - todo.append(QPoint(x + 1, y)); - } - if ((block = getBlock(x - 1, y)) && block->collision == old_coll && block->elevation == old_elev) { - todo.append(QPoint(x - 1, y)); - } - if ((block = getBlock(x, y + 1)) && block->collision == old_coll && block->elevation == old_elev) { - todo.append(QPoint(x, y + 1)); - } - if ((block = getBlock(x, y - 1)) && block->collision == old_coll && block->elevation == old_elev) { - todo.append(QPoint(x, y - 1)); - } + block.collision = collision; + block.elevation = elevation; + setBlock(x, y, block, true); + if (getBlock(x + 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) { + todo.append(QPoint(x + 1, y)); + } + if (getBlock(x - 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) { + todo.append(QPoint(x - 1, y)); + } + if (getBlock(x, y + 1, &block) && block.collision == old_coll && block.elevation == old_elev) { + todo.append(QPoint(x, y + 1)); + } + if (getBlock(x, y - 1, &block) && block.collision == old_coll && block.elevation == old_elev) { + todo.append(QPoint(x, y - 1)); + } } } void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) { - Block *block = getBlock(x, y); - if (block && (block->collision != collision || block->elevation != elevation)) { + Block block; + if (getBlock(x, y, &block) && (block.collision != collision || block.elevation != elevation)) { _floodFillCollisionElevation(x, y, collision, elevation); } } void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) { - Block *block = getBlock(initialX, initialY); - if (block && (block->collision != collision || block->elevation != elevation)) { - uint old_coll = block->collision; - uint old_elev = block->elevation; + Block block; + if (getBlock(initialX, initialY, &block) && (block.collision != collision || block.elevation != elevation)) { + uint old_coll = block.collision; + uint old_elev = block.elevation; for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { - block = getBlock(x, y); - if (block && block->collision == old_coll && block->elevation == old_elev) { - block->collision = collision; - block->elevation = elevation; - setBlock(x, y, *block, true); + if (getBlock(x, y, &block) && block.collision == old_coll && block.elevation == old_elev) { + block.collision = collision; + block.elevation = elevation; + setBlock(x, y, block, true); } } } diff --git a/src/core/metatile.cpp b/src/core/metatile.cpp index e870dcad..4c97418d 100644 --- a/src/core/metatile.cpp +++ b/src/core/metatile.cpp @@ -2,35 +2,12 @@ #include "tileset.h" #include "project.h" -Metatile::Metatile() -{ - tiles = new QList; -} - -Metatile* Metatile::copy() { - Metatile *copy = new Metatile; - copy->behavior = this->behavior; - copy->layerType = this->layerType; - copy->encounterType = this->encounterType; - copy->terrainType = this->terrainType; - copy->tiles = new QList; - copy->label = this->label; - for (Tile tile : *this->tiles) { - copy->tiles->append(tile); - } - return copy; -} - -void Metatile::copyInPlace(Metatile *other) { - this->behavior = other->behavior; - this->layerType = other->layerType; - this->encounterType = other->encounterType; - this->terrainType = other->terrainType; - this->label = other->label; - for (int i = 0; i < this->tiles->length(); i++) { - (*this->tiles)[i] = other->tiles->at(i); - } -} +Metatile::Metatile() : + behavior(0), + layerType(0), + encounterType(0), + terrainType(0) +{ } int Metatile::getBlockIndex(int index) { if (index < Project::getNumMetatilesPrimary()) { diff --git a/src/core/metatileparser.cpp b/src/core/metatileparser.cpp index 7c52c187..852c26af 100644 --- a/src/core/metatileparser.cpp +++ b/src/core/metatileparser.cpp @@ -2,19 +2,15 @@ #include "config.h" #include "log.h" #include "project.h" +#include -MetatileParser::MetatileParser() -{ - -} - -QList *MetatileParser::parse(QString filepath, bool *error, bool primaryTileset) +QList MetatileParser::parse(QString filepath, bool *error, bool primaryTileset) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; logError(QString("Could not open Advance Map 1.92 Metatile .bvd file '%1': ").arg(filepath) + file.errorString()); - return nullptr; + return { }; } QByteArray in = file.readAll(); @@ -23,7 +19,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim if (in.length() < 9 || in.length() % 2 != 0) { *error = true; logError(QString("Advance Map 1.92 Metatile .bvd file '%1' is an unexpected size.").arg(filepath)); - return nullptr; + return { }; } int projIdOffset = in.length() - 4; @@ -46,7 +42,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim } else { *error = true; logError(QString("Detected unsupported game type from .bvd file. Last 4 bytes of file must be 'RSE ' or 'FRLG'.")); - return nullptr; + return { }; } int maxMetatiles = primaryTileset ? Project::getNumMetatilesPrimary() : Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary(); @@ -57,32 +53,32 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim if (numMetatiles > maxMetatiles) { *error = true; logError(QString(".bvd file contains data for %1 metatiles, but the maximum number of metatiles is %2.").arg(numMetatiles).arg(maxMetatiles)); - return nullptr; + return { }; } if (numMetatiles < 1) { *error = true; logError(QString(".bvd file contains no data for metatiles.")); - return nullptr; + return { }; } int expectedFileSize = 4 + (metatileSize * numMetatiles) + (attrSize * numMetatiles) + 4; if (in.length() != expectedFileSize) { *error = true; logError(QString(".bvd file is an unexpected size. Expected %1 bytes, but it has %2 bytes.").arg(expectedFileSize).arg(in.length())); - return nullptr; + return { }; } - QList *metatiles = new QList(); + QList metatiles; for (int i = 0; i < numMetatiles; i++) { Metatile *metatile = new Metatile(); - QList *tiles = new QList(); + QList tiles; for (int j = 0; j < 8; j++) { int metatileOffset = 4 + i * metatileSize + j * 2; uint16_t word = static_cast( static_cast(in.at(metatileOffset)) | (static_cast(in.at(metatileOffset + 1)) << 8)); Tile tile(word & 0x3ff, (word >> 10) & 1, (word >> 11) & 1, (word >> 12) & 0xf); - tiles->append(tile); + tiles.append(tile); } int attrOffset = 4 + (numMetatiles * metatileSize) + (i * attrSize); @@ -104,7 +100,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim metatile->terrainType = 0; } metatile->tiles = tiles; - metatiles->append(metatile); + metatiles.append(metatile); } return metatiles; diff --git a/src/core/paletteutil.cpp b/src/core/paletteutil.cpp index 3a6f7ff7..4bc7eab3 100644 --- a/src/core/paletteutil.cpp +++ b/src/core/paletteutil.cpp @@ -2,11 +2,15 @@ #include "log.h" #include #include +#include -PaletteUtil::PaletteUtil() -{ - -} +QList parsePal(QString filepath, bool *error); +QList parseJASC(QString filepath, bool *error); +QList parseAdvanceMapPal(QString filepath, bool *error); +QList parseAdobeColorTable(QString filepath, bool *error); +QList parseTileLayerPro(QString filepath, bool *error); +QList parseAdvancePaletteEditor(QString filepath, bool *error); +int clampColorValue(int value); QList PaletteUtil::parse(QString filepath, bool *error) { QFileInfo info(filepath); @@ -34,7 +38,35 @@ QList PaletteUtil::parse(QString filepath, bool *error) { return QList(); } -QList PaletteUtil::parsePal(QString filepath, bool *error) { +void PaletteUtil::writeJASC(QString filepath, QVector palette, int offset, int nColors) { + if (!nColors) { + logWarn(QString("Cannot save a palette with no colors.")); + return; + } + if (offset > palette.size() || offset + nColors > palette.size()) { + logWarn("Palette offset out of range for color table."); + return; + } + + QString text = "JASC-PAL\r\n0100\r\n"; + text += QString::number(nColors) + "\r\n"; + + for (int i = offset; i < offset + nColors; i++) { + QRgb color = palette.at(i); + text += QString::number(qRed(color)) + " " + + QString::number(qGreen(color)) + " " + + QString::number(qBlue(color)) + "\r\n"; + } + + QFile file(filepath); + if (file.open(QIODevice::WriteOnly)) { + file.write(text.toUtf8()); + } else { + logWarn(QString("Could not write to file '%1': ").arg(filepath) + file.errorString()); + } +} + +QList parsePal(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -53,7 +85,7 @@ QList PaletteUtil::parsePal(QString filepath, bool *error) { } } -QList PaletteUtil::parseJASC(QString filepath, bool *error) { +QList parseJASC(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -105,9 +137,9 @@ QList PaletteUtil::parseJASC(QString filepath, bool *error) { return QList(); } - palette.append(qRgb(this->clampColorValue(red), - this->clampColorValue(green), - this->clampColorValue(blue))); + palette.append(qRgb(clampColorValue(red), + clampColorValue(green), + clampColorValue(blue))); } else { *error = true; logError(QString("JASC palette file '%1' had an unexpected format. Invalid color '%2'.").arg(filepath).arg(line)); @@ -120,7 +152,7 @@ QList PaletteUtil::parseJASC(QString filepath, bool *error) { return palette; } -QList PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) { +QList parseAdvanceMapPal(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -143,16 +175,16 @@ QList PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) { unsigned char red = static_cast(in.at(i)); unsigned char green = static_cast(in.at(i + 1)); unsigned char blue = static_cast(in.at(i + 2)); - palette.append(qRgb(this->clampColorValue(red), - this->clampColorValue(green), - this->clampColorValue(blue))); + palette.append(qRgb(clampColorValue(red), + clampColorValue(green), + clampColorValue(blue))); i += 4; } return palette; } -QList PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) { +QList parseAdobeColorTable(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -175,16 +207,16 @@ QList PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) { unsigned char red = static_cast(in.at(i)); unsigned char green = static_cast(in.at(i + 1)); unsigned char blue = static_cast(in.at(i + 2)); - palette.append(qRgb(this->clampColorValue(red), - this->clampColorValue(green), - this->clampColorValue(blue))); + palette.append(qRgb(clampColorValue(red), + clampColorValue(green), + clampColorValue(blue))); i += 3; } return palette; } -QList PaletteUtil::parseTileLayerPro(QString filepath, bool *error) { +QList parseTileLayerPro(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -213,16 +245,16 @@ QList PaletteUtil::parseTileLayerPro(QString filepath, bool *error) { unsigned char red = static_cast(in.at(i)); unsigned char green = static_cast(in.at(i + 1)); unsigned char blue = static_cast(in.at(i + 2)); - palette.append(qRgb(this->clampColorValue(red), - this->clampColorValue(green), - this->clampColorValue(blue))); + palette.append(qRgb(clampColorValue(red), + clampColorValue(green), + clampColorValue(blue))); i += 3; } return palette; } -QList PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool *error) { +QList parseAdvancePaletteEditor(QString filepath, bool *error) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; @@ -258,44 +290,16 @@ QList PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool *error int red = (raw & 0x1F) * 8; int green = ((raw >> 5) & 0x1F) * 8; int blue = ((raw >> 10) & 0x1F) * 8; - palette.append(qRgb(this->clampColorValue(red), - this->clampColorValue(green), - this->clampColorValue(blue))); + palette.append(qRgb(clampColorValue(red), + clampColorValue(green), + clampColorValue(blue))); } file.close(); return palette; } -void PaletteUtil::writeJASC(QString filepath, QVector palette, int offset, int nColors) { - if (!nColors) { - logWarn(QString("Cannot save a palette with no colors.")); - return; - } - if (offset > palette.size() || offset + nColors > palette.size()) { - logWarn("Palette offset out of range for color table."); - return; - } - - QString text = "JASC-PAL\r\n0100\r\n"; - text += QString::number(nColors) + "\r\n"; - - for (int i = offset; i < offset + nColors; i++) { - QRgb color = palette.at(i); - text += QString::number(qRed(color)) + " " - + QString::number(qGreen(color)) + " " - + QString::number(qBlue(color)) + "\r\n"; - } - - QFile file(filepath); - if (file.open(QIODevice::WriteOnly)) { - file.write(text.toUtf8()); - } else { - logWarn(QString("Could not write to file '%1': ").arg(filepath) + file.errorString()); - } -} - -int PaletteUtil::clampColorValue(int value) { +int clampColorValue(int value) { if (value < 0) { value = 0; } diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index e37772e8..ea1807e2 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -12,15 +12,11 @@ const QRegularExpression ParseUtil::re_poryScriptLabel("\\b(script)(\\((global|l const QRegularExpression ParseUtil::re_globalPoryScriptLabel("\\b(script)(\\((global)\\))?\\s*\\b(?