- dsdehacked: allow dynamic creation of new states.

This commit is contained in:
Christoph Oelckers 2021-09-12 21:04:40 +02:00
commit b44741b8aa
6 changed files with 85 additions and 23 deletions

View file

@ -346,6 +346,13 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState
arc.w->Uint((uint32_t)(state - info->GetStates()));
arc.w->EndArray();
}
else if (state->DehIndex >= 0)
{
arc.w->StartArray();
arc.w->String("@DehExtraState@");
arc.w->Uint(state->DehIndex);
arc.w->EndArray();
}
else
{
arc.w->Null();
@ -373,11 +380,18 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState
assert(cls.IsString() && ndx.IsUint());
if (cls.IsString() && ndx.IsUint())
{
PClassActor *clas = PClass::FindActor(UnicodeToString(cls.GetString()));
auto str = UnicodeToString(cls.GetString());
PClassActor *clas = PClass::FindActor(str);
if (clas && ndx.GetUint() < (unsigned)clas->GetStateCount())
{
state = clas->GetStates() + ndx.GetUint();
}
else if (!strcmp(str, "@DehExtraState@"))
{
state = nullptr;
auto pState = dehExtStates.CheckKey(ndx.GetInt());
if (pState) state = *pState;
}
else
{
// this can actually happen by changing the DECORATE so treat it as a warning, not an error.