1
0
mirror of synced 2024-11-24 06:50:15 +01:00
TaikoLocalServer/Application/Utils/PlaySettingConverter.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2024-11-20 13:05:53 +01:00
using System.Collections.Specialized;
namespace Application.Utils;
public static class PlaySettingConverter
{
public static PlaySetting ShortToPlaySetting(short input)
{
var bits = new BitVector32(input);
var speedSection = BitVector32.CreateSection(15);
var vanishSection = BitVector32.CreateSection(1, speedSection);
var inverseSection = BitVector32.CreateSection(1, vanishSection);
var randomSection = BitVector32.CreateSection(2, inverseSection);
var randomType = (RandomType)bits[randomSection];
randomType.Throw().IfOutOfRange();
var result = new PlaySetting
{
Speed = (uint)bits[speedSection],
IsVanishOn = bits[vanishSection] == 1,
IsInverseOn = bits[inverseSection] == 1,
RandomType = randomType
};
return result;
}
public static short PlaySettingToShort(PlaySetting setting)
{
var bits = new BitVector32();
var speedSection = BitVector32.CreateSection(15);
var vanishSection = BitVector32.CreateSection(1, speedSection);
var inverseSection = BitVector32.CreateSection(1, vanishSection);
var randomSection = BitVector32.CreateSection(2, inverseSection);
bits[speedSection] = (int)setting.Speed;
bits[vanishSection] = setting.IsVanishOn ? 1 : 0;
bits[inverseSection] = setting.IsInverseOn ? 1 : 0;
bits[randomSection] = (int)setting.RandomType;
return (short)bits.Data;
}
}