Skip to content

Commit 2c0a65e

Browse files
committed
Add support for character description
1 parent ec560b9 commit 2c0a65e

3 files changed

Lines changed: 73 additions & 3 deletions

File tree

VndbCharacterNames/Program.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ public static void Main(string[] args)
1818
bool shouldAddDefinition = true;
1919
bool createAliasEntries = true;
2020
VndbSpoilerLevel maxSpoilerLevelForAliases = VndbSpoilerLevel.No;
21+
bool includeSpoilersInDescription = false;
2122
string? pathOfCharacterImages = null;
2223
bool addDefinitionToOneWordNames = false;
2324
bool addDefinitionToGivenNames = false;
2425
bool addDefinitionToSurnames = false;
26+
bool addDescriptionToDefinition = false;
2527

2628
bool validArgs = false;
27-
if (args.Length >= 8)
29+
if (args.Length >= 9)
2830
{
2931
string jsonFolderPath = args[0].Trim('"', ' ');
3032
if (!Directory.Exists(jsonFolderPath))
@@ -81,6 +83,21 @@ public static void Main(string[] args)
8183
if (result is not null)
8284
{
8385
shouldAddDefinition = result.Value;
86+
87+
result = GetBoolArgValue(args, "--add-description-to-definition", 2);
88+
if (result is not null)
89+
{
90+
addDescriptionToDefinition = result.Value;
91+
if (addDescriptionToDefinition)
92+
{
93+
result = GetBoolArgValue(args, "--include-spoilers-in-description", 2);
94+
if (result is not null)
95+
{
96+
includeSpoilersInDescription = result.Value;
97+
}
98+
}
99+
}
100+
84101
result = GetBoolArgValue(args, "--add-character-details-to-one-word-full-names", 2);
85102
if (result is not null)
86103
{
@@ -177,6 +194,12 @@ public static void Main(string[] args)
177194
shouldAddDefinition = GetAnswerOfYesNoQuestion("Add character details (age, height, etc.) to the definition of full names? Y/N");
178195
if (shouldAddDefinition)
179196
{
197+
addDescriptionToDefinition = GetAnswerOfYesNoQuestion("Add character description to the definition? Y/N");
198+
if (addDescriptionToDefinition)
199+
{
200+
includeSpoilersInDescription = GetAnswerOfYesNoQuestion("Include spoilers in the description? Y/N");
201+
}
202+
180203
addDefinitionToOneWordNames = GetAnswerOfYesNoQuestion("Add character details (age, height, etc.) to the definition of a character's full name when it consists of a single word? Y/N");
181204
if (addDefinitionToOneWordNames)
182205
{
@@ -224,7 +247,7 @@ public static void Main(string[] args)
224247
}
225248
}
226249

227-
string definition = vndbNameRecord.GetDefinition();
250+
string definition = vndbNameRecord.GetDefinition(addDescriptionToDefinition, includeSpoilersInDescription);
228251
List<NameRecord>? aliasRecords = createAliasEntries
229252
? vndbNameRecord.GetAliasRecords()
230253
: null;

VndbCharacterNames/Utils.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,13 @@ internal static partial class Utils
4545

4646
[GeneratedRegex(@"(.+?)\s*\(([^,]+?)\)", RegexOptions.CultureInvariant)]
4747
public static partial Regex NameInParentheses { get; }
48+
49+
[GeneratedRegex(@"\[spoiler\][\s\S]*?\[/spoiler\]", RegexOptions.CultureInvariant)]
50+
public static partial Regex DescriptionInSpoilerTags { get; }
51+
52+
[GeneratedRegex("\n{3,}", RegexOptions.CultureInvariant)]
53+
public static partial Regex ExcessNewlines { get; }
54+
55+
[GeneratedRegex(@"\[(\/)?(?:b|i|u|s|url|quote|spoiler|raw|code)(?:=[^\]]+)?\]", RegexOptions.CultureInvariant)]
56+
public static partial Regex BbCodeTags { get; }
4857
}

VndbCharacterNames/VndbNameRecord.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal sealed class VndbNameRecord(string fullName,
1717
string? cupSize,
1818
string? sex,
1919
string? imagePath,
20+
string? description,
2021
int? bust,
2122
int? waist,
2223
int? hip,
@@ -51,6 +52,9 @@ internal sealed class VndbNameRecord(string fullName,
5152
[JsonPropertyName("Image Path")]
5253
public string? ImagePath { get; } = imagePath;
5354

55+
[JsonPropertyName("Description")]
56+
public string? Description { get; set; } = description;
57+
5458
[JsonPropertyName("Bust")]
5559
public int? Bust { get; } = bust;
5660

@@ -100,7 +104,32 @@ internal sealed class VndbNameRecord(string fullName,
100104
: $"B/W/H: {Bust?.ToString(CultureInfo.InvariantCulture) ?? "?"}/{Waist?.ToString(CultureInfo.InvariantCulture) ?? "?"}/{Hip?.ToString(CultureInfo.InvariantCulture) ?? "?"} cm";
101105
}
102106

103-
public string GetDefinition()
107+
private string? GetDescription(bool includeSpoilersInDescription)
108+
{
109+
if (Description is null)
110+
{
111+
return null;
112+
}
113+
114+
if (!includeSpoilersInDescription)
115+
{
116+
Description = Utils.DescriptionInSpoilerTags.Replace(Description, "");
117+
}
118+
119+
Description = Utils.BbCodeTags.Replace(Description, "");
120+
Description = Utils.ExcessNewlines.Replace(Description, "\n\n");
121+
Description = Description.Trim();
122+
123+
if (Description.Length is 0)
124+
{
125+
Description = null;
126+
return null;
127+
}
128+
129+
return $"\n{Description}";
130+
}
131+
132+
public string GetDefinition(bool addDescriptionToDefinition, bool includeSpoilersInDescription)
104133
{
105134
StringBuilder definitionStringBuilder = new();
106135
_ = definitionStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Full name: {FullName} ({FullNameInRomaji})");
@@ -177,6 +206,15 @@ public string GetDefinition()
177206
_ = definitionStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"VN: {VisualNovelTitles[0]}");
178207
}
179208

209+
if (addDescriptionToDefinition)
210+
{
211+
string? description = GetDescription(includeSpoilersInDescription);
212+
if (description is not null)
213+
{
214+
_ = definitionStringBuilder.AppendLine(description);
215+
}
216+
}
217+
180218
return definitionStringBuilder.Length > 0
181219
? definitionStringBuilder.ToString(0, definitionStringBuilder.Length - Environment.NewLine.Length)
182220
: FullNameInRomaji;

0 commit comments

Comments
 (0)