Elin Decompiled Documentation EA 23.343.5 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 [JsonIgnore]
40 public string BioId { get; private set; }
41
42 public static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner = null, string charaId = null)
43 {
44 var (fileInfo, eMod) = PackageIterator.GetFilesEx("Data/bio_" + biographyId + ".json").LastOrDefault();
45 if (fileInfo == null)
46 {
47 return null;
48 }
49 if (owner == null)
50 {
51 owner = eMod as ModPackage;
52 }
53 return new CustomBiographyContent
54 {
55 ContentId = "Biography/" + charaId.IsEmpty(biographyId),
56 BioId = biographyId,
57 Owner = owner,
58 File = fileInfo
59 };
60 }
61
62 public override void OnSetLang(string lang)
63 {
64 CustomBiographyContent customBiographyContent = CreateFromId(BioId.IsEmpty(base.ContentId.Split('/')[^1]));
65 if (customBiographyContent != null)
66 {
67 base.File = customBiographyContent.File;
68 base.LastModified = DateTime.MinValue;
69 }
70 }
71
72 public void RefreshCharaBio(Chara chara)
73 {
74 Load();
75 Biography bio = chara.bio;
76 if (birthDay != 0)
77 {
78 bio.birthDay = birthDay;
79 }
80 if (birthMonth != 0)
81 {
82 bio.birthMonth = birthMonth;
83 }
84 if (birthYear != 0)
85 {
86 bio.birthYear = birthYear;
87 }
88 Dictionary<int, LangWord.Row> langWord = EClass.sources.langWord.map;
89 if (!langWord.ContainsKey(-100))
90 {
91 _lastWordKey = -100;
92 Dictionary<int, LangWord.Row> dictionary = langWord;
94 {
95 id = -100
96 };
97 LangWord.Row row = obj;
98 dictionary[-100] = obj;
99 row.name = (row.name_JP = (row.name_L = ""));
100 }
101 if (!birthPlace.IsEmpty())
102 {
103 bio.idHome = SetTempWord(birthPlace, 0);
104 }
105 if (!birthLocation.IsEmpty())
106 {
107 bio.idLoc = SetTempWord(birthLocation, 1);
108 }
109 if (!dad.IsEmpty())
110 {
111 bio.idAdvDad = -100;
112 bio.idDad = SetTempWord(dad, 2);
113 }
114 if (!mom.IsEmpty())
115 {
116 bio.idAdvMom = -100;
117 bio.idMom = SetTempWord(mom, 3);
118 }
119 if (!likeThing.IsEmpty() && EClass.sources.cards.map.ContainsKey(likeThing))
120 {
121 bio.idLike = likeThing;
122 }
123 if (!likeHobby.IsEmpty())
124 {
125 int element = Core.GetElement(likeHobby);
126 if (element != EClass.sources.elements.rows[0].id)
127 {
128 bio.idHobby = element;
129 }
130 }
131 int SetTempWord(string text, int tempIndex)
132 {
133 int num = _tempLangKey[tempIndex];
134 if (num == 0 || !langWord.ContainsKey(num))
135 {
136 while (langWord.ContainsKey(_lastWordKey))
137 {
138 _lastWordKey--;
139 }
140 num = _lastWordKey;
141 }
142 LangWord.Row row2 = (langWord[num] = new LangWord.Row
143 {
144 id = num
145 });
146 row2.name = (row2.name_JP = (row2.name_L = text));
147 return _tempLangKey[tempIndex] = num;
148 }
149 }
150
151 protected override void LoadContent()
152 {
153 CustomBiographyContent customBiographyContent = IO.LoadFile<CustomBiographyContent>(base.File.FullName);
154 background = customBiographyContent.background;
155 birthDay = customBiographyContent.birthDay;
156 birthMonth = customBiographyContent.birthMonth;
157 birthYear = customBiographyContent.birthYear;
158 birthLocation = customBiographyContent.birthLocation;
159 birthPlace = customBiographyContent.birthPlace;
160 dad = customBiographyContent.dad;
161 mom = customBiographyContent.mom;
162 likeThing = customBiographyContent.likeThing;
163 likeHobby = customBiographyContent.likeHobby;
164 favCategory = customBiographyContent.favCategory;
165 favFood = customBiographyContent.favFood;
166 }
167}
Biography bio
Definition: Card.cs:45
Definition: Chara.cs:10
Definition: Core.cs:14
static int GetElement(string id)
Definition: Core.cs:753
void RefreshCharaBio(Chara chara)
static CustomBiographyContent CreateFromId(string biographyId, ModPackage owner=null, string charaId=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