Skip to content

Commit

Permalink
Difficulties and custom track speed
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Dec 18, 2022
1 parent 9bd3379 commit 72e16cc
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Assets/Script/BeatLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace YARG {
public class BeatLine : Poolable {
private void Update() {
transform.localPosition -= new Vector3(0f, 0f, Time.deltaTime * Game.Instance.SongSpeed);
transform.localPosition -= new Vector3(0f, 0f, Time.deltaTime * pool.player.trackSpeed);

if (transform.localPosition.z < -3f) {
MoveToPool();
Expand Down
5 changes: 0 additions & 5 deletions Assets/Script/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ public float SongTime {
get => realSongTime + calibration;
}

public float SongSpeed {
get;
private set;
}
public Chart chart;

private void Awake() {
Instance = this;

chart = null;
SongSpeed = 7f;
calibration = -0.23f;
realSongTime = 0f;

Expand Down
4 changes: 2 additions & 2 deletions Assets/Script/NoteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void SetLength(float length) {
return;
}

length *= Game.Instance.SongSpeed;
length *= notePool.player.trackSpeed;
lengthCache = length;

lineRenderer.enabled = true;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void MissNote() {
}

private void Update() {
transform.localPosition -= new Vector3(0f, 0f, Time.deltaTime * Game.Instance.SongSpeed);
transform.localPosition -= new Vector3(0f, 0f, Time.deltaTime * notePool.player.trackSpeed);

if (isHitting) {
// Get the new line start position. Said position should be at
Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/NotePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace YARG {
public class NotePool : MonoBehaviour {
public PlayerManager.Player player;

[SerializeField]
private GameObject notePrefab;

Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace YARG {
public static class PlayerManager {
public class Player {
public string name;

public InputStrategy inputStrategy;
public float trackSpeed = 7f;

public string chosenInstrument = "guitar";
public int chosenDifficulty = 4;
Expand Down
5 changes: 5 additions & 0 deletions Assets/Script/Pools/Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

namespace YARG.Pools {
public class Pool : MonoBehaviour {
public PlayerManager.Player player;

/// <summary>
/// Unity inspector class ('cause we can't use dictionaries for some reason).
/// </summary>
[Serializable]
public class KVP {
public string id;
Expand Down
18 changes: 12 additions & 6 deletions Assets/Script/Serialization/MidiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ public override void Parse(Chart chart) {
try {
switch (trackName.Text) {
case "PART GUITAR":
chart.guitar[3] = ParseGuitar(trackChunk);
for (int i = 0; i < 4; i++) {
chart.guitar[i] = ParseGuitar(trackChunk, i);
}
break;
case "PART BASS":
chart.bass[3] = ParseGuitar(trackChunk);
for (int i = 0; i < 4; i++) {
chart.bass[i] = ParseGuitar(trackChunk, i);
}
break;
case "PART KEYS":
chart.keys[3] = ParseGuitar(trackChunk);
for (int i = 0; i < 4; i++) {
chart.keys[i] = ParseGuitar(trackChunk, i);
}
break;
case "BEAT":
chart.events = ParseBeats(trackChunk);
Expand All @@ -70,10 +76,10 @@ public override void Parse(Chart chart) {
difficulty?.Sort(new Comparison<NoteInfo>((a, b) => a.time.CompareTo(b.time)));
}
}
chart.events.Sort(new Comparison<EventInfo>((a, b) => a.time.CompareTo(b.time)));
chart.events?.Sort(new Comparison<EventInfo>((a, b) => a.time.CompareTo(b.time)));
}

private List<NoteInfo> ParseGuitar(TrackChunk trackChunk) {
private List<NoteInfo> ParseGuitar(TrackChunk trackChunk, int difficulty) {
var tempo = midi.GetTempoMap();

long totalDelta = 0;
Expand All @@ -91,7 +97,7 @@ private List<NoteInfo> ParseGuitar(TrackChunk trackChunk) {
}

// Expert octave
if (noteEvent.GetNoteOctave() != 7) {
if (noteEvent.GetNoteOctave() != 4 + difficulty) {
continue;
}

Expand Down
11 changes: 7 additions & 4 deletions Assets/Script/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ private void Awake() {
}

private void Start() {
notePool.player = player;
genericPool.player = player;

// Inputs

input = (FiveFretInputStrategy) player.inputStrategy;
Expand All @@ -81,7 +84,7 @@ private void Start() {

// Adjust hit window
var scale = hitWindow.localScale;
hitWindow.localScale = new(scale.x, Game.HIT_MARGIN * Game.Instance.SongSpeed * 2f, scale.z);
hitWindow.localScale = new(scale.x, Game.HIT_MARGIN * player.trackSpeed * 2f, scale.z);
}

private void OnDestroy() {
Expand Down Expand Up @@ -109,10 +112,10 @@ private void Update() {
// Update track UV
var trackMaterial = trackRenderer.material;
var oldOffset = trackMaterial.GetTextureOffset("_BaseMap");
float movement = Time.deltaTime * Game.Instance.SongSpeed / 4f;
float movement = Time.deltaTime * player.trackSpeed / 4f;
trackMaterial.SetTextureOffset("_BaseMap", new(oldOffset.x, oldOffset.y - movement));

float relativeTime = Game.Instance.SongTime + ((TRACK_SPAWN_OFFSET + 1.75f) / Game.Instance.SongSpeed);
float relativeTime = Game.Instance.SongTime + ((TRACK_SPAWN_OFFSET + 1.75f) / player.trackSpeed);

// Since chart is sorted, this is guaranteed to work
while (chart.Count > visualChartIndex && chart[visualChartIndex].time <= relativeTime) {
Expand Down Expand Up @@ -295,7 +298,7 @@ private void SpawnNote(NoteInfo noteInfo, float time) {
}

private float CalcLagCompensation(float currentTime, float noteTime) {
return (currentTime - noteTime) * Game.Instance.SongSpeed;
return (currentTime - noteTime) * player.trackSpeed;
}
}
}
16 changes: 16 additions & 0 deletions Assets/Script/UI/MainMenu.EditPlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private void SetupEditPlayers() {

var radioGroup = root.Q<RadioButtonGroup>("InputStrategyRadio");
var botMode = root.Q<Toggle>("BotMode");
var trackSpeed = root.Q<FloatField>("TrackSpeed");
var inputDeviceDropdown = root.Q<DropdownField>("InputDevice");
var inputStrategyPanel = root.Q<VisualElement>("InputStrategy");
var settingsList = root.Q<ListView>("SettingsList");
Expand Down Expand Up @@ -83,6 +84,8 @@ private void SetupEditPlayers() {

UpdateSettingsList(settingsList, playerList.selectedIndex);
}

trackSpeed.value = player.trackSpeed;
};

// Initialize player list buttons
Expand Down Expand Up @@ -149,6 +152,19 @@ private void SetupEditPlayers() {
playerList.RefreshItem(playerList.selectedIndex);
});

trackSpeed.RegisterValueChangedCallback(e => {
if (trackSpeed != e.target) {
return;
}

if (playerList.selectedIndex == -1) {
return;
}

var player = PlayerManager.players[playerList.selectedIndex];
player.trackSpeed = trackSpeed.value;
});

radioGroup.RegisterValueChangedCallback(e => {
if (radioGroup != e.target) {
return;
Expand Down
5 changes: 3 additions & 2 deletions Assets/UI/EditPlayers.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
<ui:ListView focusable="true" name="PlayersList" style="height: 100%;" />
</ui:VisualElement>
<ui:VisualElement name="InputStrategy" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); min-width: auto; min-height: auto; width: 30%;">
<ui:Label tabindex="-1" text="Input Strategy" display-tooltip-when-elided="true" style="-unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:Label tabindex="-1" text="Settings" display-tooltip-when-elided="true" name="Label" style="-unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:DropdownField index="-1" choices="System.Collections.Generic.List`1[System.String]" name="InputDevice" />
<ui:Toggle label="Bot Mode" name="BotMode" style="flex-wrap: nowrap; flex-direction: row;" />
<ui:FloatField label="Track Speed" value="7" name="TrackSpeed" />
<ui:RadioButtonGroup value="-1" choices="Five Fret" name="InputStrategyRadio" />
</ui:VisualElement>
<ui:VisualElement name="Settings" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); min-width: auto; min-height: auto; width: 40%;">
<ui:Label tabindex="-1" text="Settings" display-tooltip-when-elided="true" style="-unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:Label tabindex="-1" text="Input Strategy" display-tooltip-when-elided="true" style="-unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:ListView focusable="true" name="SettingsList" selection-type="None" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:VisualElement>
Expand Down
2 changes: 2 additions & 0 deletions Assets/UI/Themes/LightStyle.uss
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ Button {
background-color: rgb(255, 255, 255);
border-radius: 5px;
border-width: 0;
/*
transition-property: all, background-color;
transition-duration: 0s, 0.25s;
transition-timing-function: ease, ease;
transition-delay: 0s, 0s;
*/
color: rgb(0, 0, 0);
}

Expand Down
8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"dependencies": {
"com.unity.ai.navigation": "1.1.0-pre.1",
"com.unity.collab-proxy": "1.17.1",
"com.unity.ide.rider": "3.0.15",
"com.unity.ai.navigation": "1.1.1",
"com.unity.collab-proxy": "1.17.6",
"com.unity.ide.rider": "3.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.inputsystem": "1.4.4",
"com.unity.nuget.newtonsoft-json": "3.0.2",
"com.unity.probuilder": "5.0.6",
"com.unity.render-pipelines.universal": "14.0.3",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.1",
"com.unity.timeline": "1.7.2",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.3",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"com.unity.ai.navigation": {
"version": "1.1.0-pre.1",
"version": "1.1.1",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -19,7 +19,7 @@
"url": "https://packages.unity.com"
},
"com.unity.collab-proxy": {
"version": "1.17.1",
"version": "1.17.6",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -35,7 +35,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.15",
"version": "3.0.16",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -114,7 +114,7 @@
"url": "https://packages.unity.com"
},
"com.unity.services.core": {
"version": "1.4.2",
"version": "1.6.0",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -166,7 +166,7 @@
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.7.1",
"version": "1.7.2",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.2.0b4
m_EditorVersionWithRevision: 2022.2.0b4 (ecac8c2f6be0)
m_EditorVersion: 2022.2.0b16
m_EditorVersionWithRevision: 2022.2.0b16 (3c3b3e6cd1d7)

0 comments on commit 72e16cc

Please sign in to comment.