示例#1
0
        internal void SetFactionData()
        {
            if (CurrentFaction == null)
            {
                throw new Exception("CurrentFaction is null");
            }
            else
            {
                _visibleFactions = new List <Guid>();
                foreach (var knownFaction in _currentFaction.GetDataBlob <FactionInfoDB>().KnownFactions)
                {
                    _visibleFactions.Add(knownFaction.Guid);
                }
                _systems.Clear();
                _systemDictionary.Clear();
                foreach (var knownsystem in _currentFaction.GetDataBlob <FactionInfoDB>().KnownSystems)
                {
                    SystemVM systemVM = SystemVM.Create(this, knownsystem);
                    _systems.Add(systemVM);
                    _systemDictionary.Add(systemVM.ID, systemVM);
                }

                Colonys.Clear();
                foreach (var colonyEntity in _currentFaction.GetDataBlob <FactionInfoDB>().Colonies)
                {
                    Colonys.Add(colonyEntity.Guid, colonyEntity.GetDataBlob <NameDB>().GetName(_currentFaction));
                }
                Colonys.SelectedIndex = 0;
            }
        }
示例#2
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]);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Creates and fills out the properties of this ViewModel from the entity with the provided ID.
        /// </summary>
        /// <exception cref="InvalidOperationException">Cannot create a Planet ViewModel without an initialized game.</exception>
        /// <exception cref="GuidNotFoundException">Thrown when the supplied ID 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));
        }
示例#6
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));
         }
     }
 }