Commit 2e76df20 authored by 16이상민's avatar 16이상민

Corrected the cause of malfunction in scene other than game: Concat () is a...

Corrected the cause of malfunction in scene other than game: Concat () is a Linq method, so it returns the result of performing the action.
parent e880d437
......@@ -351,7 +351,7 @@ public class JudgeManager : MonoBehaviour
}
}
class MotionGageManager : MonoBehaviour
class MotionGageManager
{
public GameObject motionGuage;
private float elapsedMotion;
......
......@@ -13,27 +13,40 @@ public class TrackInfo
public float BPM { get; private set; }
public int Level { get; private set; }
public float BeatInterval
{ get { return 4 * 60 * 1000f / BPM; } }
public AudioSource BGM { get; private set; }
public List<string> TrackList { get; private set; }
public List<Note> Notes { get; private set; }
public TrackInfo(string path): this(new FileInfo(path))
public
TrackInfo(
string path)
: this(
new FileInfo(
path))
{ }
public TrackInfo(FileInfo file)
public
TrackInfo(
FileInfo file)
{
MultiDictionary<string, string> parseResult = ParseBPE(file);
ExtractTrackHeader(parseResult);
TrackNotes notes = new TrackNotes();
notes.ExtractNotes(parseResult, BPM);
Notes = notes.Notes;
notes.ExtractNotes(parseResult, BeatInterval);
Notes = notes.Notes.ToList();
}
MultiDictionary<string, string> ParseBPE(FileInfo file)
private
MultiDictionary<string, string>
ParseBPE(
FileInfo file)
{
MultiDictionary<string, string> result = new MultiDictionary<string, string>();
......@@ -55,7 +68,10 @@ public class TrackInfo
return result;
}
private void ExtractTrackHeader(MultiDictionary<string, string> parseResult)
private
void
ExtractTrackHeader(
MultiDictionary<string, string> parseResult)
{
TrackHeader header = new TrackHeader();
header.ExtractHeader(parseResult);
......@@ -97,22 +113,32 @@ internal class MultiDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, Li
}
}
public bool TryGetValue(TKey key, out List<TValue> value)
public
bool
TryGetValue(
TKey key,
out List<TValue> value)
{
return dictionary.TryGetValue(key, out value);
}
public IEnumerator<KeyValuePair<TKey, List<TValue>>> GetEnumerator()
public
IEnumerator<KeyValuePair<TKey, List<TValue>>>
GetEnumerator()
{
return dictionary.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
IEnumerator
IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool Remove(TKey key)
public
bool
Remove(
TKey key)
{
return dictionary.Remove(key);
}
......@@ -128,18 +154,39 @@ internal class TrackHeader
public AudioSource BGM { get; private set; }
public List<string> TrackList { get; private set; }
public void ExtractHeader(MultiDictionary<string, string> parseResult)
{
Title = ExtractMetaString(parseResult, "#TITLE");
Artist = ExtractMetaString(parseResult, "#ARTIST");
Genre = ExtractMetaString(parseResult, "#GENRE");
BPM = ExtractBPM(parseResult);
Level = ExtractLevel(parseResult);
TrackList = ExtractMetaList(parseResult, "#TRACKLIST");
BGM = Resources.Load(ExtractMetaString(parseResult, "#WAV")) as AudioSource;
}
private List<string> ExtractMetaList(MultiDictionary<string, string> parseResult, string key)
public
void
ExtractHeader(
MultiDictionary<string, string> parseResult)
{
Title = ExtractMetaString(
parseResult,
"#TITLE");
Artist = ExtractMetaString(
parseResult,
"#ARTIST");
Genre = ExtractMetaString(
parseResult,
"#GENRE");
BPM = ExtractBPM(
parseResult);
Level = ExtractLevel(
parseResult);
TrackList = ExtractMetaList(
parseResult,
"#TRACKLIST");
BGM = Resources.Load(
ExtractMetaString(
parseResult,
"#WAV"))
as AudioSource;
}
private
List<string>
ExtractMetaList(
MultiDictionary<string, string> parseResult,
string key)
{
List<string> list;
......@@ -149,17 +196,24 @@ internal class TrackHeader
return list;
}
return null;
return Enumerable.Empty<string>().ToList();
}
private string ExtractMetaString(MultiDictionary<string, string> parseResult, string key)
private
string
ExtractMetaString(
MultiDictionary<string, string> parseResult,
string key)
{
List<string> list = ExtractMetaList(parseResult, key);
return list == null ? null : list[0];
return list.Count() == 0 ? null : list[0];
}
private float ExtractBPM(MultiDictionary<string, string> parseResult)
private
float
ExtractBPM(
MultiDictionary<string, string> parseResult)
{
string str = ExtractMetaString(parseResult, "#BPM");
......@@ -170,7 +224,10 @@ internal class TrackHeader
return 0;
}
private int ExtractLevel(MultiDictionary<string, string> parseResult)
private
int
ExtractLevel(
MultiDictionary<string, string> parseResult)
{
string str = ExtractMetaString(parseResult, "#PLAYLEVEL");
......@@ -184,24 +241,32 @@ internal class TrackHeader
internal class TrackNotes
{
private List<Note> notes = new List<Note>();
public List<Note> Notes
{ get { return notes; } }
public IEnumerable<Note> Notes
{ get; private set; }
public void ExtractNotes(MultiDictionary<string, string> parseResult, float BPM)
public
void
ExtractNotes(
MultiDictionary<string, string> parseResult,
float interval)
{
var validSigns = ExtractValidSigns(parseResult);
CreateNotes(validSigns, BPM);
CreateBeatLines(ExtractEnd(validSigns), BPM);
CreateNotes(validSigns, interval);
CreateBeatLines(ExtractEnd(validSigns), interval);
}
IEnumerable<KeyValuePair<string, List<string>>> ExtractValidSigns(MultiDictionary<string, string> parseResult)
private
IEnumerable<KeyValuePair<string, List<string>>>
ExtractValidSigns(
MultiDictionary<string, string> parseResult)
{
return parseResult.Where(x => IsValidSignType(x.Key));
}
bool IsValidSignType(string signType)
private
bool
IsValidSignType(
string signType)
{
int measure;
......@@ -211,63 +276,113 @@ internal class TrackNotes
signType.Substring(4, 3));
}
int ExtractEnd(IEnumerable<KeyValuePair<string, List<string>>> validSigns)
private
int
ExtractEnd(
IEnumerable<KeyValuePair<string, List<string>>> validSigns)
{
return validSigns.Select(x => int.Parse(x.Key.Substring(1, 3))).Max();
}
void CreateBeatLines(int end, float BPM)
private
void
CreateBeatLines(
int end,
float interval)
{
Notes.Concat(Enumerable.Range(1, (end + 1) * 4)
.Select(x => new Note(NoteType.BeatLine, (x / 4.0f) * (4 * 60 * 1000f / BPM))));
Notes = Notes.Concat(Enumerable.Range(1, (end + 1) * 4)
.Select(x => new Note(NoteType.BeatLine, (x / 4.0f) * interval)))
.ToList();
}
void CreateNotes(IEnumerable<KeyValuePair<string, List<string>>> validSigns, float BPM)
private
void
CreateNotes(
IEnumerable<KeyValuePair<string, List<string>>> validSigns,
float interval)
{
notes = new List<Note>();
Notes = Enumerable.Empty<Note>();
var noteMaker = new NoteMaker();
validSigns.ToList().ForEach(x => AddNoteSign(x, 4 * 60 * 1000f / BPM, new NoteMaker()));
validSigns.ToList().ForEach(x => AddNoteSign(x, interval, noteMaker));
}
void AddNoteSign(KeyValuePair<string, List<string>> parsedItem, float miliSeconds, NoteMaker noteMaker)
private
void
AddNoteSign(
KeyValuePair<string, List<string>> parsedItem,
float interval,
NoteMaker noteMaker)
{
parsedItem.Value.ForEach(x => Notes.Concat(NoteSignGenerator.SignToNotes(x, parsedItem.Key, miliSeconds, noteMaker)));
parsedItem.Value.ForEach(x => Notes = Notes.Concat(NoteSignGenerator.SignToNotes(x, parsedItem.Key, interval, noteMaker)));
}
}
internal class NoteSignGenerator
{
public static IEnumerable<Note> SignToNotes(string sign, string signType, float miliSeconds, NoteMaker noteMaker)
public static
IEnumerable<Note>
SignToNotes(
string sign,
string signType,
float interval,
NoteMaker noteMaker)
{
return GenerateNoteSequence(Enumerable.Range(0, sign.Length / 2),
x => CurrentCode(x, sign),
x => ComputeTiming(int.Parse(signType.Substring(1, 3)), x, sign.Length / 2, miliSeconds),
x => ComputeTiming(int.Parse(signType.Substring(1, 3)), x, sign.Length / 2, interval),
(code, timing) => MakeNote(noteMaker, code, signType.Substring(4, 3), timing));
}
static string CurrentCode(int location, string sign)
private static
string
CurrentCode(
int location,
string sign)
{
return sign.Substring(location * 2, 2);
}
static float ComputeTiming(float measure, int location, int sequenceSize, float miliSeconds)
private static
float
ComputeTiming(
float measure,
int location,
int sequenceSize,
float interval)
{
return (measure + (float)location / sequenceSize) * miliSeconds;
return (measure + (float)location / sequenceSize) * interval;
}
static Note MakeNote(NoteMaker noteMaker, string code, string type, float timing)
private static
Note
MakeNote(
NoteMaker noteMaker,
string code,
string type,
float timing)
{
return noteMaker.Make(code, type, timing);
}
static IEnumerable<Note> GenerateNoteSequence(IEnumerable<int> range, Func<int, string> currentCode, Func<int, float> calcTiming, Func<string, float, Note> concreteNote)
private static
IEnumerable<Note>
GenerateNoteSequence(
IEnumerable<int> range,
Func<int, string> currentCode,
Func<int, float> calcTiming,
Func<string, float, Note> concreteNote)
{
return DiscreteRange(range, x => currentCode(x))
.Select(x => concreteNote(currentCode(x), calcTiming(x)))
.Where(x => x != null);
}
static IEnumerable<int> DiscreteRange(IEnumerable<int> range, Func<int, string> currentCode)
private static
IEnumerable<int>
DiscreteRange(
IEnumerable<int> range,
Func<int, string> currentCode)
{
return range.Where(x => currentCode(x).Equals("00"));
}
......@@ -277,7 +392,12 @@ internal abstract class NoteMakerBase
{
protected float? Timing = null;
public Note Make(string code, string type, float timing)
public
Note
Make(
string code,
string type,
float timing)
{
if (NotValidType(type))
return null;
......@@ -291,39 +411,74 @@ internal abstract class NoteMakerBase
return null;
}
bool IsShort(string type)
private
bool
IsShort(
string type)
{
return type[0] == 'S';
}
bool IsLongEnd(string type)
private
bool
IsLongEnd(
string type)
{
return type[0] == 'L' && Timing != null;
}
void RegisterTiming(float timing)
private
void
RegisterTiming(
float timing)
{
Timing = timing;
}
abstract protected bool NotValidType(string type);
abstract protected Note MakeShort(string code, string type, float timing);
abstract protected Note MakeLong(string code, string type, float timing);
abstract protected
bool
NotValidType(
string type);
abstract protected
Note
MakeShort(
string code,
string type,
float timing);
abstract protected
Note
MakeLong(
string code,
string type,
float timing);
}
internal class ButtonNoteMaker : NoteMakerBase
{
override protected bool NotValidType(string type)
override protected
bool
NotValidType(
string type)
{
return type.Substring(1) != "BT";
}
override protected Note MakeShort(string code, string type, float timing)
override protected
Note
MakeShort(
string code,
string type,
float timing)
{
return new Note(code, type, timing);
}
override protected Note MakeLong(string code, string type, float timing)
override protected
Note
MakeLong(
string code,
string type,
float timing)
{
float start = Timing.Value;
Timing = null;
......@@ -334,20 +489,33 @@ internal class ButtonNoteMaker : NoteMakerBase
internal class MotionNoteMaker : NoteMakerBase
{
override protected bool NotValidType(string type)
override protected
bool
NotValidType(
string type)
{
Type motionType;
return type.Substring(1) != "MO" ||
!MotionNote.keymap.TryGetValue(type, out motionType);
}
override protected Note MakeShort(string code, string type, float timing)
override protected
Note
MakeShort(
string code,
string type,
float timing)
{
return (MotionNote)Activator.CreateInstance
(MotionNote.keymap[type], code, timing);
}
override protected Note MakeLong(string code, string type, float timing)
override protected
Note
MakeLong(
string code,
string type,
float timing)
{
float start = Timing.Value;
Timing = null;
......@@ -362,7 +530,12 @@ internal class NoteMaker
ButtonNoteMaker buttonNoteMaker = new ButtonNoteMaker();
MotionNoteMaker motionNoteMaker = new MotionNoteMaker();
public Note Make(string code, string type, float timing)
public
Note
Make(
string code,
string type,
float timing)
{
return motionNoteMaker.Make(code, type, timing) ??
buttonNoteMaker.Make(code, type, timing);
......
......@@ -94,7 +94,7 @@ public class TrackManager : MonoBehaviour {
var stretched = Enumerable.Empty<TrackInfo>();
Enumerable.Range(0, 1 + (4 / tracks.Count()))
.ToList()
.ForEach(x => stretched.Concat(tracks));
.ForEach(x => stretched = stretched.Concat(tracks));
return stretched;
}
......@@ -120,9 +120,9 @@ public class TrackManager : MonoBehaviour {
Artist.text = "Artist :" + info.Artist.ToString();
BPM.text = "BPM :" + info.BPM .ToString();
trackInfo.GetComponentsInChildren<Transform>()
.ToList()
.ForEach(x => Destroy(x));
trackInfo.transform.Cast<Transform>()
.ToList()
.ForEach(x => Destroy(x.gameObject));
info.TrackList
.ForEach(x => Instantiate(trackInfoItemPrefab, trackInfo.transform)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment