Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
setchi committed Oct 30, 2015
1 parent ca80ea3 commit 24c951f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 66 deletions.
9 changes: 0 additions & 9 deletions Assets/Resources.meta

This file was deleted.

9 changes: 0 additions & 9 deletions Assets/Resources/Settings.meta

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Resources/Settings/default.json

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/Resources/Settings/default.json.meta

This file was deleted.

10 changes: 10 additions & 0 deletions Assets/Scripts/DTO/SettingsDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@ public class SettingsDTO
public string workSpacePath;
public int maxBlock;
public List<int> noteInputKeyCodes;

public static SettingsDTO GetDefaultSettings()
{
return new SettingsDTO
{
workSpacePath = "",
maxBlock = 5,
noteInputKeyCodes = new List<int> { 114, 99, 103, 121, 98 }
};
}
}
}
34 changes: 17 additions & 17 deletions Assets/Scripts/GLDrawing/BeatNumberRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class BeatNumberRenderer : SingletonMonoBehaviour<BeatNumberRenderer>
List<Text> textPool = new List<Text>();

static int size;
static int prevActiveCount = 0;
static int currentActiveCount = 0;
static int countPrevActive = 0;
static int countCurrentActive = 0;

static public void Render(Vector3 pos, int number)
{
if (currentActiveCount < size)
if (countCurrentActive < size)
{
if (currentActiveCount >= prevActiveCount)
if (countCurrentActive >= countPrevActive)
{
Instance.textPool[currentActiveCount].gameObject.SetActive(true);
Instance.textPool[countCurrentActive].gameObject.SetActive(true);
}

Instance.rectTransformPool[currentActiveCount].position = pos;
Instance.textPool[currentActiveCount].text = number.ToString();
Instance.rectTransformPool[countCurrentActive].position = pos;
Instance.textPool[countCurrentActive].text = number.ToString();
}
else
{
Expand All @@ -39,35 +39,35 @@ static public void Render(Vector3 pos, int number)
size++;
}

currentActiveCount++;
countCurrentActive++;
}

static public void Begin()
{
prevActiveCount = currentActiveCount;
currentActiveCount = 0;
countPrevActive = countCurrentActive;
countCurrentActive = 0;
}

static public void End()
{
if (currentActiveCount < prevActiveCount)
if (countCurrentActive < countPrevActive)
{
for (int i = currentActiveCount; i < prevActiveCount; i++)
for (int i = countCurrentActive; i < countPrevActive; i++)
{
Instance.textPool[i].gameObject.SetActive(false);
}
}

if (currentActiveCount * 2 < size)
if (countCurrentActive * 2 < size)
{
foreach (var text in Instance.textPool.Skip(currentActiveCount + 1))
foreach (var text in Instance.textPool.Skip(countCurrentActive + 1))
{
DestroyObject(text.gameObject);
}

Instance.rectTransformPool.RemoveRange(currentActiveCount, size - currentActiveCount);
Instance.textPool.RemoveRange(currentActiveCount, size - currentActiveCount);
size = currentActiveCount;
Instance.rectTransformPool.RemoveRange(countCurrentActive, size - countCurrentActive);
Instance.textPool.RemoveRange(countCurrentActive, size - countCurrentActive);
size = countCurrentActive;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/GLDrawing/WaveformRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using NoteEditor.Model;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using UniRx;

namespace NoteEditor.GLDrawing
{
Expand Down Expand Up @@ -37,7 +37,7 @@ void LateUpdate()

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

if (HasUpdate(timeSamples))
if (!HasUpdate(timeSamples))
return;

UpdateCache(timeSamples);
Expand Down Expand Up @@ -71,7 +71,7 @@ void ResetTexture()

bool HasUpdate(float timeSamples)
{
return cachedCanvasWidth == NoteCanvas.Width.Value && cachedTimeSamples == timeSamples;
return cachedCanvasWidth != NoteCanvas.Width.Value || cachedTimeSamples != timeSamples;
}

void UpdateCache(float timeSamples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ namespace NoteEditor.Presenter
public class SmoothedTimeSamplesPresenter : MonoBehaviour
{
void Awake()
{
Audio.OnLoad.First().Subscribe(_ => Init());
}

void Init()
{
var prevFrameSamples = 0f;
var counter = 0;
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/Presenter/Settings/SettingsWindowPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NoteEditor.Model;
using NoteEditor.Utility;
using NoteEditor.DTO;
using NoteEditor.Model;
using System.IO;
using System.Linq;
using UniRx;
Expand Down Expand Up @@ -27,8 +27,7 @@ string LoadSettingsJson()

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

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

0 comments on commit 24c951f

Please sign in to comment.