public static void LoadBuildings(GenericReader reader) { try { m_BuildingTable = new Dictionary<string,BuildingEntry>(); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { string name = reader.ReadString(); int type = reader.ReadInt(); switch (type) { case 0: m_BuildingTable[name] = new BuildingEntry(reader, type); break; case 1: m_BuildingTable[name] = new ComponentEntry(reader); break; case 2: m_BuildingTable[name] = new AddonEntry(reader); break; } } } catch (Exception err) { m_BuildingTable.Clear(); Console.WriteLine(err.ToString()); } }
public static bool ImportBuilding(string filename) { bool finished = false; string binpath = Path.Combine(BaseBuilding.SavePath, filename + ".bin"); if (File.Exists(binpath)) { using (FileStream bin = CustomSaving.GetFileStream(binpath)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); try { int count = reader.ReadInt(); for (int i = 0; i < count; i++) { string name = reader.ReadString(); int type = reader.ReadInt(); switch (type) { case 0: m_BuildingTable[name] = new BuildingEntry(reader, type); break; case 1: m_BuildingTable[name] = new ComponentEntry(reader); break; case 2: m_BuildingTable[name] = new AddonEntry(reader); break; } } finished = true; } catch (Exception error) { Console.WriteLine(error.ToString()); } finally { reader.Close(); } } } return finished; }