mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Save and copy editor flags with scene. Replaced EditorComponent with DontSafe-flag
This commit is contained in:
@@ -5,4 +5,5 @@ enum EditorFlags
|
||||
Default = 0,
|
||||
HideInHierarchy = 1,
|
||||
HideInScene = 2,
|
||||
DontSave = 4
|
||||
}
|
||||
|
||||
@@ -36,16 +36,6 @@ namespace GlitchyEngine.World
|
||||
}
|
||||
}
|
||||
|
||||
/// If an entity has the EditorComponent it won't be displayed in the scene hierarchy.
|
||||
struct EditorComponent
|
||||
{
|
||||
bool b = false;
|
||||
public this()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Component("Sprite Renderer")]
|
||||
struct SpriteRendererComponent
|
||||
{
|
||||
|
||||
@@ -143,7 +143,6 @@ namespace GlitchyEngine.World
|
||||
// Copy components
|
||||
CopyComponents<MeshRendererComponent>(this, target);
|
||||
CopyComponents<MeshComponent>(this, target);
|
||||
CopyComponents<EditorComponent>(this, target);
|
||||
CopyComponents<SpriteRendererComponent>(this, target);
|
||||
CopyComponents<CircleRendererComponent>(this, target);
|
||||
CopyComponents<CameraComponent>(this, target);
|
||||
@@ -153,6 +152,8 @@ namespace GlitchyEngine.World
|
||||
CopyComponents<BoxCollider2DComponent>(this, target);
|
||||
CopyComponents<CircleCollider2DComponent>(this, target);
|
||||
CopyComponents<PolygonCollider2DComponent>(this, target);
|
||||
|
||||
CopyComponents<EditorFlagsComponent>(this, target);
|
||||
|
||||
if (copyScripts)
|
||||
{
|
||||
@@ -193,15 +194,30 @@ namespace GlitchyEngine.World
|
||||
Entity sourceEntity = .(sourceHandle, source);
|
||||
|
||||
Entity targetEntity = target.GetEntityByID(sourceEntity.UUID);
|
||||
targetEntity.AddComponent<TComponent>(*sourceComponent);
|
||||
|
||||
if (targetEntity.TryGetComponent<TComponent>(let targetComponent))
|
||||
{
|
||||
*targetComponent = *sourceComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetEntity.AddComponent<TComponent>(*sourceComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new
|
||||
{
|
||||
if (source.TryGetComponent<TComponent>(let component))
|
||||
if (source.TryGetComponent<TComponent>(let sourceComponent))
|
||||
{
|
||||
target.AddComponent<TComponent>(*component);
|
||||
if (target.TryGetComponent<TComponent>(let targetComponent))
|
||||
{
|
||||
*targetComponent = *sourceComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.AddComponent<TComponent>(*sourceComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,7 +917,6 @@ namespace GlitchyEngine.World
|
||||
|
||||
CopyComponent<MeshRendererComponent>(original, copy);
|
||||
CopyComponent<MeshComponent>(original, copy);
|
||||
CopyComponent<EditorComponent>(original, copy);
|
||||
CopyComponent<SpriteRendererComponent>(original, copy);
|
||||
CopyComponent<CircleRendererComponent>(original, copy);
|
||||
CopyComponent<CameraComponent>(original, copy);
|
||||
@@ -911,6 +926,8 @@ namespace GlitchyEngine.World
|
||||
CopyComponent<BoxCollider2DComponent>(original, copy);
|
||||
CopyComponent<CircleCollider2DComponent>(original, copy);
|
||||
CopyComponent<PolygonCollider2DComponent>(original, copy);
|
||||
|
||||
CopyComponent<EditorFlagsComponent>(original, copy);
|
||||
|
||||
// Copy ScriptComponent... needs extra handling for the script instances
|
||||
if (original.TryGetComponent<ScriptComponent>(let sourceScript))
|
||||
|
||||
@@ -10,6 +10,7 @@ using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Content;
|
||||
using GlitchyEngine.Scripting;
|
||||
using GlitchyEngine.Serialization;
|
||||
using GlitchyEngine.World.Components;
|
||||
|
||||
namespace GlitchyEngine.World;
|
||||
|
||||
@@ -72,8 +73,7 @@ class SceneSerializer
|
||||
{
|
||||
Entity entity = .(e, _scene);
|
||||
|
||||
// TODO: also serialize object with EditorComponent (e.g. to save the location of the editor camera)
|
||||
if (entity.HasComponent<EditorComponent>())
|
||||
if (entity.EditorFlags.HasFlag(.DontSave))
|
||||
continue;
|
||||
|
||||
SerializeEntity(writer, entity);
|
||||
@@ -113,8 +113,6 @@ class SceneSerializer
|
||||
{
|
||||
Serialize.Value(writer, "Id", entity.UUID);
|
||||
|
||||
SerializeComponent<EditorComponent>(writer, entity, "EditorComponent", scope (component) => {});
|
||||
|
||||
SerializeComponent<NameComponent>(writer, entity, "NameComponent", scope (component) =>
|
||||
{
|
||||
Serialize.Value(writer, "Name", component.Name);
|
||||
@@ -245,41 +243,11 @@ class SceneSerializer
|
||||
|
||||
_objectsNotWritten.Remove(entity.UUID);
|
||||
}
|
||||
});
|
||||
|
||||
//if (component.HasScript)
|
||||
// TODO: Thats not a good check, I think. At least we know the script class is valid
|
||||
//if (ScriptEngine.GetScriptClass(component.ScriptClassName) != null)
|
||||
//{
|
||||
//Serialize.Value(writer, "Fields", );
|
||||
|
||||
// TODO: Serialize Script Instance!
|
||||
/*let fields = ScriptEngine.GetScriptFieldMap(entity);
|
||||
|
||||
writer.Identifier("Fields");
|
||||
|
||||
using (writer.ArrayBlock())
|
||||
{
|
||||
for (var (fieldName, fieldInstance) in fields)
|
||||
{
|
||||
if (fieldInstance.Type == .None)
|
||||
continue;
|
||||
|
||||
switch (fieldInstance.Type)
|
||||
{
|
||||
case .Enum, .Class, .Struct:
|
||||
// TODO: implement
|
||||
default:
|
||||
writer.Identifier(fieldName);
|
||||
|
||||
String str = scope .();
|
||||
fieldInstance.Type.ToString(str);
|
||||
writer.Type(str);
|
||||
|
||||
Serialize.Value(writer, ValueView(fieldInstance.Type.GetBeefType(), &fieldInstance.[Friend]_data), gBonEnv);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//}
|
||||
SerializeComponent<EditorFlagsComponent>(writer, entity, "Editor", scope (component) =>
|
||||
{
|
||||
Serialize.Value(writer, "Flags", component.Flags);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -450,8 +418,6 @@ class SceneSerializer
|
||||
|
||||
switch(identifier)
|
||||
{
|
||||
case "EditorComponent":
|
||||
Try!(DeserializeComponent<EditorComponent>(reader, entity, scope (component) => { return .Ok; }));
|
||||
case "NameComponent":
|
||||
Try!(DeserializeComponent<NameComponent>(reader, entity, scope (component) =>
|
||||
{
|
||||
@@ -698,6 +664,13 @@ class SceneSerializer
|
||||
SerializedObject.BonDeserialize(reader, _serializedObjects, gBonEnv);
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}));
|
||||
case "Editor":
|
||||
Try!(DeserializeComponent<EditorFlagsComponent>(reader, entity, scope (component) =>
|
||||
{
|
||||
Try!(Deserialize.Value(reader, "Flags", out component.Flags));
|
||||
|
||||
return .Ok;
|
||||
}));
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user