Beispiel #1
0
        private void loadbtn_Clicked(ControlBase sender, ClickedEventArgs arguments)
        {
            var window = (WindowControl)sender.Parent.Parent;
            var tv     = (TreeControl)window.FindChildByName("loadtree", true);

            var en = (List <TreeNode>)tv.SelectedChildren;

            if (en.Count > 0)
            {
                var selected = en[0];
                if (selected.UserData is sol_track)
                {
                    var data = (sol_track)selected.UserData;
                    try
                    {
                        game.EnableSong = false;
                        game.Track.ChangeTrack(TrackLoader.LoadTrack(data));
                    }
                    catch
                    {
                        window.Close();
                        var wc = PopupWindow.Create(this, game, "An error occured loading the track.", "Error", true, false);
                        wc.FindChildByName("Okay", true).Clicked += (o, e) => { wc.Close(); };
                        return;
                    }
                }
                else if (selected.UserData is string[])
                {
                    var data = (string[])selected.UserData;
                    try
                    {
                        game.EnableSong = false;
                        game.Track.ChangeTrack(TrackLoader.LoadTrackTRK(data[0], data[1]));
                    }
                    catch
                    {
                        window.Close();
                        var wc = PopupWindow.Create(this, game, "An error occured loading the track. \nIt might be from a newer version.", "Error", true, false);
                        wc.FindChildByName("Okay", true).Clicked += (o, e) => { wc.Close(); };
                        return;
                    }
                }
                game.Track.TrackUpdated();
                window.Close();
            }
        }
Beispiel #2
0
 public void BackupTrack(bool Crash = true)
 {
     try
     {
         if (_track.Lines.Count == 0)
         {
             return;
         }
         var saveindex  = 0;
         var trackfiles =
             TrackLoader.EnumerateTRKFiles(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar +
                                           _track.Name);
         for (var i = 0; i < trackfiles.Length; i++)
         {
             var s = Path.GetFileNameWithoutExtension(trackfiles[i]);
             s = s.Remove(s.IndexOf(' '));
             if (int.TryParse(s, out saveindex))
             {
                 break;
             }
         }
         saveindex++;
         if (saveindex < 2 && !Crash)
         {
             return;
         }
         var save = Crash ? (saveindex + " " + "Crash Backup") : " Autosave";
         game.Loading = true;
         EnterTrackRead();
         {
             TrackLoader.SaveTrackTrk(_track, save, game.CurrentSong?.ToString());
         }
         ExitTrackRead();
         game.Loading = false;
         game.Invalidate();
     }
     catch
     {
         //ignored
     }
 }
Beispiel #3
0
        public void ExportAsSol()
        {
            if (_track.Lines.Count != 0)
            {
                var  features = TrackLoader.TrackFeatures(_track);
                bool six_one;
                bool redmultiplier;
                bool scenerywidth;
                features.TryGetValue("SIX_ONE", out six_one);
                features.TryGetValue("REDMULTIPLIER", out redmultiplier);
                features.TryGetValue("SCENERY_WIDTH", out scenerywidth);
                if (six_one || redmultiplier || scenerywidth)
                {
                    var window = PopupWindow.Create(game.Canvas, game, "Unable to export SOL file due to it containing special LRA specific features,\nspecifically, " + (six_one ? "\nthe track is based on 6.1, " : "") + (redmultiplier ? "\nthe track uses red multiplier lines, " : "") + (scenerywidth ? "\nthe track uses varying scenery line width " : "") + "\nand therefore cannot be loaded", "Error!", true, false);

                    window.FindChildByName("Okay", true).Clicked += (o, e) =>
                    {
                        window.Close();
                    };
                }
                else
                {
                    var window = PopupWindow.Create(game.Canvas, game, "Are you sure you wish to save this track as an SOL file? It will overwrite any file named savedLines.sol", "Are you sure?", true, true);

                    window.FindChildByName("Okay", true).Clicked += (o, e) =>
                    {
                        window.Close();
                        TrackLoader.SaveTrackSol(_track);
                        game.Canvas.UpdateSaveNodes();
                    };
                    window.FindChildByName("Cancel", true).Clicked += (o, e) =>
                    {
                        window.Close();
                    };
                }
            }
        }
Beispiel #4
0
        private void WriteTrack(List <Amf0Object> parent, Track trk)
        {
            Amf0Object track = new Amf0Object(parent.Count);

            parent.Add(track);
            var trackdata = new List <Amf0Object>();

            track.data = trackdata;
            trackdata.Add(new Amf0Object("label", trk.Name));
            trackdata.Add(new Amf0Object("version", "6.2"));
            trackdata.Add(new Amf0Object("level", trk.Lines.Count));
            var sl      = new Amf0Object("startLine");
            var dataobj = new Amf0Object("data")
            {
                type = Amf0Object.Amf0Type.AMF0_ECMA_ARRAY
            };

            var data = new List <Amf0Object>();

            dataobj.data = data;
            sl.data      = new List <Amf0Object>()
            {
                new Amf0Object(0, trk.Start.X), new Amf0Object(1, trk.Start.Y)
            };

            trackdata.Add(sl);
            trackdata.Add(dataobj);

            SortedList <int, Line> list = new SortedList <int, Line>();

            for (int i = trk.Lines.Count - 1; i >= 0; i--)
            {
                var id = trk.Lines[i].ID;
                if (id < 0)
                {
                    id = Math.Abs(id) + trk._idcounter + 100;
                }
                list.Add(id, trk.Lines[i]);
            }
            int counter = 0;

            for (int i = list.Values.Count - 1; i >= 0; i--)
            {
                var line     = list.Values[i];
                var stl      = line as StandardLine;
                var lineobj  = new Amf0Object(counter++);
                var linedata = new List <Amf0Object>();
                linedata.Add(new Amf0Object(0, line.Position.X));
                linedata.Add(new Amf0Object(1, line.Position.Y));
                linedata.Add(new Amf0Object(2, line.Position2.X));
                linedata.Add(new Amf0Object(3, line.Position2.Y));
                linedata.Add(new Amf0Object(4, stl != null ? (int)((StandardLine)line).Extension : 0));
                linedata.Add(new Amf0Object(5, stl != null ? (bool)((StandardLine)line).inv : false));
                linedata.Add(new Amf0Object(6, stl?.Prev?.ID));
                linedata.Add(new Amf0Object(7, stl?.Next?.ID));
                linedata.Add(new Amf0Object(8, list.Keys[i]));
                linedata.Add(new Amf0Object(9, TrackLoader.LineTypeForSOL(line.GetLineType())));

                lineobj.type = Amf0Object.Amf0Type.AMF0_ECMA_ARRAY;
                lineobj.data = linedata;
                data.Add(lineobj);
            }
            if (trk.ZeroStart)
            {
                List <Amf0Object> kevans = new List <Amf0Object>();
                kevans.Add(new Amf0Object(0)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                List <Amf0Object> in1 = new List <Amf0Object>();
                in1.Add(new Amf0Object(0)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                in1.Add(new Amf0Object(1)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                in1.Add(new Amf0Object(2)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                kevans.Add(new Amf0Object(1)
                {
                    type = Amf0Object.Amf0Type.AMF0_ECMA_ARRAY, data = in1
                });
                List <Amf0Object> importantpart = new List <Amf0Object>(3);
                importantpart.Add(new Amf0Object(0)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                importantpart.Add(new Amf0Object(1)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                importantpart.Add(new Amf0Object(2)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                importantpart.Add(new Amf0Object(3)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                importantpart.Add(new Amf0Object(4)
                {
                    type = Amf0Object.Amf0Type.AMF0_NULL
                });
                importantpart.Add(new Amf0Object(5, true));
                kevans.Add(new Amf0Object(2)
                {
                    type = Amf0Object.Amf0Type.AMF0_ECMA_ARRAY, data = importantpart
                });
                trackdata.Add(new Amf0Object("trackData")
                {
                    data = kevans, type = Amf0Object.Amf0Type.AMF0_ECMA_ARRAY
                });
            }
        }
Beispiel #5
0
        private void savebtn_Clicked(ControlBase sender, ClickedEventArgs arguments)
        {
            var window = sender.Parent.Parent as WindowControl;

            if (window == null)
            {
                throw new Exception("Invalid window data");
            }
            if (window.UserData != null)
            {
                var tb        = (TextBox)window.FindChildByName("tb", true);
                var saveindex = 0;
                var txt       = (string)window.UserData;
                if (txt == "<create new track>")
                {
                    txt = tb.Text;
                    if (txt.Length == 0)
                    {
                        return;
                    }
                }
                if (
                    Directory.Exists(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar + txt +
                                     Path.DirectorySeparatorChar))
                {
                    var trackfiles =
                        TrackLoader.EnumerateTRKFiles(Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar +
                                                      txt);
                    for (var i = 0; i < trackfiles.Length; i++)
                    {
                        var s     = Path.GetFileNameWithoutExtension(trackfiles[i]);
                        var index = s.IndexOf(" ", StringComparison.Ordinal);
                        if (index != -1)
                        {
                            s = s.Remove(index);
                        }
                        if (int.TryParse(s, out saveindex))
                        {
                            break;
                        }
                    }
                }
                var invalidchars = Path.GetInvalidFileNameChars();
                for (var i = 0; i < txt.Length; i++)
                {
                    if (invalidchars.Contains(txt[i]))
                    {
                        sender.SetToolTipText("Attempted to save with an invalid name");
                        return;
                    }
                }
                game.Track.Name = txt;
                saveindex++;
                var save = saveindex + " " + tb.Text;
                try
                {
                    game.Track.Save(save, game.CurrentSong);
                }
                catch
                {
                    sender.SetToolTipText("An error occured trying to save");
                    return;
                }
                savenode node = null;
                for (var i = 0; i < _nodes.Count; i++)
                {
                    if (_nodes[i].name.Equals(game.Track.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        node = _nodes[i];
                        break;
                    }
                }
                if (node == null)
                {
                    node = new savenode {
                        data = new List <savenode>(), name = game.Track.Name
                    };
                    _nodes.Add(node);
                }
                ((List <savenode>)node.data).Insert(0, new savenode {
                    name = (save), data = new[] { game.Track.Name, save }
                });
            }
            window.Close();
        }
Beispiel #6
0
        private void InitSaveNodes()
        {
            if (_nodeslocked)
            {
                return;
            }
            game.Loading = true;
            lock (_nodes)
            {
                _nodeslocked = true;
                _nodes.Clear();
                var files = Program.CurrentDirectory + "Tracks";
                if (Directory.Exists(files))
                {
                    var solfiles =
                        Directory.GetFiles(files, "*.*")
                        .Where(s => s != null && s.EndsWith(".sol", StringComparison.OrdinalIgnoreCase));

                    foreach (var file in solfiles)
                    {
                        List <sol_track> tracks = null;
                        try
                        {
                            tracks = TrackLoader.LoadSol(file);
                        }
                        catch
                        {
                            //ignored
                        }
                        if (tracks != null)
                        {
                            var node = new savenode {
                                name = "[SOL] " + Path.GetFileNameWithoutExtension(file)
                            };
                            var addnode = new List <savenode>();
                            for (var i = 0; i < tracks.Count; i++)
                            {
                                addnode.Add(new savenode {
                                    name = tracks[i].name, data = tracks[i]
                                });
                            }
                            node.data = addnode;
                            _nodes.Add(node);
                        }
                    }
                    var trkfiles =
                        Directory.GetFiles(files, "*.*")
                        .Where(s => s != null && s.EndsWith(".trk", StringComparison.OrdinalIgnoreCase));
                    foreach (var trk in trkfiles)
                    {
                        var save = Path.GetFileNameWithoutExtension(trk);
                        var node = new savenode {
                            name = "[TRK] " + save
                        };
                        var addnode = new List <savenode>();
                        addnode.Add(new savenode {
                            name = (save), data = new[] { save, null }
                        });
                        node.data = addnode;
                        _nodes.Add(node);
                    }
                    var folders = Directory.GetDirectories(files);
                    foreach (var folder in folders)
                    {
                        var trackname = Path.GetFileName(folder);
                        var node      = new savenode {
                            name = trackname
                        };
                        var trackfiles = TrackLoader.EnumerateTRKFiles(folder);
                        var addnode    = new List <savenode>();
                        for (var i = 0; i < trackfiles.Length; i++)
                        {
                            var trk  = trackfiles[i];
                            var save = Path.GetFileNameWithoutExtension(trk);
                            addnode.Add(new savenode {
                                name = (save), data = new[] { trackname, save }
                            });
                        }
                        node.data = addnode;
                        _nodes.Add(node);
                    }
                }
                _nodeslocked = false;
            }
            game.Loading = false;
            game.Invalidate();
        }
Beispiel #7
0
 internal void Save(string savename, Audio.Song song)
 {
     TrackLoader.SaveTrackTrk(_track, savename, song.ToString());
 }