コード例 #1
0
 public JSON.Element SaveState()
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["paths"] = JSON.Element.NewArray(paths.Select(path => Waypath.ToJSON(path)).ToList())
     }));
 }
コード例 #2
0
 public static JSON.Element ToJSON(Waypath path)
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["name"] = JSON.Element.NewString(path.name),
         ["points"] = JSON.Element.NewArray(path.points.Select(point => Waypoint.ToJSON(point)).ToList())
     }));
 }
コード例 #3
0
 JSON.Element SerializeState()
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["currentPathIndex"] = JSON.Element.NewNumber(currentPathIndex),
         ["paths"] = JSON.Element.NewArray(paths.Select(path => Waypath.ToJSON(path)).ToList()),
         ["traveler"] = traveller.SaveState()
     }));
 }
コード例 #4
0
 void DeserializeState(JSON.Element state)
 {
     paths.Clear();
     paths.AddRange(
         state
         .jsonObject["paths"].jsonArray
         .Select(element => Waypath.FromJSON(element))
         );
     currentPathIndex = (int)state.jsonObject["paths"].jsonNumber;
     if (paths.Count < 1)
     {
         paths.Add(new Waypath(name: "Default Waypath", points: new List <Waypoint>()));
         currentPathIndex = 0;
     }
     recorder.SetPath(paths[currentPathIndex]);
     traveller.SetPath(paths[currentPathIndex]);
     traveller.LoadState(state.jsonObject["traveler"]);
     DrawPaths();
 }
コード例 #5
0
        public WaypointTraveller(MotorControl motorControl, IMyRemoteControl mainControl, IMyTextSurface outputSurface)
        {
            this.motorControl  = motorControl;
            this.mainControl   = mainControl;
            this.outputSurface = outputSurface;

            this.currentPointIndex = 0;
            this.travelState       = TravelState.Stopped;
            this.path = new Waypath("Default Path", new List <Waypoint>());

            commandTree = new PanelCommander.CommandTree()
            {
                label    = "Waypath Traveller",
                commands = new List <PanelCommander.Command>()
                {
                    new PanelCommander.Command()
                    {
                        label = "Travel", action = Travel
                    },
                    new PanelCommander.Command()
                    {
                        label = "Pause", action = Pause
                    },
                    new PanelCommander.Command()
                    {
                        label = "Skip", action = Skip
                    },
                    new PanelCommander.Command()
                    {
                        label = "Back", action = Back
                    },
                    new PanelCommander.Command()
                    {
                        label = "Reset", action = Reset
                    },
                    new PanelCommander.Command()
                    {
                        label = "Stop", action = Stop
                    },
                },
                subtrees = new List <PanelCommander.CommandTree>(),
            };
        }
コード例 #6
0
        public WaypathRecorder(
            IMyRemoteControl mainControl,
            Waypath initalPath,
            IMyTextSurface outputSurface,
            Action <Waypath> onPathUpdate
            )
        {
            this.mainControl   = mainControl;
            this.outputSurface = outputSurface;
            this.pathName      = initalPath.name;
            this.pathPoints    = initalPath.points.ToList();
            this.onPathUpdate  = onPathUpdate;

            commandTree = new PanelCommander.CommandTree()
            {
                label    = "Recorder",
                commands = new List <PanelCommander.Command>()
                {
                    new PanelCommander.Command()
                    {
                        label = "Record", action = RecordPoint
                    },
                    new PanelCommander.Command()
                    {
                        label = "Undo", action = Undo
                    },
                    new PanelCommander.Command()
                    {
                        label = "Reset", action = Reset
                    },
                    new PanelCommander.Command()
                    {
                        label = "Reverse", action = Reverse
                    }
                },
                subtrees = new List <PanelCommander.CommandTree>(),
            };

            DrawOutput();
        }
コード例 #7
0
 void OnRecorderPathUpdate(Waypath newPath)
 {
     paths[currentPathIndex] = newPath;
     traveller.SetPath(newPath);
     DrawPaths();
 }
コード例 #8
0
 public void SetPath(Waypath path)
 {
     this.path = path;
     this.currentPointIndex = 0;
 }
コード例 #9
0
 public void AddWaypath(Waypath path)
 {
     paths.Add(path);
     DrawOutput();
 }
コード例 #10
0
 public void LoadState(JSON.Element rootElement)
 {
     paths = rootElement.jsonObject["paths"].jsonArray.Select(element => Waypath.FromJSON(element)).ToList();
     DrawOutput();
 }
コード例 #11
0
 public static JSON.Element ToJSON(Location location)
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["name"] = JSON.Element.NewString(location.name),
         ["position"] = Vector3Utils.Vector3ToJSON(location.position),
         ["pathsToLocations"] = JSON.Element.NewObject(location.pathsToLocations
                                                       .Select(pathToLocation => new KeyValuePair <string, JSON.Element>(pathToLocation.Key, Waypath.ToJSON(pathToLocation.Value)))
                                                       .ToDictionary(entry => entry.Key, entry => entry.Value)),
     }));
 }
コード例 #12
0
 public static Location FromJSON(JSON.Element rootElement)
 {
     return(new Location()
     {
         name = rootElement.jsonObject["name"].jsonString,
         position = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["position"]),
         pathsToLocations = rootElement.jsonObject["paths"].jsonObject
                            .Select(element => new KeyValuePair <string, Waypath>(element.Key, Waypath.FromJSON(element.Value)))
                            .ToDictionary(entry => entry.Key, entry => entry.Value)
     });
 }
コード例 #13
0
 public void SetPath(Waypath path)
 {
     pathName = path.name;
     pathPoints.Clear();
     pathPoints.AddRange(path.points);
 }