public void AddEntity(YmapEntityDef ent) { //used by the editor to add to the ymap. List <YmapEntityDef> allents = new List <YmapEntityDef>(); if (AllEntities != null) { allents.AddRange(AllEntities); } ent.Index = allents.Count; ent.Ymap = this; allents.Add(ent); AllEntities = allents.ToArray(); if ((ent.Parent == null) || (ent.Parent.Ymap != this)) { //root entity, add to roots. List <YmapEntityDef> rootents = new List <YmapEntityDef>(); if (RootEntities != null) { rootents.AddRange(RootEntities); } rootents.Add(ent); RootEntities = rootents.ToArray(); } HasChanged = true; }
public void CreateYmapEntities(YmapEntityDef owner, MloArchetypeData mlod) { if (owner == null) { return; } if (mlod.entities == null) { return; } AllEntities = new YmapEntityDef[mlod.entities.Length]; for (int i = 0; i < mlod.entities.Length; i++) { YmapEntityDef e = new YmapEntityDef(null, i, ref mlod.entities[i]); e.MloParent = owner; e.Position = owner.Position + owner.Orientation.Multiply(e.Position); e.Orientation = Quaternion.Multiply(owner.Orientation, e.Orientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); if ((owner.Orientation != Quaternion.Identity) && (owner.Orientation.Z != 1.0f)) { } AllEntities[i] = e; } }
public bool AddEntity(YmapEntityDef ent, int roomIndex) { if (ent == null) { return(false); } // entity already exists in our array. so we'll just add // it to the instanced entities list and continue. MloInstanceData mloInstance = ent.MloParent?.MloInstance; MCEntityDef ymcent = mloInstance?.TryGetArchetypeEntity(ent); if (ymcent != null) { return(true); } if (roomIndex > rooms.Length) { throw new ArgumentOutOfRangeException($"Room index {roomIndex} exceeds the amount of rooms in {Name}."); } var mcEntityDef = new MCEntityDef(ref ent._CEntityDef, this); // Add the new entity def to the entities list. AddEntity(ent, mcEntityDef); // Update the attached objects in the room index specified. AttachEntityToRoom(ent, roomIndex); return(true); }
public void UpdateEntity(YmapEntityDef e) { e.Position = Owner.Position + Owner.Orientation.Multiply(e.MloRefPosition); e.Orientation = Quaternion.Multiply(Owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); }
public void CreateYmapEntities(YmapEntityDef owner, MloArchetype mloa) { Owner = owner; if (owner == null) { return; } if (mloa.entities == null) { return; } var ec = mloa.entities.Length; Entities = new YmapEntityDef[ec]; for (int i = 0; i < ec; i++) { YmapEntityDef e = new YmapEntityDef(null, i, ref mloa.entities[i]); e.MloRefPosition = e.Position; e.MloRefOrientation = e.Orientation; e.MloParent = owner; e.Position = owner.Position + owner.Orientation.Multiply(e.MloRefPosition); e.Orientation = Quaternion.Multiply(owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); Entities[i] = e; } }
public void AddEntity(YmapEntityDef ent) { if (Entities == null) { Entities = new List <YmapEntityDef>(); } Entities.Add(ent); }
public bool DeleteEntity(YmapEntityDef ent) { if (Entities == null) { return(false); } return(Entities.Remove(ent)); }
// attaches the specified ymap entity index to the room at roomIndex. private void AttachEntityToRoom(YmapEntityDef ent, int roomIndex) { if (roomIndex > rooms.Length) { return; // the room index is bigger than the rooms we have... } var attachedObjs = rooms[roomIndex].AttachedObjects?.ToList() ?? new List <uint>(); attachedObjs.Add((uint)ent.Index); rooms[roomIndex].AttachedObjects = attachedObjs.ToArray(); }
public void AddChild(YmapEntityDef c) { if (ChildList == null) { ChildList = new List <YmapEntityDef>(); } c.Parent = this; c.ParentGuid = CEntityDef.guid; c.ParentName = CEntityDef.archetypeName; ChildList.Add(c); }
public bool DeleteEntity(YmapEntityDef ent) { if (Entities == null) { throw new NullReferenceException("The Entities list returned null in our MloInstanceData. This could be an issue with initialization. The MloInstance probably doesn't exist."); } if (ent.Index >= Entities.Length) { throw new ArgumentOutOfRangeException("The index of the entity was greater than the amount of entities that exist in this MloInstance. Likely an issue with initializion."); } int index = 0; YmapEntityDef[] newentities = new YmapEntityDef[Entities.Length - 1]; YmapEntityDef delentity = Entities[ent.Index]; bool del = false; for (int i = 0; i < Entities.Length; i++) { if (Entities[i] == delentity) { del = true; continue; } newentities[index] = Entities[i]; newentities[index].Index = index; index++; } if (!del) { throw new ArgumentException("The entity specified was not found in this MloInstance. It cannot be deleted."); } if (Owner.Archetype is MloArchetype arch) { if (arch.RemoveEntity(ent)) { if (ent.MloEntitySet != null) { if (!ent.MloEntitySet.Entities.Remove(ent)) { return(false); } } // Delete was successful... Entities = newentities; return(true); } } throw new InvalidCastException("The owner of this archetype's archetype definition is not an MloArchetype."); }
public bool RemoveEntity(YmapEntityDef ent) { if (ent.Index >= entities.Length) { return(false); } MCEntityDef delent = entities[ent.Index]; MloInstanceData inst = ent.MloParent?.MloInstance; if (inst == null) { return(false); } if (delent != null) { MCEntityDef[] newentities = new MCEntityDef[entities.Length - 1]; bool didDel = false; int index = 0; int delIndex = 0; for (int i = 0; i < entities.Length; i++) { if (entities[i] == delent) { delIndex = i; didDel = true; continue; } newentities[index] = entities[i]; YmapEntityDef ymapEntityDef = inst.TryGetYmapEntity(newentities[index]); if (ymapEntityDef != null) { ymapEntityDef.Index = index; } index++; } entities = newentities; if (didDel) { FixRoomIndexes(delIndex); FixPortalIndexes(delIndex); } return(didDel); } return(false); }
private YmapEntityDef CreateYmapEntity(YmapEntityDef owner, MCEntityDef ment, int i) { YmapEntityDef e = new YmapEntityDef(null, i, ref ment._Data); e.Extensions = ment.Extensions; e.MloRefPosition = e.Position; e.MloRefOrientation = e.Orientation; e.MloParent = owner; e.Position = owner.Position + owner.Orientation.Multiply(e.MloRefPosition); e.Orientation = Quaternion.Multiply(owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); return(e); }
public void CreateYmapEntities(YmapEntityDef owner, MloArchetype mloa) { Owner = owner; if (owner == null) { return; } if (mloa.entities == null) { return; } var ec = mloa.entities.Length; var entlist = new List <YmapEntityDef>(); for (int i = 0; i < ec; i++) { YmapEntityDef e = CreateYmapEntity(owner, mloa.entities[i], i); entlist.Add(e); } int lasti = ec; var entitySets = mloa.entitySets; if (entitySets != null) { for (int i = 0; i < entitySets.Length; i++) { var entitySet = entitySets[i]; if (entitySet.Entities != null) { for (int j = 0; j < entitySet.Entities.Length; j++) { YmapEntityDef e = CreateYmapEntity(owner, entitySet.Entities[j], lasti); e.MloEntitySet = entitySet; entlist.Add(e); lasti++; } } } } if (defaultEntitySets != null) { } Entities = entlist.ToArray(); }
public void AddEntity(YmapEntityDef e) { if (e == null) { return; } if (Entities == null) { Entities = new YmapEntityDef[0]; } var entities = Entities.ToList(); entities.Add(e); Entities = entities.ToArray(); }
public bool RemoveEntity(YmapEntityDef ent) { //used by the editor to remove from the ymap. if (ent == null) { return(false); } var res = true; int idx = ent.Index; List <YmapEntityDef> newAllEntities = new List <YmapEntityDef>(); List <YmapEntityDef> newRootEntities = new List <YmapEntityDef>(); for (int i = 0; i < AllEntities.Length; i++) { var oent = AllEntities[i]; oent.Index = newAllEntities.Count; if (oent != ent) { newAllEntities.Add(oent); } else if (i != idx) { res = false; //indexes didn't match.. this shouldn't happen! } } for (int i = 0; i < RootEntities.Length; i++) { var oent = RootEntities[i]; if (oent != ent) { newRootEntities.Add(oent); } } if ((AllEntities.Length == newAllEntities.Count) || (RootEntities.Length == newRootEntities.Count)) { res = false; } AllEntities = newAllEntities.ToArray(); RootEntities = newRootEntities.ToArray(); HasChanged = true; return(res); }
public void UpdateEntities() { if (Entities == null) { return; } if (Owner == null) { return; } for (int i = 0; i < Entities.Length; i++) { YmapEntityDef e = Entities[i]; UpdateEntity(e); } }
public bool DeleteEntity(YmapEntityDef ent) { var del = false; if (ent.MloEntitySet != null) { del = ent.MloEntitySet.DeleteEntity(ent); UpdateAllEntityIndexes(); return(del); } if (Entities == null) { throw new NullReferenceException("The Entities list returned null in our MloInstanceData. This could be an issue with initialization. The MloInstance probably doesn't exist."); } if (ent.Index >= Entities.Length) { throw new ArgumentOutOfRangeException("The index of the entity was greater than the amount of entities that exist in this MloInstance. Likely an issue with initializion."); } int index = 0; var newentities = new YmapEntityDef[Entities.Length - 1]; for (int i = 0; i < Entities.Length; i++) { if (i == ent.Index) { del = true; continue; } newentities[index] = Entities[i]; newentities[index].Index = index; index++; } if (del) { Entities = newentities; UpdateAllEntityIndexes(); return(true); } else { throw new ArgumentException("The entity specified was not found in this MloInstance. It cannot be deleted."); } }
// Adds an entity to the entities array and then set's the index of the // ymap entity to the index of the new MCEntityDef. private void AddEntity(YmapEntityDef ent, MCEntityDef mcEntityDef) { if (ent == null || mcEntityDef == null) { return; // no entity?... } // initialize the array. if (entities == null) { entities = new MCEntityDef[0]; } List <MCEntityDef> entList = entities.ToList(); entList.Add(mcEntityDef); ent.Index = entList.IndexOf(mcEntityDef); entities = entList.ToArray(); }
public MCEntityDef TryGetArchetypeEntity(YmapEntityDef ymapEntity) { if (ymapEntity == null) { return(null); } if (Owner?.Archetype == null) { return(null); } if (!(Owner.Archetype is MloArchetype mloa)) { return(null); } var index = Array.FindIndex(Entities, x => x == ymapEntity); if ((index >= 0) && (index < mloa.entities.Length)) { return(mloa.entities[index]); } if (EntitySets != null) { for (int e = 0; e < EntitySets.Length; e++) { var entset = EntitySets[e]; var ents = entset.Entities; var set = entset.EntitySet; var setents = set?.Entities; if ((ents == null) || (setents == null)) { continue; } var idx = ents.IndexOf(ymapEntity); if ((idx >= 0) && (idx < setents.Length)) { return(setents[idx]); } } } return(null); }
public void UpdateEntities() { if (Entities == null) { return; } if (Owner == null) { return; } for (int i = 0; i < Entities.Length; i++) { YmapEntityDef e = Entities[i]; e.Position = Owner.Position + Owner.Orientation.Multiply(e.MloRefPosition); e.Orientation = Quaternion.Multiply(Owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); } }
public MCEntityDef TryGetArchetypeEntity(YmapEntityDef ymapEntity) { if (ymapEntity == null) { return(null); } if (Owner?.Archetype == null) { return(null); } if (!(Owner.Archetype is MloArchetype mloa)) { return(null); } if (ymapEntity.Index >= mloa.entities.Length) { return(null); } var entity = mloa.entities[ymapEntity.Index]; return(entity); }
public void AddEntity(YmapEntityDef e) { if (e == null) { return; } if (e.MloEntitySet != null) { e.MloEntitySet.AddEntity(e); } else { if (Entities == null) { Entities = new YmapEntityDef[0]; } var entities = Entities.ToList(); entities.Add(e); Entities = entities.ToArray(); } UpdateAllEntityIndexes(); }
public bool AddEntity(YmapEntityDef ent, int roomIndex, int portalIndex = -1, int entsetIndex = -1) { if (ent == null) { return(false); } if (roomIndex >= (rooms?.Length ?? 0)) { throw new ArgumentOutOfRangeException($"Room index {roomIndex} exceeds the amount of rooms in {Name}."); } if (portalIndex >= (portals?.Length ?? 0)) { throw new ArgumentOutOfRangeException($"Portal index {portalIndex} exceeds the amount of portals in {Name}."); } if (entsetIndex >= (entitySets?.Length ?? 0)) { throw new ArgumentOutOfRangeException($"EntitySet index {entsetIndex} exceeds the amount of entitySets in {Name}."); } var mcEntityDef = new MCEntityDef(ref ent._CEntityDef, this); if ((roomIndex >= 0) || (portalIndex >= 0)) { var entList = entities?.ToList() ?? new List <MCEntityDef>(); ent.Index = entList.Count; entList.Add(mcEntityDef); entities = entList.ToArray(); if (roomIndex >= 0) { var attachedObjs = rooms[roomIndex].AttachedObjects?.ToList() ?? new List <uint>(); attachedObjs.Add((uint)ent.Index); rooms[roomIndex].AttachedObjects = attachedObjs.ToArray(); } if (portalIndex >= 0) { var attachedObjs = portals[portalIndex].AttachedObjects?.ToList() ?? new List <uint>(); attachedObjs.Add((uint)ent.Index); portals[portalIndex].AttachedObjects = attachedObjs.ToArray(); } } else if (entsetIndex >= 0) { var entset = entitySets[entsetIndex]; var entList = entset.Entities?.ToList() ?? new List <MCEntityDef>(); entList.Add(mcEntityDef); entset.Entities = entList.ToArray(); var locs = entset.Locations?.ToList() ?? new List <uint>(); locs.Add(0);//choose a better default location? entset.Locations = locs.ToArray(); var mloInstance = ent.MloParent?.MloInstance; if ((mloInstance?.EntitySets != null) && (entsetIndex < mloInstance.EntitySets.Length)) { ent.MloEntitySet = mloInstance.EntitySets[entsetIndex]; } } else { return(false); } UpdateAllEntityIndexes(); return(true); }
public MloInstanceData(YmapEntityDef owner, MloArchetype mloa) { Owner = owner; MloArch = mloa; }
private void EnsureEntities(Meta Meta) { //CMloInstanceDefs = MetaTypes.ConvertDataArray<CMloInstanceDef>(Meta, MetaName.CMloInstanceDef, CMapData.entities); CMloInstanceDefs = MetaTypes.GetTypedDataArray <CMloInstanceDef>(Meta, MetaName.CMloInstanceDef); if (CMloInstanceDefs != null) { } var eptrs = MetaTypes.GetPointerArray(Meta, CMapData.entities); //CEntityDefs = MetaTypes.ConvertDataArray<CEntityDef>(Meta, MetaName.CEntityDef, CMapData.entities); CEntityDefs = MetaTypes.GetTypedDataArray <CEntityDef>(Meta, MetaName.CEntityDef); if (CEntityDefs != null) { } int instcount = 0; if (CEntityDefs != null) { instcount += CEntityDefs.Length; } if (CMloInstanceDefs != null) { instcount += CMloInstanceDefs.Length; } if (instcount > 0) { //build the entity hierarchy. List <YmapEntityDef> roots = new List <YmapEntityDef>(instcount); List <YmapEntityDef> alldefs = new List <YmapEntityDef>(instcount); if (CEntityDefs != null) { for (int i = 0; i < CEntityDefs.Length; i++) { YmapEntityDef d = new YmapEntityDef(this, i, ref CEntityDefs[i]); alldefs.Add(d); } } if (CMloInstanceDefs != null) { for (int i = 0; i < CMloInstanceDefs.Length; i++) { YmapEntityDef d = new YmapEntityDef(this, i, ref CMloInstanceDefs[i]); alldefs.Add(d); } } for (int i = 0; i < alldefs.Count; i++) { YmapEntityDef d = alldefs[i]; int pind = d.CEntityDef.parentIndex; bool isroot = false; if ((pind < 0) || (pind >= alldefs.Count) || (pind >= i)) //index check? might be a problem { isroot = true; } else { YmapEntityDef p = alldefs[pind]; if ((p.CEntityDef.lodLevel <= d.CEntityDef.lodLevel) || ((p.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) && (d.CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD))) { isroot = true; p = null; } } if (isroot) { roots.Add(d); } else { YmapEntityDef p = alldefs[pind]; p.AddChild(d); } } for (int i = 0; i < alldefs.Count; i++) { alldefs[i].ChildListToArray(); } AllEntities = alldefs.ToArray(); RootEntities = roots.ToArray(); foreach (var ent in AllEntities) { ent.Extensions = MetaTypes.GetExtensions(Meta, ent.CEntityDef.extensions); } } }
public void CreateYmapEntities(YmapEntityDef owner, MloArchetype mloa) { Owner = owner; if (owner == null) { return; } if (mloa.entities == null) { return; } var ec = mloa.entities.Length; var entlist = new List <YmapEntityDef>(); for (int i = 0; i < ec; i++) { YmapEntityDef e = CreateYmapEntity(owner, mloa.entities[i], i); entlist.Add(e); } int lasti = ec; var entitySets = mloa.entitySets; if (entitySets != null) { for (int i = 0; i < entitySets.Length; i++) { var entitySet = entitySets[i]; if (entitySet.Entities != null) { EntitySets[entitySet._Data.name] = new MloInstanceEntitySet(entitySet, this); MloInstanceEntitySet instset = EntitySets[entitySet._Data.name]; for (int j = 0; j < entitySet.Entities.Length; j++) { YmapEntityDef e = CreateYmapEntity(owner, entitySet.Entities[j], lasti); EntitySets[entitySet._Data.name].Entities.Add(e); e.MloEntitySet = instset; lasti++; } } } } if ((defaultEntitySets != null) && (entitySets != null)) { for (var i = 0; i < defaultEntitySets.Length; i++) { uint index = defaultEntitySets[i]; if (index >= entitySets.Length) { continue; } MCMloEntitySet set = entitySets[index]; MloInstanceEntitySet instset = EntitySets[set._Data.name]; instset.Visible = true; } } Entities = entlist.ToArray(); }
public bool RemoveEntity(YmapEntityDef ent) { if (ent == null) { return(false); } if ((ent.MloEntitySet?.Entities != null) && (ent.MloEntitySet?.EntitySet != null)) { var instents = ent.MloEntitySet.Entities; var set = ent.MloEntitySet.EntitySet; var idx = instents.IndexOf(ent); if (idx >= 0) { var ents = set.Entities.ToList(); ents.RemoveAt(idx); set.Entities = ents.ToArray(); var locs = set.Locations.ToList(); locs.RemoveAt(idx); set.Locations = locs.ToArray(); UpdateAllEntityIndexes(); return(true); } return(false); } if (ent.Index >= entities.Length) { return(false); } var delent = entities[ent.Index]; if (delent != null) { var newentities = new MCEntityDef[entities.Length - 1]; var didDel = false; int index = 0; int delIndex = 0; for (int i = 0; i < entities.Length; i++) { if (entities[i] == delent) { delIndex = i; didDel = true; continue; } var newent = entities[i]; newentities[index] = newent; index++; } entities = newentities; if (didDel) { FixRoomIndexes(delIndex); FixPortalIndexes(delIndex); UpdateAllEntityIndexes(); } return(didDel); } return(false); }