public int CreateEntity(string entityName, Dictionary <string, string> otherParameters) { var newEntityId = GetNewEntityId(); Dictionary <string, string> allParameters; List <Trait> allTraits; if (otherParameters.ContainsKey("Material")) { allParameters = CombineParameterDictionaries(otherParameters, ECSDatabase.GetComponentData(entityName, otherParameters["Material"])); allTraits = ECSDatabase.GetTraitData(entityName, otherParameters["Material"]); } else { allParameters = CombineParameterDictionaries(otherParameters, ECSDatabase.GetComponentData(entityName)); allTraits = ECSDatabase.GetTraitData(entityName); } GenerateComponents(newEntityId, allParameters, allTraits); GameEvents.CreateEntityEvent.NewCreateEntityEvent(newEntityId); return(newEntityId); }
public int GenerateLevel(string levelName) { var levelEntityId = GetNewEntityId(); var levelDetails = Levels.LevelData.LevelDatabase.GetLevelData(levelName); var tileDictionary = new Dictionary <int, int>(); foreach (KeyValuePair <int, string> kvp in levelDetails.TileDictionary) { var componentData = ECSDatabase.GetComponentData(kvp.Value); var traitData = ECSDatabase.GetTraitData(kvp.Value); var tileEntityId = GetNewEntityId(); GenerateComponents(tileEntityId, componentData, traitData); tileDictionary[kvp.Key] = tileEntityId; } for (int i = 0; i < levelDetails.TileGrid.Length; i++) { levelDetails.TileGrid[i] = tileDictionary[levelDetails.TileGrid[i]]; } var mapComponent = new MapComponent(levelEntityId, levelDetails); AddComponent(levelEntityId, mapComponent); // TODO: Add all the other entities here. // TODO: Figure out where to put the Create Level Event. return(levelEntityId); }
public int CreateEntity(string entityName, Dictionary <string, string> otherParameters) { var newEntityId = GetNewEntityId(); Dictionary <string, string> allParameters; List <Trait> allTraits; if (otherParameters.ContainsKey("Material")) { allParameters = CombineParameterDictionaries(otherParameters, ECSDatabase.GetComponentData(entityName, otherParameters["Material"])); allTraits = ECSDatabase.GetTraitData(entityName, otherParameters["Material"]); } else { allParameters = CombineParameterDictionaries(otherParameters, ECSDatabase.GetComponentData(entityName)); allTraits = ECSDatabase.GetTraitData(entityName); } if (allParameters.ContainsKey("BackgroundComponent")) { var component = new BackgroundComponent(newEntityId, allParameters); AddComponent(newEntityId, component); } if (allParameters.ContainsKey("ForegroundComponent")) { var component = new ForegroundComponent(newEntityId, allParameters); AddComponent(newEntityId, component); } if (allParameters.ContainsKey("MapComponent")) { var component = new MapComponent(newEntityId, allParameters); AddComponent(newEntityId, component); } if (allParameters.ContainsKey("PositionComponent")) { var component = new PositionComponent(newEntityId, allParameters); AddComponent(newEntityId, component); } // TODO: Setup all the components here. foreach (Trait trait in allTraits) { AddTrait(newEntityId, trait); } GameEvents.CreateEntityEvent.NewCreateEntityEvent(newEntityId); return(newEntityId); }
public void TestComponentDatabaseErrorHandling() { // Intentionally not testing the bad file formats, since I don't think it's worth adding to the project for it. ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); ErrorLogger.SetToTest(); var badEntityData = ECSDatabase.GetComponentData("Not an Entity!!!"); Assert.AreEqual(0, badEntityData.Count); Assert.AreEqual("Couldn't find entity Not an Entity!!! in data file", ErrorLogger.GetNextMessage()); }
public void TestForegroundComponentData() { ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); var entity1Data = ECSDatabase.GetComponentData("TestEntity1"); Assert.IsTrue(entity1Data.ContainsKey("ForegroundComponent")); Assert.AreEqual("Orange", entity1Data["ForegroundColor"]); Assert.AreEqual("g", entity1Data["Symbol"]); Assert.AreEqual("Actor", entity1Data["ForegroundDisplayLayer"]); var entity2Data = ECSDatabase.GetComponentData("TestEntity3"); Assert.IsTrue(entity2Data.ContainsKey("ForegroundComponent")); Assert.AreEqual("#", entity2Data["Symbol"]); Assert.AreEqual("Furnishing", entity2Data["ForegroundDisplayLayer"]); }
public void TestBackgroundComponentData() { ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); var entity1Data = ECSDatabase.GetComponentData("TestEntity4"); Assert.IsTrue(entity1Data.ContainsKey("BackgroundComponent")); Assert.AreEqual("Grey", entity1Data["BackgroundColor"]); Assert.AreEqual("DarkGrey", entity1Data["FogColor"]); Assert.AreEqual("Tile", entity1Data["BackgroundDisplayLayer"]); var entity2Data = ECSDatabase.GetComponentData("TestEntity5"); Assert.IsTrue(entity2Data.ContainsKey("BackgroundComponent")); Assert.AreEqual("Blue", entity2Data["BackgroundColor"]); Assert.AreEqual("DarkBlue", entity2Data["FogColor"]); Assert.AreEqual("Tile", entity2Data["BackgroundDisplayLayer"]); }
public void TestTraitData() { ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); var entity1Traits = ECSDatabase.GetTraitData("TestEntity1"); Assert.IsTrue(entity1Traits.Contains(Components.Trait.BlockMove)); Assert.IsFalse(entity1Traits.Contains(Components.Trait.BlockLOS)); var entity2Traits = ECSDatabase.GetTraitData("TestEntity3", "TestMaterial1"); Assert.IsTrue(entity2Traits.Contains(Components.Trait.BlockLOS)); Assert.IsTrue(entity2Traits.Contains(Components.Trait.BlockMove)); Assert.IsTrue(entity2Traits.Contains(Components.Trait.Wood)); var entity3Traits = ECSDatabase.GetTraitData("TestEntity4"); Assert.AreEqual(0, entity3Traits.Count); }
public void TestComponentTypes() { ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); var entity1Data = ECSDatabase.GetComponentData("TestEntity1"); Assert.IsTrue(entity1Data.ContainsKey("ForegroundComponent")); Assert.IsTrue(entity1Data.ContainsKey("PositionComponent")); Assert.IsFalse(entity1Data.ContainsKey("BackgroundComponent")); var entity2data = ECSDatabase.GetComponentData("TestEntity3", "TestMaterial1"); Assert.IsTrue(entity2data.ContainsKey("ForegroundComponent")); Assert.IsTrue(entity2data.ContainsKey("PositionComponent")); Assert.IsFalse(entity2data.ContainsKey("BackgroundComponent")); var entity3Data = ECSDatabase.GetComponentData("TestEntity4"); Assert.IsTrue(entity3Data.ContainsKey("BackgroundComponent")); Assert.IsFalse(entity3Data.ContainsKey("ForegroundComponent")); Assert.IsFalse(entity3Data.ContainsKey("PositionComponent")); }
public void TestReadData() { ECSDatabase.SetParentFolder(TestContext.CurrentContext.TestDirectory); var data = ECSDatabase.GetComponentData("TestEntity1"); }