Skip to content

Commit 76b9380

Browse files
committed
[+] 为OgkChart,重写那些应该被重写的基类工具方法
1 parent 7a7d93c commit 76b9380

3 files changed

Lines changed: 57 additions & 11 deletions

File tree

chart/BaseChart.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,7 @@ public virtual void Sort()
120120
public virtual void Shift(Rational offset, decimal? bpm = null)
121121
{
122122
bpm ??= StartBpm;
123-
124-
if (offset < 0)
125-
{ // 向前平移。此时存在的一种极端情况就是指定的区间跨过了多个BPM区间。
126-
// 传入的bpm参数本质是一种写死的InvariantBar,因此要把它转为可变Bar,才是真正的要去应用的offset。
127-
offset = -BpmList.ConvertTime(0, -offset, bpm, null);
128-
}
129-
else if (offset > 0)
130-
{ // 向后平移。需要把传入的offset的量换算到乐曲开头BPM下,才是真正的量。
131-
offset = offset * (Rational)StartBpm / (Rational)bpm;
132-
}
123+
offset = _calcOffsetForShift(offset, bpm.Value);
133124

134125
// 对BpmList和MetList的处理:需要确保首项为0
135126
BpmList = new BPMList(BpmList.Select(x => x with { Time = x.Time + offset })
@@ -160,4 +151,18 @@ BaseNote addOffset(BaseNote note)
160151
return note;
161152
}
162153
}
154+
155+
protected Rational _calcOffsetForShift(Rational offset, decimal bpm)
156+
{
157+
if (offset < 0)
158+
{ // 向前平移。此时存在的一种极端情况就是指定的区间跨过了多个BPM区间。
159+
// 传入的bpm参数本质是一种写死的InvariantBar,因此要把它转为可变Bar,才是真正的要去应用的offset。
160+
offset = -BpmList.ConvertTime(0, -offset, bpm, null);
161+
}
162+
else if (offset > 0)
163+
{ // 向后平移。需要把传入的offset的量换算到乐曲开头BPM下,才是真正的量。
164+
offset = offset * (Rational)StartBpm / (Rational)bpm;
165+
}
166+
return offset;
167+
}
163168
}

chart/ogk/Bullet.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace MuConvert.ogk;
77
public interface IBullet
88
{
99
public BulletPallete? Detail { get; set; }
10+
public Rational Time { get; }
1011
}
1112

1213
/**
@@ -32,7 +33,7 @@ public class Bullet: IBullet
3233
public BulletPallete Detail { get; set; } = new();
3334
#pragma warning restore CS8767
3435

35-
public Rational Time;
36+
public Rational Time { get; set; }
3637
public int Pos;
3738

3839
public BulletDamage Damage = BulletDamage.NML;

chart/ogk/OgkChart.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,44 @@ public class OgkChart: BaseChart<OgkNote>
3838

3939
// 部分谱面中会有,上方的敌人在上面进行水平方向的移动的情况。
4040
public List<EnemyMovement> EnemyMovements = [];
41+
42+
public override decimal StartTime => Math.Min(base.StartTime, (decimal)ToSecond(Bullets.First().Time));
43+
public override decimal EndTime => Math.Max(base.EndTime, (decimal)ToSecond(Bullets.Last().Time));
44+
public override int TotalNotes => throw new NotImplementedException();
45+
46+
public override void Sort()
47+
{
48+
base.Sort();
49+
// 在base通用实现的基础上,额外排序我们自己新增的四个字段
50+
Lanes = Lanes.OrderBy(x => x.Time).ToList();
51+
Bullets = Bullets.OrderBy(x => x.Time).ToList();
52+
EnemyList.Sort();
53+
EnemyMovements = EnemyMovements.OrderBy(x => x.Time).ToList();
54+
}
55+
56+
public override void Shift(Rational offset, decimal? bpm = null)
57+
{
58+
bpm ??= StartBpm;
59+
offset = _calcOffsetForShift(offset, bpm.Value);
60+
61+
base.Shift(offset, bpm);
62+
// 在base通用实现的基础上,额外移动我们自己新增的四个字段
63+
Lanes = Lanes.Where(x => addOffset(x).Time >= 0).ToList();
64+
EnemyList = EnemyList.Select(x => x with {Time = x.Time + offset}).Where(x=>x.Time >= 0).ToList();
65+
EnemyMovements = EnemyMovements.Where(x => addOffset(x).Time >= 0).ToList();
66+
67+
foreach (var bul in Bullets)
68+
{
69+
if (bul is Bullet bullet) bullet.Time += offset;
70+
else if (bul is Beam beam) beam.Points = beam.Points.Select(x => x with { Time = x.Time + offset }).ToList();
71+
else throw Utils.Fail();
72+
}
73+
Bullets = Bullets.Where(x => x.Time >= 0).ToList();
74+
75+
T addOffset<T>(T lane)where T: OgkBaseLane<OgkLanePoint>
76+
{
77+
lane.Points = lane.Points.Select(x => x with {Time = x.Time + offset}).ToList();
78+
return lane;
79+
}
80+
}
4181
}

0 commit comments

Comments
 (0)