private static void SetupImport() { BuildingInformation = new BuildingInformationCollection(); /* This is where behavior for each .grid-attribute is being inserted into the dictionary. */ if (!AttributeMethods.ContainsKey(ParentTypes.Person)) { AttributeMethods.Add(ParentTypes.Person, Tuple.Create( new Action(delegate { Target = new PersonInformation(); TargetInformationList = typeof(PersonInformation).GetProperties().ToList(); }), new Func <string, object[]>(value => new object[] { value }), new Action(delegate { ((BuildingInformationCollection)BuildingInformation).PeopleCollection[CurrentPerson++] = (PersonInformation)Target; }))); } if (!AttributeMethods.ContainsKey(ParentTypes.Settings)) { AttributeMethods.Add(ParentTypes.Settings, Tuple.Create( new Action(delegate { Target = BuildingInformation; TargetInformationList = typeof(BuildingInformationCollection).GetProperties().ToList(); }), new Func <string, object[]>(value => new object[] { value }), new Action(delegate { }))); } if (!AttributeMethods.ContainsKey(ParentTypes.People)) { AttributeMethods.Add(ParentTypes.People, AttributeMethods[ParentTypes.Settings]); } if (!AttributeMethods.ContainsKey(ParentTypes.Floor)) { AttributeMethods.Add(ParentTypes.Floor, Tuple.Create( new Action(delegate { Target = new FloorInformation(); TargetInformationList = typeof(FloorInformation).GetProperties().ToList(); }), new Func <string, object[]>(delegate(string value) { return(value.Replace(" ", "").Split(',')); }), new Action(delegate { ((BuildingInformationCollection)BuildingInformation).FloorCollection[CurrentFloor++] = (FloorInformation)Target; }))); } }
internal static void EffectuateFloorPlanSettings(BuildingInformationCollection buildingInformation, ref IFloorPlan floorPlan, ref Dictionary <int, Person> allPeople) { const int freeTypeIntRepresentation = (int)Tile.Types.Free; /* Step 1: Subject the types of each tile to the type of the tile in the BuildingInformationCollection */ for (int z = 0; z < buildingInformation.Floors; z++) { for (int y = 0; y < buildingInformation.Height; y++) { for (int x = 0; x < buildingInformation.Width; x++) { int type = int.Parse(buildingInformation.FloorCollection[z].Rows[y][x].ToString()); /* If the point is already marked as free, continue - no need to force-convert it to free */ if (type == freeTypeIntRepresentation) { continue; } Tile.Types newType = (Tile.Types)type; if (newType == Tile.Types.Person) { PersonInformation personInfo = buildingInformation.PeopleCollection.FirstOrDefault(p => p.Position == Coordinate(x, y, z)); allPeople.Add(personInfo.ID, new Person(personInfo.ID, personInfo.MovementSpeed, floorPlan.Tiles[personInfo.Position] as BuildingBlock)); } floorPlan.Tiles[Coordinate(x, y, z)].Type = newType; } } } }
public IFloorPlan ImportFloorPlan(string fileName) { BuildingInformationCollection buildingInformation = Import.ImportBuilding(fileName); IFloorPlan temporaryFloorPlan = CreateFloorPlan(buildingInformation); Import.EffectuateFloorPlanSettings(buildingInformation, ref temporaryFloorPlan, ref _allPeople); return(temporaryFloorPlan); }
private IFloorPlan CreateFloorPlan(BuildingInformationCollection buildingInformation) { string[] headers = new string[buildingInformation.Floors]; for (int currentFloor = 0; currentFloor < buildingInformation.Floors; currentFloor++) { if (buildingInformation.FloorCollection[currentFloor] == null) { continue; } headers[currentFloor] = buildingInformation.FloorCollection[currentFloor].Header; } return(CreateFloorPlan(buildingInformation.Width, buildingInformation.Height, buildingInformation.Floors, buildingInformation.Description, headers)); }
private IFloorPlan CreateFloorPlan(BuildingInformationCollection buildingInformation) { string[] headers = new string[buildingInformation.Floors]; for (int currentFloor = 0; currentFloor < buildingInformation.Floors; currentFloor++) { if (buildingInformation.FloorCollection[currentFloor] == null) continue; headers[currentFloor] = buildingInformation.FloorCollection[currentFloor].Header; } return CreateFloorPlan(buildingInformation.Width, buildingInformation.Height, buildingInformation.Floors, buildingInformation.Description, headers); }