Exemplo n.º 1
0
        public void CreateNewColony()
        {
            Entity            faction = FactionFactory.CreateFaction(_game, "Terran");
            StarSystemFactory sysfac  = new StarSystemFactory(_game);
            StarSystem        sol     = sysfac.CreateSol(_game);
            //Entity starSystem = Entity.Create(_game.GlobalManager);
            //Entity planet = Entity.Create(starSystem.Manager, new List<BaseDataBlob>());
            List <Entity> solBodies         = sol.SystemManager.GetAllEntitiesWithDataBlob <NameDB>(_smAuthToken);
            Entity        planet            = solBodies.Find(item => item.GetDataBlob <NameDB>().DefaultName == "Earth");
            Entity        species           = SpeciesFactory.CreateSpeciesHuman(faction, _game.GlobalManager);
            var           requiredDataBlobs = new List <Type>()
            {
                typeof(ColonyInfoDB),
                typeof(NameDB),
                typeof(InstallationsDB)
            };

            //Entity colony = ColonyFactory.CreateColony(faction, planet);
            ColonyFactory.CreateColony(faction, species, planet);
            Entity       colony       = faction.GetDataBlob <FactionInfoDB>().Colonies[0];
            ColonyInfoDB colonyInfoDB = colony.GetDataBlob <ColonyInfoDB>();

            //NameDB nameDB = colony.GetDataBlob<NameDB>();

            //Assert.IsTrue(HasAllRequiredDatablobs(colony, requiredDataBlobs), "Colony Entity doesn't contains all required datablobs");
            Assert.IsTrue(colonyInfoDB.PlanetEntity == planet, "ColonyInfoDB.PlanetEntity refs to wrong entity");
        }
Exemplo n.º 2
0
        public void GetDataBlobByEntity()
        {
            Entity testEntity = PopulateEntityManager();

            // Get the Population DB of a specific entity.
            ColonyInfoDB popDB = testEntity.GetDataBlob <ColonyInfoDB>();

            Assert.IsNotNull(popDB);

            // get a DB we know the entity does not have:
            AtmosphereDB atmoDB = testEntity.GetDataBlob <AtmosphereDB>();

            Assert.IsNull(atmoDB);

            // test with invalid data blob type
            Assert.Catch(typeof(KeyNotFoundException), () =>
            {
                testEntity.GetDataBlob <BaseDataBlob>();
            });

            // and again for the second lookup type:
            // Get the Population DB of a specific entity.
            int typeIndex = EntityManager.GetTypeIndex <ColonyInfoDB>();

            popDB = testEntity.GetDataBlob <ColonyInfoDB>(typeIndex);
            Assert.IsNotNull(popDB);

            // get a DB we know the entity does not have:
            typeIndex = EntityManager.GetTypeIndex <AtmosphereDB>();
            atmoDB    = testEntity.GetDataBlob <AtmosphereDB>(typeIndex);
            Assert.IsNull(atmoDB);

            // test with invalid type index:
            Assert.Catch(typeof(ArgumentOutOfRangeException), () =>
            {
                testEntity.GetDataBlob <AtmosphereDB>(-42);
            });

            // test with invalid T vs type at typeIndex
            typeIndex = EntityManager.GetTypeIndex <ColonyInfoDB>();
            Assert.Catch(typeof(InvalidCastException), () =>
            {
                testEntity.GetDataBlob <SystemBodyInfoDB>(typeIndex);
            });
        }
Exemplo n.º 3
0
        internal override void Display()
        {
            ImGui.SetNextWindowSize(new Vector2(400, 400), ImGuiCond.Once);
            if (IsActive == true && ImGui.Begin("Planetary window: " + _lookedAtEntity.Name, ref IsActive, _flags))
            {
                if (ImGui.SmallButton("general info"))
                {
                    _selectedSubWindow = PlanetarySubWindows.generalInfo;
                }
                ImGui.SameLine();
                if (ImGui.SmallButton("installations"))
                {
                    _selectedSubWindow = PlanetarySubWindows.installations;
                }
                ImGui.BeginChild("data");
                switch (_selectedSubWindow)
                {
                case PlanetarySubWindows.generalInfo:
                    if (_lookedAtEntity.Entity.HasDataBlob <MassVolumeDB>())
                    {
                        var tempMassVolume = _lookedAtEntity.Entity.GetDataBlob <MassVolumeDB>();
                        ImGui.Text("radius: " + Stringify.Distance(tempMassVolume.RadiusInM));
                        ImGui.Text("mass: " + tempMassVolume.MassDry.ToString() + " kg");
                        ImGui.Text("volume: " + tempMassVolume.Volume_m3.ToString() + " m^3");
                        ImGui.Text("density: " + tempMassVolume.Density_gcm + " kg/m^3");
                    }
                    if (_lookedAtEntity.Entity.HasDataBlob <ColonyInfoDB>())
                    {
                        ColonyInfoDB tempColonyInfo = _lookedAtEntity.Entity.GetDataBlob <ColonyInfoDB>();
                        ImGui.Text("populations: ");
                        foreach (var popPerSpecies in tempColonyInfo.Population)
                        {
                            ImGui.Text(popPerSpecies.Value.ToString() + " of species: ");
                            ImGui.SameLine();
                            if (popPerSpecies.Key.HasDataBlob <NameDB>())
                            {
                                ImGui.Text(popPerSpecies.Key.GetDataBlob <NameDB>().DefaultName);
                            }
                            else
                            {
                                ImGui.Text("unknown.");
                            }
                        }
                    }
                    if (_lookedAtEntity.Entity.HasDataBlob <InstallationsDB>())
                    {
                        InstallationsDB tempInstallations = _lookedAtEntity.Entity.GetDataBlob <InstallationsDB>();
                    }


                    break;

                case PlanetarySubWindows.installations:
                    break;

                default:
                    break;
                }
                ImGui.EndChild();
                ImGui.End();
            }
        }