-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMapCompSaveHandler.cs
More file actions
94 lines (82 loc) · 3.85 KB
/
MapCompSaveHandler.cs
File metadata and controls
94 lines (82 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace TechAdvancing
{
public class MapCompSaveHandler : MapComponent
{
#if DEBUG
const bool IS_DEBUG = true;
#else
const bool IS_DEBUG = false;
#endif
public MapCompSaveHandler(Map map) : base(map)
{
}
public static Dictionary<string, int> Configvalues = new Dictionary<string, int>();
internal static List<string> GetConfigValueNames => Configvalues.Keys.ToList();
/// <summary>
/// Stores all the pawns that joined along with their old Faction
/// </summary>
public static Dictionary<Pawn, Faction> ColonyPeople = new Dictionary<Pawn, Faction>(); //pawn , ORIGINAL faction
public static bool IsValueSaved(string key) { return Configvalues.ContainsKey(key); }
public static void RemoveConfigValue(string key) { Configvalues.Remove(key); }
public static void TA_ExposeData(string key, ref int value, TA_Expose_Mode mode = TA_Expose_Mode.Load)
{
if (mode == TA_Expose_Mode.Save)
{
LogOutput.WriteLogMessage(Errorlevel.Debug, "Adding " + key + " : " + value + "to save dictionary");
if (Configvalues.ContainsKey(key))
{
Configvalues.Remove(key);
}
Configvalues.Add(key, value);
}
else if (mode == TA_Expose_Mode.Load)
{
if (Configvalues.TryGetValue(key, out int tempval))
{
value = tempval;
}
else if (Configvalues.TryGetValue(Enum.GetNames(typeof(TA_Expose_Name)).Contains(key) ? ((int)Enum.Parse(typeof(TA_Expose_Name), key)).ToString() : key, out tempval)) // TODO remove backwards compatability fallback
{
value = tempval;
LogOutput.WriteLogMessage(Errorlevel.Information, "Value " + key + " was loaded via fallback. (A new save system is in place. But this message shouldnt appear anymore after saving)");
}
else
{
LogOutput.WriteLogMessage(Errorlevel.Information, "Value " + key + " could not be loaded. This usually happens when updating to the new config-system. Try saving and reloading the map.");
}
LogOutput.WriteLogMessage(Errorlevel.Debug, "Successfully loaded " + key + " : " + value + "from save dictionary.");
}
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Collections.Look(ref Configvalues, "TA_Expose_Numbers", LookMode.Value, LookMode.Value);
int isPplDictSaved = 1;
//LogOutput.WriteLogMessage(Errorlevel.Information, "val:" + isPplDictSaved.ToString());
Scribe_Values.Look(ref isPplDictSaved, "TA_Expose_People_isSaved", -1, true);
//LogOutput.WriteLogMessage(Errorlevel.Information, "val:" + isPplDictSaved.ToString());
if (ColonyPeople != null)
{
ColonyPeople.RemoveAll(x => x.Key == null);
}
if (isPplDictSaved == 1)
{
var l1 = new List<Pawn>();
var l2 = new List<Faction>();
Scribe_Collections.Look(ref ColonyPeople, "TA_Expose_People", LookMode.Reference, LookMode.Reference, ref l1, ref l2,
logNullErrors: IS_DEBUG, saveDestroyedKeys: false, saveDestroyedValues: false);
//LogOutput.WriteLogMessage(Errorlevel.Information, "Read TA_ExposePeople");
}
//TechAdvancing_Config_Tab.ExposeData(TA_Expose_Mode.Load);
if (ColonyPeople == null)
{
ColonyPeople = new Dictionary<Pawn, Faction>();
}
}
}
}