########################################################################
#	Hello Worlds - Libre 3D RPG game.
#	Copyright (C) 2020  CYBERDEViL
#
#	This file is part of Hello Worlds.
#
#	Hello Worlds 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.
#
#	Hello Worlds 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 <https://www.gnu.org/licenses/>.
#
########################################################################


from core.signals import Signal

class Model:
	def __init__(self):
		self.destroyed = Signal()
		self.changed = Signal()

	def destroy(self):
		self.destroyed.emit()

class ItemModel(Model):
	""" Basic item model
	Game items and spells will extend this.
	"""
	def __init__(self, name="", iconPath="assets/icons/unknown.png", desc=""):
		Model.__init__(self)

		# TODO check if iconPath exists, else set assets/icons/unknown.png

		self._name = name
		self._iconPath = iconPath
		self._desc = desc

	@property
	def name(self): return self._name

	@property
	def iconPath(self): return self._iconPath

	@property
	def description(self): return self._desc

class StatsModel(Model):
	def __init__(self, rawData={}):
		Model.__init__(self)

		self.setRawData(rawData)

	def setRawData(self, rawData):
		print(rawData)
		self._data = {
			'level'		: IntModel(
							max=rawData.level.max,
							value=rawData.level.value),

			'health'	: IntModel(
							max=rawData.health.max,
							value=rawData.health.value),

			'energy'	: IntModel(
							max=rawData.energy.max,
							value=rawData.energy.value),
			'strength'	: 1,
			'stamina'	: 1,
			'resistance': 2,
			'reflexes'	: 0.5,
			'spitit'	: 0,
		}

	@property
	def health(self): return self._data['health']

	@property
	def level(self): return self._data['level']

	@property
	def energy(self): return self._data['energy']

class PlayerStatsModel(StatsModel):
	def __init__(self, rawData={}):
		StatsModel.__init__(self, rawData=rawData)

	@property
	def experience(self): return self._data['experience']

	def setRawData(self, rawData):
		StatsModel.setRawData(self, rawData)
		self._data.update({
			'experience'	: IntModel(
							max=rawData.experience.max,
							value=rawData.experience.value)
		})

class SelectedNpcModel(Model):
	changed = Signal(int) # selected id
	def __init__(self):
		""" Shared by a mouse-handler and the ui
		"""
		self._selectedId = None

	@property
	def selectedId(self): return self._selectedId

	@selectedId.setter
	def selectedId(self, id):
		self._selectedId = id
		self.changed.emit(id)

class IntModel(Model):
	def __init__(self, min=0, max=100, value=0, stepSize=1):
		""" Used for example: character / npc -level
		"""
		self.valueChanged = Signal(int)
		Model.__init__(self)
		self.__min = min
		self.__max = max
		self.__value = value
		self.__stepSize = stepSize

	@property
	def min(self): return self.__min

	@property
	def max(self): return self.__max

	@property
	def value(self): return self.__value

	@value.setter
	def value(self, value):
		self.__value = value
		self.valueChanged.emit(value)

class FloatModel(IntModel):
	def __init__(self, min=0, max=100, value=0, stepSize=.01):
		""" Used for example: character / npc -stats
		"""
		self.valueChanged = Signal(float)
		IntModel.__init__(self, min=min, max=max, value=value, stepSize=stepSize)
