// ----------------------------------------------------------------------
 public List <iCS_EditorObject> Filter(Func <iCS_EditorObject, bool> cond)
 {
     return(P.filter(
                c => c != null && c.IsValid && cond(c),
                EditorObjects
                ));
 }
예제 #2
0
        // -------------------------------------------------------------------
        /// Generate the code for the class fields.
        ///
        /// @param indentSize The indentation needed for the class definition.
        /// @return The class fileds code.
        ///
        string GenerateClassFields(int indentSize)
        {
            var indent = ToIndent(indentSize);
            var result = new StringBuilder(1024);
            // Fields
            var publicFields  = P.filter(f => f.IsPublic, myFields);
            var privateFields = P.filter(f => !f.IsPublic, myFields);

            if (publicFields.Count != 0)
            {
                result.Append(GenerateCodeBanner(indent, "PUBLIC FIELDS"));
                foreach (var f in publicFields)
                {
                    result.Append(f.GenerateCode(indentSize));
                }
                result.Append("\n");
            }
            if (privateFields.Count != 0)
            {
                result.Append(GenerateCodeBanner(indent, "PRIVATE FIELDS"));
                foreach (var f in privateFields)
                {
                    result.Append(f.GenerateCode(indentSize));
                }
                result.Append("\n");
            }
            return(result.ToString());
        }
        // =======================================================================
        // Errors/Warning display functionality
        // -----------------------------------------------------------------------
        void DisplayErrorsAndWarnings()
        {
            // -- Nothing to display if no error/warning exists --
            if (!ErrorController.IsErrorOrWarning)
            {
                return;
            }
            // -- Update the repaint timer --
            UpdateErrorRepaintTimer();
            // -- Get errors/warnings for this visual script --
            var errors   = ErrorController.GetErrorsFor(VisualScript);
            var warnings = ErrorController.GetWarningsFor(VisualScript);

            // -- Filter out invalid objects --
            errors   = P.filter(e => IStorage.IsValid(e.ObjectId), errors);
            warnings = P.filter(w => IStorage.IsValid(w.ObjectId), warnings);
            // -- Return if no errors or warnings --
            if ((errors.Count + warnings.Count) == 0)
            {
                return;
            }
            // -- Show scene errors/warnings --
            DisplayVisualScriptErrorsAndWarnings(errors, warnings);
            // -- Show errors/warnings on the nodes of our visual script --
            DisplayObjectErrorsAndWarnings(errors, warnings);
        }
        // -----------------------------------------------------------------------
        void DisplayObjectErrorsAndWarnings(List <ErrorWarning> errors, List <ErrorWarning> warnings)
        {
            // -- Determine wich objects have errors or warnings --
            var objectIds = P.append(P.map(e => e.ObjectId, errors), P.map(w => w.ObjectId, warnings));

            objectIds = P.removeDuplicates(objectIds);

            // -- Display the errors/warnings on the objects in the graph --
            foreach (var id in objectIds)
            {
                // -- Determine if node is visible --
                var node = IStorage[id];
                if (!DisplayRoot.IsParentOf(node))
                {
                    continue;
                }
                var pos = node.GlobalPosition;
                if (!VisibleGraphRect.Contains(pos))
                {
                    continue;
                }
                // -- Determine errors/warnings for this particular node --
                var nodeErrors   = P.filter(e => e.ObjectId == id, errors);
                var nodeWarnings = P.filter(w => w.ObjectId == id, warnings);
                // -- Display the appropriate error/warning icon --
                var r = Math3D.BuildRectCenteredAt(pos, 32f, 32f);
                r = myGraphics.TranslateAndScale(r);
                DisplayErrorsAndWarningAt(r, nodeErrors, nodeWarnings);
            }
        }
예제 #5
0
        // -------------------------------------------------------------------
        /// Builds the list of function parameters.
        protected override void BuildParameterList()
        {
            var parameters = GetParameters(VSObject);

            parameters   = P.filter(p => p.IsFixDataPort, parameters);
            myParameters = new FunctionDefinitionParameter[parameters.Length];
            foreach (var p in parameters)
            {
                myParameters[p.PortIndex] = new FunctionDefinitionParameter(p, this);
            }
        }
        // ----------------------------------------------------------------------
        public static string[] FilterAndSort(string search, string[] lst, float minScore)
        {
            var scores   = GetScores(search, lst);
            var ts       = P.zip(scores, lst);
            var filtered = P.filter((t) => t.Item1 > minScore, ts);

            P.sort(
                filtered,
                (t1, t2) => {
                var diff = t2.Item1 - t1.Item1;
                return(Math3D.IsZero(diff) ? 0 : (diff < 0 ? -1 : 1));
            }
                );
            return(P.map((t) => P.uncurry((score, str) => str, t), filtered));
        }
예제 #7
0
        // -------------------------------------------------------------------
        /// Builds the list of function parameters.
        protected virtual void BuildParameterList()
        {
            var parameters = GetParameters(VSObject);

            parameters   = P.filter(p => p.IsInDataPort && p.ProducerPort == null, parameters);
            myParameters = new FunctionDefinitionParameter[parameters.Length];
            foreach (var p in parameters)
            {
                if (p.PortIndex >= parameters.Length)
                {
                    Debug.LogWarning("iCanScript: Internal error: Port index out of range: " + p.PortIndex);
                }
                else
                {
                    myParameters[p.PortIndex] = new FunctionDefinitionParameter(p, this);
                }
            }
        }
        // -------------------------------------------------------------------------
        /// Returns the list of enable ports that affects the function call
        ///
        /// @param funcNode Visual script representing the function call.
        /// @return Array of all enable ports that affects the function call.
        ///
        public static iCS_EditorObject[] GetAllRelatedEnablePorts(iCS_EditorObject funcNode)
        {
            // -- Gather all enable ports --
            var enablePorts = new List <iCS_EditorObject>();

            while (funcNode != null)
            {
                var enables = GetEnablePorts(funcNode);
                if (enables.Length != 0 && !IsAtLeastOneEnableAlwaysTrue(enables))
                {
                    enables = P.filter(e => !IsEnableAlwaysFalse(e), enables);
                    enablePorts.AddRange(enables);
                }
                funcNode = funcNode.ParentNode;
            }
            // -- Reorder ports starting from parent --
            enablePorts.Reverse();
            return(enablePorts.ToArray());
        }
        // ----------------------------------------------------------------------
        /// Returns the members of type T installed on this type.
        ///
        /// @return The array of member <T> installed on this type.
        ///
        public T[] GetMembers <T>() where T : LibraryObject
        {
            var events = P.filter(p => p is T, children);

            return(P.map(p => p as T, events).ToArray());
        }
        // -------------------------------------------------------------------------
        /// Returns the list of output ports.
        iCS_EditorObject[] GetOutputDataPorts()
        {
            var parameters = GetParameters(VSObject);

            return(P.filter(p => p.IsOutDataPort, parameters));
        }
 public static List <ErrorWarning> GetWarningsFor(string serviceKey, iCS_VisualScriptImp vs, int objectId)
 {
     return(P.filter(e => e.ServiceId == serviceKey && e.VisualScript == vs && e.ObjectId == objectId, Warnings));
 }
 public static List <ErrorWarning> GetErrorsFor(iCS_VisualScriptImp vs, int objectId)
 {
     return(P.filter(e => e.VisualScript == vs && e.ObjectId == objectId, Errors));
 }
 public static List <ErrorWarning> GetWarningsFor(iCS_VisualScriptImp vs)
 {
     return(P.filter(e => e.VisualScript == vs, Warnings));
 }
 // ======================================================================
 // OPERATIONS
 // ----------------------------------------------------------------------
 public static void Clear(string serviceId)
 {
     myErrors   = P.filter(d => d.ServiceId != serviceId, myErrors);
     myWarnings = P.filter(d => d.ServiceId != serviceId, myWarnings);
 }