Example #1
0
        protected ValueInput ValueInput(Type type, string key)
        {
            EnsureUniqueInput(key);
            var port = new ValueInput(key, type);

            valueInputs.Add(port);
            return(port);
        }
        protected override void Definition()
        {
            source = ValueInput <GameObject>(nameof(source), null).NullMeansSelf();

            base.Definition();

            Requirement(source, assign);
        }
Example #3
0
        protected override void Definition()
        {
            base.Definition();

            condition = ValueInput <bool>(nameof(condition));

            Requirement(condition, enter);
        }
Example #4
0
        private object GetDefaultValue(ValueInput input)
        {
            if (!TryGetDefaultValue(input, out var defaultValue))
            {
                throw new InvalidOperationException("Value input port does not have a default value.");
            }

            return(defaultValue);
        }
        protected override void Definition()
        {
            name = ValueInput(nameof(name), string.Empty);

            if (kind == VariableKind.Object)
            {
                @object = ValueInput <GameObject>(nameof(@object), null).NullMeansSelf();
            }
        }
        protected void Connect(ValueOutput source, ValueInput destination)
        {
            Undo.IncrementCurrentGroup();
            LudiqEditorUtility.editedObject.BeginOverride(m_Reference.serializedObject);
            var widget            = new ValueOutputWidget(m_Canvas, source);
            var connectMethodInfo = GetConnectionMethodInfo(widget.GetType());

            connectMethodInfo?.Invoke(widget, new object[] { widget.port, destination });
            LudiqEditorUtility.editedObject.EndOverride();
        }
Example #7
0
        protected override void Definition()
        {
            base.Definition();

            seconds      = ValueInput(nameof(seconds), 0f);
            unscaledTime = ValueInput(nameof(unscaledTime), false);

            Requirement(seconds, enter);
            Requirement(unscaledTime, enter);
        }
Example #8
0
        public static object FetchValue(ValueInput input, GraphReference reference)
        {
            var flow = New(reference);

            var result = flow.GetValue(input);

            flow.Dispose();

            return(result);
        }
Example #9
0
        public bool TryGetDefaultValue(ValueInput input, out object defaultValue)
        {
            if (!input.unit.defaultValues.TryGetValue(input.key, out defaultValue))
            {
                return(false);
            }

            if (input.nullMeansSelf && defaultValue == null)
            {
                defaultValue = stack.self;
            }

            return(true);
        }
Example #10
0
 protected override void Definition()
 {
     if (custom)
     {
         enter     = ControlInput(nameof(enter), ThrowCustom);
         exception = ValueInput <Exception>(nameof(exception));
         Requirement(exception, enter);
     }
     else
     {
         enter   = ControlInput(nameof(enter), ThrowMessage);
         message = ValueInput(nameof(message), string.Empty);
         Requirement(message, enter);
     }
 }
Example #11
0
        private bool CanPredict(ValueInput input)
        {
            if (!input.hasValidConnection)
            {
                if (!TryGetDefaultValue(input, out var defaultValue))
                {
                    return(false);
                }

                if (typeof(Component).IsAssignableFrom(input.type))
                {
                    defaultValue = defaultValue?.ConvertTo(input.type);
                }

                if (!input.allowsNull && defaultValue == null)
                {
                    return(false);
                }

                return(true);
            }

            var output = input.validConnectedPorts.Single();

            if (!CanPredict(output))
            {
                return(false);
            }

            var connectedValue = GetValue(output);

            if (!ConversionUtility.CanConvert(connectedValue, input.type, false))
            {
                return(false);
            }

            if (typeof(Component).IsAssignableFrom(input.type))
            {
                connectedValue = connectedValue?.ConvertTo(input.type);
            }

            if (!input.allowsNull && connectedValue == null)
            {
                return(false);
            }

            return(true);
        }
Example #12
0
        protected override void OnFieldsGUI(Rect position)
        {
            base.OnFieldsGUI(position);

            if (typeMetadata.value != null && ValueInput.SupportsDefaultValue((Type)typeMetadata.value))
            {
                y += EditorGUIUtility.standardVerticalSpacing;

                OnHasDefaultValueGUI(position.VerticalSection(ref y, GetHasDefaultValueHeight(position.width)));

                if ((bool)hasDefaultValueMetadata.value)
                {
                    y += EditorGUIUtility.standardVerticalSpacing;

                    OnDefaultValueGUI(position.VerticalSection(ref y, GetDefaultValueHeight(position.width)));
                }
            }
        }
Example #13
0
        public object GetValue(ValueInput input)
        {
            if (locals.TryGetValue(input, out var local))
            {
                return(local);
            }

            var connection = input.connection;

            if (connection != null)
            {
                if (enableDebug)
                {
                    var connectionEditorData = stack.GetElementDebugData <IUnitConnectionDebugData>(connection);

                    connectionEditorData.lastInvokeFrame = EditorTimeBinding.frame;
                    connectionEditorData.lastInvokeTime  = EditorTimeBinding.time;
                }

                var output = connection.source;

                var value = GetValue(output);

                if (enableDebug)
                {
                    var connectionEditorData = stack.GetElementDebugData <ValueConnection.DebugData>(connection);

                    connectionEditorData.lastValue         = value;
                    connectionEditorData.assignedLastValue = true;
                }

                return(value);
            }
            else if (TryGetDefaultValue(input, out var defaultValue))
            {
                return(defaultValue);
            }
            else
            {
                throw new MissingValuePortInputException(input.key);
            }
        }
Example #14
0
        protected override float GetHeight(float width, GUIContent label)
        {
            var height = base.GetHeight(width, label);

            if (typeMetadata.value != null && ValueInput.SupportsDefaultValue((Type)typeMetadata.value))
            {
                height += EditorGUIUtility.standardVerticalSpacing;

                height += GetHasDefaultValueHeight(width);

                if ((bool)hasDefaultValueMetadata.value)
                {
                    height += EditorGUIUtility.standardVerticalSpacing;

                    height += GetDefaultValueHeight(width);
                }
            }

            return(height);
        }
Example #15
0
        protected override void Definition()
        {
            member.EnsureReflected();

            if (!IsMemberValid(member))
            {
                throw new NotSupportedException("The member type is not valid for this unit.");
            }

            if (member.requiresTarget)
            {
                target = ValueInput(member.targetType, nameof(target));

                target.SetDefaultValue(member.targetType.PseudoDefault());

                if (typeof(UnityObject).IsAssignableFrom(member.targetType))
                {
                    target.NullMeansSelf();
                }
            }
        }
Example #16
0
        protected override void Definition()
        {
            base.Definition();

            name = ValueInput(nameof(name), string.Empty);
        }
Example #17
0
        private IEnumerable <Warning> ValueInputWarnings(ValueInput valueInput)
        {
            // We can disable null reference check if no self is available
            // and the port requires an owner, for example in macros.
            var trustFutureOwner = valueInput.nullMeansSelf && reference.self == null;

            var checkForNullReference = BoltFlow.Configuration.predictPotentialNullReferences && !valueInput.allowsNull && !trustFutureOwner;

            var checkForMissingComponent = BoltFlow.Configuration.predictPotentialMissingComponents && typeof(Component).IsAssignableFrom(valueInput.type);

            // Note that we cannot directly check the input's predicted value, because it
            // will return false for safeguard specifically because it might be missing requirements.
            // Therefore, we first check the connected value, then the default value.

            // If the port is connected to a predictable output, use the connected value to perform checks.
            if (valueInput.hasValidConnection)
            {
                var valueOutput = valueInput.validConnectedPorts.Single();

                if (Flow.CanPredict(valueOutput, reference))
                {
                    if (checkForNullReference)
                    {
                        if (Flow.Predict(valueOutput, reference) == null)
                        {
                            yield return(Warning.Severe($"{PortLabel(valueInput)} cannot be null."));
                        }
                    }

                    if (checkForMissingComponent)
                    {
                        var connectedPredictedValue = Flow.Predict(valueOutput, reference);

                        // This check is necessary, because the predicted value could be
                        // incompatible as connections with non-guaranteed conversions are allowed.
                        if (ConversionUtility.CanConvert(connectedPredictedValue, typeof(GameObject), true))
                        {
                            var gameObject = ConversionUtility.Convert <GameObject>(connectedPredictedValue);

                            if (gameObject != null)
                            {
                                var component = (Component)ConversionUtility.Convert(gameObject, valueInput.type);

                                if (component == null)
                                {
                                    yield return(Warning.Caution($"{PortLabel(valueInput)} is missing a {valueInput.type.DisplayName()} component."));
                                }
                            }
                        }
                    }
                }
            }
            // If the port isn't connected but has a default value, use the default value to perform checks.
            else if (valueInput.hasDefaultValue)
            {
                if (checkForNullReference)
                {
                    if (Flow.Predict(valueInput, reference) == null)
                    {
                        yield return(Warning.Severe($"{PortLabel(valueInput)} cannot be null."));
                    }
                }

                if (checkForMissingComponent)
                {
                    var unconnectedPredictedValue = Flow.Predict(valueInput, reference);

                    if (ConversionUtility.CanConvert(unconnectedPredictedValue, typeof(GameObject), true))
                    {
                        var gameObject = ConversionUtility.Convert <GameObject>(unconnectedPredictedValue);

                        if (gameObject != null)
                        {
                            var component = (Component)ConversionUtility.Convert(gameObject, valueInput.type);

                            if (component == null)
                            {
                                yield return(Warning.Caution($"{PortLabel(valueInput)} is missing a {valueInput.type.DisplayName()} component."));
                            }
                        }
                    }
                }
            }
            // The value isn't connected and has no default value,
            // therefore it is certain to be missing at runtime.
            else
            {
                yield return(Warning.Severe($"{PortLabel(valueInput)} is missing."));
            }
        }
Example #18
0
 protected override void Definition()
 {
     name = ValueInput(nameof(name), defaultName);
 }
Example #19
0
        protected static bool CompareNames(Flow flow, ValueInput namePort, string calledName)
        {
            Ensure.That(nameof(calledName)).IsNotNull(calledName);

            return(calledName.Trim().Equals(flow.GetValue <string>(namePort)?.Trim(), StringComparison.OrdinalIgnoreCase));
        }
Example #20
0
 public object GetConvertedValue(ValueInput input)
 {
     return(GetValue(input, input.type));
 }
Example #21
0
 public T GetValue <T>(ValueInput input)
 {
     return((T)GetValue(input, typeof(T)));
 }
Example #22
0
 public object GetValue(ValueInput input, Type type)
 {
     return(ConversionUtility.Convert(GetValue(input), type));
 }
Example #23
0
        protected override void Definition()
        {
            base.Definition();

            target = ValueInput <GameObject>(nameof(target), null).NullMeansSelf();
        }
Example #24
0
 public static object FetchValue(ValueInput input, Type type, GraphReference reference)
 {
     return(ConversionUtility.Convert(FetchValue(input, reference), type));
 }
Example #25
0
 public static T FetchValue <T>(ValueInput input, GraphReference reference)
 {
     return((T)FetchValue(input, typeof(T), reference));
 }
Example #26
0
 /// <summary>
 /// Getting the value of the destination may fetch the value of the source.
 /// </summary>
 protected void Requirement(ValueInput source, ValueOutput destination)
 {
     Relation(source, destination);
 }