std::unique_ptr<AnimatedTilesetData>
convertAnimationFrames(const AnimationFramesInput& input, const PaletteInput& paletteInput,
                       ErrorList& err)
{
    bool valid = input.validate(err);
    if (!valid) {
        return nullptr;
    }

    const unsigned initialErrorCount = err.errorCount();

    const auto& firstImageFilename = input.frameImageFilenames.front();
    const auto& imgSize = ImageCache::loadPngImage(firstImageFilename)->size();

    auto ret = std::make_unique<AnimatedTilesetData>(input.bitDepth);
    ret->animationDelay = input.animationDelay;

    const usize mapSize(imgSize.width / 8, imgSize.height / 8);

    const auto palette = extractFirstPalette(paletteInput, input.bitDepth, err);
    if (palette.empty()) {
        return nullptr;
    }

    auto invalidImagesError = std::make_unique<InvalidImageError>();

    const auto frameTiles = tilesFromFrameImages(input, palette, err);
    if (initialErrorCount != err.errorCount()) {
        return nullptr;
    }
    const auto tilesetIntermediate = combineFrameTiles(frameTiles, mapSize.width, err);

    if (input.addTransparentTile) {
        ret->staticTiles.addTile();
    }

    buildTilesetAndTilemap(*ret, mapSize, tilesetIntermediate);

    if (initialErrorCount != err.errorCount()) {
        return nullptr;
    }

    valid = ret->validate(err);
    if (!valid) {
        return nullptr;
    }

    return ret;
}
示例#2
0
bool Animation::_validate(const FrameSetT& frameSet, ErrorList& err) const
{
    const unsigned oldErrorCount = err.errorCount();

    if (oneShot == false && nextAnimation.isValid()) {
        if (!frameSet.animations.find(nextAnimation)) {
            err.addError(animationError(*this, "Cannot find animation " + nextAnimation));
        }
    }

    if (frames.size() == 0) {
        err.addError(animationError(*this, "Expected at least one animation frame"));
    }

    for (unsigned i = 0; i < frames.size(); i++) {
        const AnimationFrame& aFrame = frames.at(i);

        if (aFrame.testFrameValid(frameSet) == false) {
            err.addError(animationFrameError(*this, i, "Cannot find frame " + aFrame.frame.name));
        }
    }

    return err.errorCount() == oldErrorCount;
}