[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20349] trunk/blender: [#18802] BGE conversion script: more attributes; updated GameTypes.py
Campbell Barton
ideasman42 at gmail.com
Sat May 23 05:19:51 CEST 2009
Revision: 20349
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20349
Author: campbellbarton
Date: 2009-05-23 05:19:47 +0200 (Sat, 23 May 2009)
Log Message:
-----------
[#18802] BGE conversion script: more attributes; updated GameTypes.py
Patch from Alex Fraser (z0r)
- All attributes in the conversion map have been checked against the docs. More ambiguities have been resolved.
- Added option to convert all text buffers in Blender.
- Updated GameTypes.py: there were inconsistencies.
The script works well (causes no errors) with 0_FPS_Template.blend and vehicle_demo.blend from the
physics-2.43-physics-testfiles pack.
Caveats:
- Conversions were checked against other deprecated attributes. I may have missed some cases where a deprecated attribute
has the same name as a non-deprecated attribute. I did catch a few though.
- As with the last version, the conversion is purely text-based and doesn't compile the code. It's easy to create a
script that would break on conversion.
Still, it should get you 90% of the way to a converted script.
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-22 21:38:18 UTC (rev 20348)
+++ trunk/blender/release/scripts/textplugin_convert_ge.py 2009-05-23 03:19:47 UTC (rev 20349)
@@ -24,6 +24,53 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+#
+# This script updates game engine scripts that were designed for pre-2.49
+# versions of Blender to run with the new API. Deprecated function calls are
+# listed in attributeRenameDict. This script searches for instances of the keys
+# in a target script and re-writes them.
+#
+# Some deprecated functions are complicated to re-write. The most common
+# conversions have been implemented, but some have not. Running this will reduce
+# the number of deprecation warnings in your scripts, but may not eliminate them
+# entirely.
+#
+# NOTE: The conversion is not guaranteed to be perfect. It is strongly
+# recommended that you review all changes after running this script.
+#
+# TODO: The following attributes are either ambiguous or need special processing
+# to handle parameters.
+#
+# getLinearVelocity (KX_SCA_AddObjectActuator)
+# Conflicts with KX_GameObject.
+# setLinearVelocity (KX_SCA_AddObjectActuator)
+# Conflicts with KX_GameObject.
+# getAngularVelocity (KX_SCA_AddObjectActuator)
+# Conflicts with KX_GameObject.
+# setAngularVelocity (KX_SCA_AddObjectActuator)
+# Conflicts with KX_GameObject.
+# setAction (BL_ShapeActionActuator, BL_ActionActuator)
+# `reset' argument has no conversion target.
+# set (KX_VisibilityActuator, KX_IpoActuator)
+# Different numbers of arguments.
+# Arguments map to multiple attributes.
+# getIndex (SCA_JoystickSensor)
+# Incompatible values: Old = 1-based index; new = 0-based.
+# getMesh (KX_SCA_ReplaceMeshActuator)
+# Return types differ. Need to call object.name.
+# getObject (KX_SCA_AddObjectActuator, KX_CameraActuator,
+# KX_TrackToActuator, KX_ParentActuator)
+# Default return type differs between classes.
+# setIndex (SCA_JoystickSensor)
+# Incompatible values: Old = 1-based index; new = 0-based.
+# setObject (KX_SCA_AddObjectActuator, KX_CameraActuator,
+# KX_TrackToActuator, KX_ParentActuator)
+# Incompatible types: Old = KX_GameObject or String; new =
+# KX_GameObject.
+# setOperation (KX_SCA_DynamicActuator, KX_StateActuator)
+# Ambiguous: different target names.
+#
+
import string
import re
@@ -36,7 +83,7 @@
"""Finds a balanced pair of parentheses, searching from lines[row][col].
The opening parenthesis must be on the starting line.
- Returns a 4-tuple containing the row and column of the opening paren, and
+ Returns two tuples containing the row and column of the opening paren, and
the row and column of the matching paren.
Throws a ParseError if the first character is not openChar, or if a matching
@@ -163,6 +210,25 @@
lines[row] = replaceSubstr(lines[row], colStart, colEnd, newName + ' = ')
+def replaceArgsWithListSetter(lines, row, colStart, colEnd, newName):
+ """Replace a call to a multi-agument setter function with a reference to a
+ list property, e.g. foo.setBar(baz, bazZ) -> foo.bar = [baz, bazZ]
+
+ The function identifier being replaced must be on line `row' and
+ between `colStart' and `colEnd'. The opening parenthesis must follow
+ immediately (whitespace is allowed). The closing parenthesis may be on the
+ same or following lines.
+
+ Throws a ConversionError if the parentheses can't be found. In this case
+ the content of `lines' will be untouched."""
+ try:
+ replaceNextParens(lines, row, colEnd, newOpenChar = '[', newCloseChar = ']')
+ except ParseError:
+ raise ConversionError, ("Deprecated function reference.")
+
+ lines[row] = replaceSubstr(lines[row], colStart, colEnd, newName + ' = ')
+
+
def replaceKeyedGetter(lines, row, colStart, colEnd, newName):
"""Replace a call to a keyed getter function with a reference to a
property, e.g. foo.getBar(baz) -> foo.bar[baz]
@@ -261,6 +327,10 @@
lines[row] = replaceSubstr(lines[row], gameLogicStart, closeCol + 1, newExpr)
def getObject(line, attributeStart):
+ '''Get the object that an attribute belongs to. `attributeStart' is the
+ index of the first character of the attribute name in the string `line'.
+ Returns: the identifier preceding `attributeStart', or None if one can't be
+ found.'''
match = re.search(r'([a-zA-Z_]\w*)\s*\.\s*$', line[0:attributeStart])
if not match:
return None
@@ -268,7 +338,7 @@
def replaceGetActuator(lines, row, colStart, colEnd, closure):
'''getActuator is ambiguous: it could belong to SCA_IController or
- SCA_ActuatorSensor. Try to resolve.
+ SCA_ActuatorSensor. Try to resolve and then convert.
Raises a ConversionError if the parentheses can't be found, or if the
ambiguity can't be resolved.'''
@@ -284,6 +354,54 @@
raise ConversionError, "Ambiguous: addActiveActuator -> actuators[key] (SCA_IController) or actuator (SCA_ActuatorSensor)."
+def replaceSetOrientation(lines, row, colStart, colEnd, closure):
+ '''setOrientation is ambiguous: it could belong to KX_SoundActuator or
+ KX_GameObject. Try to resolve and then convert. If the type can't be
+ determined, it is assumed to be a KX_GameObject. Currently, only the
+ conversion for KX_GameObject is implemented.
+
+ Raises a ConversionError if the parentheses can't be found, or if the
+ object is found to be a KX_SoundActuator.'''
+ # Get the name of the object this attribute is attached to.
+ obName = getObject(lines[row], colStart)
+ if obName:
+ # Try to find out whether the object is an actuator.
+ assn = findLastAssignment(lines, row, obName)
+ if assn:
+ match = re.search(r'([a-zA-Z_]\w*)' # Controller identifier
+ r'\s*\.\s*' # Dot
+ r'(actuators\s*\[|getActuator\s*\()', # Dictionary/getter identifier
+ assn)
+ if match:
+ # It's probably a KX_SoundActuator.
+ raise ConversionError, "Not implemented: Can't convert arguments to matrix."
+
+ # It's probably a KX_GameObject.
+ replaceSimpleSetter(lines, row, colStart, colEnd, 'localOrientation')
+
+def replaceSetPosition(lines, row, colStart, colEnd, closure):
+ '''setPosition is ambiguous: it could belong to KX_SoundActuator or
+ KX_GameObject. Try to resolve and then convert. If the type can't be
+ determined, it is assumed to be a KX_GameObject.
+
+ Raises a ConversionError if the parentheses can't be found.'''
+ # Get the name of the object this attribute is attached to.
+ obName = getObject(lines[row], colStart)
+ if obName:
+ # Try to find out whether the object is an actuator.
+ assn = findLastAssignment(lines, row, obName)
+ if assn:
+ match = re.search(r'([a-zA-Z_]\w*)' # Controller identifier
+ r'\s*\.\s*' # Dot
+ r'(actuators\s*\[|getActuator\s*\()', # Dictionary/getter identifier
+ assn)
+ if match:
+ # It's probably a KX_SoundActuator.
+ replaceSimpleSetter(lines, row, colStart, colEnd, 'position')
+
+ # It's probably a KX_GameObject.
+ replaceSimpleSetter(lines, row, colStart, colEnd, 'localPosition')
+
#
# Deprecated attribute information. The format is:
# deprecatedAttributeName: {(conversionFunction, closure): classList}
@@ -298,24 +416,31 @@
'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']},
- # Unimplemented! There are probably more of these below that would cause errors.
- #'getLinearVelocity': {(replaceSimpleGetter, 'linearVelocity'): ['KX_SCA_AddObjectActuator']},
- #'setLinearVelocity': {(replaceSimpleSetter, 'linearVelocity'): ['KX_SCA_AddObjectActuator']},
- #'getAngularVelocity': {(replaceSimpleGetter, 'angularVelocity'): ['KX_SCA_AddObjectActuator']},
- #'setAngularVelocity': {(replaceSimpleSetter, 'angularVelocity'): ['KX_SCA_AddObjectActuator']},
+ # Keyed getters/setters
+ 'getSensor': {(replaceKeyedGetter, 'sensors'): ['SCA_IController']},
- # Generic converters
+ # Multi-arg -> List setter
+ 'setAxis': {(replaceArgsWithListSetter, 'axis'): ['SCA_JoystickSensor']},
+ 'setHat': {(replaceArgsWithListSetter, 'hat'): ['SCA_JoystickSensor']},
+ 'setVelocity': {(replaceArgsWithListSetter, 'velocity'): ['KX_SoundActuator']},
+
+ # Straight rename
+ 'getButtonValue': {(replaceRename, 'getButtonActiveList'): ['SCA_JoystickSensor']},
+
+ # 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']},
- 'getActuators': {(replaceKeyedGetter, 'actuators'): ['SCA_IController']},
'getAxis': {(replaceSimpleGetter, 'axis'): ['SCA_JoystickSensor']},
- 'getAxisValue': {(replaceSimpleGetter, 'axisSingle'): ['SCA_JoystickSensor']},
+ 'getAxisValue': {(replaceSimpleGetter, 'axisValues'): ['SCA_JoystickSensor']},
'getBlendin': {(replaceSimpleGetter, 'blendIn'): ['BL_ShapeActionActuator',
- 'BL_ActionActuator']},
+ 'BL_ActionActuator']},
'getBodies': {(replaceSimpleGetter, 'bodies'): ['KX_NetworkMessageSensor']},
'getButton': {(replaceSimpleGetter, 'button'): ['SCA_JoystickSensor']},
- 'getButtonValue': {(replaceRename, 'getButtonActiveList'): ['SCA_JoystickSensor']},
'getCamera': {(replaceSimpleGetter, 'camera'): ['KX_SceneActuator']},
'getConeOrigin': {(replaceSimpleGetter, 'coneOrigin'): ['KX_RadarSensor']},
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list