Exemplo n.º 1
0
    public void UnregisterDirectInput(int id, string name)
    {
        name = name == null ? workBundleName : name;

        CubeBundle bundle      = this.bundles.Single(x => x.Name == name);
        var        directInput = bundle.DirectInputs.SingleOrDefault(x => x.ID == id);

        // removing from persistance
        bundle.DirectInputs.Remove(directInput);
        // removing from existing connections
        bundle.ParaDirectInputConnections = bundle.ParaDirectInputConnections
                                            .Where(x => x.DirectInput.ID != id)
                                            .ToList();
    }
Exemplo n.º 2
0
    public object RunCube(string bundleName, Variable[] variables = null)
    {
        bundleName = bundleName == null ? workBundleName : bundleName;

        // looking for existing bundle with the given name
        CubeBundle bundle = this.bundles.SingleOrDefault(x => x.Name == bundleName);

        // if not found try load persisted bundle with given name
        if (bundle == null)
        {
            this.AddBundle(bundleName);
            this.LoadPersistedData(bundleName, false);
            Debug.Log($"Bundle not Found, Loading Bundle: {bundleName}");
        }

        // if the bundle is still null, well nothing we can do, abort!
        bundle = this.bundles.SingleOrDefault(x => x.Name == bundleName);
        if (bundle == null)
        {
            Debug.LogError($"Bundle not Found After Loading it, ABORT");
            return(null);
        }

        if (variables == null)
        {
            variables = new Variable[0];
        }

        if (bundle.ResultMethodCall == null)
        {
            Debug.Log("Result Not Connected!");
            return(null);
        }

        // run the recursion
        object result = this.RunCubeRecursion(bundle.ResultMethodCall, bundle, variables);

        // most times the result is null so we have nothing to display
        if (result != null)
        {
            Debug.Log("SUCCESS " + result.ToString());
        }

        return(result);
    }
Exemplo n.º 3
0
    public Node UnregisterClassName(string className, string name)
    {
        name = name == null ? workBundleName : name;
        CubeBundle    bundle = this.bundles.Single(x => x.Name == name);
        ClassTracking ct     = bundle.ClassTypeNamesForPersistance.SingleOrDefault(x => x.Name == className);

        if (ct != null)
        {
            bundle.ClassTypeNamesForPersistance.Remove(ct);
        }

        // removing the connections itself, not the visualisation or anything else
        bundle.ParaMethConnections = bundle.ParaMethConnections
                                     .Where(x => x.Method.ClassNode != ct.node || x.Parameter.ClassNode != ct.node)
                                     .ToList();
        bundle.ParaDirectInputConnections = bundle.ParaDirectInputConnections
                                            .Where(x => x.Parameter.ClassNode != ct.node)
                                            .ToList();

        return(ct.node);
    }
Exemplo n.º 4
0
    private object RunCubeRecursion(MethodNode node, CubeBundle bundle, Variable[] variables)
    {
        List <object> values = new List <object>();

        foreach (var paramater in node.MyParamaters)
        {
            var constant = bundle.ParaDirectInputConnections.Where(x => x.Parameter.ParameterInfo.ID == paramater.ID)
                           .ToArray();
            if (constant.Length > 1)
            {
                Debug.Log("MORE THANT ONE CONSTANT!!!!");
                Debug.Break();
            }

            if (constant.Length == 1)
            {
                if (constant[0].DirectInput.IsVariable())
                {
                    // Finding the variable with the right name and getting it's value. The values are passed by the resultUI.
                    values.Add(variables.SingleOrDefault(x => x.Name == constant[0].DirectInput.VariableName)?.Value);
                }
                else
                {
                    values.Add(constant[0].DirectInput.GetVal());
                }

                try
                {
                    values[values.Count - 1] =
                        Convert.ChangeType(values[values.Count - 1], paramater.Info.ParameterType);
                }
                catch (Exception e)
                {
                    // Debug.Log("Error converting");
                }

                continue;
            }

            var method = bundle.ParaMethConnections.Where(x => x.Parameter.ParameterInfo.ID == paramater.ID).ToArray();
            if (method.Length > 1)
            {
                Debug.Log("MORE THANT ONE CONSTANT!!!!");
                Debug.Break();
            }

            if (method.Length == 0)
            {
                /// Hack to let me only pass one float of many and the rest to be 0
                values.Add(paramater.Info.DefaultValue);
                Debug.Log("Property not assigned to - Giving it the default!");
            }
            else
            {
                values.Add(RunCubeRecursion(method[0].Method, bundle, variables));
            }

            values[values.Count - 1] = Convert.ChangeType(values[values.Count - 1], paramater.Info.ParameterType);
        }

        object obj = node.Object;

        object[] par = values.ToArray();

        //DEBUGGING
        // Debug.Log("###########################################################################################");
        // Debug.Log($"<<<<{node.Object.GetType().Name}>>>");
        // Debug.Log($">>>{node.MyMethodInfo.Info.Name}<<<");
        for (int i = 0; i < node.MyParamaters.Length; i++)
        {
            var param = node.MyParamaters[i];

            // Debug.Log($"{param.Info.ParameterType.Name} {par[i]?.ToString()}");
        }
        //...

        object result = node.MyMethodInfo.Info.Invoke(obj, par);

        //Debug.Log("PASSED");

        return(result);
    }