athena/src/Athena/SpriteFileWriter.cpp

121 lines
3.7 KiB
C++
Raw Normal View History

#ifndef ATHENA_NO_SAKURA
2014-04-20 09:14:15 +00:00
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
2014-04-20 09:14:15 +00:00
#include "Athena/SpriteFileWriter.hpp"
#include "Athena/SpriteFile.hpp"
#include "Athena/Sprite.hpp"
#include "Athena/SpritePart.hpp"
#include "Athena/SpriteFrame.hpp"
#include "Athena/InvalidOperationException.hpp"
#include "Athena/InvalidDataException.hpp"
namespace Athena
{
namespace io
{
2015-05-19 03:24:56 +00:00
SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length)
: base(data, length)
{
}
SpriteFileWriter::SpriteFileWriter(const std::string& filepath)
: base(filepath)
{
}
void SpriteFileWriter::writeFile(Sakura::SpriteFile* file)
{
if (!file)
2014-04-20 09:14:15 +00:00
THROW_INVALID_OPERATION_EXCEPTION("SSpriteFileWriter::writeFile -> file cannot be NULL");
2014-04-20 09:14:15 +00:00
base::writeUint32(Sakura::SpriteFile::Magic);
base::writeUint32(Sakura::SpriteFile::Version);
2014-04-20 09:14:15 +00:00
base::writeUint16(file->textureCount());
base::writeUint32(file->width());
base::writeUint32(file->height());
base::writeFloat(file->originX());
base::writeFloat(file->originY());
2014-04-20 09:14:15 +00:00
base::writeUint16(file->spriteCount());
2014-04-20 09:14:15 +00:00
base::writeUint32(0xFFFFFFFF);
for (Sakura::STexture* texture : file->textures())
{
base::writeString(texture->Filepath);
base::writeBool(texture->Preload);
}
#ifndef ATHENA_USE_QT
2015-05-19 03:24:56 +00:00
for (std::pair<std::string, Sakura::Sprite*> spritePair : file->sprites())
{
Sakura::Sprite* sprite = spritePair.second;
base::writeString(sprite->name());
2014-02-27 05:47:39 +00:00
#else
2015-05-19 03:24:56 +00:00
foreach (Sakura::Sprite* sprite, file->sprites().values())
2014-02-27 05:47:39 +00:00
{
base::writeString(sprite->name().toStdString());
#endif
2014-04-20 09:14:15 +00:00
base::writeUint16(sprite->frameCount());
base::writeUint16(sprite->stateCount());
for (int id : sprite->stateIds())
2014-04-20 09:14:15 +00:00
base::writeUint16(id);
2014-02-27 05:47:39 +00:00
for (Sakura::SpriteFrame* frame : sprite->frames())
{
2014-02-27 05:47:39 +00:00
base::writeFloat(frame->frameTime());
2014-04-20 09:14:15 +00:00
base::writeUint16(frame->partCount());
2015-05-19 03:24:56 +00:00
for (Sakura::SpritePart* part : frame->parts())
{
#ifndef ATHENA_USE_QT
2014-02-27 05:47:39 +00:00
base::writeString(part->name());
#else
base::writeString(part->name().toStdString());
#endif
base::writeBool(part->hasCollision());
#ifndef ATHENA_USE_QT
2014-02-27 05:47:39 +00:00
base::writeFloat(part->offset().x);
base::writeFloat(part->offset().y);
base::writeFloat(part->textureOffset().x);
base::writeFloat(part->textureOffset().y);
2014-04-20 09:14:15 +00:00
base::writeUint32(part->size().x);
base::writeUint32(part->size().y);
2014-02-27 05:47:39 +00:00
#else
base::writeFloat(part->offset().x());
base::writeFloat(part->offset().y());
base::writeFloat(part->textureOffset().x());
base::writeFloat(part->textureOffset().y());
2014-04-20 09:14:15 +00:00
base::writeUint32(part->size().width());
base::writeUint32(part->size().height());
2014-02-27 05:47:39 +00:00
#endif
base::writeBool(part->flippedHorizontally());
base::writeBool(part->flippedVertically());
}
}
}
save();
}
} // io
} // zelda
#endif // ATHENA_NO_SAKURA