Example #1
0
        public SystemVM GetSystem(Guid bodyGuid)
        {
            Entity bodyEntity;
            Guid   rootGuid = new Guid();

            if (_systemDictionary.ContainsKey(bodyGuid))
            {
                rootGuid = bodyGuid;
            }

            else if (Game.GlobalManager.FindEntityByGuid(bodyGuid, out bodyEntity))
            {
                if (bodyEntity.HasDataBlob <OrbitDB>())
                {
                    rootGuid = bodyEntity.GetDataBlob <OrbitDB>().ParentDB.Root.Guid;
                }
            }
            else
            {
                throw new GuidNotFoundException(bodyGuid);
            }

            if (!_systemDictionary.ContainsKey(rootGuid))
            {
                SystemVM systemVM = SystemVM.Create(this, rootGuid);
                _systems.Add(systemVM);
                _systemDictionary.Add(rootGuid, systemVM);
            }
            return(_systemDictionary[rootGuid]);
        }
Example #2
0
        /// <summary>
        /// Creates and fills out the properties of this ViewModel from the provided entity.
        /// </summary>
        public static SystemVM Create(GameVM gameVM, StarSystem starSystem)
        {
            SystemVM newVM = new SystemVM(gameVM, starSystem);

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

            return(newVM);
        }
Example #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);
        }
Example #4
0
        /// <summary>
        /// Creates and fills out the properties of this ViewModel from the entity with the provided Guid.
        /// </summary>
        /// <exception cref="InvalidOperationException">Cannot create a Planet ViewModel without an initialized game.</exception>
        /// <exception cref="GuidNotFoundException">Thrown when the supplied Guid is not found in the game.</exception>
        internal static StarVM Create(GameVM gameVM, Guid guid, SystemVM systemVM)
        {
            if (gameVM.Game == null)
            {
                throw new InvalidOperationException("Cannot create a StarVM without an initialized game.");
            }

            Entity entity;

            if (!gameVM.Game.GlobalManager.FindEntityByGuid(guid, out entity))
            {
                throw new GuidNotFoundException(guid);
            }

            return(Create(gameVM, entity, systemVM));
        }
Example #5
0
 public void Init(SystemVM systemVM)
 {
     _system       = systemVM;
     _childStars   = new BindingList <StarVM>();
     _childPlanets = new BindingList <PlanetVM>();
     if (Entity.GetDataBlob <OrbitDB>().Parent != null)
     {
         _parentStarGuid = Entity.GetDataBlob <OrbitDB>().Parent.Guid;
     }
     foreach (var childOrbit in Entity.GetDataBlob <OrbitDB>().Children)
     {
         if (childOrbit.HasDataBlob <StarInfoDB>())
         {
             _childStars.Add(_system.GetStar(childOrbit.Guid));
         }
         else if (childOrbit.HasDataBlob <SystemBodyInfoDB>())
         {
             _childPlanets.Add(_system.GetPlanet(childOrbit.Guid));
         }
     }
 }