Changeset 547


Ignore:
Timestamp:
06/17/10 17:29:08 (9 years ago)
Author:
beliar
Message:
  • Replaced setNonConsumableKeys call with a KeyFilter?
  • Renamed scripts/engine.py to scripts/controller.py, the class scripts.Engine to scripts.Controller and all variables called model to controller to avoid confusing those with fife.engine
Location:
branches/code-cleanup-and-refactoring/game
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/code-cleanup-and-refactoring/game/local_loaders/xmlmap.py

    r541 r547  
    112112        self.data = data 
    113113        self.vfs = self.engine.getVFS() 
    114         self.model = self.engine.getModel() 
     114        self.controller = self.engine.getModel() 
    115115        self.pool = self.engine.getImagePool() 
    116116        self.anim_pool = self.engine.getAnimationPool() 
     
    149149        map = None 
    150150        try: 
    151             self.map = self.model.createMap(str(id)) 
     151            self.map = self.controller.createMap(str(id)) 
    152152            self.map.setResourceFile(self.source) 
    153153        # NameClash appears as general fife.Exception; any ideas? 
     
    241241 
    242242            allow_diagonals = pathing == "cell_edges_and_diagonals" 
    243             cell_grid = self.model.getCellGrid(grid_type) 
     243            cell_grid = self.controller.getCellGrid(grid_type) 
    244244            if not cell_grid: self._err('<layer> declared with invalid '\ 
    245245                                       'cell grid type. (%s)' % grid_type) 
     
    311311            self.n_space = n_space 
    312312 
    313             object = self.model.getObject(str(object_id), str(n_space)) 
     313            object = self.controller.getObject(str(object_id), str(n_space)) 
    314314            if not object: 
    315315                print ''.join(['Object with id=', str(object_id), ' ns=', \ 
  • branches/code-cleanup-and-refactoring/game/run.py

    r544 r547  
    2727utils.addPaths ('./lib', './lib/extensions') 
    2828 
    29 if not os.path.exists('settings.xml'): 
    30     shutil.copyfile('settings-dist.xml', 'settings.xml') 
    31  
    3229#from settings import Setting 
    3330 
     
    4744 
    4845if __name__ == '__main__': 
     46    if TDS.get("FIFE", "UsePsyco"): 
     47        # Import Psyco if available 
     48        try: 
     49            import psyco 
     50            psyco.full() 
     51            print "Psyco acceleration in use" 
     52        except ImportError: 
     53            print "Psyco acceleration not used" 
     54    else: 
     55        print "Psyco acceleration not used" 
    4956    main() 
    5057 
  • branches/code-cleanup-and-refactoring/game/scripts/console.py

    r479 r547  
    2222        @type appListener: ApplicationListener 
    2323        @param appListener: ApplicationListener object providing a link with 
    24         the engine, the world and the model""" 
     24        the engine, the world and the controller""" 
    2525        exit_help   = "Terminate application" 
    2626        grid_help   = "Toggle grid display" 
     
    4646        self.app_listener = app_listener 
    4747        self.world = self.app_listener.world  
    48         self.engine = self.app_listener.model 
     48        self.engine = self.app_listener.controller 
    4949        self.game_state = self.app_listener.world.data.game_state 
    5050 
     
    7878           @param command: The command to run. 
    7979           @return: The response""" 
    80         if self.app_listener.model.pc_run == 1: 
    81             self.app_listener.model.pc_run = 0 
     80        if self.app_listener.controller.pc_run == 1: 
     81            self.app_listener.controller.pc_run = 0 
    8282            return "PC is now walking" 
    8383        else: 
    84             self.app_listener.model.pc_run = 1 
     84            self.app_listener.controller.pc_run = 1 
    8585            return "PC is now running" 
    8686             
     
    124124                l_args = command.lower()[end_load + 1:].strip() 
    125125                l_path, l_filename = l_args.split(' ') 
    126                 self.app_listener.model.load_save = True 
    127                 self.app_listener.model.savegame = os.path.join(l_path, l_filename) 
     126                self.app_listener.controller.load_save = True 
     127                self.app_listener.controller.savegame = os.path.join(l_path, l_filename) 
    128128                result = "Load triggered" 
    129129 
     
    146146                s_args = command.lower()[end_save+1:].strip() 
    147147                s_path, s_filename = s_args.split(' ') 
    148                 self.app_listener.model.save(s_path, s_filename) 
     148                self.app_listener.controller.save(s_path, s_filename) 
    149149                result = "Saved to file: " + s_path + s_filename 
    150150 
  • branches/code-cleanup-and-refactoring/game/scripts/controller.py

    r546 r547  
    2424import yaml 
    2525 
    26 class Engine: 
    27     """Engine holds the logic for the game. 
     26class Controller(object): 
     27    """Controller holds the logic for the game. 
    2828       Since some data (object position and so forth) is held in the 
    2929       fife, and would be pointless to replicate, we hold a instance of 
  • branches/code-cleanup-and-refactoring/game/scripts/map.py

    r541 r547  
    4040        self.agent_layer = None 
    4141        self.top_layer = None 
    42         self.model = engine.getModel() 
     42        self.controller = engine.getModel() 
    4343        self.transitions = [] 
    4444        self.cur_cam2_x = 0 
     
    5353        # We have to delete the map in Fife. 
    5454        if self.map: 
    55             self.model.deleteObjects() 
    56             self.model.deleteMap(self.map) 
     55            self.controller.deleteObjects() 
     56            self.controller.deleteMap(self.map) 
    5757        self.transitions = [] 
    5858        self.map = None 
     
    9797            y = float(self.data.target_position[1]) 
    9898            z = 0 
    99             pc_obj = self.model.getObject("player", "PARPG") 
     99            pc_obj = self.controller.getObject("player", "PARPG") 
    100100            inst = self.agent_layer.createInstance(pc_obj,\ 
    101101                                            fife.ExactModelCoordinate(x,y,z),\ 
  • branches/code-cleanup-and-refactoring/game/scripts/parpg.py

    r544 r547  
    1515 
    1616from fife import fife 
    17 from fife.extensions import fife_compat, fifelog, pychan 
     17from fife.extensions import pychan 
    1818from fife.extensions.basicapplication import ApplicationBase 
     19from scripts import controller 
    1920 
    2021from scripts import world 
    21 from scripts import engine 
    2222from scripts import console 
    23 from scripts.engine import Engine 
    2423from scripts.common import eventlistenerbase 
    2524 
     25class KeyFilter(fife.IKeyFilter): 
     26    """ 
     27    This is the implementation of the fife.IKeyFilter class. 
     28     
     29    Prevents any filtered keys from being consumed by guichan. 
     30    """ 
     31    def __init__(self, keys): 
     32        fife.IKeyFilter.__init__(self) 
     33        self._keys = keys 
     34 
     35    def isFiltered(self, event): 
     36        return event.getKey().getValue() in self._keys 
    2637 
    2738class ApplicationListener(eventlistenerbase.EventListenerBase): 
    28     def __init__(self, engine, world, model): 
     39    def __init__(self, engine, world, controller): 
    2940        """Initialise the instance. 
    30            @type engine: fife.Engine 
     41           @type engine: fife.Controller 
    3142           @param engine: ??? 
    3243           @type world: world.World 
    3344           @param world: ??? 
    34            @type model: engine.Engine 
    35            @param model: an instance of PARPG's engine""" 
     45           @type controller: engine.Controller 
     46           @param controller: an instance of PARPG's engine""" 
    3647        super(ApplicationListener, self).__init__(engine, 
    3748                                                  reg_keys=True,reg_cmd=True, 
     
    4152        self.engine = engine 
    4253        self.world = world 
    43         self.model = model 
    44         engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,]) 
     54        self.controller = controller 
     55        keyfilter = KeyFilter([fife.Key.ESCAPE]) 
     56        keyfilter.__disown__()         
     57         
     58        engine.getEventManager().setKeyFilter(keyfilter) 
    4559        self.quit = False 
    4660        self.aboutWindow = None 
     
    7387class PARPGApplication(ApplicationBase): 
    7488    """Main Application class 
    75        We use an MVC data model. 
    76        self.world is our view,self.engine is our model 
     89       We use an MVC data controller. 
     90       self.world is our view,self.engine is our controller 
    7791       This file is the minimal controller""" 
    7892    def __init__(self, setting): 
     
    8195        super(PARPGApplication, self).__init__(setting) 
    8296        self.world = world.World(self.engine) 
    83         self.model = engine.Engine(self.world) 
    84         self.model.readObjectDB(self._setting.get("PARPG",  
     97        self.controller = controller.Controller(self.world) 
     98        self.controller.readObjectDB(self._setting.get("PARPG",  
    8599                                                  "ObjectDatabaseFile")) 
    86         self.world.data = self.model 
     100        self.world.data = self.controller 
    87101        self.world.initHud() 
    88         self.listener = ApplicationListener(self.engine, self.world, self.model) 
     102        self.listener = ApplicationListener(self.engine, self.world, self.controller) 
    89103        self.world.quitFunction = self.listener.quitGame 
    90         self.model.loadMap("main-map", str(self._setting.get("PARPG",  
     104        self.controller.loadMap("main-map", str(self._setting.get("PARPG",  
    91105                                                             "MapFile"))) 
    92106        pychan.init(self.engine, debug = True) 
     
    105119            self.breakRequested = True 
    106120        else: 
    107             self.model.pump() 
     121            self.controller.pump() 
    108122            self.world.pump() 
Note: See TracChangeset for help on using the changeset viewer.