示例#1
0
        /// <summary>
        /// Parse raw string data from the .yaml into a collection of Buildings
        /// </summary>
        /// <param name="unparsedBuildingData"></param>
        /// <returns></returns>
        private List <Building> ParseBuildingData(List <string> unparsedBuildingData)
        {
            List <Building> parsedBuildings = new List <Building>();

            BuildingParameters buildingInformation = CreateNewDataHolder();

            foreach (string buildingData in unparsedBuildingData)
            {
                string[] data = buildingData.Split(':');

                switch (data[0].TrimStart(new char[] { ' ', '-' }))
                {
                case "id":
                    if (data[1].TrimStart(new char[] { ' ' }).Equals("joulesAvailable"))
                    {
                        break;
                    }
                    EntityID id = (EntityID)Enum.Parse(typeof(EntityID), data[1]);
                    if (id != EntityID.FieldRation)
                    {
                        buildingInformation.ID = id;
                    }
                    break;

                case "temperature":
                    break;

                case "location_x":
                    buildingInformation.Location.X = int.Parse(data[1]);
                    break;

                case "location_y":
                    buildingInformation.Location.Y = int.Parse(data[1]);
                    break;

                case "rotationOrientation":
                    string rotation = data[1].Substring(2);
                    buildingInformation.Rotation = int.Parse(rotation);
                    break;

                case "storage":
                case "rottable":
                case "amounts":
                    break;

                case "connections":
                    buildingInformation.Connection = (Connection)int.Parse(data[1]);
                    break;

                case "other_values":
                    if (buildingInformation.ID != EntityID.None)
                    {
                        //assume complete object, add and create new holder
                        parsedBuildings.Add(BuildingFactory.CreateNew(buildingInformation));
                        buildingInformation = CreateNewDataHolder();
                    }
                    break;

                default:
                    break;
                }
            }

            return(parsedBuildings);
        }