public static void FromPathmapFile(string file) { PathMap map = PathMap.ImportFromXML(file); string baseEditorFile = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del"); string baseEditorContent = File.ReadAllText(baseEditorFile); Diagnostics diagnostics = new Diagnostics(); DeltinScript deltinScript = new DeltinScript( new FileGetter(null), diagnostics, new ScriptFile(diagnostics, new Uri(baseEditorFile), baseEditorContent), (varCollection) => { // Set the initial nodes. Rule initialNodes = new Rule("Initial Nodes"); initialNodes.Actions = ArrayBuilder <Element> .Build( WorkshopArrayBuilder.SetVariable(null, map.NodesAsWorkshopData(), null, LoadNodes, false), WorkshopArrayBuilder.SetVariable(null, map.SegmentsAsWorkshopData(), null, LoadSegments, false) ); return(new Rule[] { initialNodes }); } ); string code = deltinScript.WorkshopCode; if (code != null) { Program.WorkshopCodeResult(code); } else { Log.Write(LogLevel.Normal, new ColorMod("Build Failed.", ConsoleColor.Red)); diagnostics.PrintDiagnostics(Log); } }
protected override void New(ActionSet actionSet, NewClassInfo newClassInfo) { Element index = (Element)newClassInfo.ObjectReference.GetVariable(); if (newClassInfo.AdditionalParameterData.Length > 0) { // Get the pathmap data. PathMap pathMap = (PathMap)newClassInfo.AdditionalParameterData[0]; IndexReference nodes = actionSet.VarCollection.Assign("_tempNodes", actionSet.IsGlobal, false); IndexReference segments = actionSet.VarCollection.Assign("_tempSegments", actionSet.IsGlobal, false); actionSet.AddAction(nodes.SetVariable(new V_EmptyArray())); actionSet.AddAction(segments.SetVariable(new V_EmptyArray())); foreach (var node in pathMap.Nodes) { actionSet.AddAction(nodes.ModifyVariable(operation: Operation.AppendToArray, value: node.ToVector())); } foreach (var segment in pathMap.Segments) { actionSet.AddAction(segments.ModifyVariable(operation: Operation.AppendToArray, value: segment.AsWorkshopData())); } actionSet.AddAction(Nodes.SetVariable((Element)nodes.GetVariable(), index: index)); actionSet.AddAction(Segments.SetVariable((Element)segments.GetVariable(), index: index)); } else { actionSet.AddAction(Nodes.SetVariable(new V_EmptyArray(), index: index)); actionSet.AddAction(Segments.SetVariable(new V_EmptyArray(), index: index)); } }
public override IWorkshopTree New(ActionSet actionSet, Constructor constructor, IWorkshopTree[] constructorValues, object[] additionalParameterData) { // Create the class. var objectData = actionSet.Translate.DeltinScript.SetupClasses().CreateObject(actionSet, "_new_PathMap"); // Get the pathmap data. PathMap pathMap = (PathMap)additionalParameterData[0]; actionSet.AddAction(objectData.ClassObject.SetVariable(pathMap.NodesAsWorkshopData(), null, 0)); actionSet.AddAction(objectData.ClassObject.SetVariable(pathMap.SegmentsAsWorkshopData(), null, 1)); return(objectData.ClassReference.GetVariable()); }
protected override void New(ActionSet actionSet, NewClassInfo newClassInfo) { // Get the pathmap data. PathMap pathMap = (PathMap)newClassInfo.AdditionalParameterData[0]; actionSet.AddAction(Nodes.SetVariable( value: pathMap.NodesAsWorkshopData(), index: (Element)newClassInfo.ObjectReference.GetVariable() )); actionSet.AddAction(Segments.SetVariable( value: pathMap.SegmentsAsWorkshopData(), index: (Element)newClassInfo.ObjectReference.GetVariable() )); }
public static void FromPathmapFile(string file) { DeltinScript deltinScript = Generate(PathMap.ImportFromXMLFile(file), OutputLanguage.enUS); string code = deltinScript.WorkshopCode; if (code != null) { Program.WorkshopCodeResult(code); } else { Log.Write(LogLevel.Normal, new ColorMod("Build Failed.", ConsoleColor.Red)); deltinScript.Diagnostics.PrintDiagnostics(Log); } }
public static DeltinScript Generate(PathMap map, OutputLanguage language) { string baseEditorFile = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del"); return(new DeltinScript(new TranslateSettings(baseEditorFile) { AdditionalRules = (varCollection) => { // Set the initial nodes. Rule initialNodes = new Rule("Initial Nodes"); initialNodes.Actions = ArrayBuilder <Element> .Build( WorkshopArrayBuilder.SetVariable(null, map.NodesAsWorkshopData(), null, LoadNodes, false), WorkshopArrayBuilder.SetVariable(null, map.SegmentsAsWorkshopData(), null, LoadSegments, false) ); return new Rule[] { initialNodes }; }, OptimizeOutput = false, OutputLanguage = language })); }
public override object Validate(ScriptFile script, IExpression value, DocRange valueRange) { string filepath = base.Validate(script, value, valueRange) as string; if (filepath == null) { return(null); } PathMap map; try { map = PathMap.ImportFromXML(filepath); } catch (InvalidOperationException) { script.Diagnostics.Error("Failed to deserialize the PathMap.", valueRange); return(null); } return(map); }