diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene b/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene new file mode 100644 index 0000000..f5bc763 --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene @@ -0,0 +1,179 @@ +{ + Version = 1, + Entities = [ + { + Id = 8893155135649576304, + NameComponent = { + Name = "Camera" + }, + TransformComponent = { + Position = { + X = 0, + Y = 2, + Z = -5 + }, + Rotation = { + X = 0, + Y = 0.21643962, + Z = 0, + W = 0.976296 + }, + Scale = { + X = 1, + Y = 1, + Z = 1 + }, + EditorEulerRotation = { + X = 0, + Y = 0.43633237, + Z = 0 + } + }, + CameraComponent = { + Primary = true, + ProjectionType = .InfinitePerspective, + PerspectiveFovY = 1.3089969, + PerspectiveNearPlane = 0.1, + PerspectiveFarPlane = 10000, + OrthographicHeight = 10, + OrthographicNearPlane = 0, + OrthographicFarPlane = 10, + AspectRatio = 1.9840086, + FixedAspectRatio = false + }, + Editor = { + Flags = .Default + } + }, + { + Id = 14812165297099037146, + NameComponent = { + Name = "Light" + }, + TransformComponent = { + Position = { + X = -3, + Y = 4, + Z = -1.5 + }, + Rotation = { + X = 0.23977584, + Y = 0.6143275, + Z = 0.031567074, + W = 0.7510744 + }, + Scale = { + X = 1, + Y = 1, + Z = 1 + }, + EditorEulerRotation = { + X = 0.3490659, + Y = 1.3089968, + Z = 0.34906587 + } + }, + LightComponent = { + LightType = .Directional, + Illuminance = 10, + Color = { + R = 1, + G = 0.9500002, + B = 0.8 + } + }, + Editor = { + Flags = .Default + } + }, + { + Id = 4185051642788402424, + NameComponent = { + Name = "Entity" + }, + TransformComponent = { + Position = { + X = 0, + Y = 0, + Z = 0 + }, + Rotation = { + X = 0, + Y = 0, + Z = 0, + W = 1 + }, + Scale = { + X = 1, + Y = 1, + Z = 1 + }, + EditorEulerRotation = { + X = 0, + Y = 0, + Z = 0 + } + }, + ScriptComponent = { + ScriptClass = "TestProject.Assets.Scripts.AdvancedSerializationTest", + Fields = (TestProject.Assets.Scripts.AdvancedSerializationTest){ + ID = 4185051642788402424, + LeTuple.Item1 = (int32)101, + LeTuple.Item2.X = (float)49, + LeTuple.Item2.Y = (float)31, + LeTuple.Item3 = &16946239429800937368, + LeListDeTuple = &13357518334354818316, + GenericStructField.MyField = (float)-56, + GenericClassField = &6770493598825812026 + } + }, + Editor = { + Flags = .Default + } + } + ], + ReferencedObjects = [ + (TestProject.BClass){ + ID = 16946239429800937368, + F = (float)131 + }, + (System.Collections.Generic.List`1[System.ValueTuple`3[System.Int32,GlitchyEngine.Math.float2,TestProject.BClass]]){ + ID = 13357518334354818316, + Count = (int32)4, + 0.Item1 = (int32)64, + 0.Item2.X = (float)-81, + 0.Item2.Y = (float)-118, + 0.Item3 = &14597969159961685574, + 1.Item1 = (int32)0, + 1.Item2.X = (float)0, + 1.Item2.Y = (float)0, + 1.Item3 = &0, + 2.Item1 = (int32)73, + 2.Item2.X = (float)165, + 2.Item2.Y = (float)115, + 2.Item3 = &15752578204681304901, + 3.Item1 = (int32)0, + 3.Item2.X = (float)0, + 3.Item2.Y = (float)0, + 3.Item3 = &0 + }, + (TestProject.BClass){ + ID = 14597969159961685574, + F = (float)23 + }, + (TestProject.BClass){ + ID = 15752578204681304901, + F = (float)159 + }, + (TestProject.Assets.Scripts.SimpleGenericClass`1[System.Double]){ + ID = 6770493598825812026, + MyField = (double)0.9599999785423279 + } + ], + StaticFields = [ + (TestProject.SerializationTest){ + ID = 1460275328679732402, + StaticNumber = (int32)0 + } + ] +} \ No newline at end of file diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene.ass b/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene.ass new file mode 100644 index 0000000..6dd9890 --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scenes/TestScene.scene.ass @@ -0,0 +1,11 @@ +{ + AssetLoader = null, + Config = null, + Importer = null, + ImporterConfig = null, + Processor = null, + ProcessorConfig = null, + Exporter = null, + ExporterConfig = null, + AssetHandle = 4008662279183989969 +} \ No newline at end of file diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs new file mode 100644 index 0000000..1521fed --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs @@ -0,0 +1,28 @@ +using GlitchyEngine; +using GlitchyEngine.Math; +using System; +using System.Collections.Generic; +using System.Text; + +namespace TestProject.Assets.Scripts; + +public class SimpleGenericClass +{ + public T MyField; +} + +public struct SimpleGenericStruct +{ + public T MyField; +} + +public class AdvancedSerializationTest : Entity +{ + public (int Prim, float2 Struc, BClass Ref) LeTuple; + + public List<(int Prim, float2 Struc, BClass Ref)> LeListDeTuple; + + public SimpleGenericStruct GenericStructField = new SimpleGenericStruct(); + + public SimpleGenericClass GenericClassField = new SimpleGenericClass(); +} diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs.ass b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs.ass new file mode 100644 index 0000000..6fdcc32 --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/AdvancedSerializationTest.cs.ass @@ -0,0 +1,11 @@ +{ + AssetLoader = null, + Config = null, + Importer = null, + ImporterConfig = null, + Processor = null, + ProcessorConfig = null, + Exporter = null, + ExporterConfig = null, + AssetHandle = 16179505410974622627 +} \ No newline at end of file diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scripts/SerializationTest.cs.ass b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/SerializationTest.cs.ass new file mode 100644 index 0000000..1c3f204 --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/SerializationTest.cs.ass @@ -0,0 +1,11 @@ +{ + AssetLoader = null, + Config = null, + Importer = null, + ImporterConfig = null, + Processor = null, + ProcessorConfig = null, + Exporter = null, + ExporterConfig = null, + AssetHandle = 13036819508142753970 +} \ No newline at end of file diff --git a/GlitchyEngine.Test/content/TestProject/Assets/Scripts/TestScript.cs.ass b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/TestScript.cs.ass new file mode 100644 index 0000000..986dc05 --- /dev/null +++ b/GlitchyEngine.Test/content/TestProject/Assets/Scripts/TestScript.cs.ass @@ -0,0 +1,11 @@ +{ + AssetLoader = null, + Config = null, + Importer = null, + ImporterConfig = null, + Processor = null, + ProcessorConfig = null, + Exporter = null, + ExporterConfig = null, + AssetHandle = 2840305762073418465 +} \ No newline at end of file diff --git a/GlitchyEngine.Test/content/TestProject/TestProject.csproj b/GlitchyEngine.Test/content/TestProject/TestProject.csproj index 1dc4ebc..86559b7 100644 --- a/GlitchyEngine.Test/content/TestProject/TestProject.csproj +++ b/GlitchyEngine.Test/content/TestProject/TestProject.csproj @@ -2,7 +2,7 @@ TestProject - net9.0 + net10.0 Library enable diff --git a/GlitchyEngine.Test/content/TestProject/TestProject.slnx b/GlitchyEngine.Test/content/TestProject/TestProject.slnx index c50ba73..b3edafd 100644 --- a/GlitchyEngine.Test/content/TestProject/TestProject.slnx +++ b/GlitchyEngine.Test/content/TestProject/TestProject.slnx @@ -1,4 +1,7 @@ + + + \ No newline at end of file diff --git a/ScriptCore/Editor/EntityEditor.cs b/ScriptCore/Editor/EntityEditor.cs index 7e55ea1..10ebfa1 100644 --- a/ScriptCore/Editor/EntityEditor.cs +++ b/ScriptCore/Editor/EntityEditor.cs @@ -613,16 +613,9 @@ internal class EntityEditor { } - else if (fieldType.IsGenericType) + else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>)) { - if (fieldType.GetGenericTypeDefinition() == typeof(List<>)) - { - newValue = ShowListEditor(fieldType, reference, fieldName); - } - else - { - ImGui.TextColored(new Vector4(1, 0, 0, 1), $"{fieldName}: Type {fieldType} is not implemented."); - } + newValue = ShowListEditor(fieldType, reference, fieldName); } else if (fieldType.IsArray) { diff --git a/ScriptCore/Serialization/SerializedObject.cs b/ScriptCore/Serialization/SerializedObject.cs index 0bc7b71..21feddb 100644 --- a/ScriptCore/Serialization/SerializedObject.cs +++ b/ScriptCore/Serialization/SerializedObject.cs @@ -176,6 +176,9 @@ public class SerializedObject public void SerializeField(string fieldName, object? fieldValue, Type fieldType) { + if (TryCustomSerializer(fieldName, fieldValue, fieldType)) + return; + // Decimals are not actually primitives, but we treat them as if they were, because they are a built-in type // and it makes more sense to send them over to the engine as a binary type than to serialize their underlying fields (which would happen when we treated them as a struct). if (fieldType.IsPrimitive || fieldType == typeof(decimal)) @@ -202,38 +205,17 @@ public class SerializedObject SerializeList(fieldName, fieldValue, fieldType, fieldType.GetElementType()!); } - else if (fieldType.IsGenericType) + else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>)) { - if (TryCustomSerializer(fieldName, fieldValue, fieldType)) - return; - - if (fieldType.GetGenericTypeDefinition() == typeof(List<>)) - { - SerializeList(fieldName, fieldValue, fieldType, fieldType.GetGenericArguments()[0]); - } - //else if (fieldType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - //{ - // ImGui.Text($"{fieldName} Dictionary"); - //} - else - { - // TODO: what to do? - Log.Error($"Generic class serialization not yet implemented"); - } + SerializeList(fieldName, fieldValue, fieldType, fieldType.GetGenericArguments()[0]); } else if (fieldType.IsValueType) { - if (TryCustomSerializer(fieldName, fieldValue, fieldType)) - return; - // Value Types cant be null SerializeStruct(fieldName, fieldValue!, fieldType); } else if (fieldType.IsClass) { - if (TryCustomSerializer(fieldName, fieldValue, fieldType)) - return; - SerializeClass(fieldName, fieldValue, fieldType); } else