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);
            }
        }
Пример #2
0
        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);
        }