mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e27237360f | ||
|
|
b927e2e709 | ||
|
|
d2c6c9a948 |
@@ -205,17 +205,29 @@ namespace GlitchyEditor.EditWindows
|
||||
positionX -= buttonSize.X + ImGui.GetStyle().FramePadding.x;
|
||||
ImGui.SameLine(positionX);
|
||||
|
||||
if (ImGui.ImageButton("save", EditorIcons.Instance.Icon_Save, (.)buttonSize))
|
||||
if (ImGui.ImageButton("save_to_editor", EditorIcons.Instance.Icon_Save, (.)buttonSize))
|
||||
{
|
||||
if (Entity editorEntity = Editor.Instance.EditorScene.GetEntityByID(entity.UUID))
|
||||
{
|
||||
Scene.CopyComponent<TComponent>(entity, editorEntity);
|
||||
|
||||
|
||||
if (typeof(TComponent) == typeof(ScriptComponent))
|
||||
{
|
||||
// TODO: Copy script data into editor
|
||||
// TODO: Somehow get the scriptserializer used to serialize the editor scene
|
||||
//scriptSerializer.SerializeScriptInstance(((ScriptComponent*)component).Instance);
|
||||
// Dirty hack to get to the serialized script instances of the editor scene.
|
||||
var serializer = EditorApp.Instance.EditorLayer.[Friend]_scriptSerializer;
|
||||
|
||||
// Dirty hack to remove the old data
|
||||
if (serializer.SerializedObjects.GetAndRemove(entity.UUID) case .Ok(let kvPair))
|
||||
{
|
||||
delete kvPair.value;
|
||||
}
|
||||
|
||||
// Just save the new data into the context (what could possibly go wrong?!)
|
||||
// this could probably serialize too much data into our context (because we can serialize reference types)
|
||||
// and leave a bunch of dangling data in it (because we can serialize reference types)
|
||||
serializer.SerializeScriptInstance(((ScriptComponent*)component).Instance);
|
||||
// This is also a massive hack to make sure we don't keep references to types, but this also mean we might serialize too much?
|
||||
serializer.FinishSerialization();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace GlitchyEditor
|
||||
private EditorLayer _editorLayer;
|
||||
|
||||
public Settings Settings { get; private set; } = new .() ~ delete _;
|
||||
|
||||
public EditorLayer EditorLayer => _editorLayer;
|
||||
|
||||
public this(String[] args)
|
||||
{
|
||||
|
||||
@@ -670,7 +670,7 @@ namespace GlitchyEngine.World
|
||||
}
|
||||
}
|
||||
|
||||
struct ScriptComponent : IDisposableComponent
|
||||
struct ScriptComponent : IDisposableComponent, ICopyComponent<ScriptComponent>
|
||||
{
|
||||
private String _scriptClassName = null;
|
||||
|
||||
@@ -705,5 +705,12 @@ namespace GlitchyEngine.World
|
||||
delete _scriptClassName;
|
||||
ReleaseRefAndNullify!(_instance);
|
||||
}
|
||||
|
||||
public static void Copy(ScriptComponent* source, ScriptComponent* target)
|
||||
{
|
||||
target.ScriptClassName = source.ScriptClassName;
|
||||
|
||||
// TODO: This is just half the work, because we actually have to somehow handle the script instance
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,53 +94,99 @@ public static class TypeExtension
|
||||
|
||||
ReadOnlySpan<char> typeName = ReadTypeName(fullName);
|
||||
rest = rest.Slice(typeName.Length);
|
||||
|
||||
if (rest.IsEmpty || rest[0] != '`')
|
||||
|
||||
if (rest.IsEmpty || (rest[0] != '[' && rest[0] != '`'))
|
||||
{
|
||||
// Non generic type, easy!
|
||||
return GetType(typeName);
|
||||
}
|
||||
|
||||
// Handle generic type
|
||||
|
||||
int brackedIndex = fullName.IndexOf('[');
|
||||
|
||||
typeName = fullName.Slice(0, brackedIndex);
|
||||
rest = fullName.Slice(brackedIndex + 1).Trim();
|
||||
|
||||
Type? genericType = GetType(typeName);
|
||||
|
||||
Console.WriteLine($"Generic Type: {genericType}");
|
||||
|
||||
List<Type> arguments = new List<Type>();
|
||||
|
||||
while (true)
|
||||
if (rest[0] == '[')
|
||||
{
|
||||
Type? argument = FindType(rest, ref rest);
|
||||
Console.WriteLine($"Argument: {argument}");
|
||||
Type? baseType = GetType(typeName);
|
||||
|
||||
Debug.Assert(argument != null);
|
||||
|
||||
arguments.Add(argument!);
|
||||
|
||||
rest = rest.TrimStart();
|
||||
|
||||
if (rest.TrimStart()[0] == ',')
|
||||
if (baseType == null)
|
||||
{
|
||||
rest = rest.Slice(1);
|
||||
Log.Error($"Failed to find element type {typeName} of array type {fullName}");
|
||||
return null;
|
||||
}
|
||||
else if (rest.TrimStart()[0] == ']')
|
||||
|
||||
// Handle array type
|
||||
int rank = 1;
|
||||
bool forceMultiDimensional = false;
|
||||
for (int i = 0; i < rest.Length; i++)
|
||||
{
|
||||
rest = rest.Slice(1);
|
||||
break;
|
||||
if (rest[i] == ',')
|
||||
{
|
||||
rank++;
|
||||
}
|
||||
else if (rest[i] == '*')
|
||||
{
|
||||
forceMultiDimensional = true;
|
||||
}
|
||||
else if (rest[i] == ']')
|
||||
{
|
||||
rest = rest.Slice(i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Assert(rest.IsEmpty);
|
||||
|
||||
// It is important to use MakeArrayType() for single-dimensional arrays, as a single-dimension array is distinct from a multi-dimension array of rank 1. The latter cannot be created using normal code, but can be created using reflection.
|
||||
if (rank == 1 && !forceMultiDimensional)
|
||||
{
|
||||
return baseType.MakeArrayType();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
return baseType.MakeArrayType(rank);
|
||||
}
|
||||
}
|
||||
|
||||
return genericType?.MakeGenericType(arguments.ToArray());
|
||||
if (rest[0] == '`')
|
||||
{
|
||||
// Handle generic type
|
||||
|
||||
int brackedIndex = fullName.IndexOf('[');
|
||||
|
||||
typeName = fullName.Slice(0, brackedIndex);
|
||||
rest = fullName.Slice(brackedIndex + 1).Trim();
|
||||
|
||||
Type? genericType = GetType(typeName);
|
||||
|
||||
List<Type> arguments = new List<Type>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
Type? argument = FindType(rest, ref rest);
|
||||
|
||||
Debug.Assert(argument != null);
|
||||
|
||||
arguments.Add(argument!);
|
||||
|
||||
rest = rest.TrimStart();
|
||||
|
||||
if (rest.TrimStart()[0] == ',')
|
||||
{
|
||||
rest = rest.Slice(1);
|
||||
}
|
||||
else if (rest.TrimStart()[0] == ']')
|
||||
{
|
||||
rest = rest.Slice(1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return genericType?.MakeGenericType(arguments.ToArray());
|
||||
}
|
||||
|
||||
Log.Error($"Failed to find a type for {typeName}.");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Type? GetType(ReadOnlySpan<char> fullName)
|
||||
|
||||
@@ -56,6 +56,7 @@ public class DeserializationObject
|
||||
{
|
||||
ScriptGlue.Serialization_GetObjectTypeName(_internalContext, out string fullTypeName);
|
||||
|
||||
// TODO: Retrieving the entire type by name is not ideal, we should probably consider using a more efficient approach.
|
||||
return GetTypeFromName(fullTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user