Esempio n. 1
0
        public static List <sol_track> LoadSol(string sol_location)
        {
            var sol    = new SOL(sol_location);
            var tracks = (List <Amf0Object>)sol.RootObject.get_property("trackList");
            var ret    = new List <sol_track>();

            for (var i = 0; i < tracks.Count; i++)
            {
                if (tracks[i].data is List <Amf0Object> )
                {
                    var add = new sol_track {
                        data = (List <Amf0Object>)tracks[i].data, filename = sol_location
                    };
                    add.name = (string)add.get_property("label");
                    ret.Add(add);
                }
            }
            return(ret);
        }
Esempio n. 2
0
        public static Track LoadTrack(sol_track trackdata)
        {
            var ret = new Track {
                Name = trackdata.name
            };
            var buffer     = (List <Amf0Object>)trackdata.get_property("data");
            var addedlines = new Dictionary <int, StandardLine>();
            var version    = trackdata.data.First(x => x.name == "version").data as string;

            if (version == "6.1")
            {
                ret.SetVersion(6.1m);
            }
            else
            {
                ret.SetVersion(6.2m);
            }
            try
            {
                var options = (List <Amf0Object>)trackdata.get_property("trackData");
                if (options.Count >= 2)
                {
                    try
                    {
                        ret.ZeroStart = (bool)options.Find(x => x.name == "2").get_property("5");
                    }
                    catch
                    {
                        //ignored
                    }
                }
            }
            catch
            {
                //ignored
            }
            var extensions = new List <Extensionentry>();

            for (var i = buffer.Count - 1; i >= 0; --i)
            {
                var line = (List <Amf0Object>)buffer[i].data;
                var type = Convert.ToInt32(line[9].data, CultureInfo.InvariantCulture);
                switch (type)
                {
                case 0:
                {
                    var l =
                        new StandardLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)),
                            Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture))
                    {
                        ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture)
                    };
                    l.SetExtension(Convert.ToInt32(line[4].data, CultureInfo.InvariantCulture));
                    if (line[6].data != null)
                    {
                        var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = prev, Next = false
                            });
                    }
                    if (line[7].data != null)
                    {
                        var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = next, Next = true
                            });
                    }
                    if (!addedlines.ContainsKey(l.ID))
                    {
                        ret.AddLines(l);
                        addedlines[l.ID] = l;
                    }
                }
                break;

                case 1:
                {
                    var l =
                        new RedLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)),
                            Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture))
                    {
                        ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture)
                    };
                    l.SetExtension(Convert.ToInt32(line[4].data, CultureInfo.InvariantCulture));
                    if (line[6].data != null)
                    {
                        var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = prev, Next = false
                            });
                    }
                    if (line[7].data != null)
                    {
                        var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = next, Next = true
                            });
                    }
                    if (!addedlines.ContainsKey(l.ID))
                    {
                        ret.AddLines(l);
                        addedlines[l.ID] = l;
                    }
                }
                break;

                case 2:
                    ret.AddLines(
                        new SceneryLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture))));
                    break;

                default:
                    throw new Exception("Unknown line type");
                }
            }
            foreach (var v in extensions)
            {
                if (v.Next)
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        v.Line.Next = sl;
                        sl.Prev     = v.Line;
                    }
                }
                else //prev
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        v.Line.Prev = sl;
                        sl.Next     = v.Line;
                    }
                }
            }
            var startlineprop = trackdata.get_property("startLine");
            var startline     = startlineprop as List <Amf0Object>;

            if (startline == null && startlineprop is double)
            {
                var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture);
                if (conv >= ret.Lines.Count || conv < 0)
                {
                    startline = new List <Amf0Object>();
                    startline.Add(new Amf0Object {
                        data = 100
                    });
                    startline.Add(new Amf0Object {
                        data = 100
                    });
                }
            }
            else if (startlineprop is double)
            {
                var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture);
                startline = new List <Amf0Object>();
                startline.Add(new Amf0Object {
                    data = ret.Lines[conv].Position.X
                });
                startline.Add(new Amf0Object {
                    data = ret.Lines[conv].Position.Y - 50 * 0.5
                });
            }
            ret.Start.X = Convert.ToDouble(startline[0].data, CultureInfo.InvariantCulture);
            ret.Start.Y = Convert.ToDouble(startline[1].data, CultureInfo.InvariantCulture);
            ret.ResetUndo();
            ret.ResetChanges();
            return(ret);
        }