Skip to content

Commit

Permalink
implement time-tags convertor.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Feb 21, 2022
1 parent 1d8a4e1 commit 2318d0b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using Newtonsoft.Json;
using NUnit.Framework;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Tests.Asserts;

namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters
{
[TestFixture]
public class TimeTagsConverterTest : BaseSingleConverterTest<TimeTagsConverter>
{
protected override JsonConverter[] CreateExtraConverts()
=> new JsonConverter[]
{
new TimeTagConverter(),
};

[Test]
public void TestSerialize()
{
var timeTags = new[]
{
new TimeTag(new TextIndex(0, TextIndex.IndexState.End), 1000),
new TimeTag(new TextIndex(0), 0)
};

const string expected = "[\"[0,start]:0\",\"[0,end]:1000\"]";
string actual = JsonConvert.SerializeObject(timeTags, CreateSettings());
Assert.AreEqual(expected, actual);
}

[Test]
public void TestDeserialize()
{
const string json = "[\"[0,end]:1000\",\"[0,start]:0\"]";

var expected = new[]
{
new TimeTag(new TextIndex(0), 0),
new TimeTag(new TextIndex(0, TextIndex.IndexState.End), 1000),
};
var actual = JsonConvert.DeserializeObject<TimeTag[]>(json, CreateSettings());
TimeTagAssert.ArePropertyEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.IO.Serialization.Converters
{
public class TimeTagsConverter : SortableJsonConvertor<TimeTag>
{
protected override IEnumerable<TimeTag> GetSortedValue(IEnumerable<TimeTag> objects)
=> TimeTagsUtils.Sort(objects);
}
}

0 comments on commit 2318d0b

Please sign in to comment.