Skip to content

Commit 3bd7713

Browse files
Merge pull request #105 from Project-Funk-Engine/Sprint-4
Finish sprint 4!
2 parents 74322c6 + 5a5264f commit 3bd7713

79 files changed

Lines changed: 1750 additions & 412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
.idea/.idea.Funk Engine/.idea/
1212

1313
*.DotSettings.user
14-
export_presets.cfg
14+
export_presets.cfg
15+
*.translation

Audio/Song1.ogg

143 KB
Binary file not shown.

Audio/Song1.ogg.import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
importer="oggvorbisstr"
44
type="AudioStreamOggVorbis"
5-
uid="uid://iq0xxe5cggs8"
5+
uid="uid://be5ial13ynf3o"
66
path="res://.godot/imported/Song1.ogg-1d785b9ae3fbaa8393048e39af66ed86.oggvorbisstr"
77

88
[deps]

Audio/Song2.ogg

58 KB
Binary file not shown.

Audio/Song2.ogg.import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
importer="oggvorbisstr"
44
type="AudioStreamOggVorbis"
5-
uid="uid://ckis6k6vuums"
5+
uid="uid://dxp7blovqh1ba"
66
path="res://.godot/imported/Song2.ogg-b95c04f3512de6fa42e0f9c35aba831f.oggvorbisstr"
77

88
[deps]

Audio/Song3.ogg

12.8 KB
Binary file not shown.

Audio/Song3.ogg.import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
importer="oggvorbisstr"
44
type="AudioStreamOggVorbis"
5-
uid="uid://ceyw5mjkem2pi"
5+
uid="uid://d4nmixdl8xoic"
66
path="res://.godot/imported/Song3.ogg-d4e6a5f1a550561df18989fb495ba591.oggvorbisstr"
77

88
[deps]

Audio/midi/Song2.mid

-1.69 KB
Binary file not shown.

Classes/MidiMaestro/MidiMaestro.cs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public partial class MidiMaestro : Resource
1010
{
1111
private MidiFile _midiFile;
1212

13+
public static TempoMap TempoMap;
14+
public static TimeSignature TimeSignature;
15+
1316
//The four note rows that we care about
1417
private midiNoteInfo[] _upNotes;
1518
private midiNoteInfo[] _downNotes;
@@ -18,8 +21,6 @@ public partial class MidiMaestro : Resource
1821

1922
//private MidiFile strippedSong;
2023

21-
private SongData songData;
22-
2324
//The path relative to the Audio folder. Will change later
2425
public MidiMaestro(string filePath)
2526
{
@@ -30,18 +31,20 @@ public MidiMaestro(string filePath)
3031

3132
if (!FileAccess.FileExists(filePath))
3233
{
33-
GD.PrintErr("ERROR: Unable to load level Midi file: " + filePath);
34+
GD.PushError("ERROR: Unable to load level Midi file: " + filePath);
3435
}
3536

3637
_midiFile = MidiFile.Read(filePath);
38+
TempoMap = _midiFile.GetTempoMap();
39+
TimeSignature = TempoMap.GetTimeSignatureAtTime(new MidiTimeSpan());
3740

3841
//Strip out the notes from the midi file
3942
foreach (var track in _midiFile.GetTrackChunks())
4043
{
4144
string trackName = track.Events.OfType<SequenceTrackNameEvent>().FirstOrDefault()?.Text;
4245
midiNoteInfo[] noteEvents = track
4346
.GetNotes()
44-
.Select(note => new midiNoteInfo(note, _midiFile.GetTempoMap()))
47+
.Select(note => new midiNoteInfo(note))
4548
.ToArray();
4649

4750
switch (trackName)
@@ -60,19 +63,6 @@ public MidiMaestro(string filePath)
6063
break;
6164
}
6265
}
63-
64-
//Populate the song data
65-
songData = new SongData
66-
{
67-
//TODO: Allow for changes in this data
68-
Bpm = 120,
69-
//Fudge the numbers a bit if we have a really short song
70-
SongLength =
71-
_midiFile.GetDuration<MetricTimeSpan>().Seconds < 20
72-
? 20
73-
: _midiFile.GetDuration<MetricTimeSpan>().Seconds,
74-
NumLoops = 1,
75-
};
7666
}
7767

7868
public midiNoteInfo[] GetNotes(ArrowType arrowType)
@@ -86,30 +76,29 @@ public midiNoteInfo[] GetNotes(ArrowType arrowType)
8676
_ => throw new ArgumentOutOfRangeException(nameof(arrowType), arrowType, null),
8777
};
8878
}
89-
90-
public SongData GetSongData()
91-
{
92-
return songData;
93-
}
9479
}
9580

9681
//A facade to wrap the midi notes. This is a simple class that wraps a Note object from the DryWetMidi library.
9782
public class midiNoteInfo
9883
{
9984
private readonly Melanchall.DryWetMidi.Interaction.Note _note;
100-
private readonly TempoMap _tempoMap;
10185

102-
public midiNoteInfo(Melanchall.DryWetMidi.Interaction.Note note, TempoMap tempoMap)
86+
public midiNoteInfo(Melanchall.DryWetMidi.Interaction.Note note)
10387
{
10488
_note = note;
105-
_tempoMap = tempoMap;
89+
}
90+
91+
public long GetStartTimeBeat()
92+
{
93+
var beatsBar = _note.TimeAs<BarBeatTicksTimeSpan>(MidiMaestro.TempoMap);
94+
return beatsBar.Bars * MidiMaestro.TimeSignature.Numerator + beatsBar.Beats;
10695
}
10796

10897
public long GetStartTimeTicks() => _note.Time;
10998

11099
public float GetStartTimeSeconds() =>
111-
_note.TimeAs<MetricTimeSpan>(_tempoMap).Milliseconds / 1000f
112-
+ _note.TimeAs<MetricTimeSpan>(_tempoMap).Seconds;
100+
_note.TimeAs<MetricTimeSpan>(MidiMaestro.TempoMap).Milliseconds / 1000f
101+
+ _note.TimeAs<MetricTimeSpan>(MidiMaestro.TempoMap).Seconds;
113102

114103
public long GetEndTime() => _note.EndTime;
115104

Classes/Notes/Note.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
public partial class Note : Resource, IDisplayable
1010
{
1111
public PuppetTemplate Owner;
12+
public int Id;
1213
public string Name { get; set; }
1314
private int _baseVal;
1415
public float CostModifier { get; private set; }
15-
private Action<BattleDirector, Note, Timing> NoteEffect; //TODO: Where/How to deal with timing.
16+
private Action<BattleDirector, Note, Timing> NoteEffect;
1617

1718
public string Tooltip { get; set; }
1819
public Texture2D Texture { get; set; }
1920

2021
public Note(
22+
int id,
2123
string name,
2224
string tooltip,
2325
Texture2D texture = null,
@@ -27,14 +29,15 @@ public Note(
2729
float costModifier = 1.0f
2830
)
2931
{
32+
Id = id;
3033
Name = name;
3134
Owner = owner;
3235
NoteEffect =
3336
noteEffect
3437
?? (
3538
(BD, source, Timing) =>
3639
{
37-
BD.GetTarget(this).TakeDamage(source._baseVal);
40+
BD.GetTarget(this).TakeDamage((int)Timing * source._baseVal);
3841
}
3942
);
4043
_baseVal = baseVal;
@@ -52,7 +55,21 @@ public Note Clone()
5255
{
5356
//Eventually could look into something more robust, but for now shallow copy is preferable.
5457
//We only would want val and name to be copied by value
55-
Note newNote = new Note(Name, Tooltip, Texture, Owner, _baseVal, NoteEffect, CostModifier);
58+
Note newNote = new Note(
59+
Id,
60+
Name,
61+
Tooltip,
62+
Texture,
63+
Owner,
64+
_baseVal,
65+
NoteEffect,
66+
CostModifier
67+
);
5668
return newNote;
5769
}
70+
71+
public int GetBaseVal()
72+
{
73+
return _baseVal;
74+
}
5875
}

0 commit comments

Comments
 (0)