Skip to content

Commit

Permalink
Better song caching
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Jan 2, 2023
1 parent 8d95d0c commit 238af32
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 26 deletions.
166 changes: 162 additions & 4 deletions Assets/Scenes/MenuScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,162 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1876917083}
m_CullTransparentMesh: 1
--- !u!1 &1886399722
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1886399723}
- component: {fileID: 1886399726}
- component: {fileID: 1886399725}
- component: {fileID: 1886399724}
m_Layer: 5
m_Name: Support Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1886399723
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2044165073}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -7.9999695, y: -30.500004}
m_SizeDelta: {x: 125, y: 11}
m_Pivot: {x: 0.9999996, y: 1}
--- !u!114 &1886399724
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: 0
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1886399725
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Custom
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2100000, guid: 1b9ed95aaf90c334f85001d466686cf6, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 9
m_fontSizeBase: 9
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 1
m_HorizontalAlignment: 4
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1886399726
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_CullTransparentMesh: 1
--- !u!1 &1986583190
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2440,11 +2596,11 @@ RectTransform:
m_Father: {fileID: 2044165073}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 46, y: -12.5}
m_SizeDelta: {x: -108, y: 24}
m_Pivot: {x: 0.5, y: 1}
m_AnchoredPosition: {x: -7.9999695, y: -12.5}
m_SizeDelta: {x: 125, y: 18}
m_Pivot: {x: 0.9999996, y: 1}
--- !u!114 &1986583192
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2595,6 +2751,7 @@ RectTransform:
m_Children:
- {fileID: 1844302445}
- {fileID: 1986583191}
- {fileID: 1886399723}
- {fileID: 1330867043}
- {fileID: 80151784}
m_Father: {fileID: 396272154}
Expand Down Expand Up @@ -2658,5 +2815,6 @@ MonoBehaviour:
songName: {fileID: 149797927}
artist: {fileID: 1290299072}
lengthText: {fileID: 1986583193}
supportText: {fileID: 1886399725}
albumCover: {fileID: 1330867046}
albumCoverAlt: {fileID: 1876917083}
80 changes: 71 additions & 9 deletions Assets/Script/Data/SongInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
using YARG.Serialization;

namespace YARG.Data {
[JsonObject(MemberSerialization.Fields)]
[JsonObject(MemberSerialization.OptIn)]
public class SongInfo {
[JsonIgnore]
public bool fetched;
[JsonIgnore]
public bool errored;

[JsonProperty]
[JsonConverter(typeof(DirectoryInfoConverter))]
public DirectoryInfo folder;

[field: JsonProperty("bassPedal2xExpertPlus")]
public bool BassPedal2xExpertPlus {
private set;
get;
}
[field: JsonProperty("live")]
public bool Live {
private set;
get;
Expand Down Expand Up @@ -46,10 +43,75 @@ public string SongName {
}
public string SongNameNoParen => SongName.Replace("(", "").Replace(")", "");

public string artistName;
public string source;
public bool WaveGroup {
private set;
get;
}

[JsonProperty("artist")]
private string _artistName;
public string ArtistName {
set {
const string WAVEGROUP = " (WaveGroup)";
WaveGroup = value.EndsWith(WAVEGROUP);
if (WaveGroup) {
value = value[..^WAVEGROUP.Length];
}

_artistName = value;
}
get => _artistName;
}

/// <value>
/// Used for JSON. Compresses flags (<see cref="BassPedal2xExpertPlus"/>, etc.) into a small string.
/// </value>
[JsonProperty("flags")]
public string JsonFlags {
get {
string o = "";

if (BassPedal2xExpertPlus) {
o += "B";
}
if (Live) {
o += "L";
}
if (WaveGroup) {
o += "W";
}

return o;
}
set {
string i = value;

if (i.StartsWith('B')) {
BassPedal2xExpertPlus = true;
i = i.Remove(0, 1);
} else {
BassPedal2xExpertPlus = false;
}
if (i.StartsWith('L')) {
Live = true;
i = i.Remove(0, 1);
} else {
Live = false;
}
if (i.StartsWith('W')) {
WaveGroup = true;
// i = i.Remove(0, 1);
} else {
WaveGroup = false;
}
}
}

[JsonProperty]
public string source;
[JsonProperty]
public float? songLength;
[JsonProperty]
public float delay;

public SongInfo(DirectoryInfo folder) {
Expand All @@ -59,10 +121,10 @@ public SongInfo(DirectoryInfo folder) {
var split = dirName.Split(" - ");
if (split.Length == 2) {
SongName = split[1];
artistName = split[0];
ArtistName = split[0];
} else {
SongName = dirName;
artistName = "Unknown";
ArtistName = "Unknown";
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void Update() {

// Audio raising and lowering based on player preformance
UpdateAudio("guitar", "guitar");
UpdateAudio("bass", "rhythm");
UpdateAudio("bass", "bass", "rhythm");
UpdateAudio("keys", "keys");

// Update beats
Expand All @@ -128,10 +128,12 @@ private void Update() {
}
}

private void UpdateAudio(string name, string audioName) {
// Skip if that audio track doesn't exist
if (!audioSources.TryGetValue(audioName, out var audioSource)) {
return;
private void UpdateAudio(string name, string audioName, string altAudioName = null) {
// Skip if that audio track doesn't exist and alt track doesn't exist
if (!audioSources.TryGetValue(audioName, out AudioSource audioSource)) {
if (altAudioName == null || !audioSources.TryGetValue(altAudioName, out audioSource)) {
return;
}
}

int total = PlayerManager.PlayersWithInstrument(name);
Expand Down
17 changes: 14 additions & 3 deletions Assets/Script/Serialization/MidiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,12 @@ private List<GenericLyricInfo> ParseGenericLyrics(TrackChunk trackChunk, TempoMa
foreach (var trackEvent in trackChunk.Events) {
totalDelta += trackEvent.DeltaTime;

if (trackEvent is not LyricEvent lyricEvent) {
if (trackEvent is not BaseTextEvent lyricEvent) {
continue;
}

// Skip if track name
if (lyricEvent.Text == "PART VOCALS") {
continue;
}

Expand All @@ -452,13 +457,19 @@ private List<GenericLyricInfo> ParseGenericLyrics(TrackChunk trackChunk, TempoMa
var time = (float) TimeConverter.ConvertTo<MetricTimeSpan>(totalDelta, tempo).TotalSeconds;
string text = lyricEvent.Text;

// Skip if state stats
if (text.StartsWith('[') && text.EndsWith(']')) {
continue;
}

// Remove all metadata
for (int i = text.Length - 1; i >= 0; i--) {
if (!char.IsWhiteSpace(text[i]) &&
if (text[i] == '#' || (
!char.IsWhiteSpace(text[i]) &&
!char.IsLetter(text[i]) &&
!char.IsNumber(text[i]) &&
text[i] != '\'' &&
text[i] != '-') {
text[i] != '-')) {

text = text.Remove(i, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/Serialization/SongIni.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static SongInfo CompleteSongInfo(SongInfo song, FileIniDataParser parser)

// Set basic info
song.SongName ??= section["name"];
song.artistName ??= section["artist"];
song.ArtistName ??= section["artist"];

// Get song source
if (section.ContainsKey("icon") && section["icon"] != "0") {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/UI/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void Awake() {
}

private void Start() {
songTitle.text = $"{Play.song.SongName} - {Play.song.artistName}";
songTitle.text = $"{Play.song.SongName} - {Play.song.ArtistName}";
}

private void Update() {
Expand Down
Loading

0 comments on commit 238af32

Please sign in to comment.