123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- ########################################################################
- # 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)
|