2using System.Collections.Generic;
3using System.ComponentModel;
10[JsonObject(MemberSerialization.OptOut)]
13 public static Dictionary<string, ReligionCustom> managed =
new Dictionary<string, ReligionCustom>();
15 public List<string> artifacts =
new List<string>();
18 public bool canJoin =
true;
20 public bool isMinorGod;
24 public bool noPunishTakeover;
26 public List<string> elements =
new List<string>();
28 public List<string> godAbilities =
new List<string>();
30 public Dictionary<string, int> offeringMtp =
new Dictionary<string, int>();
32 public Dictionary<string, string> offeringValue =
new Dictionary<string, string>();
34 public override string SourceType =>
"SourceReligion";
38 string text = r.id.Split(
'#')[0];
41 owner = ModUtil.FindSourceRowPackage(r);
43 CustomReligionContent obj =
new CustomReligionContent
45 ContentId =
"Religion/" + text,
48 canJoin = (!r.id.Contains(
"#noJoin") && !r.id.Contains(
"#cannot")),
49 isMinorGod = r.id.Contains(
"#minor")
57 obj.RegisterCustomReligion();
61 public void RegisterCustomReligion(
ReligionCustom religionCustom =
null)
63 Dictionary<string, ReligionCustom> dictionary = managed;
64 string sourceId = base.SourceId;
67 dictionary[sourceId] = obj;
68 religionCustom2.content =
this;
71 public static void Init()
73 (FileInfo, EMod)[] filesEx = PackageIterator.GetFilesEx(
"Data/religion_data.json");
74 for (
int i = 0; i < filesEx.Length; i++)
76 var (fileInfo, package) = filesEx[i];
79 foreach (var (key, customReligionContent2) in
IO.LoadFile<Dictionary<string, CustomReligionContent>>(fileInfo.FullName))
81 if (managed.TryGetValue(key, out var value))
83 value.content.canJoin = customReligionContent2.canJoin;
84 value.content.isMinorGod = customReligionContent2.isMinorGod;
85 value.content.noPunish = customReligionContent2.noPunish;
86 value.content.noPunishTakeover = customReligionContent2.noPunishTakeover;
87 value.content.artifacts = customReligionContent2.artifacts;
88 value.content.elements = customReligionContent2.elements;
89 value.content.offeringMtp = customReligionContent2.offeringMtp;
90 value.content.offeringValue = customReligionContent2.offeringValue;
91 value.content.godAbilities = customReligionContent2.godAbilities;
97 ModUtil.LogModError(
"exception while loading religion data '" + fileInfo.ShortPath() +
"'\n" + ex.Message, package);
98 Debug.LogException(ex);
101 LoadDeprecatedCwlSpec();
102 static void LoadDeprecatedCwlSpec()
106 if (row.HasTag(
CTAG.godArtifact))
109 if (religionCustom !=
null && !religionCustom.
content.artifacts.Contains(row.id))
111 religionCustom.
content.artifacts.Add(row.id);
117 if (row2.tag.Contains(
"godAbility"))
120 if (religionCustom2 !=
null && !religionCustom2.
content.godAbilities.Contains(row2.alias))
122 religionCustom2.
content.godAbilities.Add(row2.alias);
126 (FileInfo, EMod)[] filesEx2 = PackageIterator.GetFilesEx(
"Data/religion_elements.json");
128 for (
int num = 0; num < filesEx2.Length; num++)
130 var (fileInfo2, package2) = filesEx2[num];
133 foreach (KeyValuePair<
string, List<string>>
item in IO.LoadFile<Dictionary<
string, List<string>>>(fileInfo2.FullName))
135 item.Deconstruct(out key2, out var value2);
137 List<string> collection = value2;
138 if (managed.TryGetValue(key3, out var value3))
140 value3.content.elements.AddRange(collection);
144 catch (Exception ex2)
146 ModUtil.LogModError(
"exception while loading '" + fileInfo2.ShortPath() +
"'\n" + ex2.Message, package2);
147 Debug.LogException(ex2);
150 filesEx2 = PackageIterator.GetFilesEx(
"Data/religion_offerings.json");
151 for (
int num = 0; num < filesEx2.Length; num++)
153 var (fileInfo3, package3) = filesEx2[num];
156 foreach (KeyValuePair<
string, Dictionary<string, int>> item2
in IO.LoadFile<Dictionary<
string, Dictionary<string, int>>>(fileInfo3.FullName))
158 item2.Deconstruct(out key2, out var value4);
160 Dictionary<string, int>
other = value4;
161 if (managed.TryGetValue(key4, out var value5))
163 value5.content.offeringMtp.Merge(
other);
167 catch (Exception ex3)
169 ModUtil.LogModError(
"exception while loading '" + fileInfo3.ShortPath() +
"'\n" + ex3.Message, package3);
170 Debug.LogException(ex3);
176 public static List<ReligionCustom> GetCustomReligions()
178 List<ReligionCustom> list =
new List<ReligionCustom>();
183 value.relation = value.
source.relation;
185 Debug.Log(
$"#mod-content {value.content}");
191 internal static void LoadReligionData(GameIOContext context)
193 if (!context.Load<Dictionary<string, ReligionCustom>>(
"custom_religion_data", out var data))
197 foreach (var (key, religionCustom2) in data)
201 Debug.Log(
"#mod-content loading Religion/" + value.id);
202 value.mood = religionCustom2.
mood;
203 value.relation = religionCustom2.
relation;
204 value.giftRank = religionCustom2.
giftRank;
209 internal static void SaveReligionData(GameIOContext context)
211 Dictionary<string, ReligionCustom> data =
null;
214 context.Load<Dictionary<string, ReligionCustom>>(
"custom_religion_data", out data);
218 Debug.LogWarning(
"#mod-content rebuilding corrupted religion data chunk\n" + ex.Message);
222 data =
new Dictionary<string, ReligionCustom>();
230 context.SaveUncompressed(
"custom_religion_data", data);
234 public override string ToString()
236 StringBuilder stringBuilder =
new StringBuilder();
237 stringBuilder.AppendLine(
$"{base.ContentId}/canJoin={canJoin}/minorGod={isMinorGod}");
238 if (artifacts.Count > 0)
240 stringBuilder.AppendLine(
$" - artifacts({artifacts.Count})/{string.Join(';', artifacts)}");
242 if (elements.Count > 0)
244 stringBuilder.AppendLine(
$" - elements({elements.Count})/{string.Join(';', elements)}");
246 if (offeringMtp.Count > 0)
248 stringBuilder.AppendLine(
$" - offeringMtp({offeringMtp.Count})/{string.Join(';', offeringMtp.Select((KeyValuePair<string, int> kv) => $"{kv.Key}={kv.Value}
"))}");
250 if (offeringValue.Count > 0)
252 stringBuilder.AppendLine(
string.Format(
" - offeringValue({0})/{1}", offeringValue.Count,
string.Join(
';', offeringValue.Select((KeyValuePair<string, string> kv) => kv.Key +
"=" + kv.Value))));
254 if (godAbilities.Count > 0)
256 stringBuilder.AppendLine(
$" - godAbilities({godAbilities.Count})/{string.Join(';', godAbilities)}");
258 return stringBuilder.ToString();
static SourceManager sources
ReligionManager religions
void Add(FileInfo fi, string path=null, string prefix="")
Dictionary< string, ModItem< T > > dict
static ModItemList< Sprite > modPortraits
static HashSet< string > allIds
CustomReligionContent content
Dictionary< string, Religion > dictAll
SourceReligion.Row source
static Dictionary< string, string > dictModItems