annotate engine/extensions/fife_compat.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents bb9902910067
children 48c99636453e
rev   line source
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 """
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 FIFE Backwards Combatibility Layer
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 ==================================
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 This module can be imported if you want to
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 run code that wasn't adapted to API changes in FIFE.
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 2008.1
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 ------
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 - Animation.addFrame now expects a fife.ResourcePtr instead of an fife.Image
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
13 - Pool.getIndex is just an alias for Pool.addResourceFromFile.
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
14 - EventManager.setNonConsumableKeys is superseeded by EventManager.setKeyFilter
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 """
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 import fife
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
20 # Utility functions
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
21
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
22 def deprecated(revision,message):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
23 print "fife_compat: Deprecation warning - See revision %d " % revision
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
24 print " - ",message
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
25
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
26 def this_is_deprecated(func,revision=0,message=None):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
27 if message is None:
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
28 message = repr(func) + " is deprecated."
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
29 def wrapped_func(*args,**kwargs):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
30 deprecated(revision,message)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
31 return func(*args,**kwargs)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
32 return wrapped_func
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
33
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 # 2008.1 compatibility functions
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 def decorate_addFrame(f):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
37
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 def addFrame(self,image_ptr, delay):
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
39 if not isinstance(image_ptr,fife.ResourcePtr):
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
40 image_ptr = fife.ResourcePtr(image_ptr)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
41 deprecated(2616,"Animation.addFrame doesn't accept Image* anymore ")
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
42 return f(self,image_ptr,delay)
151
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 return addFrame
afcd83f7fac8 Backwards compatibility module fife_compat.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44
152
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
45 fife.Animation.addFrame = decorate_addFrame(fife.Animation.addFrame)
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
46 fife.Pool.getIndex = this_is_deprecated(
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
47 fife.Pool.addResourceFromFile,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
48 revision = 2617,
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
49 message = "Use addResourceFromFile instead of getIndex"
679ed3e15513 Deprecation: getIndex is now thrown out.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 151
diff changeset
50 )
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
51
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
52 def _compat_NonConsumableKeys():
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
53 class CompatKeyFilter(fife.IKeyFilter):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
54 def __init__(self, keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
55 fife.IKeyFilter.__init__(self)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
56 self.keys = keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
57
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
58 def isFiltered(self, event):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
59 return event.getKey().getValue() in self.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
60
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
61 def _setNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
62 deprecated(2636, "Write an IKeyFilter instead of using EventManager.setNonConsumableKeys.\n" +
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
63 "You probably don't need it anyway")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
64 self.compat_keyfilter = CompatKeyFilter(keys)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
65 self.compat_keyfilter.__disown__()
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
66 self.setKeyFilter(self.compat_keyfilter)
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
67
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
68 def _getNonConsumableKeys(self,keys):
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
69 deprecated(2636, "Write an IKeyFilter instead of using EventManager.getNonConsumableKeys.")
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
70 return self.compat_keyfilter.keys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
71
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
72 fife.EventManager.setNonConsumableKeys = _setNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
73 fife.EventManager.getNonConsumableKeys = _getNonConsumableKeys
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
74
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 152
diff changeset
75 _compat_NonConsumableKeys()