[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20372] trunk/blender: Patch #18815: BGE: More updates to deprecation documentation and 2. 49 conversion script by Alex Frases(z0r)

Dalai Felinto dfelinto at gmail.com
Sun May 24 06:45:10 CEST 2009


Revision: 20372
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20372
Author:   dfelinto
Date:     2009-05-24 06:45:10 +0200 (Sun, 24 May 2009)

Log Message:
-----------
Patch #18815: BGE: More updates to deprecation documentation and 2.49 conversion script by Alex Frases(z0r)

 - Fixed some deprecation warnings in documentation.
 - Added more conversions to script.
 - Added more attributes to script todo list.
 - Print out name of text buffer when encountering an error in batch mode.
 - Refactor: Simplified attribute map.
 - Added notImplemented function to print warnings for missing conversions. References documentation.

Modified Paths:
--------------
    trunk/blender/release/scripts/textplugin_convert_ge.py
    trunk/blender/source/gameengine/PyDoc/GameTypes.py

Modified: trunk/blender/release/scripts/textplugin_convert_ge.py
===================================================================
--- trunk/blender/release/scripts/textplugin_convert_ge.py	2009-05-24 01:55:24 UTC (rev 20371)
+++ trunk/blender/release/scripts/textplugin_convert_ge.py	2009-05-24 04:45:10 UTC (rev 20372)
@@ -39,16 +39,23 @@
 # recommended that you review all changes after running this script.
 #
 # TODO: The following attributes are either ambiguous or need special processing
-# to handle parameters.
+# to handle parameters. Deprecated attributes that map to multiple target
+# attributes will require a refactor of the main conversion loop in the
+# convert248to249 function: currently, it doesn't allow any conversion to
+# advance the row index by more than one.
 #
-# getLinearVelocity  (KX_SCA_AddObjectActuator)
+# getLinearVelocity  (KX_SCA_AddObjectActuator, KX_ObjectActuator)
 #                    Conflicts with KX_GameObject.
-# setLinearVelocity  (KX_SCA_AddObjectActuator)
+#                    Maps to multiple attributes.
+# setLinearVelocity  (KX_SCA_AddObjectActuator, KX_ObjectActuator)
 #                    Conflicts with KX_GameObject.
-# getAngularVelocity (KX_SCA_AddObjectActuator)
+#                    Maps to multiple attributes.
+# getAngularVelocity (KX_SCA_AddObjectActuator, KX_ObjectActuator)
 #                    Conflicts with KX_GameObject.
-# setAngularVelocity (KX_SCA_AddObjectActuator)
+#                    Maps to multiple attributes.
+# setAngularVelocity (KX_SCA_AddObjectActuator, KX_ObjectActuator)
 #                    Conflicts with KX_GameObject.
+#                    Maps to multiple attributes.
 # setAction          (BL_ShapeActionActuator, BL_ActionActuator)
 #                    `reset' argument has no conversion target.
 # set                (KX_VisibilityActuator, KX_IpoActuator)
@@ -69,6 +76,26 @@
 #                    KX_GameObject.
 # setOperation       (KX_SCA_DynamicActuator, KX_StateActuator)
 #                    Ambiguous: different target names.
+# getDRot            (KX_ObjectActuator)
+#                    Maps to multiple attributes.
+# setDRot            (KX_ObjectActuator)
+#                    Arguments map to multiple attributes.
+# getDLoc            (KX_ObjectActuator)
+#                    Maps to multiple attributes.
+# setDLoc            (KX_ObjectActuator)
+#                    Arguments map to multiple attributes.
+# getTorque          (KX_ObjectActuator)
+#                    Maps to multiple attributes.
+# setTorque          (KX_ObjectActuator)
+#                    Arguments map to multiple attributes.
+# getForce           (KX_ObjectActuator)
+#                    Maps to multiple attributes.
+# setForce           (KX_ObjectActuator)
+#                    Arguments map to multiple attributes.
+# position           (KX_GameObject)
+#                    Conflicts with KX_SoundActuator.
+# orientation        (KX_GameObject)
+#                    Conflicts with KX_SoundActuator.
 #
 
 import string
@@ -268,7 +295,9 @@
 	lines[row] = replaceSubstr(lines[row], colStart, colEnd, 'position')
 
 def replaceRename(lines, row, colStart, colEnd, newName):
-	"""Replace an identifier with another, e.g. foo.getBar() -> foo.getBaz()
+	"""Replace an identifier with another, e.g.
+	foo.getBar() -> foo.getBaz()
+	foo.bar -> foo.baz
 	
 	The identifier being replaced must be on line `row' and between `colStart'
 	and `colEnd'."""
@@ -402,233 +431,268 @@
 	# It's probably a KX_GameObject.
 	replaceSimpleSetter(lines, row, colStart, colEnd, 'localPosition')
 
+def replaceSplitProperty(lines, row, colStart, colEnd, (newGetter, newSetter)):
+	'''Some property attributes behave differently when being written to or read
+	from. Try to determine the operation, and replace accordingly. E.G.
+	o.position = foo -> o.localPosition = foo   # set
+	foo = o.position -> foo = o.worldPosition   # get
+
+	This implementation can not handle cases where the object is returned from
+	a function, e.g.
+	foo = bar.getObject().position # Error!
+
+	Raises a ConversionError if the operation can't be determined, or if the
+	object is returned from a function.'''
+	assnRegex = re.compile(r'(=\s*)?' # Getter
+							r'[a-zA-Z_]\w*' # Object identifier
+							r'\.([a-zA-Z_][a-zA-Z0-9_.]*)+' # Trailing attributes
+							r'(\s*=)?') # Setter
+	match = assnRegex.search(lines[row])
+	
+	if not match:
+		raise ConversionError, "Can't determine operation (getting or setting)."
+
+	setting = False
+	getting = False
+	if match.group(1):
+			getting = True
+	if match.group(3):
+			setting = True
+	if (getting and setting) or ((not getting) and (not setting)):
+			raise ConversionError, "Can't determine operation (getting or setting)."
+
+	if getting:
+			replaceRename(lines, row, colStart, colEnd, newGetter)
+	else:
+			replaceRename(lines, row, colStart, colEnd, newSetter)
+
+def notImplemented(lines, row, colStart, colEnd, classNames):
+	message = "Conversion not implemented. See documentation for " +\
+	          string.join(classNames, ', ')
+	raise ConversionError, message
+
 #
 # Deprecated attribute information. The format is:
-# deprecatedAttributeName: {(conversionFunction, closure): classList}
+# deprecatedAttributeName: (conversionFunction, closure)
 # Usually the closure will be the name of the superceding attribute.
 #
-# If an attribute maps to more than one function/attribute pair, the conversion
-# is ambiguous and can't be performed.
+# Since each deprecated attribute can appear in this dictionary only once, it is
+# the conversion function's responsibility to resolve ambiguity.
 #
 attributeRenameDict = {
  # Special cases
- 'addActiveActuator': {(replaceAddActiveActuator, None): []},
- 'getActuator': {(replaceGetActuator, None): ['SCA_IController', 'SCA_ActuatorSensor']},
- 'getXPosition': {(replaceGetXYPosition, '0'): ['SCA_MouseSensor']},
- 'getYPosition': {(replaceGetXYPosition, '1'): ['SCA_MouseSensor']},
- 'setOrientation': {(replaceSetOrientation, None): ['KX_GameObject', 'KX_SoundActuator']},
- 'setPosition': {(replaceSetPosition, None): ['KX_GameObject', 'KX_SoundActuator']},
+ 'addActiveActuator': (replaceAddActiveActuator, None), # 
+ 'getActuator': (replaceGetActuator, None), # SCA_IController, SCA_ActuatorSensor
+ 'getXPosition': (replaceGetXYPosition, '0'), # SCA_MouseSensor
+ 'getYPosition': (replaceGetXYPosition, '1'), # SCA_MouseSensor
+ 'setOrientation': (replaceSetOrientation, None), # KX_GameObject, KX_SoundActuator
+ 'setPosition': (replaceSetPosition, None), # KX_GameObject, KX_SoundActuator
 
  # Keyed getters/setters
- 'getSensor': {(replaceKeyedGetter, 'sensors'): ['SCA_IController']},
+ 'getSensor': (replaceKeyedGetter, 'sensors'), # SCA_IController
 
  # Multi-arg -> List setter
- 'setAxis': {(replaceArgsWithListSetter, 'axis'): ['SCA_JoystickSensor']},
- 'setHat': {(replaceArgsWithListSetter, 'hat'): ['SCA_JoystickSensor']},
- 'setVelocity': {(replaceArgsWithListSetter, 'velocity'): ['KX_SoundActuator']},
+ 'setAxis': (replaceArgsWithListSetter, 'axis'), # SCA_JoystickSensor
+ 'setForceLimitX': (replaceArgsWithListSetter, 'forceLimitX'), # KX_ObjectActuator
+ 'setForceLimitY': (replaceArgsWithListSetter, 'forceLimitY'), # KX_ObjectActuator
+ 'setForceLimitZ': (replaceArgsWithListSetter, 'forceLimitZ'), # KX_ObjectActuator
+ 'setHat': (replaceArgsWithListSetter, 'hat'), # SCA_JoystickSensor
+ 'setPID': (replaceArgsWithListSetter, 'pid'), # KX_ObjectActuator
+ 'setVelocity': (replaceArgsWithListSetter, 'velocity'), # KX_SoundActuator
 
  # Straight rename
- 'getButtonValue': {(replaceRename, 'getButtonActiveList'): ['SCA_JoystickSensor']},
+ 'getButtonValue': (replaceRename, 'getButtonActiveList'), # SCA_JoystickSensor
 
+ # Split properties
+ 'scaling': (replaceSplitProperty, ('worldScaling', 'localScaling')), # KX_GameObject
+
  # Simple getters/setters
- 'getSensors': {(replaceSimpleGetter, 'sensors'): ['SCA_IController']},
- 'getActuators': {(replaceSimpleGetter, 'actuators'): ['SCA_IController']},
- 'enableViewport': {(replaceSimpleSetter, 'useViewport'): ['KX_Camera']},
- 'getAction': {(replaceSimpleGetter, 'action'): ['BL_ShapeActionActuator', 'BL_ActionActuator']},
- 'getAxis': {(replaceSimpleGetter, 'axis'): ['SCA_JoystickSensor']},
- 'getAxisValue': {(replaceSimpleGetter, 'axisValues'): ['SCA_JoystickSensor']},
- 'getBlendin': {(replaceSimpleGetter, 'blendIn'): ['BL_ShapeActionActuator',
-                                                   'BL_ActionActuator']},
- 'getBodies': {(replaceSimpleGetter, 'bodies'): ['KX_NetworkMessageSensor']},
- 'getButton': {(replaceSimpleGetter, 'button'): ['SCA_JoystickSensor']},
- 'getCamera': {(replaceSimpleGetter, 'camera'): ['KX_SceneActuator']},
- 'getConeOrigin': {(replaceSimpleGetter, 'coneOrigin'): ['KX_RadarSensor']},
- 'getConeTarget': {(replaceSimpleGetter, 'coneTarget'): ['KX_RadarSensor']},
- 'getContinue': {(replaceSimpleGetter, 'useContinue'): ['BL_ActionActuator']},
- 'getCurrentlyPressedKeys': {(replaceSimpleGetter, 'events'): ['SCA_KeyboardSensor']},
- 'getDelay': {(replaceSimpleGetter, 'delay'): ['SCA_DelaySensor']},
- 'getDistribution': {(replaceSimpleGetter, 'distribution'): ['SCA_RandomActuator']},
- 'getDuration': {(replaceSimpleGetter, 'duration'): ['SCA_DelaySensor']},
- 'getEnd': {(replaceSimpleGetter, 'frameEnd'): ['BL_ShapeActionActuator',
-                                                'KX_IpoActuator',
-                                                'BL_ActionActuator']},
- 'getExecutePriority': {(replaceSimpleGetter, 'executePriority'): ['SCA_ILogicBrick']},
- 'getFile': {(replaceSimpleGetter, 'fileName'): ['KX_GameActuator']},
- 'getFilename': {(replaceSimpleGetter, 'fileName'): ['KX_SoundActuator']},
- 'getForceIpoActsLocal': {(replaceSimpleGetter, 'useIpoLocal'): ['KX_IpoActuator']},
- 'getFrame': {(replaceSimpleGetter, 'frame'): ['BL_ShapeActionActuator', 'BL_ActionActuator']},
- 'getFrameMessageCount': {(replaceSimpleGetter, 'frameMessageCount'): ['KX_NetworkMessageSensor']},
- 'getFrameProperty': {(replaceSimpleGetter, 'framePropName'): ['BL_ShapeActionActuator',
-                                                               'BL_ActionActuator']},
- 'getFrequency': {(replaceSimpleGetter, 'frequency'): ['SCA_ISensor']},
- 'getGain': {(replaceSimpleGetter, 'volume'): ['KX_SoundActuator', 'KX_CDActuator']},
- 'getHat': {(replaceSimpleGetter, 'hat'): ['SCA_JoystickSensor']},

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list