source: trunk/game/scripts/map.py @ 323

Revision 323, 4.5 KB checked in by eliedebrauwer, 10 years ago (diff)

Ticket #73: Patch by eliedebrauwer, removed obj_hashes from world, and from the maps, added logic to restore PC and NPC behaviour based on the layer ID, added logic to trigger the map load using within the pump(). Load still not functional. comment[s:trac, t:73]

  • Property svn:eol-style set to native
Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18import fife
19import time
20from local_loaders.loaders import loadMapFile
21from scripts.common.eventlistenerbase import EventListenerBase
22
23from settings import Setting
24TDS = Setting()
25
26class Map(fife.MapChangeListener):
27    """Map class used to flag changes in the map"""
28    def __init__(self, engine, data):
29        # init mapchange listener
30        fife.MapChangeListener.__init__(self)
31        self.map = None
32        self.engine = engine
33        self.data = data
34       
35        # init map attributes
36        self.cameras = {}
37        self.agent_layer = None
38        self.model = engine.getModel()
39        self.view = engine.getView()
40        self.transitions = []
41        self.cur_cam2_x = 0
42        self.initial_cam2_x = 0
43        self.cam2_scrolling_right = True
44        self.target_rotation = 0
45        self.outline_renderer = None
46       
47    def reset(self):
48        """Reset the data to default settings.
49           @return: None"""
50        # We have to delete the map in Fife.
51        # TODO: We're killing the PC now, but later we will have to save the PC
52        if self.map:
53            self.model.deleteObjects()
54            self.model.deleteMap(self.map)
55        self.transitions = []
56        self.map = None
57        self.agent_layer = None
58        # We have to clear the cameras in the view as well, or we can't reuse
59        # camera names like 'main'
60        self.view.clearCameras()
61        self.cameras = {}
62        self.cur_cam2_x = 0
63        self.initial_cam2_x = 0
64        self.cam2_scrolling_right = True
65        self.target_rotation = 0
66        self.outline_renderer = None
67       
68    def makeActive(self):
69        """Makes this map the active one.
70        """
71        pass
72       
73    def load(self, filename):
74        """Load a map given the filename.
75           @type filename: string
76           @param filename: Name of map to load
77           @return: None"""
78        self.reset()
79        self.map = loadMapFile(filename, self.engine, self.data)
80         
81        # there must be a PC object on the objects layer!
82        self.agent_layer = self.map.getLayer('ObjectLayer')
83       
84        # it's possible there's no transition layer
85        size = len('TransitionLayer')
86        for layer in self.map.getLayers():
87            # could be many layers, but hopefully no more than 3
88            if(layer.getId()[:size] == 'TransitionLayer'):
89                self.transitions.append(self.map.getLayer(layer.getId()))
90               
91        # init the camera
92        for cam in self.view.getCameras():
93            self.cameras[cam.getId()] = cam
94        self.view.resetRenderers()
95        self.target_rotation = self.cameras['main'].getRotation()
96       
97        self.outline_render = fife.InstanceRenderer.\
98                                        getInstance(self.cameras['main'])
99       
100        # set the render text
101        rend = fife.FloatingTextRenderer.getInstance(self.cameras['main'])
102        text = self.engine.getGuiManager().\
103                        createFont('fonts/rpgfont.png', 0, \
104                                   str(TDS.readSetting("FontGlyphs", \
105                                                       strip=False)))
106        rend.changeDefaultFont(text)
107               
108    def addPC(self, agent):
109        """Add the player character to the map
110           @type agent: Fife.instance of PC
111           @return: None"""
112        # actually this is real easy, we just have to
113        # attach the main camera to the PC, if a camera
114        # was already used, we simply recycle it.
115        if self.cameras['main'].getAttached() == None:
116            self.cameras['main'].attach(agent)
117
118       
119    def toggle_renderer(self, r_name):
120        """Enable or disable a renderer.
121           @return: None"""
122        renderer = self.cameras['main'].getRenderer(str(r_name))
123        renderer.setEnabled(not renderer.isEnabled())
124
Note: See TracBrowser for help on using the repository browser.