forked from jaildesigner-jailgames/jaildoctors_dilemma
[DOC:29/10/2025] la surface ara se pillarà del .ANI
Tots els arxius .ani i .room retocats per a adequarse als canvis.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
#include "utils/utils.hpp" // Para printWithDots
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
@@ -31,6 +32,25 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
SurfaceAnimatedSprite::SurfaceAnimatedSprite(const std::string& file_path)
|
||||
: SurfaceMovingSprite() {
|
||||
// Carga las animaciones
|
||||
if (!file_path.empty()) {
|
||||
Animations v = loadAnimationsFromFile(file_path);
|
||||
setAnimations(v);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor
|
||||
SurfaceAnimatedSprite::SurfaceAnimatedSprite(const Animations& animations)
|
||||
: SurfaceMovingSprite() {
|
||||
if (!animations.empty()) {
|
||||
setAnimations(animations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
SurfaceAnimatedSprite::SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const std::string& file_path)
|
||||
: SurfaceMovingSprite(std::move(surface)) {
|
||||
@@ -197,20 +217,26 @@ void SurfaceAnimatedSprite::resetAnimation() {
|
||||
}
|
||||
|
||||
// Helper: Parsea los parámetros de configuración globales (frame_width, frame_height)
|
||||
auto parseGlobalParameter(const std::string& line, float& frame_width, float& frame_height) -> bool {
|
||||
auto parseGlobalParameter(const std::string& line, std::shared_ptr<Surface>& surface, float& frame_width, float& frame_height) -> bool {
|
||||
size_t pos = line.find('=');
|
||||
if (pos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string key = line.substr(0, pos);
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
|
||||
if (key == "tileSetFile") {
|
||||
std::string value = line.substr(pos + 1);
|
||||
surface = Resource::get()->getSurface(value);
|
||||
return true;
|
||||
}
|
||||
if (key == "frame_width") {
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
frame_width = value;
|
||||
return true;
|
||||
}
|
||||
if (key == "frame_height") {
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
frame_height = value;
|
||||
return true;
|
||||
}
|
||||
@@ -295,11 +321,13 @@ void SurfaceAnimatedSprite::setAnimations(const Animations& animations) {
|
||||
|
||||
// Parsea el fichero para buscar variables y valores
|
||||
if (line != "[animation]") {
|
||||
if (parseGlobalParameter(line, frame_width, frame_height)) {
|
||||
frames_per_row = surface_->getWidth() / frame_width;
|
||||
const int W = surface_->getWidth() / frame_width;
|
||||
const int H = surface_->getHeight() / frame_height;
|
||||
max_tiles = W * H;
|
||||
if (parseGlobalParameter(line, surface_, frame_width, frame_height)) {
|
||||
if (surface_) {
|
||||
frames_per_row = surface_->getWidth() / frame_width;
|
||||
const int W = surface_->getWidth() / frame_width;
|
||||
const int H = surface_->getHeight() / frame_height;
|
||||
max_tiles = W * H;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,12 @@ class SurfaceAnimatedSprite : public SurfaceMovingSprite {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
// [DOC:29/10/2025] la surface ara se pillarà del .ANI.
|
||||
// Necesite constructors que no requereixquen la surface al crear el objecte,
|
||||
// ja que la trau al llegir el arxiu. Aixó afecta a totes les classes base...
|
||||
SurfaceAnimatedSprite(const std::string& file_path);
|
||||
SurfaceAnimatedSprite(const Animations& animations);
|
||||
// [/DOC]
|
||||
SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const std::string& file_path);
|
||||
SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const Animations& animations);
|
||||
explicit SurfaceAnimatedSprite(std::shared_ptr<Surface> surface)
|
||||
|
||||
@@ -17,6 +17,12 @@ SurfaceMovingSprite::SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_F
|
||||
y_(pos.y),
|
||||
flip_(SDL_FLIP_NONE) { SurfaceSprite::pos_ = pos; }
|
||||
|
||||
SurfaceMovingSprite::SurfaceMovingSprite()
|
||||
: SurfaceSprite(),
|
||||
x_(0.0F),
|
||||
y_(0.0F),
|
||||
flip_(SDL_FLIP_NONE) { SurfaceSprite::clear(); }
|
||||
|
||||
SurfaceMovingSprite::SurfaceMovingSprite(std::shared_ptr<Surface> surface)
|
||||
: SurfaceSprite(std::move(surface)),
|
||||
x_(0.0F),
|
||||
|
||||
@@ -32,6 +32,7 @@ class SurfaceMovingSprite : public SurfaceSprite {
|
||||
// Constructor
|
||||
SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos, SDL_FlipMode flip);
|
||||
SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos);
|
||||
explicit SurfaceMovingSprite();
|
||||
explicit SurfaceMovingSprite(std::shared_ptr<Surface> surface);
|
||||
|
||||
// Destructor
|
||||
|
||||
@@ -15,6 +15,10 @@ SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface, SDL_FRect rect)
|
||||
pos_(rect),
|
||||
clip_((SDL_FRect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
SurfaceSprite::SurfaceSprite()
|
||||
: pos_((SDL_FRect){0.0F, 0.0F, 0.0F, 0.0F}),
|
||||
clip_(pos_) {}
|
||||
|
||||
SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface)
|
||||
: surface_(std::move(std::move(surface))),
|
||||
pos_((SDL_FRect){0.0F, 0.0F, surface_->getWidth(), surface_->getHeight()}),
|
||||
|
||||
@@ -18,6 +18,7 @@ class SurfaceSprite {
|
||||
// Constructor
|
||||
SurfaceSprite(std::shared_ptr<Surface>, float x, float y, float w, float h);
|
||||
SurfaceSprite(std::shared_ptr<Surface>, SDL_FRect rect);
|
||||
SurfaceSprite();
|
||||
explicit SurfaceSprite(std::shared_ptr<Surface>);
|
||||
|
||||
// Destructor
|
||||
|
||||
Reference in New Issue
Block a user