Looking up tracks
If you're a mod trying to determine things about tracks, you'll probably be looking for some way to look up information about that track. Look no further than the TrackLookup API!
Basic usage
Simply call TrackLookup.lookup with the trackref you want to look up:
open BaboonAPI.Hooks.Tracks
let track = TrackLookup.lookup "mare"
track.trackname_long // => "Old Gray Mare"
|
Note that this method will throw an exception if the track can't be found. If you want to handle this, use TrackLookup.tryLookup instead:
let maybeTrack = TrackLookup.tryLookup "mare"
maybeTrack |> Option.map (fun track -> track.trackname_long)
// => Some("Old Gray Mare")
|
Checking whether a track is custom
While BaboonAPI has no knowledge of custom tracks itself, you can use an is
pattern to conditionally cast
the returned TromboneTrack to a subclass.
For example, TrombLoader's custom track class is named CustomTrack
:
open TrombLoader.CustomTracks
let bakaMitaiTrack = TrackLookup.lookup "BakaMitai"
match bakaMitaiTrack with
| :? CustomTrack as ct ->
// This is a TrombLoader track!
ct.folderPath
| track ->
// Not a TrombLoader track - something else!
track.trackname_long
|
Looking up scores
If you want to look up locally saved high scores for a track, you can use TrackLookup.trackScore:
let possibleScores = TrackLookup.lookupScore "BakaMitai"
If the track has been played at least once, you'll get a Some(SavedTrackScore)
back!
Otherwise, you'll get None. Note that the track might exist even if its score hasn't been saved -
use tryLookup
if you want to check that!
match possibleScores with
| Some score ->
let lastFiveHighScores = score.highScores
let highestRank = score.highestRank
// Now we have highscores!
()
| None ->
// Track wasn't found in score storage!
()
Additional utilities
If you need a SingleTrackData
for whatever reason, you can convert any TromboneTrack
easily:
let trackData = TrackLookup.toTrackData bakaMitaiTrack
trackData.trackname_long // => "Baka Mitai"
<summary> Public hooks to look up registered tracks </summary>
<summary> Look up a track by trackref </summary>
<summary> Look up a track by trackref, returning None if the track doesn't exist. </summary>
type CustomTrack = interface TromboneTrack new: trackRef: string * name: string * shortName: string * author: string * description: string * endpoint: float32 * year: int * genre: string * difficulty: int * tempo: float32 * backgroundMovement: string * savednotespacing: int * timesig: int * lyrics: List<Lyric> * note_color_start: float32 array * note_color_end: float32 array * notes: float32 array array * bgdata: float32 array array -> unit member IsVisible: unit -> bool member LoadChart: unit -> SavedLevel member LoadTrack: unit -> LoadedTromboneTrack val author: string val description: string val endpoint: float32 val name: string val shortName: string ...
--------------------
CustomTrack(trackRef: string, name: string, shortName: string, author: string, description: string, endpoint: float32, year: int, genre: string, difficulty: int, tempo: float32, backgroundMovement: string, savednotespacing: int, timesig: int, lyrics: System.Collections.Generic.List<CustomTrack.Lyric>, note_color_start: float32 array, note_color_end: float32 array, notes: float32 array array, bgdata: float32 array array) : CustomTrack
<summary>Get the current high scores for a track.</summary>
<returns>None if there is no saved data for the trackref, Some otherwise.</returns>
<summary> Convert a TromboneTrack into a SingleTrackData </summary>