BGE: Added getActionName() function to KX_GameObject()

It works similar to getActionFrame(), you have to give a layer or not (for layer 0) as the argument and it returns the name of the animation that the object is currently playing.

Example:

```
import bge
own = bge.logic.getCurrentController().owner
own.playAction("SomeAction",0,20)
print(own.getActionName())
```
>> SomeAction

Here is an example file, just open the blend file with the terminal opened
and press P, you can see how the current animation is being printed:
{F217484}

Reviewers: moguri, hg1, panzergame, campbellbarton

Reviewed By: panzergame

Subscribers: campbellbarton, hg1, #game_engine

Projects: #game_engine

Differential Revision: https://developer.blender.org/D1443
This commit is contained in:
Mateo de Mayo 2015-08-03 23:47:46 +02:00 committed by Porteries Tristan
parent 73522e1157
commit 23f54076db
7 changed files with 65 additions and 4 deletions

@ -972,6 +972,16 @@ base class --- :class:`SCA_IObject`
:return: The current frame of the action
:rtype: float
.. method:: getActionName(layer=0)
Gets the name of the current action playing in the supplied layer.
:arg layer: The layer that you want to get the action name from.
:type layer: integer
:return: The name of the current action
:rtype: string
.. method:: setActionFrame(frame, layer=0)
Set the current frame of the action playing in the supplied layer.

@ -301,6 +301,18 @@ float BL_Action::GetFrame()
return m_localtime;
}
const char *BL_Action::GetName()
{
if (m_action != NULL) {
return m_action->id.name + 2;
}
else {
return "";
}
}
void BL_Action::SetFrame(float frame)
{
// Clamp the frame to the start and end frame

@ -112,6 +112,8 @@ public:
// Accessors
float GetFrame();
const char *GetName();
struct bAction *GetAction();
// Mutators

@ -68,6 +68,12 @@ float BL_ActionManager::GetActionFrame(short layer)
return action ? action->GetFrame() : 0.f;
}
const char *BL_ActionManager::GetActionName(short layer)
{
BL_Action *action = GetAction(layer);
return action ? action->GetName() : "";
}
void BL_ActionManager::SetActionFrame(short layer, float frame)
{
BL_Action *action = GetAction(layer);

@ -84,6 +84,11 @@ public:
*/
float GetActionFrame(short layer);
/**
* Gets the name of the current action
*/
const char *GetActionName(short layer);
/**
* Sets the current frame of an action
*/

@ -494,6 +494,11 @@ float KX_GameObject::GetActionFrame(short layer)
return GetActionManager()->GetActionFrame(layer);
}
const char *KX_GameObject::GetActionName(short layer)
{
return GetActionManager()->GetActionName(layer);
}
void KX_GameObject::SetActionFrame(short layer, float frame)
{
GetActionManager()->SetActionFrame(layer, frame);
@ -1957,6 +1962,7 @@ PyMethodDef KX_GameObject::Methods[] = {
KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction),
KX_PYMETHODTABLE(KX_GameObject, stopAction),
KX_PYMETHODTABLE(KX_GameObject, getActionFrame),
KX_PYMETHODTABLE(KX_GameObject, getActionName),
KX_PYMETHODTABLE(KX_GameObject, setActionFrame),
KX_PYMETHODTABLE(KX_GameObject, isPlayingAction),
@ -3947,6 +3953,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame,
return PyFloat_FromDouble(GetActionFrame(layer));
}
KX_PYMETHODDEF_DOC(KX_GameObject, getActionName,
"getActionName(layer=0)\n"
"Gets the name of the current action playing in the supplied layer\n")
{
short layer = 0;
if (!PyArg_ParseTuple(args, "|h:getActionName", &layer))
return NULL;
layer_check(layer, "getActionName");
return PyUnicode_FromString(GetActionName(layer));
}
KX_PYMETHODDEF_DOC(KX_GameObject, setActionFrame,
"setActionFrame(frame, layer=0)\n"
"Set the current frame of the action playing in the supplied layer\n")

@ -276,6 +276,11 @@ public:
*/
float GetActionFrame(short layer);
/**
* Gets the name of the current action
*/
const char *GetActionName(short layer);
/**
* Sets the current frame of an action
*/
@ -1037,6 +1042,7 @@ public:
KX_PYMETHOD_DOC(KX_GameObject, playAction);
KX_PYMETHOD_DOC(KX_GameObject, stopAction);
KX_PYMETHOD_DOC(KX_GameObject, getActionFrame);
KX_PYMETHOD_DOC(KX_GameObject, getActionName);
KX_PYMETHOD_DOC(KX_GameObject, setActionFrame);
KX_PYMETHOD_DOC(KX_GameObject, isPlayingAction);