Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vertical spritesheets for overworld graphics #574

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/core/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class EventVisitor {
virtual void visitSign(SignEvent *) = 0;
};

struct EventGraphics
{
QImage spritesheet;
int spriteWidth;
int spriteHeight;
bool inanimate;
};


///
Expand Down Expand Up @@ -258,7 +265,7 @@ class ObjectEvent : public Event {

public:
void setFrameFromMovement(QString movement);
void setPixmapFromSpritesheet(QImage, int, int, bool);
void setPixmapFromSpritesheet(EventGraphics * gfx);


protected:
Expand Down
8 changes: 0 additions & 8 deletions include/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
#include <QVariant>
#include <QFileSystemWatcher>

struct EventGraphics
{
QImage spritesheet;
int spriteWidth;
int spriteHeight;
bool inanimate;
};

// The displayed name of the special map value used by warps with multiple potential destinations
static QString DYNAMIC_MAP_NAME = "Dynamic";

Expand Down
35 changes: 26 additions & 9 deletions src/core/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,39 @@ void ObjectEvent::loadPixmap(Project *project) {
this->usingSprite = false;
} else {
this->setFrameFromMovement(project->facingDirections.value(this->movement));
this->setPixmapFromSpritesheet(eventGfx->spritesheet, eventGfx->spriteWidth, eventGfx->spriteHeight, eventGfx->inanimate);
this->setPixmapFromSpritesheet(eventGfx);
}
}

void ObjectEvent::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight, bool inanimate)
void ObjectEvent::setPixmapFromSpritesheet(EventGraphics * gfx)
{
int frame = inanimate ? 0 : this->frame;
QImage img = spritesheet.copy(frame * spriteWidth % spritesheet.width(), 0, spriteWidth, spriteHeight);
if (this->hFlip && !inanimate) {
img = img.transformed(QTransform().scale(-1, 1));
QImage img;
if (gfx->inanimate) {
img = gfx->spritesheet.copy(0, 0, gfx->spriteWidth, gfx->spriteHeight);
} else {
int x = 0;
int y = 0;

// Get frame's position in spritesheet.
// Assume horizontal layout. If position would exceed sheet width, try vertical layout.
if ((this->frame + 1) * gfx->spriteWidth <= gfx->spritesheet.width()) {
x = this->frame * gfx->spriteWidth;
} else if ((this->frame + 1) * gfx->spriteHeight <= gfx->spritesheet.height()) {
y = this->frame * gfx->spriteHeight;
}

img = gfx->spritesheet.copy(x, y, gfx->spriteWidth, gfx->spriteHeight);

// Right-facing sprite is just the left-facing sprite mirrored
if (this->hFlip) {
img = img.transformed(QTransform().scale(-1, 1));
}
}
// Set first palette color fully transparent.
img.setColor(0, qRgba(0, 0, 0, 0));
pixmap = QPixmap::fromImage(img);
this->spriteWidth = spriteWidth;
this->spriteHeight = spriteHeight;
this->spriteWidth = gfx->spriteWidth;
this->spriteHeight = gfx->spriteHeight;
this->usingSprite = true;
}

Expand Down Expand Up @@ -435,7 +452,7 @@ void CloneObjectEvent::loadPixmap(Project *project) {
this->usingSprite = false;
} else {
this->setFrameFromMovement(project->facingDirections.value(this->movement));
this->setPixmapFromSpritesheet(eventGfx->spritesheet, eventGfx->spriteWidth, eventGfx->spriteHeight, eventGfx->inanimate);
this->setPixmapFromSpritesheet(eventGfx);
}
}

Expand Down
Loading