mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-24 21:11:52 +00:00
Exposed FindStateByString() to ZScript.
This allows for using ZScript code to jump to different versions of states without using If/Else blocks or Switch cases.
This commit is contained in:
parent
c8a7507e8e
commit
e1f585f6fd
2 changed files with 12 additions and 2 deletions
|
@ -387,7 +387,7 @@ FState *FStateLabelStorage::GetState(int pos, PClassActor *cls, bool exact)
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// State label conversion function for scripts
|
||||
// State label conversion functions for scripts
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
|
@ -395,7 +395,7 @@ DEFINE_ACTION_FUNCTION(AActor, FindState)
|
|||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
PARAM_INT(newstate);
|
||||
PARAM_BOOL(exact)
|
||||
PARAM_BOOL(exact);
|
||||
ACTION_RETURN_STATE(StateLabels.GetState(newstate, self->GetClass(), exact));
|
||||
}
|
||||
|
||||
|
@ -407,6 +407,15 @@ DEFINE_ACTION_FUNCTION(AActor, ResolveState)
|
|||
ACTION_RETURN_STATE(newstate);
|
||||
}
|
||||
|
||||
// find state by string instead of label
|
||||
DEFINE_ACTION_FUNCTION(AActor, FindStateByString)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
PARAM_STRING(newstate);
|
||||
PARAM_BOOL(exact);
|
||||
ACTION_RETURN_STATE(self->GetClass()->FindStateByString(newstate.GetChars(), exact));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Search one list of state definitions for the given name
|
||||
|
|
|
@ -798,6 +798,7 @@ class Actor : Thinker native
|
|||
native bool CheckMissileRange();
|
||||
native bool SetState(state st, bool nofunction = false);
|
||||
clearscope native state FindState(statelabel st, bool exact = false) const;
|
||||
clearscope native state FindStateByString(string st, bool exact = false) const;
|
||||
bool SetStateLabel(statelabel st, bool nofunction = false) { return SetState(FindState(st), nofunction); }
|
||||
native action state ResolveState(statelabel st); // this one, unlike FindState, is context aware.
|
||||
native void LinkToWorld(LinkContext ctx = null);
|
||||
|
|
Loading…
Reference in a new issue