changeset 143:7b21d460fc31

Removed imports of the old objects.
author KarstenBock@gmx.net
date Sat, 01 Oct 2011 14:39:27 +0200
parents a5ea5b8f63d4
children a6b25c2cedab
files src/parpg/charactercreationcontroller.py src/parpg/inventory.py
diffstat 2 files changed, 71 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/src/parpg/charactercreationcontroller.py	Sat Oct 01 14:38:56 2011 +0200
+++ b/src/parpg/charactercreationcontroller.py	Sat Oct 01 14:39:27 2011 +0200
@@ -21,7 +21,8 @@
 from controllerbase import ControllerBase
 from gamescenecontroller import GameSceneController
 from gamesceneview import GameSceneView
-from parpg.inventory import Inventory
+from parpg.world import World
+from parpg.entities import General
 
 DEFAULT_STAT_VALUE = 50
 
@@ -52,40 +53,8 @@
         return 9
     else:
         return 10    
-
-#TODO: Should be replaced with the real character class once its possible
-class SimpleCharacter(object):
-    """This is a simple class that is used to store the data during the
-    character creation"""
-    
-    def __init__(self, name, gender, origin, age, picture, traits,
-                 primary_stats, secondary_stats, inventory):
-        self.name = name
-        self.gender = gender
-        self.origin = origin
-        self.age = age
-        self.picture = picture
-        self.traits = traits
-        self.statistics = {}
-        for primary_stat in primary_stats:
-            short_name = primary_stat.short_name
-            self.statistics[short_name] = char_stats.PrimaryStatisticValue(
-                                                    primary_stat,
-                                                    self,
-                                                    DEFAULT_STAT_VALUE)
-            long_name = primary_stat.long_name
-            self.statistics[long_name] = char_stats.PrimaryStatisticValue(
-                                                    primary_stat,
-                                                    self,
-                                                    DEFAULT_STAT_VALUE)
-        for secondary_stat in secondary_stats:
-            name = secondary_stat.name            
-            self.statistics[name] = char_stats.SecondaryStatisticValue(
-                                                    secondary_stat,
-                                                    self)
-        self.inventory = inventory
             
-class CharacterCreationController(ControllerBase):
+class CharacterCreationController(ControllerBase, World):
     """Controller defining the behaviour of the character creation screen."""
     
     #TODO: Change to actual values
@@ -96,6 +65,9 @@
     GENDERS = ["Male", "Female",]
     PICTURES = {"Male": ["None",], "Female": ["None",],}
     TRAITS = {}
+    MAX_BULK = 100
+    INV_SLOTS = 20
+    
     def __init__(self, engine, view, model, application):
         """Construct a new L{CharacterCreationController} instance.
            @param engine: Rendering engine used to display the associated view.
@@ -109,10 +81,10 @@
            @type application: 
                L{fife.extensions.basicapplication.ApplicationBase}"""
         ControllerBase.__init__(self, engine, view, model, application)
+        World.__init__(self)
         self.settings = self.model.settings
         self.view.start_new_game_callback = self.startNewGame
         self.view.cancel_new_game_callback = self.cancelNewGame
-        self.view.show()
         # FIXME M. George Hansen 2011-06-06: character stats scripts aren't
         #     finished, unfortunately.
 #        primary_stats_file = \
@@ -121,19 +93,35 @@
 #        secondary_stats_file = \
 #            vfs.VFS.open('character_scripts/secondary_stats.xml')
 #        secondary_stats = XmlSerializer.deserialize(secondary_stats_file)
+
+    def reset_character(self):
         primary_stats = []
         secondary_stats = []
-        self.char_data = SimpleCharacter(
-            "",
-            self.GENDERS[0],
-            self.ORIGINS.keys()[0],
-            20,
-            self.PICTURES[self.GENDERS[0]][0],
-            [],
-            primary_stats,
-            secondary_stats,
-            Inventory()
+        inventory = []
+        for x in xrange(self.INV_SLOTS):
+            inventory.append(None)
+        self.char_data = General(self, "PlayerCharacter")
+        self.char_data.description.view_name = "Player"
+        self.char_data.description.real_name = "Enter name here"
+        self.char_data.characterstats.gender = self.GENDERS[0]
+        self.char_data.characterstats.origin = self.ORIGINS.keys()[0]
+        self.char_data.characterstats.age = 20
+        self.char_data.characterstats.picture = (
+            self.PICTURES[self.GENDERS[0]][0]
         )
+        for primary_stat in primary_stats:
+            short_name = primary_stat.short_name
+            self.char_data.characterstats.primary_stats[short_name] = (
+                char_stats.PrimaryStatisticValue(
+                    primary_stat, self, DEFAULT_STAT_VALUE)
+            )
+        for secondary_stat in secondary_stats:
+            name = secondary_stat.name            
+            self.char_data.characterstats.secondary_stats[name] = (
+                char_stats.SecondaryStatisticValue(secondary_stat, self)
+            )
+        self.char_data.container.max_bulk = self.MAX_BULK
+        self.char_data.container.children = inventory
         self._stat_points = 200
   
        
@@ -161,6 +149,10 @@
         self.application.view = view
         self.application.manager.activate_mode(controller)
     
+    def on_activate(self):
+        self.reset_character()
+        self.view.show()
+    
     def on_deactivate(self):
         """Called when the controller is removed from the list.
            @return: None"""
@@ -170,30 +162,30 @@
     def name(self):
         """Returns the name of the character.
         @return: Name of the character"""
-        return self.char_data.name
+        return self.char_data.description.real_name
     
     @property
     def age(self):
         """Returns the age of the character.
         @return: Age of the character"""
-        return self.char_data.age
+        return self.char_data.characterstats.age
     
     @property
     def gender(self):
         """Returns the gender of the character.
         @return: Gender of the character"""
-        return self.char_data.gender
+        return self.char_data.characterstats.gender
     
     @property
     def origin(self):
         """Returns the origin of the character.
         @return: Origin of the character"""
-        return self.char_data.origin
+        return self.char_data.characterstats.origin
     
     @property
     def picture(self):
         """Returns the ID of the current picture of the character."""
-        return self.char_data.picture
+        return self.char_data.characterstats.picture
     
     def getStatPoints(self):
         """Returns the remaining statistic points that can be distributed"""
@@ -206,7 +198,8 @@
         if self.canIncreaseStatistic(statistic):
             cost = self.getStatisticIncreaseCost(statistic)
             if  cost <= self._stat_points:
-                self.char_data.statistics[statistic].value += 1
+                (self.char_data.characterstats.
+                 primary_stats[statistic].value) += 1
                 self._stat_points -= cost  
 
     def getStatisticIncreaseCost(self, statistic):
@@ -214,7 +207,8 @@
         @param statistic: Name of the statistic to increase
         @type statistic: string
         @return cost to increase the statistic"""
-        cur_value = self.char_data.statistics[statistic].value
+        cur_value = (self.char_data.characterstats.
+                     primary_stats[statistic].value)
         new_value = cur_value + 1
         offset =  new_value - DEFAULT_STAT_VALUE
         return getStatCost(offset)
@@ -224,7 +218,7 @@
         @param statistic: Name of the statistic to check
         @type statistic: string
         @return: True if the statistic can be increased, False if not."""
-        stat = self.char_data.statistics[statistic].value
+        stat = self.char_data.characterstats.primary_stats[statistic].value
         return stat < stat.statistic_type.maximum
     
     def decreaseStatistic(self, statistic):
@@ -233,7 +227,7 @@
         @type statistic: string""" 
         if self.canDecreaseStatistic(statistic):
             gain = self.getStatisticDecreaseGain(statistic)
-            self.char_data.statistics[statistic].value -= 1
+            self.char_data.characterstats.primary_stats[statistic].value -= 1
             self._stat_points += gain  
 
     def getStatisticDecreaseGain(self, statistic):
@@ -241,7 +235,8 @@
         @param statistic: Name of the statistic to decrease
         @type statistic: string
         @return cost to decrease the statistic"""
-        cur_value = self.char_data.statistics[statistic].value
+        cur_value = (self.char_data.characterstats.
+                     primary_stats[statistic].value)
         new_value = cur_value - 1
         offset =  new_value - DEFAULT_STAT_VALUE
         return getStatCost(offset)
@@ -251,7 +246,7 @@
         @param statistic: Name of the statistic to check
         @type statistic: string
         @return: True if the statistic can be decreased, False if not."""
-        stat = self.char_data.statistics[statistic].value
+        stat = self.char_data.characterstats.primary_stats[statistic].value
         return stat > stat.statistic_type.minimum
     
     def getStatisticValue(self, statistic):
@@ -259,12 +254,17 @@
         @param statistic: Name of the primary or secondary statistic
         @type statistic: string
         @return: Value of the given statistic"""
-        return self.char_data.statistics[statistic]
+        if self.char_data.characterstats.primary_stats.has_key:
+            return self.char_data.characterstats.primary_stats[statistic]
+        else:
+            return self.char_data.characterstats.secondary_stats[statistic]
     
     def areAllStatisticsValid(self):
         """Checks if all statistics are inside the minimum/maximum values
         @return True if all statistics are valid False if not"""
-        for stat in self.char_data.statistics.items():
+        all_stats = self.char_data.characterstats.primary_stats.items()
+        all_stats.extend(self.char_data.characterstats.secondary_stats.items())
+        for stat in all_stats:
             if not (stat.value > stat.statistic_type.minumum and\
                 stat.value < stat.statistic_type.maximum):
                 return False
@@ -274,7 +274,7 @@
         """Sets the name of the character to the given value.
         @param name: New name
         @type name: string"""
-        self.char_data.name = name
+        self.char_data.description.real_name = name
     
     def isNameValid(self, name):
         """Checks whether the name is valid.
@@ -290,7 +290,7 @@
         @param origin: New origin
         @type origin: string"""
         if self.isOriginValid(origin):
-            self.char_data.origin = origin
+            self.char_data.characterstats.origin = origin
             #TODO: Make changes according to origin
    
     def isOriginValid(self, origin):
@@ -305,7 +305,7 @@
         @param gender: New gender
         @param gender: string"""
         if self.isGenderValid(gender):
-            self.char_data.gender = gender
+            self.char_data.characterstats.gender = gender
     
     def isGenderValid(self, gender):
         """Checks whether the gender is valid.
@@ -320,7 +320,7 @@
         @type age: integer
         """
         if self.isAgeValid(age):
-            self.char_data.age = age
+            self.char_data.characterstats.age = age
     
     def isAgeValid(self, age):
         """Checks whether the age is valid.
@@ -334,7 +334,7 @@
         @param picture: ID of the new picture
         @type picture: string"""
         if self.isPictureValid(picture):
-            self.char_data.picture = picture
+            self.char_data.characterstats.picture = picture
     
     def isPictureValid(self, picture):
         """Checks whether the picture is valid.
@@ -349,26 +349,26 @@
         @type trait: string"""
         if self.canAddAnotherTrait() and self.isTraitValid(trait)\
                 and not self.hasTrait(trait):
-            self.char_data.traits.append(trait)                
+            self.char_data.characterstats.traits.append(trait)                
     
     def canAddAnotherTrait(self):
         """Checks whether another trait can be added.
         @return: True if another trait can be added, False if not"""
-        return len(self.char_data.traits) < self.MAX_TRAITS
+        return len(self.char_data.characterstats.traits) < self.MAX_TRAITS
     
     def removeTrait(self, trait):
         """Remove trait from character.
         @param trait: ID of the trait to remove
         @type trait: string"""
         if self.hasTrait(trait):
-            self.char_data.traits.remove(trait)
+            self.char_data.characterstats.traits.remove(trait)
     
     def hasTrait(self, trait):
         """Checks whether the character has the trait.
         @param trait: ID of the trait to check
         @type trait: string
         @return: True if the character has the trait, False if not"""
-        return trait in self.char_data.traits
+        return trait in self.char_data.characterstats.traits
     
     def isTraitValid(self, trait):
         """Checks whether the trait is valid.
@@ -380,9 +380,9 @@
     def areCurrentTraitsValid(self):
         """Checks whether the characters traits are valid.
         @return: True if the traits are valid, False if not"""
-        if len(self.char_data.traits) > self.MAX_TRAITS:
+        if len(self.char_data.characterstats.traits) > self.MAX_TRAITS:
             return False 
-        for trait in self.char_data.traits:
+        for trait in self.char_data.characterstats.traits:
             if not self.isTraitValid(trait):
                 return False
         return True
--- a/src/parpg/inventory.py	Sat Oct 01 14:38:56 2011 +0200
+++ b/src/parpg/inventory.py	Sat Oct 01 14:39:27 2011 +0200
@@ -13,8 +13,8 @@
 # You should have received a copy of the GNU General Public License
 # along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
 
-from parpg.objects.base import Container
-from parpg.objects.composed import SingleItemContainer as Slot
+#from parpg.objects.base import Container
+#from parpg.objects.composed import SingleItemContainer as Slot
 
 import copy