Beispiel #1
0
        void ExportAss(string filename)
        {
            var content = File.ReadAllText(filename);
            var xml = new XmlDocument();
            xml.LoadXml(content);

            List<Bullet> bullets = new List<Bullet>();

            var list = xml.SelectNodes("/i/d").OfType<XmlNode>();
            foreach (var d in list)
            {
                var attrs = d.Attributes["p"].Value;
                var b = new Bullet(d);
                bullets.Add(b);
            }

            var s = new Screen(540, 460, 384);
            var events = s.Conv(bullets);
            var assfile = Path.ChangeExtension(filename, ".ass");

            File.WriteAllText(assfile, @"[Script Info]
            Title:
            Original Script: BiliBili
            Script Updated By: BiliBili Translator
            ScriptType: v4.00
            Collisions: Normal
            PlayResX: 540
            PlayResY: 384
            PlayDepth: 32
            Timer: 100.0000
            WrapStyle: 2

            [V4+ Styles]
            Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColor, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
            Style: Default,SimHei,15,11861244,11861244,0,-2147483640,-1,0,0,0,100,100,1,0.00,1,1,0,10,30,30,30,1
            Style: Static,黑体,25,11861244,11861244,0,-2147483640,-1,0,0,0,100,100,2,0.00,1,1,0,2,0,0,0,1
            Style: Scroll,黑体,25,11861244,11861244,0,-2147483640,-1,0,0,0,100,100,2,0.00,1,1,0,2,0,0,0,1

            [Events]
            Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
            ");
            File.AppendAllLines(assfile, events.ConvertAll(a => a.ToString()));
        }
Beispiel #2
0
        private void Put(Bullet b)
        {
            var bt = new bullet();
            bt.start = Convert.ToInt32(Math.Round(Convert.ToDouble(b.start) * 100));
            bt.fs = Convert.ToInt32(b.size);
            bt.data = b;
            bt.width = bt.fs * b.content.Length;
            Enum.TryParse(b.type, out bt.type);

            int defaultRow = 1;
            Dictionary<int, List<bullet>> s = scrolls;
            bt.end = bt.start + 400;
            if (bt.type == BulletType.Static_Bottom)
            {
                s = staticsBottom;
                defaultRow = Height - bt.fs - 3;
                bt.end = bt.start + 350;
            }
            else if (bt.type == BulletType.Static_Top)
            {
                s = staticsTop;
                bt.end = bt.start + 350;
            }
            bt.row = defaultRow;

            if (s.Any())
            {
                List<bullet> list;
                bool put = false;
                foreach (var pair in s)
                {
                    list = pair.Value;
                    //if (s.TryGetValue(bt.row, out list))
                    //{
                    switch (bt.type)
                    {
                        case BulletType.Scroll:
                            put = CanPutScroll(bt, list);
                            break;
                        case BulletType.Static_Bottom:
                            put = CanPutStaticBottom(bt, list);
                            break;
                        case BulletType.Static_Top:
                            put = CanPutStaticTop(bt, list);
                            break;
                    }

                    if (put)
                    {
                        bt.row = pair.Key;
                        list.Add(bt);
                        break;
                    }
                    //}
                }
                if (!put)
                {
                    var pair = s.Last();
                    if (bt.type == BulletType.Static_Bottom)
                    {

                        int next = pair.Key - bt.fs - 1;
                        if (next > 0)
                            bt.row = next;
                    }
                    else
                    {
                        int next = pair.Key + bt.fs + 1;
                        if (next < Height)
                            bt.row = next;
                    }
                    if (!s.TryGetValue(bt.row, out list))
                    {
                        list = new List<bullet>();
                        list.Add(bt);
                        s.Add(bt.row, list);
                    }
                    else
                    {
                        list.Add(bt);
                    }
                }
            }
            else
            {
                var list = new List<bullet>();
                list.Add(bt);
                s.Add(bt.row, list);
            }

            bullets.Add(bt);
        }