Mercurial > fife-parpg
comparison engine/python/fife/extensions/fife_compat.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 """ | |
25 FIFE Backwards Combatibility Layer | |
26 ================================== | |
27 | |
28 This module can be imported if you want to | |
29 run code that wasn't adapted to API changes in FIFE. | |
30 | |
31 2008.1 | |
32 ------ | |
33 | |
34 - Animation.addFrame now expects a fife.ResourcePtr instead of an fife.Image | |
35 - Pool.getIndex is just an alias for Pool.addResourceFromFile. | |
36 - EventManager.setNonConsumableKeys is superseeded by EventManager.setKeyFilter | |
37 | |
38 """ | |
39 | |
40 from fife import fife | |
41 | |
42 # Utility functions | |
43 | |
44 def deprecated(revision,message): | |
45 print "fife_compat: Deprecation warning - See revision %d " % revision | |
46 print " - ",message | |
47 | |
48 def this_is_deprecated(func,revision=0,message=None): | |
49 if message is None: | |
50 message = repr(func) + " is deprecated." | |
51 def wrapped_func(*args,**kwargs): | |
52 deprecated(revision,message) | |
53 return func(*args,**kwargs) | |
54 return wrapped_func | |
55 | |
56 # 2008.1 compatibility functions | |
57 | |
58 def decorate_addFrame(f): | |
59 | |
60 def addFrame(self,image_ptr, delay): | |
61 if not isinstance(image_ptr,fife.ResourcePtr): | |
62 image_ptr = fife.ResourcePtr(image_ptr) | |
63 deprecated(2616,"Animation.addFrame doesn't accept Image* anymore ") | |
64 return f(self,image_ptr,delay) | |
65 return addFrame | |
66 | |
67 fife.Animation.addFrame = decorate_addFrame(fife.Animation.addFrame) | |
68 fife.Pool.getIndex = this_is_deprecated( | |
69 fife.Pool.addResourceFromFile, | |
70 revision = 2617, | |
71 message = "Use addResourceFromFile instead of getIndex" | |
72 ) | |
73 | |
74 def _compat_NonConsumableKeys(): | |
75 class CompatKeyFilter(fife.IKeyFilter): | |
76 def __init__(self, keys): | |
77 fife.IKeyFilter.__init__(self) | |
78 self.keys = keys | |
79 | |
80 def isFiltered(self, event): | |
81 return event.getKey().getValue() in self.keys | |
82 | |
83 def _setNonConsumableKeys(self,keys): | |
84 deprecated(2636, "Write an IKeyFilter instead of using EventManager.setNonConsumableKeys.\n" + | |
85 "You probably don't need it anyway") | |
86 self.compat_keyfilter = CompatKeyFilter(keys) | |
87 self.compat_keyfilter.__disown__() | |
88 self.setKeyFilter(self.compat_keyfilter) | |
89 | |
90 def _getNonConsumableKeys(self,keys): | |
91 deprecated(2636, "Write an IKeyFilter instead of using EventManager.getNonConsumableKeys.") | |
92 return self.compat_keyfilter.keys | |
93 | |
94 fife.EventManager.setNonConsumableKeys = _setNonConsumableKeys | |
95 fife.EventManager.getNonConsumableKeys = _getNonConsumableKeys | |
96 | |
97 _compat_NonConsumableKeys() |