Skip to content

Commit 24c951f

Browse files
author
setchi
committed
Refactor
1 parent ca80ea3 commit 24c951f

File tree

9 files changed

+33
-66
lines changed

9 files changed

+33
-66
lines changed

Assets/Resources.meta

Lines changed: 0 additions & 9 deletions
This file was deleted.

Assets/Resources/Settings.meta

Lines changed: 0 additions & 9 deletions
This file was deleted.

Assets/Resources/Settings/default.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Resources/Settings/default.json.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/Scripts/DTO/SettingsDTO.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@ public class SettingsDTO
77
public string workSpacePath;
88
public int maxBlock;
99
public List<int> noteInputKeyCodes;
10+
11+
public static SettingsDTO GetDefaultSettings()
12+
{
13+
return new SettingsDTO
14+
{
15+
workSpacePath = "",
16+
maxBlock = 5,
17+
noteInputKeyCodes = new List<int> { 114, 99, 103, 121, 98 }
18+
};
19+
}
1020
}
1121
}

Assets/Scripts/GLDrawing/BeatNumberRenderer.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ public class BeatNumberRenderer : SingletonMonoBehaviour<BeatNumberRenderer>
1515
List<Text> textPool = new List<Text>();
1616

1717
static int size;
18-
static int prevActiveCount = 0;
19-
static int currentActiveCount = 0;
18+
static int countPrevActive = 0;
19+
static int countCurrentActive = 0;
2020

2121
static public void Render(Vector3 pos, int number)
2222
{
23-
if (currentActiveCount < size)
23+
if (countCurrentActive < size)
2424
{
25-
if (currentActiveCount >= prevActiveCount)
25+
if (countCurrentActive >= countPrevActive)
2626
{
27-
Instance.textPool[currentActiveCount].gameObject.SetActive(true);
27+
Instance.textPool[countCurrentActive].gameObject.SetActive(true);
2828
}
2929

30-
Instance.rectTransformPool[currentActiveCount].position = pos;
31-
Instance.textPool[currentActiveCount].text = number.ToString();
30+
Instance.rectTransformPool[countCurrentActive].position = pos;
31+
Instance.textPool[countCurrentActive].text = number.ToString();
3232
}
3333
else
3434
{
@@ -39,35 +39,35 @@ static public void Render(Vector3 pos, int number)
3939
size++;
4040
}
4141

42-
currentActiveCount++;
42+
countCurrentActive++;
4343
}
4444

4545
static public void Begin()
4646
{
47-
prevActiveCount = currentActiveCount;
48-
currentActiveCount = 0;
47+
countPrevActive = countCurrentActive;
48+
countCurrentActive = 0;
4949
}
5050

5151
static public void End()
5252
{
53-
if (currentActiveCount < prevActiveCount)
53+
if (countCurrentActive < countPrevActive)
5454
{
55-
for (int i = currentActiveCount; i < prevActiveCount; i++)
55+
for (int i = countCurrentActive; i < countPrevActive; i++)
5656
{
5757
Instance.textPool[i].gameObject.SetActive(false);
5858
}
5959
}
6060

61-
if (currentActiveCount * 2 < size)
61+
if (countCurrentActive * 2 < size)
6262
{
63-
foreach (var text in Instance.textPool.Skip(currentActiveCount + 1))
63+
foreach (var text in Instance.textPool.Skip(countCurrentActive + 1))
6464
{
6565
DestroyObject(text.gameObject);
6666
}
6767

68-
Instance.rectTransformPool.RemoveRange(currentActiveCount, size - currentActiveCount);
69-
Instance.textPool.RemoveRange(currentActiveCount, size - currentActiveCount);
70-
size = currentActiveCount;
68+
Instance.rectTransformPool.RemoveRange(countCurrentActive, size - countCurrentActive);
69+
Instance.textPool.RemoveRange(countCurrentActive, size - countCurrentActive);
70+
size = countCurrentActive;
7171
}
7272
}
7373
}

Assets/Scripts/GLDrawing/WaveformRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using NoteEditor.Model;
22
using System.Linq;
3+
using UniRx;
34
using UnityEngine;
45
using UnityEngine.UI;
5-
using UniRx;
66

77
namespace NoteEditor.GLDrawing
88
{
@@ -37,7 +37,7 @@ void LateUpdate()
3737

3838
var timeSamples = Mathf.Min(Audio.SmoothedTimeSamples.Value, Audio.Source.clip.samples - 1);
3939

40-
if (HasUpdate(timeSamples))
40+
if (!HasUpdate(timeSamples))
4141
return;
4242

4343
UpdateCache(timeSamples);
@@ -71,7 +71,7 @@ void ResetTexture()
7171

7272
bool HasUpdate(float timeSamples)
7373
{
74-
return cachedCanvasWidth == NoteCanvas.Width.Value && cachedTimeSamples == timeSamples;
74+
return cachedCanvasWidth != NoteCanvas.Width.Value || cachedTimeSamples != timeSamples;
7575
}
7676

7777
void UpdateCache(float timeSamples)

Assets/Scripts/Presenter/Common/SmoothedTimeSamplesPresenter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace NoteEditor.Presenter
88
public class SmoothedTimeSamplesPresenter : MonoBehaviour
99
{
1010
void Awake()
11-
{
12-
Audio.OnLoad.First().Subscribe(_ => Init());
13-
}
14-
15-
void Init()
1611
{
1712
var prevFrameSamples = 0f;
1813
var counter = 0;

Assets/Scripts/Presenter/Settings/SettingsWindowPresenter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using NoteEditor.Model;
2-
using NoteEditor.Utility;
1+
using NoteEditor.DTO;
2+
using NoteEditor.Model;
33
using System.IO;
44
using System.Linq;
55
using UniRx;
@@ -27,8 +27,7 @@ string LoadSettingsJson()
2727

2828
if (!File.Exists(filePath))
2929
{
30-
var defaultSettings = Resources.Load("Settings/default") as TextAsset;
31-
File.WriteAllText(filePath, defaultSettings.text, System.Text.Encoding.UTF8);
30+
File.WriteAllText(filePath, LitJson.JsonMapper.ToJson(SettingsDTO.GetDefaultSettings()), System.Text.Encoding.UTF8);
3231
}
3332

3433
return File.ReadAllText(filePath, System.Text.Encoding.UTF8);

0 commit comments

Comments
 (0)