diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-05-23 07:19:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-05-23 07:19:47 +0400 |
commit | cfa2b4f0a5530e0cdda09d466fff267ad9e7eccc (patch) | |
tree | f42013abc3e6c208f4be1d3f6476852d063673aa | |
parent | 89049782dea9ce6ffc0a9de2cb95db4a448db05d (diff) |
[#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.
-rw-r--r-- | release/scripts/textplugin_convert_ge.py | 286 | ||||
-rw-r--r-- | source/gameengine/PyDoc/GameTypes.py | 52 |
2 files changed, 242 insertions, 96 deletions
diff --git a/release/scripts/textplugin_convert_ge.py b/release/scripts/textplugin_convert_ge.py index 4a472247dcc..043b40252d9 100644 --- a/release/scripts/textplugin_convert_ge.py +++ b/release/scripts/textplugin_convert_ge.py @@ -24,6 +24,53 @@ Tooltip: 'Attemps to update deprecated usage of game engine API.' # 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 @@ def findBalancedParens(lines, row, col, openChar = '(', closeChar = ')'): """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 @@ def replaceSimpleSetter(lines, row, colStart, colEnd, newName): 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 @@ def replaceAddActiveActuator(lines, row, colStart, colEnd, closure): 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 getObject(line, attributeStart): 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 @@ def replaceGetActuator(lines, row, colStart, colEnd, closure): 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 @@ attributeRenameDict = { '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']}, + + # 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']}, - # Generic converters + # 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']}, 'getConeTarget': {(replaceSimpleGetter, 'coneTarget'): ['KX_RadarSensor']}, @@ -325,8 +450,8 @@ attributeRenameDict = { 'getDistribution': {(replaceSimpleGetter, 'distribution'): ['SCA_RandomActuator']}, 'getDuration': {(replaceSimpleGetter, 'duration'): ['SCA_DelaySensor']}, 'getEnd': {(replaceSimpleGetter, 'frameEnd'): ['BL_ShapeActionActuator', - 'KX_IpoActuator', - 'BL_ActionActuator']}, + 'KX_IpoActuator', + 'BL_ActionActuator']}, 'getExecutePriority': {(replaceSimpleGetter, 'executePriority'): ['SCA_ILogicBrick']}, 'getFile': {(replaceSimpleGetter, 'fileName'): ['KX_GameActuator']}, 'getFilename': {(replaceSimpleGetter, 'fileName'): ['KX_SoundActuator']}, @@ -334,21 +459,20 @@ attributeRenameDict = { 'getFrame': {(replaceSimpleGetter, 'frame'): ['BL_ShapeActionActuator', 'BL_ActionActuator']}, 'getFrameMessageCount': {(replaceSimpleGetter, 'frameMessageCount'): ['KX_NetworkMessageSensor']}, 'getFrameProperty': {(replaceSimpleGetter, 'framePropName'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'getFrequency': {(replaceSimpleGetter, 'frequency'): ['SCA_ISensor']}, 'getGain': {(replaceSimpleGetter, 'volume'): ['KX_SoundActuator', 'KX_CDActuator']}, 'getHat': {(replaceSimpleGetter, 'hat'): ['SCA_JoystickSensor']}, 'getHeight': {(replaceSimpleGetter, 'height'): ['KX_CameraActuator']}, 'getHitNormal': {(replaceSimpleGetter, 'hitNormal'): ['KX_MouseFocusSensor', 'KX_RaySensor']}, 'getHitObject': {(replaceSimpleGetter, 'hitObject'): ['KX_MouseFocusSensor', - 'KX_RaySensor', - 'KX_TouchSensor']}, + 'KX_RaySensor', + 'KX_TouchSensor']}, 'getHitObjectList': {(replaceSimpleGetter, 'hitObjectList'): ['KX_TouchSensor']}, 'getHitPosition': {(replaceSimpleGetter, 'hitPosition'): ['KX_MouseFocusSensor', - 'KX_RaySensor']}, + 'KX_RaySensor']}, 'getHold1': {(replaceSimpleGetter, 'hold1'): ['SCA_KeyboardSensor']}, 'getHold2': {(replaceSimpleGetter, 'hold2'): ['SCA_KeyboardSensor']}, - 'getIndex': {(replaceSimpleGetter, 'index'): ['SCA_JoystickSensor']}, 'getInvert': {(replaceSimpleGetter, 'invert'): ['SCA_ISensor']}, 'getIpoAdd': {(replaceSimpleGetter, 'useIpoAdd'): ['KX_IpoActuator']}, 'getIpoAsForce': {(replaceSimpleGetter, 'useIpoAsForce'): ['KX_IpoActuator']}, @@ -359,16 +483,11 @@ attributeRenameDict = { 'getLooping': {(replaceSimpleGetter, 'looping'): ['KX_SoundActuator']}, 'getMass': {(replaceSimpleGetter, 'mass'): ['KX_GameObject']}, 'getMax': {(replaceSimpleGetter, 'max'): ['KX_CameraActuator']}, - 'getMesh': {(replaceSimpleGetter, 'mesh'): ['KX_SCA_ReplaceMeshActuator']}, 'getMin': {(replaceSimpleGetter, 'min'): ['KX_CameraActuator']}, 'getName': {(replaceSimpleGetter, 'name'): ['KX_Scene']}, 'getNumAxes': {(replaceSimpleGetter, 'numAxis'): ['SCA_JoystickSensor']}, 'getNumButtons': {(replaceSimpleGetter, 'numButtons'): ['SCA_JoystickSensor']}, 'getNumHats': {(replaceSimpleGetter, 'numHats'): ['SCA_JoystickSensor']}, - 'getObject': {(replaceSimpleGetter, 'object'): ['KX_SCA_AddObjectActuator', - 'KX_CameraActuator', - 'KX_TrackToActuator', - 'KX_ParentActuator']}, 'getObjectList': {(replaceSimpleGetter, 'objects'): ['KX_Scene']}, 'getOperation': {(replaceSimpleGetter, 'mode'): ['KX_SCA_DynamicActuator']}, 'getOrientation': {(replaceSimpleGetter, 'worldOrientation'): ['KX_GameObject']}, @@ -380,12 +499,13 @@ attributeRenameDict = { 'getPosition': {(replaceSimpleGetter, 'worldPosition'): ['KX_GameObject']}, 'getPressedKeys': {(replaceSimpleGetter, 'events'): ['SCA_KeyboardSensor']}, 'getPriority': {(replaceSimpleGetter, 'priority'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'getProjectionMatrix': {(replaceSimpleGetter, 'projection_matrix'): ['KX_Camera']}, 'getProperty': {(replaceSimpleGetter, 'propName'): ['SCA_PropertySensor', - 'SCA_RandomActuator']}, + 'SCA_RandomActuator', + 'SCA_PropertyActuator']}, 'getRayDirection': {(replaceSimpleGetter, 'rayDirection'): ['KX_MouseFocusSensor', - 'KX_RaySensor']}, + 'KX_RaySensor']}, 'getRaySource': {(replaceSimpleGetter, 'raySource'): ['KX_MouseFocusSensor']}, 'getRayTarget': {(replaceSimpleGetter, 'rayTarget'): ['KX_MouseFocusSensor']}, 'getRepeat': {(replaceSimpleGetter, 'repeat'): ['SCA_DelaySensor']}, @@ -393,11 +513,9 @@ attributeRenameDict = { 'getScene': {(replaceSimpleGetter, 'scene'): ['KX_SceneActuator']}, 'getScript': {(replaceSimpleGetter, 'script'): ['SCA_PythonController']}, 'getSeed': {(replaceSimpleGetter, 'seed'): ['SCA_RandomActuator']}, - 'getSensor': {(replaceKeyedGetter, 'sensors'): ['SCA_IController']}, - 'getSensors': {(replaceKeyedGetter, 'sensors'): ['SCA_IController']}, 'getStart': {(replaceSimpleGetter, 'frameStart'): ['BL_ShapeActionActuator', - 'KX_IpoActuator', - 'BL_ActionActuator']}, + 'KX_IpoActuator', + 'BL_ActionActuator']}, 'getState': {(replaceSimpleGetter, 'state'): ['SCA_IController', 'KX_GameObject']}, 'getSubject': {(replaceSimpleGetter, 'subject'): ['KX_NetworkMessageSensor']}, 'getSubjects': {(replaceSimpleGetter, 'subjects'): ['KX_NetworkMessageSensor']}, @@ -415,14 +533,11 @@ attributeRenameDict = { 'isConnected': {(replaceSimpleGetter, 'connected'): ['SCA_JoystickSensor']}, 'isPositive': {(replaceSimpleGetter, 'positive'): ['SCA_ISensor']}, 'isTriggered': {(replaceSimpleGetter, 'triggered'): ['SCA_ISensor']}, - 'set': {(replaceSimpleSetter, 'visibility'): ['KX_VisibilityActuator']}, - 'setAction': {(replaceSimpleSetter, 'action'): ['BL_ShapeActionActuator', 'BL_ActionActuator']}, 'setActuator': {(replaceSimpleSetter, 'actuator'): ['SCA_ActuatorSensor']}, - 'setAxis': {(replaceSimpleSetter, 'axis'): ['SCA_JoystickSensor']}, 'setBlendin': {(replaceSimpleSetter, 'blendIn'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'setBlendtime': {(replaceSimpleSetter, 'blendTime'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'setBodyType': {(replaceSimpleSetter, 'usePropBody'): ['KX_NetworkMessageActuator']}, 'setButton': {(replaceSimpleSetter, 'button'): ['SCA_JoystickSensor']}, 'setCamera': {(replaceSimpleSetter, 'camera'): ['KX_SceneActuator']}, @@ -430,22 +545,20 @@ attributeRenameDict = { 'setDelay': {(replaceSimpleSetter, 'delay'): ['SCA_DelaySensor']}, 'setDuration': {(replaceSimpleSetter, 'duration'): ['SCA_DelaySensor']}, 'setEnd': {(replaceSimpleSetter, 'frameEnd'): ['BL_ShapeActionActuator', - 'KX_IpoActuator', - 'BL_ActionActuator']}, + 'KX_IpoActuator', + 'BL_ActionActuator']}, 'setExecutePriority': {(replaceSimpleSetter, 'executePriority'): ['SCA_ILogicBrick']}, 'setFile': {(replaceSimpleSetter, 'fileName'): ['KX_GameActuator']}, 'setFilename': {(replaceSimpleSetter, 'fileName'): ['KX_SoundActuator']}, 'setForceIpoActsLocal': {(replaceSimpleSetter, 'useIpoLocal'): ['KX_IpoActuator']}, 'setFrame': {(replaceSimpleSetter, 'frame'): ['BL_ShapeActionActuator', 'BL_ActionActuator']}, 'setFrameProperty': {(replaceSimpleSetter, 'framePropName'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'setFrequency': {(replaceSimpleSetter, 'frequency'): ['SCA_ISensor']}, 'setGain': {(replaceSimpleSetter, 'volume'): ['KX_SoundActuator', 'KX_CDActuator']}, - 'setHat': {(replaceSimpleSetter, 'hat'): ['SCA_JoystickSensor']}, 'setHeight': {(replaceSimpleSetter, 'height'): ['KX_CameraActuator']}, 'setHold1': {(replaceSimpleSetter, 'hold1'): ['SCA_KeyboardSensor']}, 'setHold2': {(replaceSimpleSetter, 'hold2'): ['SCA_KeyboardSensor']}, - 'setIndex': {(replaceSimpleSetter, 'index'): ['SCA_JoystickSensor']}, 'setInvert': {(replaceSimpleSetter, 'invert'): ['SCA_ISensor']}, 'setIpoAdd': {(replaceSimpleSetter, 'useIpoAdd'): ['KX_IpoActuator']}, 'setIpoAsForce': {(replaceSimpleSetter, 'useIpoAsForce'): ['KX_IpoActuator']}, @@ -456,31 +569,22 @@ attributeRenameDict = { 'setMax': {(replaceSimpleSetter, 'max'): ['KX_CameraActuator']}, 'setMesh': {(replaceSimpleSetter, 'mesh'): ['KX_SCA_ReplaceMeshActuator']}, 'setMin': {(replaceSimpleSetter, 'min'): ['KX_CameraActuator']}, - 'setObject': {(replaceSimpleSetter, 'object'): ['KX_SCA_AddObjectActuator', - 'KX_CameraActuator', - 'KX_TrackToActuator', - 'KX_ParentActuator']}, - 'setOperation': {(replaceSimpleSetter, 'mode'): ['KX_SCA_DynamicActuator'], - (replaceSimpleSetter, 'operation'): ['KX_StateActuator']}, - 'setOrientation': {(replaceSimpleSetter, 'localOrientation'): ['KX_GameObject'], - (replaceSimpleSetter, 'orientation'): ['KX_SoundActuator']}, 'setPitch': {(replaceSimpleSetter, 'pitch'): ['KX_SoundActuator']}, - 'setPosition': {(replaceSimpleSetter, 'localPosition'): ['KX_GameObject'], - (replaceSimpleSetter, 'position'): ['KX_SoundActuator']}, 'setPriority': {(replaceSimpleSetter, 'priority'): ['BL_ShapeActionActuator', - 'BL_ActionActuator']}, + 'BL_ActionActuator']}, 'setProjectionMatrix': {(replaceSimpleSetter, 'projection_matrix'): ['KX_Camera']}, 'setProperty': {(replaceSimpleSetter, 'propName'): ['KX_IpoActuator', - 'SCA_PropertySensor', - 'SCA_RandomActuator']}, + 'SCA_PropertySensor', + 'SCA_RandomActuator', + 'SCA_PropertyActuator']}, 'setRepeat': {(replaceSimpleSetter, 'repeat'): ['SCA_DelaySensor']}, 'setRollOffFactor': {(replaceSimpleSetter, 'rollOffFactor'): ['KX_SoundActuator']}, 'setScene': {(replaceSimpleSetter, 'scene'): ['KX_SceneActuator']}, 'setScript': {(replaceSimpleSetter, 'script'): ['SCA_PythonController']}, 'setSeed': {(replaceSimpleSetter, 'seed'): ['SCA_RandomActuator']}, 'setStart': {(replaceSimpleSetter, 'frameStart'): ['BL_ShapeActionActuator', - 'KX_IpoActuator', - 'BL_ActionActuator']}, + 'KX_IpoActuator', + 'BL_ActionActuator']}, 'setState': {(replaceSimpleSetter, 'state'): ['KX_GameObject']}, 'setSubject': {(replaceSimpleSetter, 'subject'): ['KX_NetworkMessageActuator']}, 'setSubjectFilterText': {(replaceSimpleSetter, 'subject'): ['KX_NetworkMessageSensor']}, @@ -493,8 +597,28 @@ attributeRenameDict = { 'setUsePosPulseMode': {(replaceSimpleSetter, 'usePosPulseMode'): ['SCA_ISensor']}, 'setUseRestart': {(replaceSimpleSetter, 'useRestart'): ['KX_SceneActuator']}, 'setValue': {(replaceSimpleSetter, 'value'): ['SCA_PropertySensor', 'SCA_PropertyActuator']}, - 'setVelocity': {(replaceSimpleSetter, 'velocity'): ['KX_SoundActuator']}, 'setXY': {(replaceSimpleSetter, 'useXY'): ['KX_CameraActuator']} + + # Unimplemented! + #'getLinearVelocity': {(replaceSimpleGetter, 'linearVelocity'): ['KX_SCA_AddObjectActuator']}, + #'setLinearVelocity': {(replaceSimpleSetter, 'linearVelocity'): ['KX_SCA_AddObjectActuator']}, + #'getAngularVelocity': {(replaceSimpleGetter, 'angularVelocity'): ['KX_SCA_AddObjectActuator']}, + #'setAngularVelocity': {(replaceSimpleSetter, 'angularVelocity'): ['KX_SCA_AddObjectActuator']}, + #'setAction': {(replaceSimpleSetter, 'action'): ['BL_ShapeActionActuator', 'BL_ActionActuator']}, + #'set': {(replaceSimpleSetter, 'visibility'): ['KX_VisibilityActuator']}, + #'getIndex': {(replaceSimpleGetter, 'index'): ['SCA_JoystickSensor']}, + #'getMesh': {(replaceSimpleGetter, 'mesh'): ['KX_SCA_ReplaceMeshActuator']}, + #'getObject': {(replaceSimpleGetter, 'object'): ['KX_SCA_AddObjectActuator', + # 'KX_CameraActuator', + # 'KX_TrackToActuator', + # 'KX_ParentActuator']}, + #'setIndex': {(replaceSimpleSetter, 'index'): ['SCA_JoystickSensor']}, + #'setObject': {(replaceSimpleSetter, 'object'): ['KX_SCA_AddObjectActuator', + # 'KX_CameraActuator', + # 'KX_TrackToActuator', + # 'KX_ParentActuator']}, + #'setOperation': {(replaceSimpleSetter, 'mode'): ['KX_SCA_DynamicActuator'], + # (replaceSimpleSetter, 'operation'): ['KX_StateActuator']}, } def convert248to249(lines, log = True, logErrors = True): @@ -629,26 +753,41 @@ def runAsTextPlugin(): from Blender import Window, sys, Draw import BPyTextPlugin, bpy - # Gets the active text object, there can be many in one blend file. - txt = bpy.data.texts.active - - # Silently return if the script has been run with no active text - if not txt: - return + message = ("Convert Game Engine script from 4.48 API to 2.49 API%t|" + "Run on active script only%x1|" + "Run on ALL text buffers%x2") + convertAllBuffers = Draw.PupMenu(message) == 2 Window.WaitCursor(1) try: - lines = txt.asLines() - for i in range(0, len(lines)): - if not lines[i].endswith('\n'): - lines[i] = lines[i] + '\n' + nconverted = 0 + nerrors = 0 - nconverted, nerrors = convert248to249(lines) + if convertAllBuffers: + texts = bpy.data.texts + else: + if not bpy.data.texts.active: + Draw.PupMenu("No active buffer.") + return + texts = [bpy.data.texts.active] - Blender.SaveUndoState('Convert GE 249') - txt.clear() - for line in lines: - txt.write(line) + Blender.SaveUndoState('Convert BGE 2.49') + + for txt in texts: + lines = txt.asLines() + for i in range(0, len(lines)): + if not lines[i].endswith('\n'): + lines[i] = lines[i] + '\n' + + nc, ne = convert248to249(lines) + nconverted = nconverted + nc + nerrors = nerrors + ne + txt.clear() + for line in lines: + txt.write(line) + + finally: + Window.WaitCursor(0) message = "Converted %d attributes." % nconverted if nerrors == 1: @@ -657,9 +796,6 @@ def runAsTextPlugin(): message = message + " There were %d errors (see console)." % nerrors message = message + "|Please review all the changes." Draw.PupMenu(message) - - finally: - Window.WaitCursor(0) def main(): try: diff --git a/source/gameengine/PyDoc/GameTypes.py b/source/gameengine/PyDoc/GameTypes.py index 3f9b627247f..a7ad29d5cfa 100644 --- a/source/gameengine/PyDoc/GameTypes.py +++ b/source/gameengine/PyDoc/GameTypes.py @@ -2561,6 +2561,7 @@ class KX_NetworkMessageActuator(SCA_IActuator): @ivar usePropBody: Send a property instead of a regular body message. @type usePropBody: boolean """ +#{Deprecated def setToPropName(name): """ Messages will only be sent to objects with the given property name. @@ -2592,6 +2593,7 @@ class KX_NetworkMessageActuator(SCA_IActuator): @param body: if the body type is True, this is the name of the property to send. if the body type is False, this is the text to send. """ +#} class KX_NetworkMessageSensor(SCA_ISensor): """ @@ -2609,8 +2611,7 @@ class KX_NetworkMessageSensor(SCA_ISensor): @ivar bodies: The list of message bodies received. (Read-only) @type bodies: list of strings """ - - +#{ Deprecated def setSubjectFilterText(subject): """ Change the message subject text that this sensor is listening to. @@ -2648,6 +2649,7 @@ class KX_NetworkMessageSensor(SCA_ISensor): @deprecated: Use the L{subjects} attribute instead. @rtype: list """ +#} class KX_ObjectActuator(SCA_IActuator): """ @@ -3431,8 +3433,7 @@ class KX_RadarSensor(KX_NearSensor): KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z, KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z """ - - +#{Deprecated #--The following methods are deprecated, please use properties instead. def getConeOrigin(): """ @@ -3450,6 +3451,7 @@ class KX_RadarSensor(KX_NearSensor): @deprecated: Use the L{coneTarget} property. @rtype: list [x, y, z] """ +#} def getConeHeight(): """ @@ -3521,7 +3523,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): @type object: KX_GameObject or None @ivar objectLastCreated: the last added object from this actuator (read-only). @type objectLastCreated: KX_GameObject or None - @ivar time: the lifetime of added objects, in frames. + @ivar time: the lifetime of added objects, in frames. Set to 0 to disable automatic deletion. @type time: integer @ivar linearVelocity: the initial linear velocity of added objects. @type linearVelocity: list [vx, vy, vz] @@ -3535,6 +3537,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): C{ERROR: GameObject I{OBName} has a AddObjectActuator I{ActuatorName} without object (in 'nonactive' layer)} """ +#{Deprecated def setObject(object): """ Sets the game object to add. @@ -3622,6 +3625,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): @rtype: L{KX_GameObject} @return: A L{KX_GameObject} or None if no object has been created. """ +#} def instantAddObject(): """ Returns the last object created by this actuator. The object can then be accessed from L{objectLastCreated}. @@ -3920,32 +3924,31 @@ class KX_SoundActuator(SCA_IActuator): the actuator to be activated - they act instantly provided that the actuator has been activated once at least. - @ivar fileName: Sets the filename of the sound this actuator plays. + @ivar fileName: The filename of the sound this actuator plays. @type fileName: string - @ivar volume: Sets the volume (gain) of the sound. + @ivar volume: The volume (gain) of the sound. @type volume: float - @ivar pitch: Sets the pitch of the sound. + @ivar pitch: The pitch of the sound. @type pitch: float - @ivar rollOffFactor: Sets the roll off factor. Rolloff defines the rate of attenuation as the sound gets further away. + @ivar rollOffFactor: The roll off factor. Rolloff defines the rate of attenuation as the sound gets further away. @type rollOffFactor: float - @ivar looping: Sets the loop mode of the actuator. + @ivar looping: The loop mode of the actuator. @type looping: integer - @ivar position: Sets the position of the sound. + @ivar position: The position of the sound as a list: [x, y, z]. @type position: float array - @ivar velocity: Sets the speed of the sound; The speed of the sound alter the pitch. + @ivar velocity: The velocity of the emitter as a list: [x, y, z]. The relative velocity to the observer determines the pitch. List of 3 floats: [x, y, z]. @type velocity: float array - @ivar orientation: Sets the orientation of the sound. When setting the orientation you can - also use quaternion [float,float,float,float] or euler angles [float,float,float] + @ivar orientation: The orientation of the sound. When setting the orientation you can also use quaternion [float,float,float,float] or euler angles [float,float,float] @type orientation: 3x3 matrix [[float]] - @ivar mode: Sets the operation mode of the actuator. You can use one of the following constant: + @ivar mode: The operation mode of the actuator. You can use one of the following constants: - KX_SOUNDACT_PLAYSTOP (1) - KX_SOUNDACT_PLAYEND (2) - KX_SOUNDACT_LOOPSTOP (3) @@ -4057,7 +4060,7 @@ class KX_SoundActuator(SCA_IActuator): """ Sets the position this sound will come from. - @deprecated: Use the L{localPosition} attribute instead. + @deprecated: Use the L{position} attribute instead. @type x: float @param x: The x coordinate of the sound. @type y: float @@ -4605,6 +4608,7 @@ class SCA_ActuatorSensor(SCA_ISensor): @ivar actuator: the name of the actuator that the sensor is monitoring. @type actuator: string """ +#{Deprecated def getActuator(): """ Return the Actuator with which the sensor operates. @@ -4621,6 +4625,7 @@ class SCA_ActuatorSensor(SCA_ISensor): @param name: actuator name @type name: string """ +#} class SCA_AlwaysSensor(SCA_ISensor): """ @@ -4649,6 +4654,7 @@ class SCA_DelaySensor(SCA_ISensor): @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once. @type repeat: integer """ +#{Deprecated def setDelay(delay): """ Set the initial delay before the positive trigger. @@ -4695,6 +4701,7 @@ class SCA_DelaySensor(SCA_ISensor): @deprecated: Use the L{repeat} attribute instead. @rtype: KX_TRUE or KX_FALSE """ +#} class SCA_JoystickSensor(SCA_ISensor): """ @@ -4748,6 +4755,7 @@ class SCA_JoystickSensor(SCA_ISensor): @type buttonIndex: integer @rtype: bool """ +#{Deprecated def getIndex(): """ Returns the joystick index to use (from 1 to 8). @@ -4786,7 +4794,7 @@ class SCA_JoystickSensor(SCA_ISensor): """ Returns the state of the joysticks axis. See differs to L{getAxis()<SCA_JoystickSensor.getAxis>} returning the current state of the joystick. - @deprecated: Use the L{axisSingle} attribute instead. + @deprecated: Use the L{axisValues} attribute instead. @rtype: list @return: 4 values, each spesifying the value of an axis between -32767 and 32767 depending on how far the axis is pushed, 0 for nothing. @@ -4876,6 +4884,7 @@ class SCA_JoystickSensor(SCA_ISensor): @deprecated: Use the L{connected} attribute instead. @rtype: bool """ +#} class SCA_KeyboardSensor(SCA_ISensor): """ @@ -4917,7 +4926,7 @@ class SCA_KeyboardSensor(SCA_ISensor): @param keycode: The code that represents the key you want to get the state of """ - #--The following methods are DEPRECATED-- +#{Deprecated def getKey(): """ Returns the key code this sensor is looking for. @@ -4981,6 +4990,7 @@ class SCA_KeyboardSensor(SCA_ISensor): @deprecated: Use the L{events} attribute instead. @rtype: list of key status. [[keycode, status]] """ +#} class SCA_NANDController(SCA_IController): """ @@ -5023,7 +5033,7 @@ class SCA_PropertyActuator(SCA_IActuator): If there is no property of this name, the call is ignored. - @deprecated: Use the L{property} attribute instead. + @deprecated: Use the L{propName} attribute instead. @type prop: string @param prop: The name of the property to set. """ @@ -5031,7 +5041,7 @@ class SCA_PropertyActuator(SCA_IActuator): """ Returns the name of the property on which to operate. - @deprecated: Use the L{property} attribute instead. + @deprecated: Use the L{propName} attribute instead. @rtype: string """ def setValue(value): @@ -5132,7 +5142,7 @@ class SCA_PythonController(SCA_IController): Properties: @ivar script: the Python script this controller executes - @type script: string, read-only + @type script: string @group Deprecated: getScript, setScript """ |