Beispiel #1
0
        /// <summary>
        /// 将.osu中的note转为SB脚本
        /// </summary>
        /// <param name="se">设置集</param>
        /// <returns>是否成功</returns>
        public bool Make(Setting se)
        {
            fsosu = new FileStream(osuPath, FileMode.Open, FileAccess.Read);
            srosu = new StreamReader(fsosu, Encoding.Default);
            //fsosu.Seek(0, SeekOrigin.Begin);
            //设置
            settings = se;
            if (settings.ics.HasValue) {
                cs = settings.ics.Value;
                csScale = Convert.ToDouble((0.8503125 - cs * 0.07015625).ToString("0.00"));
            }
            if (settings.iar.HasValue) {
                ar = settings.iar.Value;
                approachTime = 1800 - (int)(150 * ar);
            }

            //准备工作
            string path = System.IO.Path.GetDirectoryName(osuPath);
            logBox.AppendText("解压皮肤资源..." + Environment.NewLine);
            for (int i = 0; i < Common.skinFile.Count(); i++) {
                string s = Common.skinFile[i];
                if (!File.Exists(path + "\\" + s + ".png")) {
                    GetSkinResource(i).Save(path + "\\" + s + ".png");
                }
            }
            //备份osb
            if (File.Exists(osbPath)) {
                for (int i = 0; i < 100; i++)
                    if (!File.Exists(osbPath + ".bak" + i.ToString())) {
                        logBox.AppendText("已有osb文件被备份为bak" + i.ToString() + Environment.NewLine);
                        File.Move(osbPath, osbPath + ".bak" + i.ToString());
                        break;
                    }
            }
            //打开文件,写入文件头
            fsSB = new FileStream(osbPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            swSB = new StreamWriter(fsSB, Encoding.Default);
            swSB.WriteLine("//Powered by osuSBNoteMaker");
            swSB.WriteLine("[Events]");
            //黑色背景
            if (settings.useBlackBG) {
                swSB.WriteLine("Sprite,Background,Centre,\"{0}.png\",320,240", Common.skinFile[3]);
                swSB.WriteLine(" C,0,-1000,3000000,0,0,0");
            }
            fsSB.Seek(0, SeekOrigin.End);
            //开始转换note
            logBox.AppendText("Working..." + Environment.NewLine);
            string[] data;
            string content = srosu.ReadLine();
            while (!content.StartsWith("[HitObjects]")) {
                content = srosu.ReadLine();
            }
            while (srosu.Peek() >= 0) {
                content = srosu.ReadLine();
                data = content.Split(',');
                HitObject note = new HitObject(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]), Convert.ToInt32(data[2]), GetObjectType(Convert.ToInt32(data[3])));
                swSB.WriteLine(makesb(note));
            }
            logBox.AppendText("完成!" + Environment.NewLine);
            swSB.Close();
            fsSB.Close();
            srosu.Close();
            fsosu.Close();
            return true;
        }
Beispiel #2
0
        /// <summary>
        /// 为给定的note生成SB脚本
        /// </summary>
        /// <param name="note">要生成的note</param>
        /// <returns>对应的SB脚本代码</returns>
        private string makesb(HitObject note)
        {
            int ix=note.x;
            int iy = settings.inverse ? 384 - note.y : note.y;
            int ihitTime=note.hitTime;
            ObjectType type = note.type;

            string x = (ix + 64).ToString();
            string y = (iy + 56).ToString();
            string objTime = (ihitTime - approachTime).ToString();
            string arTime = approachTime.ToString();
            string lifeTime = (approachTime + 150).ToString();
            string objScale = csScale.ToString();
            string s = null;
            string endl = Environment.NewLine;
            if (type != ObjectType.Spinner) {
                if (type == ObjectType.Circle) {
                    //hitcircle
                    s = s.AppendLine("Sprite,Foreground,Centre,\"{2}.png\",{0},{1}", x, y, Common.skinFile[0]);
                    s = s.AppendLine("  L,{0},1 ", objTime);
                    s = s.AppendLine("  F,0,0,150,0,1");
                    s = s.AppendLine("  C,0,0,0,{0},{1},{2}", R, G, B);
                    s = s.AppendLine("  S,0,0,{0},{1}", arTime, objScale);
                    s = s.AppendLine("  F,0,150,{0},1", arTime);
                    s = s.AppendLine("  F,0,{0},{1},1,0", arTime, lifeTime);
                    //hitcircleoverlay
                    s = s.AppendLine("Sprite,Foreground,Centre,\"{2}.png\",{0},{1}", x, y, Common.skinFile[1]);
                    s = s.AppendLine("  L,{0},1 ", objTime);
                    s = s.AppendLine("  F,0,0,150,0,1");
                    s = s.AppendLine("  S,0,0,{0},{1}", arTime, objScale);
                    s = s.AppendLine("  F,0,150,{0},1", arTime);
                    s = s.AppendLine("  F,0,{0},{1},1,0", arTime, lifeTime);
                }
                //approachcircle
                s = s.AppendLine("Sprite,Foreground,Centre,\"{2}.png\",{0},{1}", x, y, Common.skinFile[2]);
                s = s.AppendLine("  L,{0},1 ", objTime);
                s = s.AppendLine("  F,0,0,{0},0,1", arTime);
                s = s.AppendLine("  S,0,0,{0},2.1,{1}", arTime, objScale);
                s = s.AppendLine("  C,0,0,0,{0},{1},{2}", R, G, B);
                s = s.AppendLine("  F,0,{0},{1},1,0", arTime, lifeTime);
            }
            return s;
        }
Beispiel #3
0
        /// <summary>
        /// 将.osu中的note转为SB脚本
        /// </summary>
        /// <param name="se">设置集</param>
        /// <returns>是否成功</returns>
        public bool Make(Setting se)
        {
            fsosu = new FileStream(osuPath, FileMode.Open, FileAccess.Read);
            srosu = new StreamReader(fsosu, Encoding.Default);
            //fsosu.Seek(0, SeekOrigin.Begin);
            //设置
            settings = se;
            if (settings.ics.HasValue)
            {
                cs      = settings.ics.Value;
                csScale = Convert.ToDouble((0.8503125 - cs * 0.07015625).ToString("0.00"));
            }
            if (settings.iar.HasValue)
            {
                ar           = settings.iar.Value;
                approachTime = 1800 - (int)(150 * ar);
            }

            //准备工作
            string path = System.IO.Path.GetDirectoryName(osuPath);

            logBox.AppendText("解压皮肤资源..." + Environment.NewLine);
            for (int i = 0; i < Common.skinFile.Count(); i++)
            {
                string s = Common.skinFile[i];
                if (!File.Exists(path + "\\" + s + ".png"))
                {
                    GetSkinResource(i).Save(path + "\\" + s + ".png");
                }
            }
            //备份osb
            if (File.Exists(osbPath))
            {
                for (int i = 0; i < 100; i++)
                {
                    if (!File.Exists(osbPath + ".bak" + i.ToString()))
                    {
                        logBox.AppendText("已有osb文件被备份为bak" + i.ToString() + Environment.NewLine);
                        File.Move(osbPath, osbPath + ".bak" + i.ToString());
                        break;
                    }
                }
            }
            //打开文件,写入文件头
            fsSB = new FileStream(osbPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            swSB = new StreamWriter(fsSB, Encoding.Default);
            swSB.WriteLine("//Powered by osuSBNoteMaker");
            swSB.WriteLine("[Events]");
            //黑色背景
            if (settings.useBlackBG)
            {
                swSB.WriteLine("Sprite,Background,Centre,\"{0}.png\",320,240", Common.skinFile[3]);
                swSB.WriteLine(" C,0,-1000,3000000,0,0,0");
            }
            fsSB.Seek(0, SeekOrigin.End);
            //开始转换note
            logBox.AppendText("Working..." + Environment.NewLine);
            string[] data;
            string   content = srosu.ReadLine();

            while (!content.StartsWith("[HitObjects]"))
            {
                content = srosu.ReadLine();
            }
            while (srosu.Peek() >= 0)
            {
                content = srosu.ReadLine();
                data    = content.Split(',');
                HitObject note = new HitObject(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]), Convert.ToInt32(data[2]), GetObjectType(Convert.ToInt32(data[3])));
                swSB.WriteLine(makesb(note));
            }
            logBox.AppendText("完成!" + Environment.NewLine);
            swSB.Close();
            fsSB.Close();
            srosu.Close();
            fsosu.Close();
            return(true);
        }