void HandleGameSettings(NetIncomingMessage message) { DateTime hostDateTime = DateTime.FromBinary(message.ReadInt64()); int len = message.ReadInt32(); byte[] data = message.ReadBytes(len); Game = new Game(); _gameVM.Game = Game; Game.OrderHandler = this; var mStream = new MemoryStream(data); StaticRefLib.GameSettings = SerializationManager.ImportGameSettings(mStream); mStream.Close(); Game.GamePulse.GameGlobalDateTime = hostDateTime; //TODO: #CleanCode: the below should probilby be in refactored to somewhere else. //TODO: #Network: it should also maybe be able to request a dataset from the server if it hasn't got it localy. if (Game.Settings.DataSets != null) { foreach (string dataSet in Game.Settings.DataSets) { StaticDataManager.LoadData(dataSet, Game); } } if (Game.StaticData.LoadedDataSets.Count == 0) { StaticDataManager.LoadData("Pulsar4x", Game); } mStream.Close(); }
public void Init() { _game = new TestGame(); StaticDataManager.LoadData("Pulsar4x", _game.Game); // TODO: Figure out correct directory _entityManager = _game.Game.GlobalManager; // Initialize gas dictionary - haven't found a good way to look up gases without doing this _gasDictionary = new Dictionary <string, AtmosphericGasSD>(); foreach (WeightedValue <AtmosphericGasSD> atmos in _game.Game.StaticData.AtmosphericGases) { _gasDictionary.Add(atmos.Value.ChemicalSymbol, atmos.Value); } _planetsList = new List <Entity>(); _planetsList.Add(_game.Earth); _speciesList = new List <Entity>(); _speciesList.Add(_game.HumanSpecies); //_speciesList.Add(_game.GreyAlienSpecies); // Set up colonies // @todo: add more colonies, especially ones with multiple species in one colony ComponentTemplateSD infrastructureSD = _game.Game.StaticData.ComponentTemplates[new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb")]; ComponentDesigner infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>()); EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesigner.CreateDesign(_game.HumanFaction)); ReCalcProcessor.ReCalcAbilities(_game.EarthColony); }
public void TestIDLookup() { // Create an empty data store: Game game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0 }); var staticDataStore = game.StaticData; // test when the store is empty: object testNullObj = staticDataStore.FindDataObjectUsingID(Guid.NewGuid()); Assert.IsNull(testNullObj); // Load the default static data to test against: StaticDataManager.LoadData("Pulsar4x", game); // test with a guid that is not in the store: object testObj = staticDataStore.FindDataObjectUsingID(Guid.Empty); // empty guid should never be in the store. Assert.IsNull(testObj); // now lets test for values that are in the store: Guid testID = staticDataStore.CargoGoods.GetMinerals().FirstOrDefault().Key; testObj = staticDataStore.FindDataObjectUsingID(testID); Assert.IsNotNull(testObj); Assert.AreEqual(testID, ((MineralSD)testObj).ID); testObj = staticDataStore.FindDataObjectUsingID(testID); Assert.IsNotNull(testObj); testID = staticDataStore.Techs.First().Key; testObj = staticDataStore.FindDataObjectUsingID(testID); Assert.IsNotNull(testObj); Assert.AreEqual(testID, ((TechSD)testObj).ID); }
public void Init() { NewGameSettings settings = new NewGameSettings(); settings.MaxSystems = 5; _game = new Game(settings); StaticDataManager.LoadData("Pulsar4x", _game); _player = _game.AddPlayer("Test Player"); _faction = DefaultStartFactory.DefaultHumans(_game, _player, "Test Faction"); _starSystem = _game.Systems.First <KeyValuePair <Guid, StarSystem> >().Value; _planets = _starSystem.SystemManager.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(); _earth = _planets.Where <Entity>(planet => planet.GetDataBlob <NameDB>().GetName(_faction) == "Earth").First <Entity>(); _ship = _starSystem.SystemManager.GetAllEntitiesWithDataBlob <ShipInfoDB>().First <Entity>(); _shipPropulsionDB = _ship.GetDataBlob <PropulsionDB>(); _target = _ship.Clone(_starSystem.SystemManager); _systems = new List <StarSystem>(); foreach (KeyValuePair <Guid, StarSystem> kvp in _game.Systems) { _systems.Add(kvp.Value); } }
public void TestLoadDefaultData() { Game game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0 }); var staticDataStore = game.StaticData; // store counts for later: int mineralsNum = staticDataStore.CargoGoods.GetMineralsList().Count; int techNum = staticDataStore.Techs.Count; int constructableObjectsNum = staticDataStore.CargoGoods.GetMaterialsList().Count; // check that data was loaded: Assert.IsNotEmpty(staticDataStore.CargoGoods.GetMineralsList()); Assert.IsNotEmpty(staticDataStore.AtmosphericGases); Assert.IsNotEmpty(staticDataStore.CargoGoods.GetMaterialsList()); Assert.IsNotEmpty(staticDataStore.CargoTypes); Assert.IsNotEmpty(staticDataStore.Techs); // now lets re-load the same data, to test that duplicates don't occure as required: StaticDataManager.LoadData("Pulsar4x", game); // now check that overwriting occured and that there were no duplicates: Assert.AreEqual(mineralsNum, staticDataStore.CargoGoods.GetMineralsList().Count); Assert.AreEqual(techNum, staticDataStore.Techs.Count); Assert.AreEqual(constructableObjectsNum, staticDataStore.CargoGoods.GetMaterialsList().Count); // now lets test some malformed data folders. StaticDataLoadException ex = Assert.Throws<StaticDataLoadException>( delegate { StaticDataManager.LoadData("MalformedData", game); }); Assert.That(ex.Message, Is.EqualTo("Error while loading static data: Bad Json provided in directory: MalformedData")); // now ,lets try for a directory that does not exist. Assert.Throws<DirectoryNotFoundException>( delegate { StaticDataManager.LoadData("DoesNotExist", game); }); }
public void Init() { var gameSettings = new NewGameSettings(); gameSettings.MaxSystems = 10; _game = new Game(gameSettings); StaticDataManager.LoadData("Pulsar4x", _game); _entityManager = new EntityManager(_game); }
public void TestOverwriteDefaultData() { Game game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0 }); StaticDataManager.LoadData("Pulsar4x", game); var staticDataStore = game.StaticData; // store counts for later: int mineralsNum = staticDataStore.CargoGoods.GetMineralsList().Count; Guid someGuid = new Guid("08f15d35-ea1d-442f-a2e3-bde04c5c22e9"); string someName = staticDataStore.CargoGoods.GetMineral(someGuid).Name; StaticDataManager.LoadData("Other", game); staticDataStore = game.StaticData; // now check that overwriting occured and that there were no duplicates: Assert.AreEqual(mineralsNum, staticDataStore.CargoGoods.GetMineralsList().Count); //check the name has been overwritten Assert.AreNotEqual(someName, staticDataStore.CargoGoods.GetMineral(someGuid).Name); }
void Start() { if (StaticDataManager.LoadData(Application.dataPath)) { // do something with data } else { StaticDataManager.SetupDefaultData(); } //string locText = localizationDictionary["MyKey"]["en"]; if (PersistentDataManager.LoadData()) { // do something with data } else { PersistentDataManager.CreateDefaultData(); PersistentDataManager.SaveData(); } LoadLocalizationData(); }
public void Init() { var gameSettings = new NewGameSettings(); gameSettings.MaxSystems = 10; _game = new Game(gameSettings); StaticDataManager.LoadData("Pulsar4x", _game); _entityManager = new EntityManager(_game); _faction = FactionFactory.CreateFaction(_game, "Terran"); // Terrian? /*_galaxyFactory = new GalaxyFactory(); * _starSystemFactory = new StarSystemFactory(_galaxyFactory); * * _starSystem = _starSystemFactory.CreateSol(_game);*/// Seems unnecessary for now _gasDictionary = new Dictionary <string, AtmosphericGasSD>(); foreach (WeightedValue <AtmosphericGasSD> atmos in _game.StaticData.AtmosphericGases) { _gasDictionary.Add(atmos.Value.ChemicalSymbol, atmos.Value); } // Create Earth _earthPlanet = setEarthPlanet(); _coldPlanet = setEarthPlanet(); _hotPlanet = setEarthPlanet(); _lowGravPlanet = setEarthPlanet(); _highGravPlanet = setEarthPlanet(); _coldPlanet.GetDataBlob <SystemBodyInfoDB>().BaseTemperature = -20.0f; _hotPlanet.GetDataBlob <SystemBodyInfoDB>().BaseTemperature = 120.0f; _lowGravPlanet.GetDataBlob <SystemBodyInfoDB>().Gravity = 0.05; _highGravPlanet.GetDataBlob <SystemBodyInfoDB>().Gravity = 5.0; _faction = FactionFactory.CreateFaction(_game, "Terran"); _humanSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _exampleSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _lowGravSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _highGravSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _lowTempSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _highTempSpecies = SpeciesFactory.CreateSpeciesHuman(_faction, _entityManager); _humanSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _exampleSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _lowGravSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _highGravSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _lowTempSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _highTempSpecies.GetDataBlob <SpeciesDB>().TemperatureToleranceRange = 20; _lowGravSpecies.GetDataBlob <SpeciesDB>().BaseGravity = 0.4; _lowGravSpecies.GetDataBlob <SpeciesDB>().MaximumGravityConstraint = 0.5; _lowGravSpecies.GetDataBlob <SpeciesDB>().MinimumGravityConstraint = 0.01; _highGravSpecies.GetDataBlob <SpeciesDB>().BaseGravity = 4.0; _highGravSpecies.GetDataBlob <SpeciesDB>().MaximumGravityConstraint = 5.5; _highGravSpecies.GetDataBlob <SpeciesDB>().MinimumGravityConstraint = 4.5; _lowTempSpecies.GetDataBlob <SpeciesDB>().BaseTemperature = -50.0; _lowTempSpecies.GetDataBlob <SpeciesDB>().MaximumTemperatureConstraint = 0.0; _lowTempSpecies.GetDataBlob <SpeciesDB>().MinimumTemperatureConstraint = -100.0; _highTempSpecies.GetDataBlob <SpeciesDB>().BaseTemperature = 200.0; _highTempSpecies.GetDataBlob <SpeciesDB>().MaximumTemperatureConstraint = 300.0; _highTempSpecies.GetDataBlob <SpeciesDB>().MinimumTemperatureConstraint = 100.0; }