-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditorEntityFactory.cs
99 lines (86 loc) · 3.43 KB
/
EditorEntityFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using System.Xml;
using Caravel.Core;
using Caravel.Core.Entity;
using Caravel.Core.Resource;
using Caravel.Debugging;
using static Caravel.Core.Cv_SceneManager;
using static Caravel.Core.Entity.Cv_Entity;
namespace CaravelEditor
{
public class EditorEntityFactory : Cv_EntityFactory
{
protected override Cv_Entity CreateEntity(string entityTypeResource,
Cv_Entity.Cv_EntityID parent,
Cv_Entity.Cv_EntityID serverEntityID,
string resourceBundle,
Cv_SceneID sceneID,
string sceneName)
{
return base.CreateEntity(entityTypeResource, parent, serverEntityID, resourceBundle, sceneID, sceneName);
}
protected override Cv_EntityComponent CreateComponent(string componentName)
{
var component = ComponentFactory.Create(Cv_EntityComponent.GetID(componentName));
if (component == null)
{
var gComponent = new GameComponent();
gComponent.Init(componentName);
return gComponent;
}
return component;
}
protected override Component CreateComponent<Component>()
{
return base.CreateComponent<Component>();
}
protected override Cv_EntityComponent CreateComponent(XmlElement componentData)
{
var component = ComponentFactory.Create(Cv_EntityComponent.GetID(componentData.Name));
if (component == null)
{
component = new GameComponent();
((GameComponent) component).Init(componentData.Name);
}
if (!component.VInitialize(componentData))
{
Cv_Debug.Error("Failed to initialize component: " + componentData.Name);
return null;
}
return component;
}
protected override Cv_EntityComponent[] ModifyEntity(Cv_Entity entity, XmlNodeList overrides)
{
var components = new List<Cv_EntityComponent>();
foreach (XmlElement componentNode in overrides)
{
var componentID = Cv_EntityComponent.GetID(componentNode.Name);
var component = entity.GetComponent(componentID);
if (component != null)
{
component.VInitialize(componentNode);
component.VOnChanged();
components.Add(component);
}
else
{
component = CreateComponent(componentNode);
if (component != null)
{
if (component is GameComponent)
{
entity.AddComponent(((GameComponent)component).ComponentName, component);
}
else
{
entity.AddComponent(component.GetType().Name, component);
}
components.Add(component);
//component.VPostInitialize();
}
}
}
return components.ToArray();
}
}
}