From 65b7e344f7b9bdc054e0a910a8d3ddb19762dd72 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 16 Jan 2017 10:36:23 +0100 Subject: [PATCH] - added custom property parsing to DECORATE as well. --- src/scripting/decorate/thingdef_parse.cpp | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index f53b97006..2eee0f01d 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -819,6 +819,63 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau return true; } +//========================================================================== +// +// Parses an actor property's parameters and calls the handler +// +//========================================================================== + +static void DispatchScriptProperty(FScanner &sc, PProperty *prop, AActor *defaults, Baggage &bag) +{ + for (unsigned i=0; iVariables.Size();i++) + { + auto f = prop->Variables[i]; + void *addr; + + if (i > 0) sc.MustGetStringName(","); + if (f->Flags & VARF_Meta) + { + addr = ((char*)bag.Info) + f->Offset; + } + else + { + addr = ((char*)defaults) + f->Offset; + } + + if (f->Type->IsKindOf(RUNTIME_CLASS(PInt))) + { + sc.MustGetNumber(); + static_cast(f->Type)->SetValue(addr, sc.Number); + } + else if (f->Type->IsKindOf(RUNTIME_CLASS(PFloat))) + { + sc.MustGetFloat(); + static_cast(f->Type)->SetValue(addr, sc.Float); + } + else if (f->Type->IsKindOf(RUNTIME_CLASS(PString))) + { + sc.MustGetString(); + *(FString*)addr = sc.String; + } + else if (f->Type->IsKindOf(RUNTIME_CLASS(PClassPointer))) + { + sc.MustGetString(); + auto cls = PClass::FindClass(sc.String); + *(PClass**)addr = cls; + if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) + { + sc.ScriptMessage("class %s is not compatible with property type %s", cls->TypeName.GetChars(), static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); + FScriptPosition::ErrorCounter++; + } + } + else + { + sc.ScriptMessage("unhandled property type %s", f->Type->DescriptiveName()); + FScriptPosition::ErrorCounter++; + } + } +} + //========================================================================== // // Parses an actor property @@ -867,6 +924,17 @@ static void ParseActorProperty(FScanner &sc, Baggage &bag) } else { + propname.Insert(0, "@property@"); + FName name(propname, true); + if (name != NAME_None) + { + auto propp = dyn_cast(bag.Info->Symbols.FindSymbol(name, true)); + if (propp != nullptr) + { + DispatchScriptProperty(sc, propp, (AActor *)bag.Info->Defaults, bag); + return; + } + } sc.ScriptError("'%s' is an unknown actor property\n", propname.GetChars()); } }