Exemplo n.º 1
0
        public void TestMod()
        {
            var ruleset = new OsuRuleset();

            var mod1 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.25 }
            };
            var mod2 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.26 }
            };
            var mod3 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.26 }
            };

            var doubleConvertedMod1 = new APIMod(mod1).ToMod(ruleset);
            var doubleConvertedMod2 = new APIMod(mod2).ToMod(ruleset);
            var doubleConvertedMod3 = new APIMod(mod3).ToMod(ruleset);

            Assert.That(mod1, Is.Not.EqualTo(mod2));
            Assert.That(doubleConvertedMod1, Is.Not.EqualTo(doubleConvertedMod2));

            Assert.That(mod2, Is.EqualTo(mod2));
            Assert.That(doubleConvertedMod2, Is.EqualTo(doubleConvertedMod2));

            Assert.That(mod2, Is.EqualTo(mod3));
            Assert.That(doubleConvertedMod2, Is.EqualTo(doubleConvertedMod3));

            Assert.That(mod3, Is.EqualTo(mod2));
            Assert.That(doubleConvertedMod3, Is.EqualTo(doubleConvertedMod2));
        }
Exemplo n.º 2
0
        public void Test()
        {
            var mod1 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.25 }
            };
            var mod2 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.26 }
            };
            var mod3 = new OsuModDoubleTime {
                SpeedChange = { Value = 1.26 }
            };
            var apiMod1 = new APIMod(mod1);
            var apiMod2 = new APIMod(mod2);
            var apiMod3 = new APIMod(mod3);

            Assert.That(mod1, Is.Not.EqualTo(mod2));
            Assert.That(apiMod1, Is.Not.EqualTo(apiMod2));

            Assert.That(mod2, Is.EqualTo(mod2));
            Assert.That(apiMod2, Is.EqualTo(apiMod2));

            Assert.That(mod2, Is.EqualTo(mod3));
            Assert.That(apiMod2, Is.EqualTo(apiMod3));

            Assert.That(mod3, Is.EqualTo(mod2));
            Assert.That(apiMod3, Is.EqualTo(apiMod2));
        }
Exemplo n.º 3
0
        public void TestAcronymIsPreserved()
        {
            var apiMod = new APIMod(new TestMod());

            var deserialized = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));

            Assert.That(deserialized.Acronym, Is.EqualTo(apiMod.Acronym));
        }
Exemplo n.º 4
0
        public void TestAcronymIsPreserved()
        {
            var apiMod = new APIMod(new TestMod());

            var deserialized = MessagePackSerializer.Deserialize <APIMod>(MessagePackSerializer.Serialize(apiMod));

            Assert.That(deserialized.Acronym, Is.EqualTo(apiMod.Acronym));
        }
Exemplo n.º 5
0
        public void TestRawSettingIsPreserved()
        {
            var apiMod = new APIMod(new TestMod {
                TestSetting = { Value = 2 }
            });

            var deserialized = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));

            Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(2.0));
        }
Exemplo n.º 6
0
        public void TestRawSettingIsPreserved()
        {
            var apiMod = new APIMod(new TestMod {
                TestSetting = { Value = 2 }
            });

            var deserialized = MessagePackSerializer.Deserialize <APIMod>(MessagePackSerializer.Serialize(apiMod));

            Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(2.0));
        }
Exemplo n.º 7
0
        public void TestDeserialiseEnumMod()
        {
            var apiMod = new APIMod(new TestModEnum {
                TestSetting = { Value = TestEnum.Value2 }
            });

            var deserialized = MessagePackSerializer.Deserialize <APIMod>(MessagePackSerializer.Serialize(apiMod));

            Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(1));
        }
Exemplo n.º 8
0
 public override void SetUp()
 {
     base.SetUp();
     ruleset          = new OsuRuleset();
     apiModDoubleTime = new APIMod {
         Acronym = "DT"
     };
     apiModDifficultyAdjust = new APIMod {
         Acronym = "DA"
     };
 }
Exemplo n.º 9
0
        public void TestConvertedModHasCorrectSetting()
        {
            var apiMod = new APIMod(new TestMod {
                TestSetting = { Value = 2 }
            });

            var deserialized = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));
            var converted    = (TestMod)deserialized.ToMod(new TestRuleset());

            Assert.That(converted.TestSetting.Value, Is.EqualTo(2));
        }
Exemplo n.º 10
0
        public void TestConvertedModHasCorrectSetting()
        {
            var apiMod = new APIMod(new TestMod {
                TestSetting = { Value = 2 }
            });

            var deserialized = MessagePackSerializer.Deserialize <APIMod>(MessagePackSerializer.Serialize(apiMod));
            var converted    = (TestMod)deserialized.ToMod(new TestRuleset());

            Assert.That(converted.TestSetting.Value, Is.EqualTo(2));
        }
Exemplo n.º 11
0
        public void TestAPIModDetachedFromSource()
        {
            var mod = new OsuModDoubleTime {
                SpeedChange = { Value = 1.01 }
            };
            var apiMod = new APIMod(mod);

            mod.SpeedChange.Value = 1.5;

            Assert.That(apiMod.Settings["speed_change"], Is.EqualTo(1.01d));
        }
Exemplo n.º 12
0
        public void TestDeserialiseDifficultyAdjustModWithExtendedLimits()
        {
            var apiMod = new APIMod(new TestModDifficultyAdjust
            {
                OverallDifficulty = { Value = 11 },
                ExtendedLimits    = { Value = true }
            });

            var deserialised = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));
            var converted    = (TestModDifficultyAdjust)deserialised.ToMod(new TestRuleset());

            Assert.That(converted.ExtendedLimits.Value, Is.True);
            Assert.That(converted.OverallDifficulty.Value, Is.EqualTo(11));
        }
Exemplo n.º 13
0
        public void TestUnknownMod()
        {
            var apiMod = new APIMod {
                Acronym = "WNG"
            };

            var deserialized = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));

            var converted = deserialized?.ToMod(new TestRuleset());

            Assert.That(converted, Is.TypeOf(typeof(UnknownMod)));
            Assert.That(converted?.Type, Is.EqualTo(ModType.System));
            Assert.That(converted?.Acronym, Is.EqualTo("WNG??"));
        }
Exemplo n.º 14
0
        public void TestDeserialiseTimeRampMod()
        {
            // Create the mod with values different from default.
            var apiMod = new APIMod(new TestModTimeRamp
            {
                AdjustPitch = { Value = false },
                InitialRate = { Value = 1.25 },
                FinalRate   = { Value = 0.25 }
            });

            var deserialised = JsonConvert.DeserializeObject <APIMod>(JsonConvert.SerializeObject(apiMod));
            var converted    = (TestModTimeRamp)deserialised.ToMod(new TestRuleset());

            Assert.That(converted.AdjustPitch.Value, Is.EqualTo(false));
            Assert.That(converted.InitialRate.Value, Is.EqualTo(1.25));
            Assert.That(converted.FinalRate.Value, Is.EqualTo(0.25));
        }
Exemplo n.º 15
0
        public static LibraryMod GetLibraryMod(APIMod mod, Game _Game)
        {
            //Setting base values
            int    modTypeID   = -1;
            int    modCat      = -1;
            string modCatName  = "";
            string modTypeName = "";

            try
            {
                //Getting Mod Type
                GameModType modType = _Game.GameModTypes.Find(mt => mt.APIName == mod.ModType);
                modTypeID   = modType.ID;
                modTypeName = modType.Name;

                //Getting category
                Category category = modType.Categories.Find(c => c.APICategory == mod.CategoryID);
                if (category != null)
                {
                    modCat     = category.ID;
                    modCatName = category.Name;
                }
                else
                {
                    category   = modType.Categories.Find(c => c.ID == 0);
                    modCat     = 0;
                    modCatName = category.Name;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(new LibraryMod()
            {
                ID = mod.ID, TypeID = modTypeID, TypeLabel = modTypeName, APICategoryName = modCatName, APICategoryID = modCat, Name = mod.Name, FinishedProcessing = false, Authors = mod.Authors, Updates = mod.UpdateCount, GameID = _Game.ID
            });
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets Mod information from Gamebanana's API
        /// </summary>
        /// <param name="_ItemType">Gamebanana's Mod Type</param>
        /// <param name="_ItemID">Gamebanana's Mod ID</param>
        /// <returns>an APIMod object with all info</returns>
        public static async Task <APIMod> GetModInformation(string _ItemType, string _ItemID)
        {
            APIMod DownloadedAPIMod = null;

            try
            {
                string queryURL = "";

                if (_ItemType == "Mod")
                {
                    queryURL = String.Format(@"{0}/{1}", HTTPUrl, _ItemID);
                }
                else
                {
                    queryURL = String.Format(@"{0}/{1}/{2}", HTTPTypeUrl, _ItemType, _ItemID);
                }

                using (HttpClient webClient = new HttpClient())
                {
                    HttpResponseMessage response = await webClient.GetAsync(queryURL);

                    if (response.IsSuccessStatusCode)
                    {
                        string responseText = await response.Content.ReadAsStringAsync();

                        DownloadedAPIMod = JsonConvert.DeserializeObject <APIMod>(responseText);
                    }
                }

                DownloadedAPIMod.ID = Int32.Parse(_ItemID);
                DownloadedAPIMod.GamebananaRootCategoryName = _ItemType;
            }
            catch (Exception e)
            {
            }

            return(DownloadedAPIMod);
        }