1
0
mirror of synced 2024-11-30 17:24:33 +01:00
TaikoLocalServer/SharedProject/Utils/PlaySettingConverter.cs
2024-03-16 17:46:06 +08:00

46 lines
1.6 KiB
C#

using System.Collections.Specialized;
using SharedProject.Enums;
using SharedProject.Models;
using Throw;
namespace SharedProject.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;
}
}