# HG changeset patch # User KarstenBock@gmx.net # Date 1320505499 -3600 # Node ID f017f8cac2c27569745d5658a863684724204912 # Parent 4dc7951c3bfc864852776cef7b370564f876cad1 Statistics are being saved and loaded. diff -r 4dc7951c3bfc -r f017f8cac2c2 charactercreationcontroller.py --- a/charactercreationcontroller.py Sat Nov 05 14:53:12 2011 +0100 +++ b/charactercreationcontroller.py Sat Nov 05 16:04:59 2011 +0100 @@ -16,15 +16,12 @@ screen.""" from parpg import vfs -import characterstatistics as char_stats from controllerbase import ControllerBase from gamescenecontroller import GameSceneController from gamesceneview import GameSceneView from parpg.world import World from parpg.entities import General - -DEFAULT_STAT_VALUE = 50 - +from parpg.components import character_statistics def getStatCost(offset): """Gets and returns the cost to increase stat based on the offset""" @@ -98,28 +95,26 @@ self.char_data.characterstats.picture = ( self.PICTURES[self.GENDERS[0]][0] ) - for primary_stat in self.model.primary_stats: - long_name = primary_stat.long_name - self.char_data.characterstats.primary_stats[long_name] = ( - char_stats.PrimaryStatisticValue( - primary_stat, self.char_data.characterstats, - DEFAULT_STAT_VALUE) - ) - for secondary_stat in self.model.secondary_stats: - name = secondary_stat.name - self.char_data.characterstats.secondary_stats[name] = ( - char_stats.SecondaryStatisticValue(secondary_stat, - self.char_data. - characterstats) - ) + self.model.create_stats(self.char_data) self.char_data.container.max_bulk = self.MAX_BULK self.char_data.container.children = inventory - self._stat_points = 200 - - + self._stat_points = 200 + + def update_agent(self): + """Updates the player agent data in the model""" + agent_data = ( + self.model.agents[self.model.ALL_AGENTS_KEY]["PlayerCharacter"] + ) + agent_data["Statistics"] = ( + character_statistics.get_stat_values( + self.char_data.characterstats + )["primary"] + ) + def startNewGame(self): """Create the new character and start a new game. @return: None""" + self.update_agent() view = GameSceneView(self.engine, self.model) controller = GameSceneController(self.engine, view, self.model, self.application) diff -r 4dc7951c3bfc -r f017f8cac2c2 components/character_statistics.py --- a/components/character_statistics.py Sat Nov 05 14:53:12 2011 +0100 +++ b/components/character_statistics.py Sat Nov 05 16:04:59 2011 +0100 @@ -38,4 +38,12 @@ for stat in stats.primary_stats: if stat.statistic_type.short_name == name: return stat - return None \ No newline at end of file + return None + +def get_stat_values(char_stats): + stats = {"primary":{}, "secondary":{}} + for name, stat in char_stats.primary_stats.iteritems(): + stats["primary"][name] = stat.value + for name, stat in char_stats.secondary_stats.iteritems(): + stats["secondary"][name] = stat.value + return stats \ No newline at end of file diff -r 4dc7951c3bfc -r f017f8cac2c2 gamemodel.py --- a/gamemodel.py Sat Nov 05 14:53:12 2011 +0100 +++ b/gamemodel.py Sat Nov 05 16:04:59 2011 +0100 @@ -33,7 +33,8 @@ from parpg.entities import createEntity from parpg import behaviours from parpg import components -from parpg.components import fifeagent, container, equip +from parpg.components import fifeagent, container, equip, character_statistics +import characterstatistics as char_stats try: import xml.etree.cElementTree as ElementTree @@ -53,6 +54,7 @@ ALL_AGENTS_KEY = "All" MAX_ID_NUMBER = 1000 GENERIC_ITEM_GFX = "generic_item" + DEFAULT_STAT_VALUE = 50 def __init__(self, engine, settings): """Initialize the instance. @@ -107,6 +109,22 @@ self.primary_stats = [] self.secondary_stats = [] + def create_stats(self, entity): + for primary_stat in self.primary_stats: + long_name = primary_stat.long_name + entity.characterstats.primary_stats[long_name] = ( + char_stats.PrimaryStatisticValue( + primary_stat, entity.characterstats, + self.DEFAULT_STAT_VALUE) + ) + for secondary_stat in self.secondary_stats: + name = secondary_stat.name + entity.characterstats.secondary_stats[name] = ( + char_stats.SecondaryStatisticValue(secondary_stat, + entity.characterstats + ) + ) + def checkAttributes(self, attributes, template): """Checks for attributes that where not given in the map file and fills them with values from the object database @@ -434,12 +452,16 @@ if (entity_data.has_key("containable") and not entity_data["containable"].has_key("item_type") ): - entity_data["containable"]["item_type"] = template - - + entity_data["containable"]["item_type"] = template + obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) + if agent.has_key("Statistics"): + self.create_stats(obj) + for name, val in agent["Statistics"].iteritems(): + obj.characterstats.primary_stats[name].value = val + if agent.has_key("Inventory"): inv = agent["Inventory"] self.createInventoryItems(inv, obj, world) @@ -749,6 +771,12 @@ if all_agents.has_key(identifier): agent_data["Map"] = map_id agent_data["Rotation"] = inst.getRotation() + elif name == "characterstats": + agent_data["Statistics"] = ( + character_statistics.get_stat_values( + entity.characterstats + )["primary"] + ) elif name == "container" and hasattr(comp_vals, "children"): inventory_data = {} @@ -774,8 +802,7 @@ equipable.entity.general.identifier } agent_data["Equipment"] = equip_data - agent_data["Entity"] = entity_data - + agent_data["Entity"] = entity_data def getAgentImportFiles(self): """Searches the agents directory for import files """