public JSON.Element SaveState() { return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>() { ["paths"] = JSON.Element.NewArray(paths.Select(path => Waypath.ToJSON(path)).ToList()) })); }
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()) })); }
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() })); }
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(); }
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>(), }; }
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(); }
void OnRecorderPathUpdate(Waypath newPath) { paths[currentPathIndex] = newPath; traveller.SetPath(newPath); DrawPaths(); }
public void SetPath(Waypath path) { this.path = path; this.currentPointIndex = 0; }
public void AddWaypath(Waypath path) { paths.Add(path); DrawOutput(); }
public void LoadState(JSON.Element rootElement) { paths = rootElement.jsonObject["paths"].jsonArray.Select(element => Waypath.FromJSON(element)).ToList(); DrawOutput(); }
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)), })); }
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) }); }
public void SetPath(Waypath path) { pathName = path.name; pathPoints.Clear(); pathPoints.AddRange(path.points); }