Exemple #1
0
        public UnrealBuiltInTypeReference(TypeReferenceRaw typeReference)
        {
            if (UnrealTypeMappings.UnsupportedSchemaTypes.Contains(typeReference.TypeName))
            {
                throw new ArgumentException(string.Format("Schema type '{0}' is currently not supported in Unreal.", typeReference.TypeName));
            }

            ReferenceType = ReferenceType.BuiltIn;
            if (UnrealTypeMappings.builtInTypeToRequiredInclude.ContainsKey(typeReference.TypeName))
            {
                RequiredIncludes = UnrealTypeMappings.builtInTypeToRequiredInclude[typeReference.TypeName];
            }
            else
            {
                RequiredIncludes = new List <string>();
            }

            UnderlyingQualifiedName   = UnrealTypeMappings.builtInSchemaTypeToCppType[typeReference.TypeName];
            UnderlyingCapitalisedName = Formatting.CppQualifiedNameToCapitalisedCamelCase(UnderlyingQualifiedName);

            UnrealType = UnrealTypeMappings.cppTypeToUnrealType[UnderlyingQualifiedName];

            ConvertUnderlyingValueToUnrealMemberVariable = GenerateCppValueToUnrealValueString;
            AssignUnderlyingValueToUnrealMemberVariable  = (capitalizedName, cppValue) => { return(string.Format("{0} = {1}", capitalizedName, GenerateCppValueToUnrealValueString(cppValue))); };

            CheckInequality = (capitalizedName, compName) =>
            {
                switch (typeReference.TypeName)
                {
                case BuiltInTypeConstants.builtInFloat:
                    return(string.Format("!FMath::IsNearlyEqual({0},{1},(float)KINDA_SMALL_NUMBER)", capitalizedName, compName));

                case BuiltInTypeConstants.builtInCoordinates:
                case BuiltInTypeConstants.builtInVector3d:
                case BuiltInTypeConstants.builtInVector3f:
                    return(string.Format("!{0}.Equals({1})", capitalizedName, compName));

                default:
                    return(string.Format("{0} != {1}", capitalizedName, compName));
                }
            };
            ConvertUnrealValueToSnapshotValue           = (VarName) => { return(string.Format("{0}", VarName)); };
            ConvertUnderlyingValueToUnrealLocalVariable = ConvertUnderlyingValueToUnrealMemberVariable;
            ConvertUnrealValueToUnderlyingValue         = GenerateUnrealValueToCppValueString;

            DefaultInitialisationString = UnrealTypeMappings.BuiltInSchemaTypeToCppDefaultValue[typeReference.TypeName];
            ArgumentName = UnrealTypeMappings.CppTypesToPassByReference.Contains(UnderlyingQualifiedName) ? string.Format("const {0}&", UnrealType) : UnrealType;
            SnapshotType = UnrealType;
            UClassName   = "";
            DefaultValue = UnrealTypeMappings.CppTypeToDefaultUnrealValue[UnderlyingQualifiedName];
        }
        public UnrealUserTypeReference(UnrealTypeDetails unrealType)
        {
            ReferenceType             = ReferenceType.UserType;
            UnderlyingQualifiedName   = unrealType.UnderlyingQualifiedName;
            UnderlyingCapitalisedName = Formatting.CppQualifiedNameToCapitalisedCamelCase(UnderlyingQualifiedName);
            UnrealType       = string.Format("U{0}*", unrealType.CapitalisedName);
            CapitalisedName  = string.Format("{0}", unrealType.CapitalisedName);
            RequiredIncludes = new List <string>();
            RequiredIncludes.Add(string.Format("\"{0}.h\"", unrealType.CapitalisedName));
            ConvertUnderlyingValueToUnrealMemberVariable = (cppValue) =>
            {
                // Set owning object as new uobject's outer.
                return(string.Format("NewObject<U{0}>(this)->Init({1})", unrealType.CapitalisedName, cppValue));
            };
            AssignUnderlyingValueToUnrealMemberVariable = (capitalizedName, cppValue) =>
            {
                return(string.Format(@"if ({0} == nullptr) {{ {0} = NewObject<U{1}>(this); }} {0}->Init({2})",
                                     capitalizedName,
                                     unrealType.CapitalisedName,
                                     cppValue));
            };
            CheckInequality = (capitalizedName, compName) => { return(string.Format("{0} && ({0}->GetUnderlying() != {1})", capitalizedName, compName)); };
            ConvertUnderlyingValueToUnrealLocalVariable = (cppValue) =>
            {
                // Set static instance package as the uobject's outer.
                return(string.Format("NewObject<U{0}>()->Init({1})", unrealType.CapitalisedName, cppValue));
            };
            ConvertUnrealValueToSnapshotValue   = (VarName) => { return(string.Format("{0}->GetUnderlying()", VarName)); };
            ConvertUnrealValueToUnderlyingValue = (unrealValue) => { return(string.Format("{0}->GetUnderlying()", unrealValue)); };

            ArgumentName = UnrealType;
            SnapshotType = unrealType.UnderlyingQualifiedName;
            UClassName   = string.Format("U{0}", unrealType.CapitalisedName);
            TypeDetails  = unrealType;
            DefaultValue = "nullptr";
        }
        public UnrealEnumTypeReference(UnrealEnumDetails unrealEnum)
        {
            ReferenceType = ReferenceType.Enum;

            UnderlyingQualifiedName   = unrealEnum.UnderlyingQualifiedName;
            UnderlyingCapitalisedName = Formatting.CppQualifiedNameToCapitalisedCamelCase(UnderlyingQualifiedName);
            UnrealType       = string.Format("E{0}", unrealEnum.CapitalisedName);
            RequiredIncludes = new List <string>();
            RequiredIncludes.Add(string.Format("\"{0}.h\"", unrealEnum.CapitalisedName));
            ConvertUnderlyingValueToUnrealMemberVariable = (cppValue) =>
            {
                // Set owning object as new uobject's outer.
                return(string.Format("static_cast<E{0}>({1})", unrealEnum.CapitalisedName, cppValue));
            };
            AssignUnderlyingValueToUnrealMemberVariable = (capitalizedName, cppValue) =>
            {
                // Set owning object as new uobject's outer.
                return(string.Format("{0} = static_cast<E{1}>({2})", capitalizedName, unrealEnum.CapitalisedName, cppValue));
            };
            CheckInequality = (capitalizedName, compName) => { return(string.Format("{0} != {1}", capitalizedName, compName)); };
            ConvertUnderlyingValueToUnrealLocalVariable = (cppValue) =>
            {
                // Set static instance package as the uobject's outer.
                return(string.Format("static_cast<E{0}>({1})", unrealEnum.CapitalisedName, cppValue));
            };
            ConvertUnrealValueToSnapshotValue = (VarName) => { return(string.Format("{0}", VarName)); };
            var underlyingQualifiedName = UnderlyingQualifiedName;

            ConvertUnrealValueToUnderlyingValue = (unrealValue) => { return(string.Format("static_cast<{0}>({1})", underlyingQualifiedName, unrealValue)); };

            DefaultInitialisationString = string.Format("static_cast<{0}>(0)", UnderlyingQualifiedName);
            ArgumentName = UnrealType;
            SnapshotType = UnrealType;
            UClassName   = "";
            DefaultValue = string.Format("static_cast<{0}>(0)", UnrealType);
        }