Ejemplo n.º 1
0
        public bool Import()
        {
            try
            {
                string     raw_json = File.ReadAllText(name + extention);
                JsonObject json     = new JsonObject(raw_json);

                name           = json.Get <string>("name");
                id             = json.Get <int>("id");
                source         = json.Get <string>("source");
                meta_value_key = json.Get <string>("meta_value_key");

                colour_r = json.Get <float>("colour_r", json.Get <int>("colour_r"));
                colour_g = json.Get <float>("colour_g", json.Get <int>("colour_g"));
                colour_b = json.Get <float>("colour_b", json.Get <int>("colour_b"));

                foreach (JsonObject input_json in json.GetObjectList("inputs"))
                {
                    NodeIO input = new NodeIO();
                    input.name         = input_json.Get <string>("name");
                    input.display_name = input_json.Get <string>("display_name", input.name);
                    input.is_execution = input_json.Get <bool>("is_execution");

                    input.colour_r = input_json.Get <float>("colour_r", input_json.Get <int>("colour_r"));
                    input.colour_g = input_json.Get <float>("colour_g", input_json.Get <int>("colour_g"));
                    input.colour_b = input_json.Get <float>("colour_b", input_json.Get <int>("colour_b"));

                    inputs.Add(input);
                }

                foreach (JsonObject output_json in json.GetObjectList("outputs"))
                {
                    NodeIO output = new NodeIO();
                    output.name         = output_json.Get <string>("name");
                    output.display_name = output_json.Get <string>("display_name", output.name);
                    output.is_execution = output_json.Get <bool>("is_execution");

                    output.colour_r = output_json.Get <float>("colour_r", output_json.Get <int>("colour_r"));
                    output.colour_g = output_json.Get <float>("colour_g", output_json.Get <int>("colour_g"));
                    output.colour_b = output_json.Get <float>("colour_b", output_json.Get <int>("colour_b"));

                    outputs.Add(output);
                }
                return(true);
            }
            catch (DirectoryNotFoundException)
            {
                VSLogger.LogError("Unable to import '" + name + extention + "'");
                return(false);
            }
            catch (FileNotFoundException)
            {
                VSLogger.LogError("Unable to import '" + name + extention + "'");
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void LoadDefaults()
        {
            Dictionary <int, Node> default_nodes = new Dictionary <int, Node>();

            //Null node
            {
                Node null_node = new Node("Null");
                null_node.id        = 0;
                null_node.module_id = 0;
                null_node.source    = "pass";
                default_nodes.Add(0, null_node);
            }

            //Start node
            {
                Node start_node = new Node("Start");
                start_node.id        = 1;
                start_node.module_id = 0;
                start_node.colour_r  = 0.1f;
                start_node.colour_g  = 0.1f;
                start_node.colour_b  = 1.0f;

                start_node.source = "{eo:end}";

                NodeIO output = new NodeIO();
                output.name         = "end";
                output.display_name = "";
                output.colour_r     = 1.0f;
                output.colour_g     = 1.0f;
                output.colour_b     = 1.0f;
                output.is_execution = true;

                start_node.outputs.Add(output);
                default_nodes.Add(1, start_node);
            }

            module_nodes.Add(0, default_nodes);
        }