-
Notifications
You must be signed in to change notification settings - Fork 6
/
Name.cs
86 lines (85 loc) · 2.17 KB
/
Name.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Noxico
{
public class Name
{
public bool Female { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string Title { get; set; }
public string NameGen { get; set; }
public Name()
{
FirstName = string.Empty;
Surname = string.Empty;
Title = string.Empty;
NameGen = string.Empty;
}
public Name(string name)
: this()
{
var split = name.Split(' ');
if (split.Length >= 1)
FirstName = split[0];
if (split.Length >= 2)
Surname = split[1];
}
public void Regenerate()
{
FirstName = Culture.GetName(NameGen, Female ? Noxico.Culture.NameType.Female : Noxico.Culture.NameType.Male);
Surname = Culture.GetName(NameGen, Noxico.Culture.NameType.Surname);
Title = "";
}
public void ResolvePatronym(Name father, Name mother)
{
if (!Surname.StartsWith("#patronym"))
return;
var parts = Surname.Split('/');
var male = parts[1];
var female = parts[2];
if (Female)
Surname = mother.FirstName + female;
else
Surname = father.FirstName + male;
}
public override string ToString()
{
return FirstName;
}
public string ToString(bool full)
{
if (!full || Surname.IsBlank())
return FirstName;
return FirstName + ' ' + Surname;
}
public string ToID()
{
//had the silly thing in reverse ^_^;
return FirstName + Surname.IsBlank(string.Empty, '_' + Surname);
}
public void SaveToFile(BinaryWriter stream)
{
Toolkit.SaveExpectation(stream, "NGEN");
stream.Write(FirstName);
stream.Write(Surname);
stream.Write(Title);
stream.Write(NameGen);
}
public static Name LoadFromFile(BinaryReader stream)
{
var newName = new Name();
Toolkit.ExpectFromFile(stream, "NGEN", "name");
newName.FirstName = stream.ReadString();
newName.Surname = stream.ReadString();
newName.Title = stream.ReadString();
var namegen = stream.ReadString();
if (Culture.NameGens.ContainsKey(namegen))
newName.NameGen = namegen;
return newName;
}
}
}