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";
36 public string ChunkName =>
"custom_religion_" + base.SourceId;
40 string text = r.id.Split(
'#')[0];
43 owner = ModUtil.FindSourceRowPackage(r);
45 CustomReligionContent obj =
new CustomReligionContent
47 ContentId =
"Religion/" + text,
50 canJoin = (!r.id.Contains(
"#noJoin") && !r.id.Contains(
"#cannot")),
51 isMinorGod = r.id.Contains(
"#minor")
58 obj.RegisterCustomReligion();
62 public void RegisterCustomReligion(
ReligionCustom religionCustom =
null)
64 Dictionary<string, ReligionCustom> dictionary = managed;
65 string sourceId = base.SourceId;
68 dictionary[sourceId] = obj;
69 religionCustom2.content =
this;
72 public static void Init()
74 (FileInfo, EMod)[] filesEx = PackageIterator.GetFilesEx(
"Data/religion_data.json");
75 for (
int i = 0; i < filesEx.Length; i++)
77 var (fileInfo, package) = filesEx[i];
80 foreach (var (key, customReligionContent2) in
IO.LoadFile<Dictionary<string, CustomReligionContent>>(fileInfo.FullName))
82 if (managed.TryGetValue(key, out var value))
84 value.content.canJoin = customReligionContent2.canJoin;
85 value.content.isMinorGod = customReligionContent2.isMinorGod;
86 value.content.artifacts = customReligionContent2.artifacts;
87 value.content.offeringMtp = customReligionContent2.offeringMtp;
88 value.content.offeringValue = customReligionContent2.offeringValue;
89 value.content.godAbilities = customReligionContent2.godAbilities;
95 ModUtil.LogModError(
"exception while loading religion data '" + fileInfo.ShortPath() +
"'\n" + ex.Message, package);
96 Debug.LogException(ex);
99 LoadDeprecatedCwlSpec();
100 static void LoadDeprecatedCwlSpec()
104 if (row2.HasTag(
CTAG.godArtifact))
106 managed.Values.FirstOrDefault((
ReligionCustom r) => row2.tag.Contains(r.
id))?.content.artifacts.Add(row2.id);
111 if (row.tag.Contains(
"godAbility"))
113 managed.Values.FirstOrDefault((
ReligionCustom r) => row.tag.Contains(r.
id))?.content.godAbilities.Add(row.alias);
116 (FileInfo, EMod)[] filesEx2 = PackageIterator.GetFilesEx(
"Data/religion_elements.json");
118 for (
int j = 0; j < filesEx2.Length; j++)
120 var (fileInfo2, package2) = filesEx2[j];
123 foreach (KeyValuePair<
string, List<string>>
item in IO.LoadFile<Dictionary<
string, List<string>>>(fileInfo2.FullName))
125 item.Deconstruct(out key2, out var value2);
127 List<string> collection = value2;
128 if (managed.TryGetValue(key3, out var value3))
130 value3.content.elements.AddRange(collection);
134 catch (Exception ex2)
136 ModUtil.LogModError(
"exception while loading '" + fileInfo2.ShortPath() +
"'\n" + ex2.Message, package2);
137 Debug.LogException(ex2);
140 filesEx2 = PackageIterator.GetFilesEx(
"Data/religion_offerings.json");
141 for (
int j = 0; j < filesEx2.Length; j++)
143 var (fileInfo3, package3) = filesEx2[j];
146 foreach (KeyValuePair<
string, Dictionary<string, int>> item2
in IO.LoadFile<Dictionary<
string, Dictionary<string, int>>>(fileInfo3.FullName))
148 item2.Deconstruct(out key2, out var value4);
150 Dictionary<string, int>
other = value4;
151 if (managed.TryGetValue(key4, out var value5))
153 value5.content.offeringMtp.Merge(
other);
157 catch (Exception ex3)
159 ModUtil.LogModError(
"exception while loading '" + fileInfo3.ShortPath() +
"'\n" + ex3.Message, package3);
160 Debug.LogException(ex3);
166 public static List<ReligionCustom> GetCustomReligions()
168 List<ReligionCustom> list =
new List<ReligionCustom>();
173 value.relation = value.
source.relation;
175 Debug.Log(
$"#mod-content {value.content}");
181 internal static void LoadReligionData(GameIOContext context)
183 if (!context.Load<Dictionary<string, ReligionCustom>>(
"custom_religion_data", out var data))
187 foreach (var (key, religionCustom2) in data)
191 Debug.Log(
"#mod-content loading Religion/" + value.id);
192 value.mood = religionCustom2.mood;
193 value.relation = religionCustom2.relation;
194 value.giftRank = religionCustom2.giftRank;
199 internal static void SaveReligionData(GameIOContext context)
201 if (!context.Load<Dictionary<string, ReligionCustom>>(
"custom_religion_data", out var data))
203 data =
new Dictionary<string, ReligionCustom>();
211 context.SaveUncompressed(
"custom_religion_data", data);
215 public override string ToString()
217 StringBuilder stringBuilder =
new StringBuilder();
218 stringBuilder.AppendLine(
$"{base.ContentId}/canJoin={canJoin}/minorGod={isMinorGod}");
219 if (artifacts.Count > 0)
221 stringBuilder.AppendLine(
$" - artifacts({artifacts.Count})/{string.Join(';', artifacts)}");
223 if (elements.Count > 0)
225 stringBuilder.AppendLine(
$" - elements({elements.Count})/{string.Join(';', elements)}");
227 if (offeringMtp.Count > 0)
229 stringBuilder.AppendLine(
$" - offeringMtp({offeringMtp.Count})/{string.Join(';', offeringMtp.Select((KeyValuePair<string, int> kv) => $"{kv.Key}={kv.Value}
"))}");
231 if (offeringValue.Count > 0)
233 stringBuilder.AppendLine(
string.Format(
" - offeringValue({0})/{1}", offeringValue.Count,
string.Join(
';', offeringValue.Select((KeyValuePair<string, string> kv) => kv.Key +
"=" + kv.Value))));
235 if (godAbilities.Count > 0)
237 stringBuilder.AppendLine(
$" - godAbilities({godAbilities.Count})/{string.Join(';', godAbilities)}");
239 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
CustomReligionContent content
Dictionary< string, Religion > dictAll
SourceReligion.Row source
static Dictionary< string, string > dictModItems