Esempio n. 1
0
        internal static PlanetVM Create(GameVM gameVM, Entity entity, StarVM parent_star)
        {
            var newvm = PlanetVM.Create(gameVM, entity);

            newvm.ParentStar = parent_star;
            return(newvm);
        }
Esempio n. 2
0
        internal PlanetVM GetPlanet(Guid bodyGuid)
        {
            Entity bodyEntity;
            Guid   planetGuid = new Guid();

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

            if (!_planetDictionary.ContainsKey(planetGuid))
            {
                PlanetVM planetVM = PlanetVM.Create(_gameVM, planetGuid);
                if (!_planets.Contains(planetVM))
                {
                    _planets.Add(planetVM);
                }
                _planetDictionary.Add(planetGuid, planetVM);
            }
            return(_planetDictionary[planetGuid]);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates and fills out the properties of this ViewModel from the provided entity.
        /// </summary>
        internal static PlanetVM Create(GameVM gameVM, Entity entity)
        {
            PlanetVM newVM = new PlanetVM(gameVM, entity);

            // Initialize the data.
            newVM.Refresh();

            return(newVM);
        }
Esempio n. 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.SystemManager.GetFirstEntityWithDataBlob <StarInfoDB>(gameVM.CurrentAuthToken);
            StarVM parentstarVM = StarVM.Create(_gameVM, parentStar, this);

            foreach (var star in starSystem.SystemManager.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.SystemManager.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);
                }
            }
        }