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,
|
Default = 0,
|
||||||
HideInHierarchy = 1,
|
HideInHierarchy = 1,
|
||||||
HideInScene = 2,
|
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")]
|
[Component("Sprite Renderer")]
|
||||||
struct SpriteRendererComponent
|
struct SpriteRendererComponent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ namespace GlitchyEngine.World
|
|||||||
// Copy components
|
// Copy components
|
||||||
CopyComponents<MeshRendererComponent>(this, target);
|
CopyComponents<MeshRendererComponent>(this, target);
|
||||||
CopyComponents<MeshComponent>(this, target);
|
CopyComponents<MeshComponent>(this, target);
|
||||||
CopyComponents<EditorComponent>(this, target);
|
|
||||||
CopyComponents<SpriteRendererComponent>(this, target);
|
CopyComponents<SpriteRendererComponent>(this, target);
|
||||||
CopyComponents<CircleRendererComponent>(this, target);
|
CopyComponents<CircleRendererComponent>(this, target);
|
||||||
CopyComponents<CameraComponent>(this, target);
|
CopyComponents<CameraComponent>(this, target);
|
||||||
@@ -154,6 +153,8 @@ namespace GlitchyEngine.World
|
|||||||
CopyComponents<CircleCollider2DComponent>(this, target);
|
CopyComponents<CircleCollider2DComponent>(this, target);
|
||||||
CopyComponents<PolygonCollider2DComponent>(this, target);
|
CopyComponents<PolygonCollider2DComponent>(this, target);
|
||||||
|
|
||||||
|
CopyComponents<EditorFlagsComponent>(this, target);
|
||||||
|
|
||||||
if (copyScripts)
|
if (copyScripts)
|
||||||
{
|
{
|
||||||
for (let (sourceHandle, sourceScript) in _ecsWorld.Enumerate<ScriptComponent>())
|
for (let (sourceHandle, sourceScript) in _ecsWorld.Enumerate<ScriptComponent>())
|
||||||
@@ -193,15 +194,30 @@ namespace GlitchyEngine.World
|
|||||||
Entity sourceEntity = .(sourceHandle, source);
|
Entity sourceEntity = .(sourceHandle, source);
|
||||||
|
|
||||||
Entity targetEntity = target.GetEntityByID(sourceEntity.UUID);
|
Entity targetEntity = target.GetEntityByID(sourceEntity.UUID);
|
||||||
|
|
||||||
|
if (targetEntity.TryGetComponent<TComponent>(let targetComponent))
|
||||||
|
{
|
||||||
|
*targetComponent = *sourceComponent;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
targetEntity.AddComponent<TComponent>(*sourceComponent);
|
targetEntity.AddComponent<TComponent>(*sourceComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void CopyComponent<TComponent>(Entity source, Entity target) where TComponent : struct, new
|
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<MeshRendererComponent>(original, copy);
|
||||||
CopyComponent<MeshComponent>(original, copy);
|
CopyComponent<MeshComponent>(original, copy);
|
||||||
CopyComponent<EditorComponent>(original, copy);
|
|
||||||
CopyComponent<SpriteRendererComponent>(original, copy);
|
CopyComponent<SpriteRendererComponent>(original, copy);
|
||||||
CopyComponent<CircleRendererComponent>(original, copy);
|
CopyComponent<CircleRendererComponent>(original, copy);
|
||||||
CopyComponent<CameraComponent>(original, copy);
|
CopyComponent<CameraComponent>(original, copy);
|
||||||
@@ -912,6 +927,8 @@ namespace GlitchyEngine.World
|
|||||||
CopyComponent<CircleCollider2DComponent>(original, copy);
|
CopyComponent<CircleCollider2DComponent>(original, copy);
|
||||||
CopyComponent<PolygonCollider2DComponent>(original, copy);
|
CopyComponent<PolygonCollider2DComponent>(original, copy);
|
||||||
|
|
||||||
|
CopyComponent<EditorFlagsComponent>(original, copy);
|
||||||
|
|
||||||
// Copy ScriptComponent... needs extra handling for the script instances
|
// Copy ScriptComponent... needs extra handling for the script instances
|
||||||
if (original.TryGetComponent<ScriptComponent>(let sourceScript))
|
if (original.TryGetComponent<ScriptComponent>(let sourceScript))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using GlitchyEngine.Renderer;
|
|||||||
using GlitchyEngine.Content;
|
using GlitchyEngine.Content;
|
||||||
using GlitchyEngine.Scripting;
|
using GlitchyEngine.Scripting;
|
||||||
using GlitchyEngine.Serialization;
|
using GlitchyEngine.Serialization;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
|
||||||
namespace GlitchyEngine.World;
|
namespace GlitchyEngine.World;
|
||||||
|
|
||||||
@@ -72,8 +73,7 @@ class SceneSerializer
|
|||||||
{
|
{
|
||||||
Entity entity = .(e, _scene);
|
Entity entity = .(e, _scene);
|
||||||
|
|
||||||
// TODO: also serialize object with EditorComponent (e.g. to save the location of the editor camera)
|
if (entity.EditorFlags.HasFlag(.DontSave))
|
||||||
if (entity.HasComponent<EditorComponent>())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SerializeEntity(writer, entity);
|
SerializeEntity(writer, entity);
|
||||||
@@ -113,8 +113,6 @@ class SceneSerializer
|
|||||||
{
|
{
|
||||||
Serialize.Value(writer, "Id", entity.UUID);
|
Serialize.Value(writer, "Id", entity.UUID);
|
||||||
|
|
||||||
SerializeComponent<EditorComponent>(writer, entity, "EditorComponent", scope (component) => {});
|
|
||||||
|
|
||||||
SerializeComponent<NameComponent>(writer, entity, "NameComponent", scope (component) =>
|
SerializeComponent<NameComponent>(writer, entity, "NameComponent", scope (component) =>
|
||||||
{
|
{
|
||||||
Serialize.Value(writer, "Name", component.Name);
|
Serialize.Value(writer, "Name", component.Name);
|
||||||
@@ -245,41 +243,11 @@ class SceneSerializer
|
|||||||
|
|
||||||
_objectsNotWritten.Remove(entity.UUID);
|
_objectsNotWritten.Remove(entity.UUID);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//if (component.HasScript)
|
SerializeComponent<EditorFlagsComponent>(writer, entity, "Editor", scope (component) =>
|
||||||
// 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)
|
Serialize.Value(writer, "Flags", component.Flags);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,8 +418,6 @@ class SceneSerializer
|
|||||||
|
|
||||||
switch(identifier)
|
switch(identifier)
|
||||||
{
|
{
|
||||||
case "EditorComponent":
|
|
||||||
Try!(DeserializeComponent<EditorComponent>(reader, entity, scope (component) => { return .Ok; }));
|
|
||||||
case "NameComponent":
|
case "NameComponent":
|
||||||
Try!(DeserializeComponent<NameComponent>(reader, entity, scope (component) =>
|
Try!(DeserializeComponent<NameComponent>(reader, entity, scope (component) =>
|
||||||
{
|
{
|
||||||
@@ -698,6 +664,13 @@ class SceneSerializer
|
|||||||
SerializedObject.BonDeserialize(reader, _serializedObjects, gBonEnv);
|
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;
|
return .Ok;
|
||||||
}));
|
}));
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ public enum EditorFlags : byte
|
|||||||
/// The entity is hidden in the scene.
|
/// The entity is hidden in the scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
HideInScene = 2,
|
HideInScene = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// The entity will not be saved.
|
||||||
|
/// </summary>
|
||||||
|
DontSave = 4
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user