Skip to content

Commit de99dcd

Browse files
committed
Refactor base game track classes to make them accessible
1 parent e6afa78 commit de99dcd

File tree

3 files changed

+95
-85
lines changed

3 files changed

+95
-85
lines changed

BaboonAPI/BaboonAPI.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="internal\ScoreStorage.fs" />
5858
<Compile Include="internal\EntryPointLoader.fs" />
5959
<Compile Include="internal\Debug.fs" />
60+
<Compile Include="internal\BaseGame.fs" />
6061
<Compile Include="patch\TrackCountPatches.fs" />
6162
<Compile Include="patch\TrackrefPatches.fs" />
6263
<Compile Include="patch\BaseTracksLoaderPatch.fs" />

BaboonAPI/internal/BaseGame.fs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
namespace BaboonAPI.Internal.BaseGame
2+
3+
open System.IO
4+
open System.Runtime.Serialization.Formatters.Binary
5+
open BaboonAPI.Hooks.Tracks
6+
open BaboonAPI.Utility
7+
open BaboonAPI.Utility.Unity
8+
open UnityEngine
9+
10+
/// Base game loaded track, emulates base game behaviour for charts
11+
type public BaseGameLoadedTrack internal (trackref: string, bundle: AssetBundle) =
12+
interface LoadedTromboneTrack with
13+
member this.LoadAudio() =
14+
let obj = bundle.LoadAsset<GameObject>($"music_{trackref}")
15+
let src = obj.GetComponent<AudioSource>()
16+
{ Clip = src.clip; Volume = src.volume }
17+
18+
member this.LoadBackground _ctx =
19+
bundle.LoadAsset<GameObject> $"BGCam_{trackref}"
20+
21+
member this.Dispose() =
22+
bundle.Unload true
23+
24+
member this.SetUpBackgroundDelayed _ _ =
25+
()
26+
27+
member this.trackref = trackref
28+
29+
interface PauseAware with
30+
member this.CanResume = true
31+
32+
member this.OnPause _ = ()
33+
34+
member this.OnResume _ = ()
35+
36+
/// Base game TromboneTrack
37+
type public BaseGameTrack internal (data: string[]) =
38+
interface TromboneTrack with
39+
member _.trackname_long = data[0]
40+
member _.trackname_short = data[1]
41+
member _.trackref = data[2]
42+
member _.year = data[3]
43+
member _.artist = data[4]
44+
member _.genre = data[5]
45+
member _.desc = data[6]
46+
member _.difficulty = int data[7]
47+
member _.length = int data[8]
48+
member _.tempo = int data[9]
49+
50+
member this.LoadTrack() =
51+
let trackref = (this :> TromboneTrack).trackref
52+
let bundle = AssetBundle.LoadFromFile $"{Application.streamingAssetsPath}/trackassets/{trackref}"
53+
new BaseGameLoadedTrack (trackref, bundle)
54+
55+
member this.IsVisible() =
56+
let trackref = (this :> TromboneTrack).trackref
57+
match trackref with
58+
| "einefinal" -> GlobalVariables.localsave.progression_trombone_champ
59+
| _ -> true
60+
61+
member this.LoadChart() =
62+
let trackref = (this :> TromboneTrack).trackref
63+
let path = $"{Application.streamingAssetsPath}/leveldata/{trackref}.tmb"
64+
use stream = File.Open(path, FileMode.Open)
65+
BinaryFormatter().Deserialize(stream) :?> SavedLevel
66+
67+
interface Previewable with
68+
member this.LoadClip() =
69+
let trackref = (this :> TromboneTrack).trackref
70+
let path = $"{Application.streamingAssetsPath}/trackclips/{trackref}-sample.ogg"
71+
72+
loadAudioClip (path, AudioType.OGGVORBIS)
73+
|> Coroutines.map (Result.map (fun audioClip -> { Clip = audioClip; Volume = 0.9f }))
74+
75+
interface Graphable with
76+
member this.CreateGraph() =
77+
match (this :> TromboneTrack).trackref with
78+
| "warmup" -> Some (SongGraph.all 10)
79+
| "einefinal" -> Some (SongGraph.all 104)
80+
| _ -> None
81+
82+
type internal BaseGameTrackRegistry(songs: SongData) =
83+
/// List of base game trackrefs
84+
member _.trackrefs =
85+
songs.data_tracktitles
86+
|> Seq.map (fun data -> data[2])
87+
|> Seq.toList
88+
89+
interface TrackRegistrationEvent.Listener with
90+
override this.OnRegisterTracks () = seq {
91+
for array in songs.data_tracktitles do
92+
yield BaseGameTrack array
93+
}

BaboonAPI/patch/BaseTracksLoaderPatch.fs

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,11 @@ open System.IO
44
open System.Runtime.Serialization.Formatters.Binary
55
open BaboonAPI.Hooks.Tracks
66
open BaboonAPI.Internal
7-
open BaboonAPI.Utility
8-
open BaboonAPI.Utility.Unity
7+
open BaboonAPI.Internal.BaseGame
98
open BepInEx.Logging
109
open HarmonyLib
1110
open UnityEngine
1211

13-
type internal BaseGameLoadedTrack(trackref: string, bundle: AssetBundle) =
14-
interface LoadedTromboneTrack with
15-
member this.LoadAudio() =
16-
let obj = bundle.LoadAsset<GameObject>($"music_{trackref}")
17-
let src = obj.GetComponent<AudioSource>()
18-
{ Clip = src.clip; Volume = src.volume }
19-
20-
member this.LoadBackground _ctx =
21-
bundle.LoadAsset<GameObject> $"BGCam_{trackref}"
22-
23-
member this.Dispose() =
24-
bundle.Unload true
25-
26-
member this.SetUpBackgroundDelayed _ _ =
27-
()
28-
29-
member this.trackref = trackref
30-
31-
interface PauseAware with
32-
member this.CanResume = true
33-
34-
member this.OnPause _ = ()
35-
36-
member this.OnResume _ = ()
37-
38-
type internal BaseGameTrack(data: string[]) =
39-
interface TromboneTrack with
40-
member _.trackname_long = data[0]
41-
member _.trackname_short = data[1]
42-
member _.trackref = data[2]
43-
member _.year = data[3]
44-
member _.artist = data[4]
45-
member _.genre = data[5]
46-
member _.desc = data[6]
47-
member _.difficulty = int data[7]
48-
member _.length = int data[8]
49-
member _.tempo = int data[9]
50-
51-
member this.LoadTrack() =
52-
let trackref = (this :> TromboneTrack).trackref
53-
let bundle = AssetBundle.LoadFromFile $"{Application.streamingAssetsPath}/trackassets/{trackref}"
54-
new BaseGameLoadedTrack (trackref, bundle)
55-
56-
member this.IsVisible() =
57-
let trackref = (this :> TromboneTrack).trackref
58-
match trackref with
59-
| "einefinal" -> GlobalVariables.localsave.progression_trombone_champ
60-
| _ -> true
61-
62-
member this.LoadChart() =
63-
let trackref = (this :> TromboneTrack).trackref
64-
let path = $"{Application.streamingAssetsPath}/leveldata/{trackref}.tmb"
65-
use stream = File.Open(path, FileMode.Open)
66-
BinaryFormatter().Deserialize(stream) :?> SavedLevel
67-
68-
interface Previewable with
69-
member this.LoadClip() =
70-
let trackref = (this :> TromboneTrack).trackref
71-
let path = $"{Application.streamingAssetsPath}/trackclips/{trackref}-sample.ogg"
72-
73-
loadAudioClip (path, AudioType.OGGVORBIS)
74-
|> Coroutines.map (Result.map (fun audioClip -> { Clip = audioClip; Volume = 0.9f }))
75-
76-
interface Graphable with
77-
member this.CreateGraph() =
78-
match (this :> TromboneTrack).trackref with
79-
| "warmup" -> Some (SongGraph.all 10)
80-
| "einefinal" -> Some (SongGraph.all 104)
81-
| _ -> None
82-
83-
type internal BaseGameTrackRegistry(songs: SongData) =
84-
/// List of base game trackrefs
85-
member _.trackrefs =
86-
songs.data_tracktitles
87-
|> Seq.map (fun data -> data[2])
88-
|> Seq.toList
89-
90-
interface TrackRegistrationEvent.Listener with
91-
override this.OnRegisterTracks () = seq {
92-
for array in songs.data_tracktitles do
93-
yield BaseGameTrack array
94-
}
95-
9612
[<HarmonyPatch(typeof<SaverLoader>, "loadLevelData")>]
9713
type LoaderPatch() =
9814
static let logger = Logger.CreateLogSource "BaboonAPI.BaseTracksLoader"

0 commit comments

Comments
 (0)