<commit_before>/*
 * This file is part of the UnTech Editor Suite.
 * Copyright (c) 2016 - 2018, <NAME> <<EMAIL>>.
 * Distributed under The MIT License: https://opensource.org/licenses/MIT
 */

#include "mttilesetrenderer.h"
#include "mttilesetresourceitem.h"
#include "gui-qt/resources/dualanimationtimer.h"
#include "gui-qt/resources/palette/paletteresourceitem.h"
#include "gui-qt/snes/tile.hpp"
#include "models/metatiles/metatile-tileset.h"
#include "models/resources/animation-frames-input.h"

#include <QPainter>
#include <cassert>

using namespace UnTech::GuiQt;
using namespace UnTech::GuiQt::MetaTiles;

MtTilesetRenderer::MtTilesetRenderer(QObject* parent)
    : QObject(parent)
    , _animationTimer(new Resources::DualAnimationTimer(this))
    , _paletteItem(nullptr)
    , _tilesetItem(nullptr)
    , _pixmaps()
    , _nPalettes(0)
    , _nTilesets(0)
    , _nMetaTiles(0)
{
    connect(_animationTimer, &Resources::DualAnimationTimer::animationFrameCountChanged,
            this, &MtTilesetRenderer::pixmapChanged);
}

void MtTilesetRenderer::setPlayButton(QAbstractButton* button)
{
    _animationTimer->setPlayButton(button);
}

void MtTilesetRenderer::setRegionCombo(QComboBox* comboBox)
{
    _animationTimer->setRegionCombo(comboBox);
}

void MtTilesetRenderer::resetAnimations()
{
    _animationTimer->resetTimer();
}

void MtTilesetRenderer::pauseAndAdvancePaletteFrame()
{
    _animationTimer->pauseAndIncrementFirstFrameCount();
}

void MtTilesetRenderer::pauseAndAdvanceTilesetFrame()
{
    _animationTimer->pauseAndIncrementSecondFrameCount();
}

void MtTilesetRenderer::setPaletteItem(Resources::PaletteResourceItem* item)
{
    if (_paletteItem != item) {
        if (_paletteItem) {
            _paletteItem->disconnect(this);
        }

        _paletteItem = item;

        resetPixmaps();
        onAnimationDelaysChanged();

        if (_paletteItem) {
            connect(_paletteItem, &AbstractResourceItem::resourceComplied,
                    this, &MtTilesetRenderer::resetPixmaps);

            connect(_paletteItem, &AbstractResourceItem::dataChanged,
                    this, &MtTilesetRenderer::onAnimationDelaysChanged);

            connect(_paletteItem->resourceList(), &AbstractResourceList::resourceItemAboutToBeRemoved,
                    this, &MtTilesetRenderer::onResourceItemAboutToBeRemoved);
        }

        paletteItemChanged();
    }
}

void MtTilesetRenderer::setTilesetItem(MtTilesetResourceItem* item)
{
    if (_tilesetItem != item) {
        if (_tilesetItem) {
            _tilesetItem->disconnect(this);
        }

        _tilesetItem = item;

        resetPixmaps();
        onAnimationDelaysChanged();

        if (_tilesetItem) {
            connect(_tilesetItem, &AbstractResourceItem::resourceComplied,
                    this, &MtTilesetRenderer::resetPixmaps);

            connect(_tilesetItem, &MtTilesetResourceItem::animationDelayChanged,
                    this, &MtTilesetRenderer::onAnimationDelaysChanged);<commit_msg>Stop MT animation when changing tilesets<commit_after>/*
 * This file is part of the UnTech Editor Suite.
 * Copyright (c) 2016 - 2018, <NAME> <<EMAIL>>.
 * Distributed under The MIT License: https://opensource.org/licenses/MIT
 */

#include "mttilesetrenderer.h"
#include "mttilesetresourceitem.h"
#include "gui-qt/resources/dualanimationtimer.h"
#include "gui-qt/resources/palette/paletteresourceitem.h"
#include "gui-qt/snes/tile.hpp"
#include "models/metatiles/metatile-tileset.h"
#include "models/resources/animation-frames-input.h"

#include <QPainter>
#include <cassert>

using namespace UnTech::GuiQt;
using namespace UnTech::GuiQt::MetaTiles;

MtTilesetRenderer::MtTilesetRenderer(QObject* parent)
    : QObject(parent)
    , _animationTimer(new Resources::DualAnimationTimer(this))
    , _paletteItem(nullptr)
    , _tilesetItem(nullptr)
    , _pixmaps()
    , _nPalettes(0)
    , _nTilesets(0)
    , _nMetaTiles(0)
{
    connect(_animationTimer, &Resources::DualAnimationTimer::animationFrameCountChanged,
            this, &MtTilesetRenderer::pixmapChanged);
}

void MtTilesetRenderer::setPlayButton(QAbstractButton* button)
{
    _animationTimer->setPlayButton(button);
}

void MtTilesetRenderer::setRegionCombo(QComboBox* comboBox)
{
    _animationTimer->setRegionCombo(comboBox);
}

void MtTilesetRenderer::resetAnimations()
{
    _animationTimer->resetTimer();
}

void MtTilesetRenderer::pauseAndAdvancePaletteFrame()
{
    _animationTimer->pauseAndIncrementFirstFrameCount();
}

void MtTilesetRenderer::pauseAndAdvanceTilesetFrame()
{
    _animationTimer->pauseAndIncrementSecondFrameCount();
}

void MtTilesetRenderer::setPaletteItem(Resources::PaletteResourceItem* item)
{
    if (_paletteItem != item) {
        if (_paletteItem) {
            _paletteItem->disconnect(this);
        }

        _paletteItem = item;

        resetPixmaps();
        onAnimationDelaysChanged();

        if (_paletteItem) {
            connect(_paletteItem, &AbstractResourceItem::resourceComplied,
                    this, &MtTilesetRenderer::resetPixmaps);

            connect(_paletteItem, &AbstractResourceItem::dataChanged,
                    this, &MtTilesetRenderer::onAnimationDelaysChanged);

            connect(_paletteItem->resourceList(), &AbstractResourceList::resourceItemAboutToBeRemoved,
                    this, &MtTilesetRenderer::onResourceItemAboutToBeRemoved);
        }

        paletteItemChanged();
    }
}

void MtTilesetRenderer::setTilesetItem(MtTilesetResourceItem* item)
{
    if (_tilesetItem != item) {
        if (_tilesetItem) {
            _tilesetItem->disconnect(this);
        }

        _tilesetItem = item;

        _animationTimer->stopTimer();

        resetPixmaps();
        onAnimationDelaysChanged();

        if (_tilesetItem) {
            connect(_tilesetItem, &AbstractResourceItem::resourceComplied,
                    this, &MtTilesetRenderer::resetPixmaps);

            connect(_tilesetItem, &MtTilesetResourceItem::animationDelayChanged,
                    this, &MtTilesetRenderer::onAnimationDelaysChanged);
{'fraction_non_alphanumeric': 0.10875287923659098, 'fraction_numerical': 0.0036196117143797303, 'mean_word_length': 3.890587288817377, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 30, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4259237', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1861, 'n_words': 263}