Mercurial > parpg-core
changeset 182:59c9ce2b8351
PARPG now works with, and needs Fife 0.3.3.
author | KarstenBock@gmx.net |
---|---|
date | Tue, 11 Oct 2011 14:47:37 +0200 |
parents | 54c4277ed905 |
children | 5d52f08633c0 |
files | src/parpg/application.py src/parpg/common/listeners/event_listener.py src/parpg/controllerbase.py src/parpg/font.py src/parpg/gamemap.py src/parpg/gamemodel.py src/parpg/sounds.py |
diffstat | 7 files changed, 67 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parpg/application.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/application.py Tue Oct 11 14:47:37 2011 +0200 @@ -18,7 +18,6 @@ from fife import fife from fife.extensions import pychan -from fife.extensions.serializers.xmlanimation import XMLAnimationLoader from fife.extensions.basicapplication import ApplicationBase from parpg import console, vfs @@ -121,9 +120,6 @@ # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py. vfs.VFS = self.engine.getVFS() vfs.VFS.addNewSource(setting.parpg.DataPath) - self._animationloader = XMLAnimationLoader(self.engine.getImagePool(), - self.engine.getVFS()) - self.engine.getAnimationPool().addResourceLoader(self._animationloader) pychan.init(self.engine, debug = True) pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) @@ -180,7 +176,9 @@ engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize) engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel) engineSetting.setInitialVolume(self._setting.fife.InitialVolume) - engineSetting.setSDLRemoveFakeAlpha(self._setting.fife.SDLRemoveFakeAlpha) + engineSetting.setSDLRemoveFakeAlpha( + self._setting.fife.SDLRemoveFakeAlpha + ) engineSetting.setScreenWidth(self._setting.fife.ScreenWidth) engineSetting.setScreenHeight(self._setting.fife.ScreenHeight) engineSetting.setRenderBackend(self._setting.fife.RenderBackend) @@ -207,7 +205,7 @@ def _pump(self): """Main game loop. - There are in fact 2 main loops, this one and the one in GameSceneView. + There are 2 main loops, this one and the one in GameSceneView. @return: None""" if self.listener.quit: self.breakRequested = True #pylint: disable-msg=C0103
--- a/src/parpg/common/listeners/event_listener.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/common/listeners/event_listener.py Tue Oct 11 14:47:37 2011 +0200 @@ -17,9 +17,10 @@ """This module contains the EventListener that receives events and distributes them to PARPG listeners""" +import logging from fife import fife -import logging +from fife.extensions import pychan logger = logging.getLogger('event_listener') @@ -39,7 +40,7 @@ fife.IMouseListener.__init__(self) self.event_manager.addMouseListener(self) fife.ConsoleExecuter.__init__(self) - engine.getGuiManager().getConsole().setConsoleExecuter(self) + pychan.manager.hook.guimanager.getConsole().setConsoleExecuter(self) self.listeners = {"Mouse" : [], "Key" : [],
--- a/src/parpg/controllerbase.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/controllerbase.py Tue Oct 11 14:47:37 2011 +0200 @@ -68,18 +68,17 @@ @param type: ??? @return: None""" cursor = self.engine.getCursor() - cursor_type = fife.CURSOR_IMAGE - img_pool = self.engine.getImagePool() + img_manager = self.engine.getImageManager() if(mc_type == "target"): - target_cursor_id = img_pool.addResourceFromFile(image) - dummy_cursor_id = img_pool.addResourceFromFile(dummy_image) - cursor.set(cursor_type, dummy_cursor_id) - cursor.setDrag(cursor_type, target_cursor_id, -16, -16) + target_cursor_id = img_manager.load(image) + dummy_cursor_id = img_manager.load(dummy_image) + cursor.set(dummy_cursor_id) + cursor.setDrag(target_cursor_id, -16, -16) else: cursor_type = fife.CURSOR_IMAGE - zero_cursor_id = img_pool.addResourceFromFile(image) - cursor.set(cursor_type, zero_cursor_id) - cursor.setDrag(cursor_type, zero_cursor_id) + zero_cursor_id = img_manager.load(image) + cursor.set(zero_cursor_id) + cursor.setDrag(zero_cursor_id) def resetMouseCursor(self): """Reset cursor to default image.
--- a/src/parpg/font.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/font.py Tue Oct 11 14:47:37 2011 +0200 @@ -1,7 +1,8 @@ import os +from fife.extensions import pychan from fife.extensions.pychan.fonts import Font -from fife.extensions.pychan.internal import get_manager + class PARPGFont(Font): """ Font class for PARPG @@ -35,7 +36,7 @@ self.size = fontdef['size'] self.antialias = fontdef['antialias'] self.color = fontdef.get('color', [255, 255, 255]) - manager = get_manager().hook.engine.getGuiManager() + manager = pychan.manager.hook.guimanager self.font = manager.createFont(self.source, self.size, '') if not self.font:
--- a/src/parpg/gamemap.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/gamemap.py Tue Oct 11 14:47:37 2011 +0200 @@ -14,6 +14,7 @@ # along with PARPG. If not, see <http://www.gnu.org/licenses/>. from fife import fife +from fife.extensions import pychan from fife.extensions.loaders import loadMapFile class GameMap(fife.MapChangeListener): @@ -101,21 +102,21 @@ self.target_rotation = self.cameras[self.my_cam_id].getRotation() - self.outline_renderer = fife.InstanceRenderer.\ - getInstance( - self.cameras[ - self.my_cam_id - ]) + self.outline_renderer = ( + fife.InstanceRenderer.getInstance(self.cameras[self.my_cam_id]) + ) # set the render text - rend = fife.FloatingTextRenderer.getInstance(self.cameras[ - self.my_cam_id - ]) - text = self.engine.getGuiManager().createFont('fonts/rpgfont.png', - 0, - self.settings.fife.FontGlyphs) + rend = fife.FloatingTextRenderer.getInstance( + self.cameras[self.my_cam_id] + ) + font = pychan.manager.hook.guimanager.createFont( + 'fonts/rpgfont.png', + 0, + self.settings.fife.FontGlyphs + ) - rend.changeDefaultFont(text) + rend.setFont(font) rend.activateAllLayers(self.map) rend.setEnabled(True) @@ -124,9 +125,9 @@ rend.activateAllLayers(self.map) # Activate the grid renderer on all layers - rend = fife.CoordinateRenderer.getInstance(self.cameras[ - self.my_cam_id - ]) + rend = fife.CoordinateRenderer.getInstance( + self.cameras[self.my_cam_id] + ) rend.setColor(0, 0, 0) rend.addActiveLayer(self.map.getLayer("GroundLayer")) @@ -137,7 +138,8 @@ """Add the player character to the map @return: None""" # Update gamestate.player_character - self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.onNewMap(self.agent_layer) + player = self.model.game_state.getObjectById("PlayerCharacter") + player.fifeagent.behaviour.onNewMap(self.agent_layer) self.centerCameraOnPlayer() def toggleRenderer(self, r_name): @@ -167,5 +169,5 @@ def centerCameraOnPlayer(self): """Center the camera on the player""" camera = self.cameras[self.my_cam_id] - player_agent = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.agent - camera.setLocation(player_agent.getLocation()) + player = self.model.game_state.getObjectById("PlayerCharacter") + camera.setLocation(player.fifeagent.behaviour.getLocation())
--- a/src/parpg/gamemodel.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/gamemodel.py Tue Oct 11 14:47:37 2011 +0200 @@ -94,12 +94,7 @@ self.dialogue_directory = settings.parpg.DialoguesPath self.dialogues = {} self.agent_import_files = {} - self.obj_loader = XMLObjectLoader( - self.engine.getImagePool(), - self.engine.getAnimationPool(), - self.engine.getModel(), - self.engine.getVFS() - ) + self.obj_loader = XMLObjectLoader(self.engine) def checkAttributes(self, attributes, template): """Checks for attributes that where not given in the map file @@ -134,7 +129,9 @@ id_number += 1 if id_number > self.MAX_ID_NUMBER: raise ValueError( - "Number exceeds MAX_ID_NUMBER:" + str(self.MAX_ID_NUMBER)) + "Number exceeds MAX_ID_NUMBER:" + + str(self.MAX_ID_NUMBER) + ) ID = ID + "_" + str(id_number) return ID @@ -207,7 +204,8 @@ def teleport(self, agent, position): """Called when a an agent is moved instantly to a new position. - The setting of position may wan to be created as its own method down the road. + The setting of position may wan to be created as its own method down + the road. @type position: String Tuple @param position: X,Y coordinates passed from engine.changeMap @return: fife.Location""" @@ -303,7 +301,8 @@ and agent_values["Entity"]["graphics"].has_key("gfx"): object_model = agent_values["Entity"]["graphics"]["gfx"] elif agent_values.has_key("Template"): - object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"] + template = self.object_db[agent_values["Template"]] + object_model = template["graphics"]["gfx"] else: object_model = self.GENERIC_ITEM_GFX import_file = self.agent_import_files[object_model] @@ -427,7 +426,8 @@ entity_data["containable"]["item_type"] = template - obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) + obj = self.createMapObject(self.active_map.agent_layer, + entity_data, inst_id, world) if agent.has_key("Inventory"): inv = agent["Inventory"] @@ -440,12 +440,16 @@ item_type = data["type"] item_data = {} item_data = self.checkAttributes(item_data, item_type) - if item_data.has_key("containable") and item_data.has_key("equipable"): + if (item_data.has_key("containable") and + item_data.has_key("equipable")): item = self.createItem( self.createUniqueID(data["ID"]), item_data, world, item_type) else: - raise Exception("Item %s is not containable or equipable." % item_type) + raise Exception( + "Item %s is not containable or equipable." % + item_type + ) else: identifier = data["ID"] if self.game_state.hasObject(identifier): @@ -533,7 +537,8 @@ self.active_map.addPC() #self.game_state.getObjectById("PlayerCharacter").fifeagent.start() if agent.has_key("PeopleKnown"): - self.game_state.getObjectById("PlayerCharacter").fifeagent.people_i_know = agent["PeopleKnown"] + player = self.game_state.getObjectById("PlayerCharacter") + player.fifeagent.people_i_know = agent["PeopleKnown"] def changeMap(self, map_name, target_position = None): """Registers for a map change on the next pump(). @@ -607,9 +612,10 @@ # For now we copy the PlayerCharacter, # in the future we will need to copy # PlayerCharacter specifics between the different PlayerCharacter's - self.game_state.getObjectById("PlayerCharacter").fifeagent = player_char - self.game_state.getObjectById("PlayerCharacter").fifeagent.setup() - self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.speed = self.settings.parpg.PCSpeed + player = self.game_state.getObjectById("PlayerCharacter") + player.fifeagent = player_char + player.fifeagent.setup() + player.fifeagent.behaviour.speed = self.settings.parpg.PCSpeed def addObject(self, layer, obj): @@ -625,7 +631,8 @@ self.game_state.current_map_name) if ref is None: # no, add it to the game state - self.game_state.addObject(obj.general.identifier, self.game_state.current_map_name, obj) + self.game_state.addObject(obj.general.identifier, + self.game_state.current_map_name, obj) else: # yes, use the current game state data obj.fifeagent.pos.X = ref.X @@ -667,10 +674,11 @@ @type position: fife.ScreenPoint @param position: Screen position to move to @return: None""" + player = self.game_state.getObjectById("PlayerCharacter") if(self.pc_run == 1): - self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.run(position) + player.fifeagent.behaviour.run(position) else: - self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.walk(position) + player.fifeagent.behaviour.walk(position) def teleportAgent(self, agent, position): """Code called when an agent should teleport to another location
--- a/src/parpg/sounds.py Mon Oct 10 15:13:56 2011 +0200 +++ b/src/parpg/sounds.py Tue Oct 11 14:47:37 2011 +0200 @@ -14,6 +14,7 @@ # along with PARPG. If not, see <http://www.gnu.org/licenses/>. # sounds.py holds the object code to play sounds and sound effects +from fife import fife class SoundEngine: def __init__(self, fife_engine): @@ -36,7 +37,7 @@ @return: None""" if(sfile is not None): # setup the new sound - sound = self.engine.getSoundClipPool().addResourceFromFile(sfile) + sound = self.engine.getSoundClipManager().load(sfile) self.music.setSoundClip(sound) self.music.setLooping(True) self.music_init = True