public void ShouldBeAbleToRetrieveANewPreferenceEntry() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color preferredColor = playerPreference.PreferredColor(); //When playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference); PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(TestConstants.TEST_PLAYER_NAME); result.RedAdditive.Should().Be(preferredColor.r); result.GreenAdditive.Should().Be(preferredColor.g); result.BlueAdditive.Should().Be(preferredColor.b); }
public void Show(string ip, int port) { NitroxServiceLocator.BeginNewLifetimeScope(); multiplayerSession = NitroxServiceLocator.LocateService <IMultiplayerSession>(); preferencesManager = NitroxServiceLocator.LocateService <PlayerPreferenceManager>(); gameObject.SetActive(true); serverIp = ip; serverPort = port; //Set Server IP in info label lowerDetailTextGameObject.GetComponent <Text>().text = $"{Language.main.Get("Nitrox_JoinServerIpAddress")}\n{(NitroxPrefs.HideIp.Value ? "****" : serverIp)}"; //Initialize elements from preferences activePlayerPreference = preferencesManager.GetPreference(serverIp); SubscribeColorChanged(); // HSV => Hue Saturation Value, HSB => Hue Saturation Brightness Color.RGBToHSV(activePlayerPreference.PreferredColor(), out float hue, out _, out float brightness); colorPicker.SetHSB(new Vector3(hue, 1f, brightness)); playerNameInputField.text = activePlayerPreference.PlayerName; StartMultiplayerClient(); }
public void ShouldGetTheLastSetPlayerPreferenceWhenJoiningANewServer() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference firstPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string firstIpAddress = "127.0.0.1"; playerPreferenceManager.SetPreference(firstIpAddress, firstPreference); PlayerPreference secondPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string secondIpAddress = "123.456.789.321"; playerPreferenceManager.SetPreference(secondIpAddress, secondPreference); PlayerPreference thirdPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color expectedColor = thirdPreference.PreferredColor(); string thirdIpAddress = "000.000.000.000"; playerPreferenceManager.SetPreference(thirdIpAddress, thirdPreference); //When PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(thirdPreference.PlayerName); result.RedAdditive.Should().Be(expectedColor.r); result.GreenAdditive.Should().Be(expectedColor.g); result.BlueAdditive.Should().Be(expectedColor.b); }