new file: .editorconfig
new file: .gitattributes new file: Charts/track.json new file: ProjectOnrinto.csproj new file: ProjectOnrinto.sln new file: Scenes/Audio/audio_stream_player.tscn new file: Scenes/Game/level.tscn new file: Scenes/Prefabs/beat.tscn new file: Scripts/Core/GameManager.cs new file: Scripts/Core/GameManager.cs.uid new file: Scripts/Core/MusicClock.cs new file: Scripts/Core/MusicClock.cs.uid new file: Scripts/Core/TrackGenerator.cs new file: Scripts/Core/TrackGenerator.cs.uid new file: Scripts/Data/ChartEvent.cs new file: Scripts/Data/ChartEvent.cs.uid new file: Scripts/Data/JsonConverter.cs new file: Scripts/Data/JsonConverter.cs.uid new file: Scripts/Data/TrackData.cs new file: Scripts/Data/TrackData.cs.uid new file: Scripts/GameObjects/NoteObject.cs new file: Scripts/GameObjects/NoteObject.cs.uid new file: icon.svg new file: icon.svg.import new file: project.godot
This commit is contained in:
94
Scripts/Data/ChartEvent.cs
Normal file
94
Scripts/Data/ChartEvent.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Onrinto.Chart;
|
||||
|
||||
public enum EventType { Hole, Obstacle, Beat, Catch, Through, Jump, Dash, Float };
|
||||
public enum AnimationType { Linear, Sin, Back };
|
||||
|
||||
public class TempoPoint
|
||||
{
|
||||
public double Tick { get; set; }
|
||||
public float BPM { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public TempoPoint(double tick, float bpm, bool isLinear)
|
||||
{
|
||||
Tick = tick;
|
||||
BPM = bpm;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpeedPoint
|
||||
{
|
||||
public double Tick { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public bool IsLinear { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public SpeedPoint(double tick, float speed, bool isLinear)
|
||||
{
|
||||
Tick = tick;
|
||||
Speed = speed;
|
||||
IsLinear = isLinear;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
|
||||
[JsonDerivedType(typeof(ChartEvent), typeDiscriminator: "Onrinto.Chart.ChartEvent")]
|
||||
[JsonDerivedType(typeof(AnimatedEvent), typeDiscriminator: "Onrinto.Chart.AnimatedEvent")]
|
||||
[Serializable]
|
||||
public class ChartEvent
|
||||
{
|
||||
|
||||
public EventType Type { get; set; }
|
||||
public double Tick { get; set; }
|
||||
public Vector2 Position { get; set; }
|
||||
public double HitTime { get; set; }
|
||||
public double HitAbsZ { get; set; }
|
||||
|
||||
public ChartEvent(EventType type, double tick, Vector2 position)
|
||||
{
|
||||
Type = type;
|
||||
Tick = tick;
|
||||
Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AnimatedEvent : ChartEvent
|
||||
{
|
||||
public AnimationType AniType { get; set; }
|
||||
public int In_Out { get; set; }
|
||||
|
||||
public double AniStartTime { get; set; }
|
||||
public double AniEndTime { get; set; }
|
||||
|
||||
public Vector2 StartPosition { get; set; }
|
||||
public Vector2 EndPosition { get; set; }
|
||||
|
||||
public float RelativeSpeed { get; set; }
|
||||
|
||||
public AnimatedEvent(
|
||||
EventType type,
|
||||
double tick,
|
||||
Vector2 position,
|
||||
AnimationType aniType,
|
||||
int in_Out,
|
||||
double aniStartTime,
|
||||
double aniEndTime,
|
||||
float relativeSpeed,
|
||||
Vector2 startPosition,
|
||||
Vector2 endPosition
|
||||
) : base(type, tick, position)
|
||||
{
|
||||
AniType = aniType;
|
||||
In_Out = in_Out;
|
||||
AniStartTime = aniStartTime;
|
||||
AniEndTime = aniEndTime;
|
||||
RelativeSpeed = relativeSpeed;
|
||||
StartPosition = startPosition;
|
||||
EndPosition = endPosition;
|
||||
}
|
||||
}
|
||||
1
Scripts/Data/ChartEvent.cs.uid
Normal file
1
Scripts/Data/ChartEvent.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bg6k051syuyb6
|
||||
46
Scripts/Data/JsonConverter.cs
Normal file
46
Scripts/Data/JsonConverter.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
//unread...
|
||||
|
||||
namespace Onrinto.Chart;
|
||||
|
||||
public class Vector2Converter : JsonConverter<Vector2>
|
||||
{
|
||||
public override Vector2 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
// 预设默认值
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
throw new JsonException("预期一个对象来解析 Vector2");
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
return new Vector2(x, y);
|
||||
|
||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||
{
|
||||
string propertyName = reader.GetString()?.ToLower(); // 统一转小写处理
|
||||
reader.Read();
|
||||
|
||||
if (propertyName == "x") x = (float)reader.GetDouble();
|
||||
else if (propertyName == "y") y = (float)reader.GetDouble();
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Vector2 value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
writer.WriteNumber("x", value.X);
|
||||
writer.WriteNumber("y", value.Y);
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
1
Scripts/Data/JsonConverter.cs.uid
Normal file
1
Scripts/Data/JsonConverter.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://25r22gy8t7ny
|
||||
119
Scripts/Data/TrackData.cs
Normal file
119
Scripts/Data/TrackData.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace Onrinto.Chart;
|
||||
|
||||
public class TrackData
|
||||
{
|
||||
public int BPM { get; set; }
|
||||
public double Offset { get; set; }
|
||||
public double TicksPerBeat { get; set; }
|
||||
public double BeatDuration => 60.0 / BPM;
|
||||
public List<ChartEvent> Events { get; set; } = new List<ChartEvent>();
|
||||
public List<TempoPoint> TempoPoints { get; set; } = new List<TempoPoint>();
|
||||
public List<SpeedPoint> RelativeSpeedPoints { get; set; } = new List<SpeedPoint>();
|
||||
public List<SpeedPoint> AbsoluteSpeedPoints { get; set; } = new List<SpeedPoint>();
|
||||
|
||||
public List<double> TempoSecondsTable { get; private set; } = new List<double>();
|
||||
public List<float> RelativeZTable { get; private set; } = new List<float>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
InitializeTempoTable();
|
||||
InitializeRelativeZTable(RelativeSpeedPoints);
|
||||
|
||||
foreach(var e in Events)
|
||||
{
|
||||
e.HitTime = TickToSeconds(e.Tick);
|
||||
e.HitAbsZ = GetZ(e.HitTime, RelativeSpeedPoints, RelativeZTable);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeTempoTable()
|
||||
{
|
||||
TempoSecondsTable.Clear();
|
||||
if(TempoPoints == null || TempoPoints.Count == 0) return;
|
||||
|
||||
TempoPoints = TempoPoints.OrderBy(tp => tp.Tick).ToList();
|
||||
double cachedSeconds = 0.0;
|
||||
TempoSecondsTable.Add(cachedSeconds);
|
||||
|
||||
for(int i = 0; i < TempoPoints.Count - 1; i++)
|
||||
{
|
||||
double ticksDelta = TempoPoints[i + 1].Tick - TempoPoints[i].Tick;
|
||||
double secondsDelta = ticksDelta / TicksPerBeat * 60.0 / TempoPoints[i].BPM;
|
||||
cachedSeconds += secondsDelta;
|
||||
TempoSecondsTable.Add(cachedSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeRelativeZTable(List<SpeedPoint> speedPoints)
|
||||
{
|
||||
RelativeZTable.Clear();
|
||||
if(speedPoints == null || speedPoints.Count == 0) return;
|
||||
|
||||
speedPoints = speedPoints.OrderBy(sp => sp.Tick).ToList();
|
||||
float cachedZ = 0.0f;
|
||||
RelativeZTable.Add(cachedZ);
|
||||
|
||||
for(int i = 0; i < speedPoints.Count - 1; i++)
|
||||
{
|
||||
double timeDelta = TickToSeconds(speedPoints[i + 1].Tick) - TickToSeconds(speedPoints[i].Tick);
|
||||
|
||||
if(speedPoints[i].IsLinear)
|
||||
{
|
||||
cachedZ += (float)timeDelta * (speedPoints[i].Speed + speedPoints[i + 1].Speed) * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
cachedZ += (float)timeDelta * speedPoints[i].Speed;
|
||||
}
|
||||
RelativeZTable.Add(cachedZ);
|
||||
}
|
||||
}
|
||||
|
||||
public double TickToSeconds(double tick)
|
||||
{
|
||||
if(TempoPoints == null || TempoPoints.Count == 0)
|
||||
return tick / TicksPerBeat * 60.0 / BPM;
|
||||
|
||||
int idx = 0;
|
||||
for(int i = 0; i < TempoPoints.Count; i++)
|
||||
{
|
||||
if(tick >= TempoPoints[i].Tick) idx = i;
|
||||
else break;
|
||||
}
|
||||
|
||||
return TempoSecondsTable[idx] + (tick - TempoPoints[idx].Tick) / TicksPerBeat * 60.0 / TempoPoints[idx].BPM;
|
||||
}
|
||||
|
||||
public float GetZ(double time, List<SpeedPoint> speedPoints, List<float> zTable)
|
||||
{
|
||||
if(speedPoints == null || speedPoints.Count == 0) return 0.0f;
|
||||
|
||||
int idx = 0;
|
||||
for(int i = 0; i < speedPoints.Count; i++)
|
||||
{
|
||||
if(time >= TickToSeconds(speedPoints[i].Tick)) idx = i;
|
||||
else break;
|
||||
}
|
||||
|
||||
var point = speedPoints[idx];
|
||||
float cachedZ = zTable[idx];
|
||||
double pointTime = TickToSeconds(point.Tick);
|
||||
double deltaTime = time - pointTime;
|
||||
|
||||
if(point.IsLinear && idx < speedPoints.Count - 1)
|
||||
{
|
||||
double nextTime = TickToSeconds(speedPoints[idx + 1].Tick);
|
||||
float t = (float)((time - pointTime) / (nextTime - pointTime));
|
||||
float currentSpeed = Mathf.Lerp(point.Speed, speedPoints[idx + 1].Speed, t);
|
||||
return cachedZ + (float)deltaTime * (point.Speed + currentSpeed) * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cachedZ + (float)deltaTime * point.Speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Data/TrackData.cs.uid
Normal file
1
Scripts/Data/TrackData.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://beb5iifgf08kg
|
||||
Reference in New Issue
Block a user