Elin Decompiled Documentation EA 23.329 Nightly
Loading...
Searching...
No Matches
CustomBiographyContent.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Newtonsoft.Json;
5
6[JsonObject(MemberSerialization.OptOut)]
8{
9 private const int FallbackWordKey = -100;
10
11 private static int _lastWordKey = -101;
12
13 public string background;
14
15 public int birthDay;
16
17 public int birthMonth;
18
19 public int birthYear;
20
21 public string birthLocation;
22
23 public string birthPlace;
24
25 public string dad;
26
27 public string mom;
28
29 public string likeThing;
30
31 public string likeHobby;
32
33 public string favCategory;
34
35 public string favFood;
36
37 private int[] _tempLangKey = new int[4];
38
39 private bool _initialized;
40
41 public static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner = null)
42 {
43 var (fileInfo, eMod) = PackageIterator.GetFilesEx("Data/bio_" + biographyId + ".json").LastOrDefault();
44 if (fileInfo == null)
45 {
46 return null;
47 }
48 if (owner == null)
49 {
50 owner = eMod as ModPackage;
51 }
52 return new CustomBiographyContent
53 {
54 ContentId = "Biography/" + biographyId,
55 Owner = owner,
56 File = fileInfo
57 };
58 }
59
60 public override void OnSetLang(string lang)
61 {
62 CustomBiographyContent customBiographyContent = CreateFromId(base.ContentId.Split('/')[^1]);
63 if (customBiographyContent != null)
64 {
65 base.File = customBiographyContent.File;
66 base.LastModified = DateTime.MinValue;
67 }
68 }
69
70 public void RefreshCharaBio(Chara chara)
71 {
72 Load();
73 if (_initialized)
74 {
75 return;
76 }
77 Biography bio = chara.bio;
78 if (birthDay != 0)
79 {
80 bio.birthDay = birthDay;
81 }
82 if (birthMonth != 0)
83 {
84 bio.birthMonth = birthMonth;
85 }
86 if (birthYear != 0)
87 {
88 bio.birthYear = birthYear;
89 }
90 Dictionary<int, LangWord.Row> langWord = EClass.sources.langWord.map;
91 if (!langWord.ContainsKey(-100))
92 {
93 _lastWordKey = -100;
94 Dictionary<int, LangWord.Row> dictionary = langWord;
96 {
97 id = -100
98 };
99 LangWord.Row row = obj;
100 dictionary[-100] = obj;
101 row.name = (row.name_JP = (row.name_L = ""));
102 }
103 if (!birthPlace.IsEmpty())
104 {
105 bio.idHome = SetTempWord(birthPlace, 0);
106 }
107 if (!birthLocation.IsEmpty())
108 {
109 bio.idLoc = SetTempWord(birthLocation, 1);
110 }
111 if (!dad.IsEmpty())
112 {
113 bio.idAdvDad = -100;
114 bio.idDad = SetTempWord(dad, 2);
115 }
116 if (!mom.IsEmpty())
117 {
118 bio.idAdvMom = -100;
119 bio.idMom = SetTempWord(mom, 3);
120 }
121 if (!likeThing.IsEmpty() && EClass.sources.cards.map.ContainsKey(likeThing))
122 {
123 bio.idLike = likeThing;
124 }
125 if (!likeHobby.IsEmpty())
126 {
127 int element = Core.GetElement(likeHobby);
128 if (element != EClass.sources.elements.rows[0].id)
129 {
130 bio.idHobby = element;
131 }
132 }
133 _initialized = true;
134 int SetTempWord(string text, int tempIndex)
135 {
136 int num = _tempLangKey[tempIndex];
137 if (num == 0 || !langWord.ContainsKey(num))
138 {
139 while (langWord.ContainsKey(_lastWordKey))
140 {
141 _lastWordKey--;
142 }
143 num = _lastWordKey;
144 }
145 LangWord.Row row3 = (langWord[num] = new LangWord.Row
146 {
147 id = num
148 });
149 row3.name = (row3.name_JP = (row3.name_L = text));
150 return _tempLangKey[tempIndex] = num;
151 }
152 }
153
154 protected override void LoadContent()
155 {
156 CustomBiographyContent customBiographyContent = IO.LoadFile<CustomBiographyContent>(base.File.FullName);
157 background = customBiographyContent.background;
158 birthDay = customBiographyContent.birthDay;
159 birthMonth = customBiographyContent.birthMonth;
160 birthYear = customBiographyContent.birthYear;
161 birthLocation = customBiographyContent.birthLocation;
162 birthPlace = customBiographyContent.birthPlace;
163 dad = customBiographyContent.dad;
164 mom = customBiographyContent.mom;
165 likeThing = customBiographyContent.likeThing;
166 likeHobby = customBiographyContent.likeHobby;
167 favCategory = customBiographyContent.favCategory;
168 favFood = customBiographyContent.favFood;
169 _initialized = false;
170 }
171}
Biography bio
Definition: Card.cs:45
Definition: Chara.cs:10
Definition: Core.cs:14
static int GetElement(string id)
Definition: Core.cs:743
void RefreshCharaBio(Chara chara)
static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner=null)
override void OnSetLang(string lang)
string ContentId
Definition: CustomContent.cs:6
Definition: EClass.cs:6
static SourceManager sources
Definition: EClass.cs:43
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceCard cards
LangWord langWord
SourceElement elements