public static void SaveUnit(SavedUnitFC unit) { if (Scribe.mode != LoadSaveMode.Inactive) { throw new Exception("Empire - Attempt to save unit while scribe is active"); } string path = GetUnitPath(unit.name); try { Scribe.saver.InitSaving(path, "unit"); int version = 0; Scribe_Values.Look(ref version, "version"); unit.ExposeData(); } catch (Exception e) { Log.Error($"Failed to save unit {unit.name} {e}"); } finally { Scribe.saver.FinalizeSaving(); } savedUnits.RemoveAll(u => u.name == unit.name); savedUnits.Add(unit); }
public static void Read() { if (Scribe.mode != LoadSaveMode.Inactive) { throw new Exception("Empire - Attempt to load saved military while scribe is active"); } savedSquads.Clear(); savedUnits.Clear(); foreach (string path in Directory.EnumerateFiles(EmpireMilitarySquadFolder)) { try { SavedSquadFC squad = new SavedSquadFC(); Scribe.loader.InitLoading(path); squad.ExposeData(); savedSquads.Add(squad); } catch (Exception e) { Log.Error("Failed to load squad at path " + path); } finally { Scribe.loader.FinalizeLoading(); } } foreach (string path in Directory.EnumerateFiles(EmpireMilitaryUnitFolder)) { try { SavedUnitFC unit = new SavedUnitFC(); Scribe.loader.InitLoading(path); unit.ExposeData(); savedUnits.Add(unit); } catch (Exception e) { Log.Error("Failed to load unit at path " + path); } finally { Scribe.loader.FinalizeLoading(); } } }
public static void RemoveUnit(SavedUnitFC unit) { savedUnits.Remove(unit); File.Delete(GetUnitPath(unit.name)); }