public static void SaveAssets(EngineContext engineContext) { var entities = new List <EntityDefinition>(); foreach (var entity in engineContext.EntityManager.Entities.OrderBy(x => x.Guid).Where(x => x.Name == "him")) { var entityDefinition = new EntityDefinition(entity.Guid); entities.Add(entityDefinition); foreach (var entityComponent in entity.Properties.Where(x => x.Value is EntityComponent).OrderBy(x => x.Key.Name)) { var componentDefinition = new EntityComponentDefinition { Name = entityComponent.Key.Name, Properties = new List <EntityComponentProperty>() }; entityDefinition.Components.Add(componentDefinition); var entityComponentValue = entityComponent.Value as EntityComponent; foreach (var field in entityComponentValue.GetType().GetFields()) { if (field.GetCustomAttributes(typeof(VersionableAttribute), true).Length == 0) { continue; } componentDefinition.Properties.Add(new EntityComponentProperty(EntityComponentPropertyType.Field, field.Name, Encode(field.GetValue(entityComponentValue)))); } foreach (var property in entityComponentValue.GetType().GetProperties()) { if (property.GetCustomAttributes(typeof(VersionableAttribute), true).Length == 0) { continue; } componentDefinition.Properties.Add(new EntityComponentProperty(EntityComponentPropertyType.Property, property.Name, Encode(property.GetValue(entityComponentValue, null)))); } componentDefinition.Properties = componentDefinition.Properties.OrderBy(x => x.Name).ToList(); } } var fileStream = new FileStream(@"C:\DEV\hotei_scene\scene.hotei", FileMode.Create, FileAccess.Write); var stream = new BinarySerializationWriter(fileStream); stream.Context.Serializer = Serializer; stream.SerializeClass(null, ref entities, ArchiveMode.Serialize); fileStream.Close(); }
// Resolve conflicts for a component public static void ResolveComponentConflicts(ThreeWayConflictType conflictType, IList <EntityComponentDefinition>[] lists, int[] indices, IList <EntityComponentDefinition> result) { switch (conflictType) { case ThreeWayConflictType.Modified1And2: var componentDefinition = new EntityComponentDefinition { Name = lists[0][indices[0]].Name, Properties = new List <EntityComponentProperty>() }; ThreeWayMergeOrdered.Merge(componentDefinition.Properties, lists[0][indices[0]].Properties, lists[1][indices[1]].Properties, lists[2][indices[2]].Properties, x => x.Name, (x, y) => x == y, ResolvePropertyConflicts); result.Add(componentDefinition); break; default: throw new NotImplementedException(); } }
public static void SaveAssets(EngineContext engineContext) { var entities = new List<EntityDefinition>(); foreach (var entity in engineContext.EntityManager.Entities.OrderBy(x => x.Guid).Where(x => x.Name == "him")) { var entityDefinition = new EntityDefinition(entity.Guid); entities.Add(entityDefinition); foreach (var entityComponent in entity.Properties.Where(x => x.Value is EntityComponent).OrderBy(x => x.Key.Name)) { var componentDefinition = new EntityComponentDefinition { Name = entityComponent.Key.Name, Properties = new List<EntityComponentProperty>() }; entityDefinition.Components.Add(componentDefinition); var entityComponentValue = entityComponent.Value as EntityComponent; foreach (var field in entityComponentValue.GetType().GetFields()) { if (field.GetCustomAttributes(typeof(VersionableAttribute), true).Length == 0) continue; componentDefinition.Properties.Add(new EntityComponentProperty(EntityComponentPropertyType.Field, field.Name, Encode(field.GetValue(entityComponentValue)))); } foreach (var property in entityComponentValue.GetType().GetProperties()) { if (property.GetCustomAttributes(typeof(VersionableAttribute), true).Length == 0) continue; componentDefinition.Properties.Add(new EntityComponentProperty(EntityComponentPropertyType.Property, property.Name, Encode(property.GetValue(entityComponentValue, null)))); } componentDefinition.Properties = componentDefinition.Properties.OrderBy(x => x.Name).ToList(); } } var fileStream = new FileStream(@"C:\DEV\hotei_scene\scene.hotei", FileMode.Create, FileAccess.Write); var stream = new BinarySerializationWriter(fileStream); stream.Context.Serializer = Serializer; stream.SerializeClass(null, ref entities, ArchiveMode.Serialize); fileStream.Close(); }
// Resolve conflicts for a component public static void ResolveComponentConflicts(ThreeWayConflictType conflictType, IList<EntityComponentDefinition>[] lists, int[] indices, IList<EntityComponentDefinition> result) { switch (conflictType) { case ThreeWayConflictType.Modified1And2: var componentDefinition = new EntityComponentDefinition { Name = lists[0][indices[0]].Name, Properties = new List<EntityComponentProperty>() }; ThreeWayMergeOrdered.Merge(componentDefinition.Properties, lists[0][indices[0]].Properties, lists[1][indices[1]].Properties, lists[2][indices[2]].Properties, x => x.Name, (x, y) => x == y, ResolvePropertyConflicts); result.Add(componentDefinition); break; default: throw new NotImplementedException(); } }