public bool TryGetFunction(string name, out ElementBaseJson function)
 {
     foreach (var value in Values)
     {
         if (value.Name == name)
         {
             function = value;
             return(true);
         }
     }
     foreach (var action in Actions)
     {
         if (action.Name == name)
         {
             function = action;
             return(true);
         }
     }
     function = null;
     return(false);
 }
 public Element(ElementBaseJson function, params IWorkshopTree[] parameterValues)
 {
     Function        = function;
     ParameterValues = parameterValues;
 }
 public static Element Part(ElementBaseJson function, params IWorkshopTree[] parameterValues)
 => new Element(function, parameterValues);
Beispiel #4
0
        ElementList(ElementBaseJson function)
        {
            _function = function;

            Name          = function.CodeName();
            Documentation = function.Documentation;

            Attributes.GetRestrictedCallTypes = this;

            if (function.Restricted != null)
            {
                _restricted = GetRestrictedCallTypeFromString(function.Restricted);
            }

            // Get the parameters.
            if (function.Parameters == null)
            {
                Parameters = new CodeParameter[0];
            }
            else
            {
                Parameters = new CodeParameter[function.Parameters.Length];
            }

            for (int i = 0; i < Parameters.Length; i++)
            {
                // Get the name and documentation.
                string name          = function.Parameters[i].Name.Replace(" ", "");
                string documentation = function.Parameters[i].Documentation;

                // If 'VariableReferenceIsGlobal' is not null, the parameter is a variable reference.
                if (function.Parameters[i].VariableReferenceIsGlobal != null)
                {
                    // Set the parameter as a variable reference parameter.
                    Parameters[i] = new VariableParameter(
                        name,
                        documentation,
                        function.Parameters[i].VariableReferenceIsGlobal.Value ? VariableType.Global : VariableType.Player,
                        new CodeTypeFromStringSolver("Any"),
                        new VariableResolveOptions()
                    {
                        CanBeIndexed = false, FullVariable = true
                    }
                        );
                }
                else // Not a variable reference parameter.
                {
                    // The type of the parameter.
                    string type = function.Parameters[i].Type ?? "Any";

                    // Get the default value.
                    IWorkshopTree             defaultValueWorkshop = null;
                    ExpressionOrWorkshopValue defaultValue         = null;
                    if (function.Parameters[i].HasDefaultValue)
                    {
                        defaultValueWorkshop = function.Parameters[i].GetDefaultValue();
                        defaultValue         = new ExpressionOrWorkshopValue(defaultValueWorkshop);
                    }

                    // Set the parameter.
                    Parameters[i] = new CodeParameter(name, documentation, new CodeTypeFromStringSolver(type), defaultValue);

                    // If the default parameter value is an Element and the Element is restricted,
                    if (defaultValueWorkshop is Element parameterElement && parameterElement.Function.Restricted != null)
                    {
                        // ...then add the restricted call type to the parameter's list of restricted call types.
                        Parameters[i].RestrictedCalls.Add(GetRestrictedCallTypeFromString(parameterElement.Function.Restricted));
                    }
                }
            }
        }