예제 #1
0
        public PlayerPreferences GetPlayerPreferences(string username)
        {
            using (var connection = GetDbConnection())
            {
                var prefs = connection.QueryFirstOrDefault <PlayerPreferencesSql>(
                    PlayerPreferencesQuery,
                    new { Username = username });
                if (prefs is null)
                {
                    return(null);
                }

                // Using Dapper for ICharacterProfile and ICharacterAppearance is annoying so
                // we do it manually
                var cmd = new SqliteCommand(HumanoidCharactersQuery, connection);
                cmd.Parameters.AddWithValue("@Id", prefs.Id);
                cmd.Prepare();

                var reader   = cmd.ExecuteReader();
                var profiles = new ICharacterProfile[_maxCharacterSlots];
                while (reader.Read())
                {
                    profiles[reader.GetInt32(0)] = new HumanoidCharacterProfile
                    {
                        Name = reader.GetString(1),
                        Age  = reader.GetInt32(2),
                        Sex  = reader.GetString(3) == "Male" ? Male : Female,
                        CharacterAppearance = new HumanoidCharacterAppearance
                        {
                            HairStyleName       = reader.GetString(4),
                            HairColor           = Color.FromHex(reader.GetString(5)),
                            FacialHairStyleName = reader.GetString(6),
                            FacialHairColor     = Color.FromHex(reader.GetString(7)),
                            EyeColor            = Color.FromHex(reader.GetString(8)),
                            SkinColor           = Color.FromHex(reader.GetString(9))
                        }
                    };
                }

                return(new PlayerPreferences
                {
                    SelectedCharacterIndex = prefs.SelectedCharacterIndex,
                    Characters = profiles.ToList()
                });
            }
        }
예제 #2
0
        public PlayerPreferences GetPlayerPreferences(string username)
        {
            var prefs = _prefsDb.GetPlayerPreferences(username);

            if (prefs is null)
            {
                return(null);
            }

            var profiles = new ICharacterProfile[_maxCharacterSlots];

            foreach (var profile in prefs.HumanoidProfiles)
            {
                profiles[profile.Slot] = new HumanoidCharacterProfile
                {
                    Name = profile.CharacterName,
                    Age  = profile.Age,
                    Sex  = profile.Sex == "Male" ? Male : Female,
                    CharacterAppearance = new HumanoidCharacterAppearance
                    {
                        HairStyleName       = profile.HairName,
                        HairColor           = Color.FromHex(profile.HairColor),
                        FacialHairStyleName = profile.FacialHairName,
                        FacialHairColor     = Color.FromHex(profile.FacialHairColor),
                        EyeColor            = Color.FromHex(profile.EyeColor),
                        SkinColor           = Color.FromHex(profile.SkinColor)
                    }
                }
            }
            ;

            return(new PlayerPreferences
            {
                SelectedCharacterIndex = prefs.SelectedCharacterSlot,
                Characters = profiles.ToList()
            });
        }