示例#1
0
        /// <summary>
        /// returns the StarVM for a given bodies guid.
        /// </summary>
        /// <param name="bodyGuid"></param>
        /// <returns></returns>
        internal StarVM GetStar(Guid bodyGuid)
        {
            Entity bodyEntity;
            Guid   starGuid = new Guid();

            if (_starDictionary.ContainsKey(bodyGuid))
            {
                starGuid = bodyGuid;
            }

            else if (_gameVM.Game.GlobalManager.FindEntityByGuid(bodyGuid, out bodyEntity))
            {
                if (bodyEntity.HasDataBlob <StarInfoDB>())
                {
                    starGuid = bodyEntity.Guid;
                }
            }
            else
            {
                throw new GuidNotFoundException(bodyGuid);
            }

            if (!_starDictionary.ContainsKey(starGuid))
            {
                StarVM starVM = StarVM.Create(_gameVM, starGuid, this);
                _starDictionary.Add(starGuid, starVM);
                if (!_stars.Contains(starVM))
                {
                    _stars.Add(starVM);
                }
            }
            return(_starDictionary[starGuid]);
        }
示例#2
0
        internal static PlanetVM Create(GameVM gameVM, Entity entity, StarVM parent_star)
        {
            var newvm = PlanetVM.Create(gameVM, entity);

            newvm.ParentStar = parent_star;
            return(newvm);
        }
示例#3
0
        /// <summary>
        /// Creates and fills out the properties of this ViewModel from the provided entity.
        /// </summary>
        public static StarVM Create(GameVM gameVM, Entity entity, SystemVM systemVM)
        {
            StarVM newVM = new StarVM(gameVM, entity);

            // Initialize the data.
            newVM.Init(systemVM);

            newVM.Refresh();

            return(newVM);
        }
示例#4
0
        private SystemVM(GameVM gameVM, StarSystem starSystem)
        {
            _gameVM           = gameVM;
            _name             = starSystem.NameDB.DefaultName;
            StarSystem        = starSystem;
            _stars            = new BindingList <StarVM>();
            _planets          = new BindingList <PlanetVM>();
            _starDictionary   = new Dictionary <Guid, StarVM>();
            _planetDictionary = new Dictionary <Guid, PlanetVM>();
            //find most massive star, this is the parent.
            Entity parentStar   = starSystem.GetFirstEntityWithDataBlob <StarInfoDB>(gameVM.CurrentAuthToken);
            StarVM parentstarVM = StarVM.Create(_gameVM, parentStar, this);

            foreach (var star in starSystem.GetAllEntitiesWithDataBlob <StarInfoDB>(gameVM.CurrentAuthToken))
            {
                StarVM starVM = StarVM.Create(_gameVM, star, this);
                if (!_stars.Contains(starVM))
                {
                    _stars.Add(starVM);
                }
                if (!_starDictionary.ContainsKey(star.Guid))
                {
                    _starDictionary.Add(star.Guid, starVM);
                }
                if (star.GetDataBlob <MassVolumeDB>().Mass > parentStar.GetDataBlob <MassVolumeDB>().Mass)
                {
                    parentStar   = star;
                    parentstarVM = starVM;
                }
            }
            _parentStar = parentstarVM;
            ID          = _parentStar.Entity.Guid;
            foreach (var planet in starSystem.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(gameVM.CurrentAuthToken))
            {
                PlanetVM planetVM = PlanetVM.Create(_gameVM, planet, parentstarVM);
                if (!_planets.Contains(planetVM))
                {
                    _planets.Add(planetVM);
                }
                if (!_planetDictionary.ContainsKey(planet.Guid))
                {
                    _planetDictionary.Add(planet.Guid, planetVM);
                }
            }
        }