Ejemplo n.º 1
0
        public void ShouldBeAbleToRetrieveUpdatedPreferencesForAnExistingIpAddress()
        {
            //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            newColor            = RandomColorGenerator.GenerateColor().ToUnity();
            PlayerPreference newPlayerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, newColor);

            //When
            playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference);
            playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, newPlayerPreference);
            PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS);

            //Then
            result.RedAdditive.Should().Be(newColor.r);
            result.GreenAdditive.Should().Be(newColor.g);
            result.BlueAdditive.Should().Be(newColor.b);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        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());
            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);
        }
Ejemplo n.º 4
0
    void Start()
    {
        //RM = GetComponent<ResourceManager> ();
        PPM = new PlayerPreferenceManager(this);
        WM  = new WindowManager(this);

        inventory = PPM.LoadItemArray("inventory");
        equipment = PPM.LoadItemArray("equipment");
    }
Ejemplo n.º 5
0
        public void Awake()
        {
            multiplayerSession = NitroxServiceLocator.LocateService <IMultiplayerSession>();
            preferencesManager = NitroxServiceLocator.LocateService <PlayerPreferenceManager>();

            InitializeJoinMenu();
            SubscribeColorChanged();

            DontDestroyOnLoad(gameObject);
        }
Ejemplo n.º 6
0
 public void UpdateScore(int score)
 {
     _currentScore += score;
     PlayerPreferenceManager.SetScore(_currentScore);
     scoreCounter.text = _currentScore.ToString("D11");
     if (_currentScore > PlayerPreferenceManager.GetHighscore())
     {
         UpdateHighScore(score);
     }
 }
Ejemplo n.º 7
0
    void Start()
    {
        highStoreText = GetComponent <Text>();

        if (PlayerPreferenceManager.GetHighscore() > 0)
        {
            highStoreText.text = PlayerPreferenceManager.GetHighscore().ToString("D11");
        }
        else
        {
            PlayerPreferenceManager.SetHighscore(9000);
            highStoreText.text = 9000.ToString("D11");
        }
    }
Ejemplo n.º 8
0
    void Start()
    {
        PlayerPreferenceManager.SetScore(_currentScore);

        if (PlayerPreferenceManager.GetHighscore() > 0)
        {
            _highScore = PlayerPreferenceManager.GetHighscore();
        }
        else
        {
            PlayerPreferenceManager.SetHighscore(9000);
            _highScore = 9000;
        }

        this.UpdateHighScore(_highScore);
    }
Ejemplo n.º 9
0
        public void SetPreferenceShouldThrowExceptionWhenGivenANullJoinServerSettingsReference()
        {
            //Arrange
            PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState();

            playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>();

            IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>();

            stateProvider.GetPreferenceState().Returns(playerPreferenceState);

            PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider);

            //Act
            Action action = () => playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, null);

            //Assert
            action.ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 10
0
        public void GetPreferenceShouldThrowExceptionWhenGivenNullIpAddress()
        {
            //Arrange
            PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState();

            playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>();

            IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>();

            stateProvider.GetPreferenceState().Returns(playerPreferenceState);

            PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider);

            //Act
            Action action = () => playerPreferenceManager.GetPreference(null);

            //Assert
            action.ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 11
0
        public void ShouldBeAbleToRetrieveADefaultPreferenceWhenThePlayerHasNone()
        {
            //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);

            //When
            PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS);

            //Then
            result.Should().NotBeNull();
            result.PlayerName.Should().BeNullOrEmpty();
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public void SetPreferenceShouldThrowExceptionWhenGivenANullIpAddress()
        {
            //Arrange
            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());

            //Act
            Action action = () => playerPreferenceManager.SetPreference(null, playerPreference);

            //Assert
            action.ShouldThrow <ArgumentNullException>();
        }
 public void Save()
 {
     PlayerPreferenceManager.Save(current);
 }
Ejemplo n.º 15
0
 private void Start()
 {
     musicManager = FindObjectOfType<MusicManager>();
     musicManager.SetVolume(PlayerPreferenceManager.GetMasterVolume());
 }
 private void Start()
 {
     musicManager           = FindObjectOfType <MusicManager>();
     volumeSlider.value     = PlayerPreferenceManager.GetMasterVolume();
     difficultySlider.value = PlayerPreferenceManager.GetDifficulty();
 }
Ejemplo n.º 17
0
 public void UpdateHighScore(int score)
 {
     _highScore = score;
     PlayerPreferenceManager.SetHighscore(_highScore);
     highScoreCounter.text = _highScore.ToString("D11");
 }
 public void SaveAndExit()
 {
     PlayerPreferenceManager.SetMasterVolume(volumeSlider.value);
     PlayerPreferenceManager.SetDifficulty(difficultySlider.value);
     levelManager.LoadLevel("01a Start");
 }