/****************************************************************************
 ** Makou Reactor Final Fantasy VII Field Script Editor
 ** Copyright (C) 2009-2022 Arzel Jérôme <myst6re@gmail.com>
 **
 ** This program 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.
 **
 ** This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************/
#pragma once

#include <QtCore>
#include <QImage>
#include "FieldModelFile.h"
#include "FieldModelTextureRefPS.h"
#include "FieldModelLoader.h"

class FieldPS;

class FieldModelFilePS : public FieldModelFile
{
public:
	FieldModelFilePS();
	bool isValid() const override;
	void clear() override;
	inline bool isModified() const {
		return _isModified;
	}
	void clearModified() {
		_isModified = false;
	}
	inline bool translateAfter() const override {
		return false;
	}
	inline const QList<FieldModelColorDir> &lightColors() const {
		return _colors;
	}
	inline void setLightColors(const QList<FieldModelColorDir> &colors) {
		if (colors != _colors) {
			_colors = colors;
			_isModified = true;
		}
	}
	inline void setLightColor(int id, const FieldModelColorDir &color) {
		if (_colors.at(id) != color) {
			_colors.replace(id, color);
			_isModified = true;
		}
	}
	inline QRgb globalColor() const {
		return _globalColor;
	}
	inline void setGlobalColor(QRgb color) {
		if (_globalColor != color) {
			_globalColor = color;
			_isModified = true;
		}
	}
	inline quint16 scale() const {
		return _scale;
	}
	inline void setScale(quint16 scale) {
		if (_scale != scale) {
			_scale = scale;
			_isModified = true;
		}
	}
	inline const QList<FieldModelAnimation> &animations() const {
		return _animations;
	}
	inline void setAnimations(const QList<FieldModelAnimation> &animations) {
		_animations = animations;
	}
	inline qsizetype animationCount() const {
		return _animations.size();
	}
	inline const FieldModelAnimation &animation(int animationID) const {
		return _animations.at(animationID);
	}
	inline void setCurrentAnimationId(qsizetype animationId) {
		_currentAnimationId = animationId;
	}
	inline const FieldModelAnimation &currentAnimation() const override {
		return _animations.at(_currentAnimationId);
	}
	bool load(FieldPS *currentField, int modelID);
	void setCurrentAnimation(int animationID);
	QImage loadedTexture(FieldModelGroup *group) override;
	inline void *textureIdForGroup(FieldModelGroup *group) const override {
		return reinterpret_cast<void *>(group);
	}
	QHash<void *, QImage> loadedTextures() override;
	QImage vramImage() const;
private:
	Q_DISABLE_COPY(FieldModelFilePS)
	QList<FieldModelColorDir> _colors;
	QList<FieldModelAnimation> _animations;
	qsizetype _currentAnimationId;
	FieldPS *_currentField;
	QHash<FieldModelGroup *, QImage> _loadedTex;
	FieldModelTexturesPS _textures;
	int _currentModelID;
	QRgb _globalColor;
	quint16 _scale;
	bool _isModified;
};
