/// <summary> /// Serializes building pack settings to XML. /// </summary> /// <param name="existingList">Existing list to modify, from population pack serialization (null if none)</param> /// <returns>New sorted list with building pack settings</returns> internal SortedList <string, BuildingRecord> SerializeBuildings(SortedList <string, BuildingRecord> existingList) { // Return list. SortedList <string, BuildingRecord> returnList = existingList ?? new SortedList <string, BuildingRecord>(); // Iterate through each key (BuildingInfo) in our dictionary and serialise it into a BuildingRecord. foreach (string prefabName in buildingDict.Keys) { string packName = buildingDict[prefabName]?.name; // Check to see if our existing list already contains this building. if (returnList.ContainsKey(prefabName)) { // Yes; update that record to include this floor pack. returnList[prefabName].schoolPack = packName; } else { // No; add a new record with this floor pack. BuildingRecord newRecord = new BuildingRecord { prefab = prefabName, schoolPack = packName }; returnList.Add(prefabName, newRecord); } } return(returnList); }
/// <summary> /// Deserializes a provided building record list. /// </summary> /// <param name="recordList">List to deserialize</param> internal void DeserializeBuildings(List <BuildingRecord> recordList) { // Iterate through each record in list. for (int i = 0; i < recordList.Count; ++i) { BuildingRecord buildingRecord = recordList[i]; // Get relevant pack (pop or floor) name. string packName = BuildingPack(buildingRecord); // Safety first! if (buildingRecord.prefab.IsNullOrWhiteSpace() || packName.IsNullOrWhiteSpace()) { continue; } // Find target preset. DataPack calcPack = calcPacks?.Find(pack => (pack?.name != null && pack.name.Equals(packName))); if (calcPack?.name == null) { Logging.Error("Couldn't find calculation pack ", packName, " for ", buildingRecord.prefab); continue; } // Add building to our dictionary. buildingDict.Add(buildingRecord.prefab, calcPack); } }
/// <summary> /// Deserializes a provided building record list. /// </summary> /// <param name="recordList">List to deserialize</param> internal void DeserializeBuildings(List <BuildingRecord> recordList) { // Iterate through each record in list. for (int i = 0; i < recordList.Count; ++i) { BuildingRecord buildingRecord = recordList[i]; // Get multiplier. float multiplier = buildingRecord.multiplier; // Ignore invalid or default records. if (buildingRecord.prefab.IsNullOrWhiteSpace() || multiplier <= 1.0f) { continue; } // Add building to our dictionary. buildingDict.Add(buildingRecord.prefab, multiplier); } }
/// <summary> /// Extracts the relevant school pack name from a building line record. /// </summary> /// <param name="buildingRecord">Building record to extract from</param> /// <returns>School pack name (if any)</returns> protected override string BuildingPack(BuildingRecord buildingRecord) => buildingRecord.schoolPack;
protected abstract string BuildingPack(BuildingRecord buildingRecord);
/// <summary> /// Extracts the relevant pack name (floor or pop pack) from a building line record. /// </summary> /// <param name="buildingRecord">Building record to extract from</param> /// <returns>Floor pack name (if any)</returns> protected override string BuildingPack(BuildingRecord buildingRecord) => buildingRecord.floorPack;