public object AddObject(string type, int posX = 0, int posY = 0, int posZ = 0, int angle = 0, bool makeSelected = false) { MapObjectNamed mo = null; MapObjectNameless nmo = null; switch (type) { case "station": mo = new MapObjectNamed_station(posX, posY, posZ, makeSelected, angle); break; case "neutral": mo = new MapObjectNamed_neutral(posX, posY, posZ, makeSelected, angle); break; case "player": mo = new MapObjectNamed_player(posX, posY, posZ, makeSelected, angle); break; case "monster": mo = new MapObjectNamed_monster(posX, posY, posZ, makeSelected, angle); break; case "anomaly": mo = new MapObjectNamed_anomaly(posX, posY, posZ, "", makeSelected); break; case "blackHole": mo = new MapObjectNamed_blackHole(posX, posY, posZ, "", makeSelected); break; case "enemy": mo = new MapObjectNamed_enemy(posX, posY, posZ, makeSelected, angle); break; case "genericMesh": mo = new MapObjectNamed_genericMesh(posX, posY, posZ, makeSelected, angle); break; case "whale": mo = new MapObjectNamed_whale(posX, posY, posZ, makeSelected, angle); break; case "nameless": nmo = new MapObjectNameless(posX, posY, posZ, ""); break; case "nebulas": nmo = new MapObjectNameless(posX, posY, posZ, "nebulas"); break; case "asteroids": nmo = new MapObjectNameless(posX, posY, posZ, "asteroids"); break; case "mines": nmo = new MapObjectNameless(posX, posY, posZ, "mines"); break; default: break; } if (mo == null && nmo==null) throw new NotImplementedException("Attempting to add object of unknown type " + type); if (mo != null) { NamedObjects.Add(mo); return mo; } else { NamelessObjects.Add(nmo); if (makeSelected) { Select_None(); SelectionNameless = nmo; } return nmo; } }
public static MapObjectNamed NewFromXml(XmlNode item) { if (!(item is XmlElement)) return null; string type = ""; MapObjectNamed mo = null; foreach (XmlAttribute att in item.Attributes) if (att.Name == "type") type = att.Value.ToString(); switch (type) { case "anomaly": mo = new MapObjectNamed_anomaly(); break; case "blackHole": mo = new MapObjectNamed_blackHole(); break; case "enemy": mo = new MapObjectNamed_enemy(); break; case "neutral": mo = new MapObjectNamed_neutral(); break; case "station": mo = new MapObjectNamed_station(); break; case "player": mo = new MapObjectNamed_player(); break; case "genericMesh": mo = new MapObjectNamed_genericMesh(); break; case "monster": mo = new MapObjectNamed_monster(); break; case "whale": mo = new MapObjectNamed_whale(); break; case "nebulas": return null; case "asteroids": return null; case "mines": return null; default: return null; } mo.FromXml(item); return mo; }