Beispiel #1
0
        private static HumanoidCharacterProfile ConvertProfiles(Profile profile)
        {
            var jobs   = profile.Jobs.ToDictionary(j => j.JobName, j => (JobPriority)j.Priority);
            var antags = profile.Antags.Select(a => a.AntagName);

            var sex = Sex.Male;

            if (Enum.TryParse <Sex>(profile.Sex, true, out var sexVal))
            {
                sex = sexVal;
            }

            var clothing = ClothingPreference.Jumpsuit;

            if (Enum.TryParse <ClothingPreference>(profile.Clothing, true, out var clothingVal))
            {
                clothing = clothingVal;
            }

            var backpack = BackpackPreference.Backpack;

            if (Enum.TryParse <BackpackPreference>(profile.Backpack, true, out var backpackVal))
            {
                backpack = backpackVal;
            }

            var gender = sex == Sex.Male ? Gender.Male : Gender.Female;

            if (Enum.TryParse <Gender>(profile.Gender, true, out var genderVal))
            {
                gender = genderVal;
            }

            // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
            var markingsRaw = profile.Markings?.Deserialize <List <string> >();

            List <Marking> markings = new();

            if (markingsRaw != null)
            {
                foreach (var marking in markingsRaw)
                {
                    var parsed = Marking.ParseFromDbString(marking);

                    if (parsed is null)
                    {
                        continue;
                    }

                    markings.Add(parsed);
                }
            }
            var markingsSet = new MarkingsSet(markings);

            return(new HumanoidCharacterProfile(
                       profile.CharacterName,
                       profile.FlavorText,
                       profile.Species,
                       profile.Age,
                       sex,
                       gender,
                       new HumanoidCharacterAppearance
                       (
                           profile.HairName,
                           Color.FromHex(profile.HairColor),
                           profile.FacialHairName,
                           Color.FromHex(profile.FacialHairColor),
                           Color.FromHex(profile.EyeColor),
                           Color.FromHex(profile.SkinColor),
                           markingsSet
                       ),
                       clothing,
                       backpack,
                       jobs,
                       (PreferenceUnavailableMode)profile.PreferenceUnavailable,
                       antags.ToList()
                       ));
        }