예제 #1
0
        public IEnumerator LoadBackImage(string path)
        {
            defaultBackground.SetActive(false);

            if (Game.Packet.loadFromResources)
            {
                imageFrame.texture = Resources.Load <Texture2D>(path);
                imageFrame.gameObject.SetActive(true);
                loaded = true;
            }
            else
            {
                var request = UnityWebRequestTexture.GetTexture(path);
                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    TSystemStatic.LogWarning("Error occured while loading background image.");
                }
                else
                {
                    imageFrame.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
                    imageFrame.gameObject.SetActive(true);
                    loaded = true;
                }
            }
        }
예제 #2
0
        public IEnumerator LoadMusic(string file, AudioType type)
        {
            loaded = false;
            if (Game.Packet.loadFromResources)
            {
                GetComponent <AudioSource>().clip   = Resources.Load <AudioClip>(file);
                GetComponent <AudioSource>().volume = TSystemConfig.Now.musicVolume;

                loaded = true;
            }
            else
            {
                var request = UnityWebRequestMultimedia.GetAudioClip(file, type);
                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    TSystemStatic.LogWarning("Error occured while loading music.");
                }
                else
                {
                    GetComponent <AudioSource>().clip   = ((DownloadHandlerAudioClip)request.downloadHandler).audioClip;
                    GetComponent <AudioSource>().volume = TSystemConfig.Now.musicVolume;

                    loaded = true;
                }
            }
        }
예제 #3
0
        public bool ParseTWx(string rawData)
        {
            bool initNoteUsed = false;

            try
            {
                var data = JsonMapper.ToObject <TWxData>(rawData);

                for (int i = 0; i < data.notes.Length; i++)
                {
                    if (!initNoteUsed && TSystemConfig.Now.gameSync <= data.notes[i].Time)
                    {
                        Game.CreateNote(new NoteData
                                            (0, 0, TSystemConfig.Now.gameSync, Game.NoteSpeed, 0, 0, NoteType.Starter, FlickType.NotFlick, Color.white, new List <int>()));
                        initNoteUsed = true;
                    }
                    var noteData = new NoteData(data.notes[i]);
                    Game.CreateNote(noteData);
                }
                return(true);
            }
            catch (Exception e)
            {
                TSystemStatic.LogWithException("Failed to parse TWx type beatmap.", e);
                return(false);
            }
        }
예제 #4
0
        public bool ParseSSTrain(string rawData)
        {
            bool  initNoteUsed = false;
            float initNotePos;

            try
            {
                var data = JsonMapper.ToObject <SSTrainData>(rawData);

                initNotePos = TSystemConfig.Now.gameSync;
                for (int i = 0; i < data.notes.Length; i++)
                {
                    if (!initNoteUsed && initNotePos <= data.notes[i].timing)
                    {
                        Game.CreateNote(new NoteData
                                            (0, 0, initNotePos, Game.NoteSpeed, 0, 0, NoteType.Starter, FlickType.NotFlick, Color.white, new List <int>()));
                        initNoteUsed = true;
                    }
                    var noteData = new NoteData(data.notes[i]);
                    // 예외적 허용: 롱 노트 끝부분 슬라이드를 종류 1번으로 처리한 채보가 존재함. 그 때 값을 2로 수정. 그리고 롱 노트 끝부분의 경우 시작지점 통일
                    if (data.notes[i].prevNoteId > 0 && Game.notes[data.notes[i].prevNoteId].Type == NoteType.HoldStart)
                    {
                        noteData.type      = NoteType.HoldEnd;
                        noteData.startLine = Game.notes[data.notes[i].prevNoteId].StartLine;
                    }
                    Game.CreateNote(noteData);
                }
                return(true);
            }
            catch (Exception e)
            {
                TSystemStatic.LogWithException("Failed to parse SSTrain type beatmap.", e);
                return(false);
            }
        }
예제 #5
0
파일: Note.cs 프로젝트: HolySkyMin/TSystem
        public void CreateTail()
        {
            foreach (var prev in previousNotes)
            {
                if (Type.IsEither(NoteType.HoldStart, NoteType.HoldEnd) && prev.Type == NoteType.HoldStart) // Hold tail
                {
                    if (prev.nextTail != null)
                    {
                        TSystemStatic.Log($"Note {prev.ID} seems to have multiple hold or slide bodys. Ignoring tail connection with note {ID}.");
                        data.type = NoteType.Tap;
                        continue;
                    }
                    var newObj = Instantiate(Game.tailTemplate);
                    newObj.transform.SetParent(Game.meshParent);
                    newObj.transform.localScale = Vector3.one;
                    newObj.name = "Tail " + prev.ID.ToString();
                    var newTail = newObj.GetComponent <Tail>();
                    newTail.Set(prev, this, false);
                    prev.nextTail = newTail;
                    previousTails.Add(newTail);

                    data.type = NoteType.HoldEnd;
                }
                else if (Type.IsEither(NoteType.SlideStart, NoteType.SlideMiddle, NoteType.SlideEnd) && prev.Type.IsEither(NoteType.SlideStart, NoteType.SlideMiddle)) // Slide tail
                {
                    if (prev.nextTail != null)
                    {
                        TSystemStatic.Log($"Note {prev.ID} seems to have multiple hold or slide bodys. Ignoring tail connection with note {ID}.");
                        if (nextNote != null && nextNote.Type.IsEither(NoteType.SlideStart, NoteType.SlideMiddle, NoteType.SlideEnd))
                        {
                            data.type = NoteType.SlideStart;
                        }
                        else
                        {
                            data.type = NoteType.Tap;
                        }
                        continue;
                    }
                    var newObj = Instantiate(Game.tailTemplate);
                    newObj.transform.SetParent(Game.meshParent);
                    newObj.transform.localScale = Vector3.one;
                    newObj.name = "Tail " + prev.ID.ToString();
                    var newTail = newObj.GetComponent <Tail>();
                    newTail.Set(prev, this, true);
                    prev.nextTail = newTail;
                    previousTails.Add(newTail);

                    if (nextNote != null && nextNote.Type.IsEither(NoteType.SlideStart, NoteType.SlideMiddle, NoteType.SlideEnd))
                    {
                        data.type = NoteType.SlideMiddle;
                    }
                    else
                    {
                        data.type = NoteType.SlideEnd;
                    }
                }
            }
        }
예제 #6
0
        // Update is called once per frame
        void Update()
        {
            if (Game.IsStarted)
            {
                foreach (var l in lines)
                {
                    var line = l.Value;

                    line.UpdateCooltime();

                    // Note garbage collection
                    while (line.notes.Count > 0 && (Game.notes[line.notes[0]].isHit || Game.notes[line.notes[0]].isDead))
                    {
                        TSystemStatic.Log($"Undeleted dead/hit note ({line.notes[0]}, {Game.notes[line.notes[0]].Type}) detected in line {l.Key}! Removing it.");
                        RemoveNote(l.Key, line.notes[0]);
                    }
                }
            }
        }
예제 #7
0
        public void ParseStructuredBeatmap(string path, BeatmapType type, out bool succeed)
        {
            string       rawData;
            StreamReader stream;

            if (Game.Packet.loadFromResources)
            {
                var beatmapFile = Resources.Load <TextAsset>(path);
                rawData = beatmapFile.text;
            }
            else
            {
                try
                {
                    stream  = new StreamReader(path);
                    rawData = stream.ReadToEnd();
                    stream.Close();
                }
                catch (Exception e)
                {
                    TSystemStatic.LogWithException("Beatmap file does not exists.", e);
                    succeed = false;
                    return;
                }
            }

            switch (type)
            {
            case BeatmapType.TWx:
                succeed = ParseTWx(rawData);
                break;

            case BeatmapType.SSTrain:
                succeed = ParseSSTrain(rawData);
                break;

            default:
                succeed = false;
                break;
            }
        }
예제 #8
0
파일: Note.cs 프로젝트: HolySkyMin/TSystem
 public void CreateConnector()
 {
     foreach (var prev in previousNotes)
     {
         if (Flick != FlickType.NotFlick && prev.Flick != FlickType.NotFlick)
         {
             if (prev.nextConnector != null)
             {
                 TSystemStatic.Log($"Note {prev.ID} seems to have multiple next-flick connection. Ignoring flick connection with note {ID}.");
                 continue;
             }
             var newObj = Instantiate(Game.connectorTemplate);
             newObj.transform.SetParent(Game.meshParent);
             newObj.transform.localScale = Vector3.one;
             newObj.name = "Connector " + prev.ID.ToString();
             var newConn = newObj.GetComponent <Connector>();
             newConn.Set(prev, this);
             prev.nextConnector = newConn;
             previousConnectors.Add(newConn);
         }
     }
 }
예제 #9
0
        public void LoadBGA(string path)
        {
            defaultBackground.SetActive(false);
            videoScreen.SetActive(true);
            loaded      = false;
            hasBgaError = false;

            if (path == "")
            {
                return;
            }

            videoPlayer.audioOutputMode = TSystemConfig.Now.enableBgaSound ? VideoAudioOutputMode.Direct : VideoAudioOutputMode.None;

            if (Game.Packet.loadFromResources)
            {
                videoPlayer.source            = VideoSource.VideoClip;
                videoPlayer.clip              = Resources.Load <VideoClip>(path);
                videoPlayer.prepareCompleted += (p) => { loaded = true; isBGA = true; };
                videoPlayer.Prepare();
            }
            else
            {
                try
                {
                    videoPlayer.source            = VideoSource.Url;
                    videoPlayer.url               = path;
                    videoPlayer.prepareCompleted += (p) => { loaded = true; isBGA = true; };
                    videoPlayer.Prepare();
                }
                catch (System.Exception e)
                {
                    TSystemStatic.LogWithException("Error occured while loading BGA.", e);
                    hasBgaError = true;
                }
            }
        }
예제 #10
0
 public virtual void AddScore(NoteData data, JudgeType result)
 {
     TSystemStatic.Log("AddScore not implemented in this basis.");
 }
예제 #11
0
 public virtual void CreateNote(NoteData data)
 {
     TSystemStatic.Log("CreateNote not implemented in this basis.");
 }
예제 #12
0
 public virtual Sprite GetNoteImage(NoteData data)
 {
     TSystemStatic.Log("GetNoteImage not implemented in this basis.");
     return(null);
 }
예제 #13
0
 public virtual GameObject GetNoteTemplate(NoteData data)
 {
     TSystemStatic.Log("GetNoteObject not implemented in this basis.");
     return(null);
 }
예제 #14
0
        protected virtual IEnumerator Start()
        {
            Mode.SetArguments();

            // Line construction
            for (int i = 0; i < Mode.lineSet.Length; i++)
            {
                var newPanel = Instantiate(linePanelTemplate);
                newPanel.GetComponent <RectTransform>().SetParent(lineParent);
                newPanel.GetComponent <RectTransform>().localScale = Vector3.one;
                newPanel.GetComponent <LinePanel>().Set(i);
                linePanels.Add(newPanel.GetComponent <LinePanel>());
                newPanel.SetActive(true);

                if (i != 0)
                {
                    newPanel.GetComponent <LinePanel>().fullBody.alpha = 0;
                }
            }

            // Beatmap Loading
            bool parseSucceed = false;

            maxReachTime = 0;
            switch (Packet.beatmap.type)
            {
            case BeatmapType.TWx:
                beatmapParser.ParseStructuredBeatmap(Packet.beatmap.path, Packet.beatmap.type, out parseSucceed);
                break;

            case BeatmapType.Deleste:
                beatmapParser.ParseDeleste(Packet.beatmap.path, out parseSucceed);
                break;

            case BeatmapType.SSTrain:
                beatmapParser.ParseStructuredBeatmap(Packet.beatmap.path, Packet.beatmap.type, out parseSucceed);
                break;
            }
            if (!parseSucceed)
            {
                TSystemStatic.LogWarning("Failed to parse beatmap. Game will NOT be played.");
                yield break;
            }
            CreateNote(new NoteData(systemNoteIdx--, 0, maxReachTime + 1, 1, 0, 0, NoteType.Ender, FlickType.NotFlick, Color.clear, new List <int>()));
            ChangeLine(0);
            AfterNoteLoading();

            // Audio Loading
            if (!Packet.noMusic)
            {
                yield return(musicPlayer.LoadMusic(Packet.musicPath, Packet.musicType));

                if (!musicPlayer.loaded)
                {
                    TSystemStatic.LogWarning("Failed to load music. Game will be played without music.");
                }
            }

            // BGA/Image Loading
            if (!Packet.noBGA)
            {
                if (Packet.bgaPath != "")
                {
                    backPlayer.LoadBGA(Packet.bgaPath);
                    yield return(new WaitUntil(() => backPlayer.loaded || backPlayer.hasBgaError));

                    if (backPlayer.hasBgaError)
                    {
                        TSystemStatic.LogWarning("Failed to load BGA. Game will be played without BGA.");
                    }
                }
                else if (Packet.backImagePath != "")
                {
                    yield return(backPlayer.LoadBackImage(Packet.backImagePath));

                    if (!backPlayer.loaded)
                    {
                        TSystemStatic.LogWarning("Failed to load background image. Game will be played without background image.");
                    }
                }
            }

            // Game values initializing
            //input.Initialize();
            noteInput.Initialize();
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
            ReadyToPlay         = true;
        }
예제 #15
0
 protected virtual IEnumerator SpecialLeaveAnimRoutine()
 {
     TSystemStatic.Log("Special leave Animation per line object is not implemented in this basis.");
     yield return(null);
 }
예제 #16
0
        public void ParseDeleste(string path, out bool succeed)
        {
            FileStream   file    = null;
            StreamReader scanner = null;

            try
            {
                file    = new FileStream(path, FileMode.Open, FileAccess.Read);
                scanner = new StreamReader(file, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
                TSystemStatic.LogWithException("Beatmap file does not exists.", e);
                succeed = false;
                return;
            }

            int d, MaxBlockNum = -1, ID = 1;

            char[]            div        = { ' ', ',', ':' };
            DelesteGlobalData StaticData = new DelesteGlobalData();
            Dictionary <int, DelesteBlockData> Blocks = new Dictionary <int, DelesteBlockData>();
            double Time = 0, Speed = 1.0;

            byte[] Color = new byte[] { 255, 255, 255, 255 };

            var SongTime = TSystemConfig.Now.gameSync;

            // Steadily, stacks the data.
            while (scanner.Peek() != -1)
            {
                try
                {
                    string   dataLine = scanner.ReadLine();
                    string[] data     = dataLine.Split(div, StringSplitOptions.RemoveEmptyEntries);

                    if (data.Length > 1 && data[0].StartsWith("#") && (data[0].Substring(1).ToUpper().Equals("BPM") || data[0].Substring(1).ToUpper().Equals("TEMPO")))
                    {
                        StaticData.CurrentBPM = double.Parse(data[1]);
                    }
                    else if (data.Length > 1 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("OFFSET"))
                    {
                        Time += (int.Parse(data[1]) / 1000d);
                    }
                    else if (data.Length > 1 && data[0].StartsWith("#") && (data[0].Substring(1).ToUpper().Equals("SONGOFFSET") || data[0].Substring(1).ToUpper().Equals("MUSICOFFSET") || data[0].Substring(1).ToUpper().Equals("BGMOFFSET")))
                    {
                        Time -= (int.Parse(data[1]) / 1000d);
                    }
                    else if (data.Length > 1 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("ATTRIBUTE"))
                    {
                        if (data[1].ToUpper().Equals("CUTE") || data[1].ToUpper().Equals("CU") || data[1].Equals("1"))
                        {
                            Color = new byte[] { 255, 100, 200, 255 };
                        }
                        else if (data[1].ToUpper().Equals("COOL") || data[1].ToUpper().Equals("CO") || data[1].Equals("2"))
                        {
                            Color = new byte[] { 85, 135, 255, 255 };
                        }
                        else if (data[1].ToUpper().Equals("PASSION") || data[1].ToUpper().Equals("PA") || data[1].Equals("3"))
                        {
                            Color = new byte[] { 255, 220, 50, 255 };
                        }
                        else if (data[1].ToUpper().Equals("ALL") || data[1].Equals("4"))
                        {
                            Color = new byte[] { 230, 255, 255, 255 };
                        }
                    }
                    else if (data.Length > 2 && data[0].StartsWith("#") && (data[0].Substring(1).ToUpper().Equals("MEASURE") || data[0].Substring(1).ToUpper().Equals("MEAS") || data[0].Substring(1).ToUpper().Equals("MEA")))
                    {
                        if (data[2].Contains("/"))
                        {
                            string[] numbers = data[2].Split(new char[] { '/' });
                            StaticData.Measure.Add(double.Parse(numbers[0]) / double.Parse(numbers[1]));
                        }
                        else
                        {
                            StaticData.Measure.Add(double.Parse(data[2]));
                        }
                        StaticData.MeasurePos.Add(double.Parse(data[1]));
                    }
                    else if (data.Length > 2 && (data[0].StartsWith("#") && (data[0].Substring(1).ToUpper().Equals("CHANGEBPM") || data[0].Substring(1).ToUpper().Equals("CHANGETEMPO"))))
                    {
                        StaticData.ChangeBPM.Add(double.Parse(data[2]));
                        StaticData.ChangeBPMPos.Add(double.Parse(data[1]));
                    }
                    else if (data.Length > 1 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("CHANGEATTRIBUTE"))
                    {
                        if (data[1].ToUpper().Equals("CUTE") || data[1].ToUpper().Equals("CU") || data[1].Equals("1"))
                        {
                            Color = new byte[] { 255, 100, 200, 255 };
                        }
                        else if (data[1].ToUpper().Equals("COOL") || data[1].ToUpper().Equals("CO") || data[1].Equals("2"))
                        {
                            Color = new byte[] { 85, 135, 255, 255 };
                        }
                        else if (data[1].ToUpper().Equals("PASSION") || data[1].ToUpper().Equals("PA") || data[1].Equals("3"))
                        {
                            Color = new byte[] { 255, 220, 50, 255 };
                        }
                        else if (data[1].ToUpper().Equals("ALL") || data[1].Equals("4"))
                        {
                            Color = new byte[] { 230, 255, 255, 255 };
                        }
                    }
                    else if (data.Length > 1 && data[0].StartsWith("#") && (data[0].Substring(1).ToUpper().Equals("HISPEED") || data[0].Substring(1).ToUpper().Equals("HS")))
                    {
                        Speed = double.Parse(data[1]);
                        if (Speed <= 0)
                        {
                            throw new Exception("TSystem does not support HiSpeed zero and below.");
                        }
                    }
                    else if (data.Length > 2 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("HS2"))
                    {
                        //if (double.Parse(data[2]) <= 0)
                        //    throw new Exception("TSystem does not support HiSpeed zero and below."));
                        //StaticData.HS2.Add(double.Parse(data[2]));
                        //StaticData.HS2Pos.Add(double.Parse(data[1]));
                        TSystemStatic.Log("While parsing Deleste file: TSystem does not support HS2.");
                    }
                    else if (data.Length > 2 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("DELAY"))
                    {
                        StaticData.Delay.Add(double.Parse(data[2]));
                        StaticData.DelayPos.Add(double.Parse(data[1]));
                    }
                    else if (data.Length > 3 && data[0].StartsWith("#") && data[0].Substring(1).ToUpper().Equals("SCROLL"))
                    {
                        StaticData.Scroll.Add(new double[2] {
                            double.Parse(data[2]) / 1000d, double.Parse(data[3]) / 1000d
                        });
                        StaticData.ScrollPos.Add(double.Parse(data[1]));
                    }
                    else if (data.Length > 0 && data[0].StartsWith("#") && int.TryParse(data[0].Substring(1, 1), out d))
                    {
                        int CurBlock = int.Parse(data[1]);
                        if (!Blocks.ContainsKey(CurBlock))
                        {
                            Blocks.Add(CurBlock, new DelesteBlockData(CurBlock));
                        }
                        Blocks[CurBlock].DataLines.Add(dataLine);
                        Blocks[CurBlock].Channel.Add(int.Parse(data[0].Substring(1)));
                        Blocks[CurBlock].Color.Add(Color);
                        Blocks[CurBlock].Speed.Add(Speed);

                        if (MaxBlockNum < CurBlock)
                        {
                            MaxBlockNum = CurBlock;
                        }
                    }
                }
                catch (Exception e)
                {
                    TSystemStatic.LogWithException("Failed to parse Deleste type beatmap.", e);
                    scanner.Close();
                    file.Close();
                    succeed = false;
                    return;
                }
            }
            scanner.Close();
            file.Close();

            // Creates note at here.
            Game.CreateNote(new NoteData(0, 0, SongTime, (float)Speed, 0, 0, NoteType.Starter, FlickType.NotFlick, new Color32(255, 255, 255, 255), new List <int>()));
            for (int i = 0; i <= MaxBlockNum; i++)
            {
                if (Blocks.ContainsKey(i))
                {
                    Blocks[i].ParseBlock(Game, ref ID, ref Time, ref StaticData);
                }
                else
                {
                    Time += ((240 / StaticData.CurrentBPM) * StaticData.BeatMultiplier);
                }
            }

            succeed = true;
        }