public static Scope GetGlobalScope()
        {
            Scope globalScope = new Scope();

            // Add workshop methods
            foreach (var workshopMethod in ElementList.Elements)
            {
                if (!workshopMethod.Hidden)
                {
                    globalScope.AddNativeMethod(workshopMethod);
                }
            }

            // Add custom methods
            foreach (var builtInMethod in CustomMethods.CustomMethodData.GetCustomMethods())
            {
                if (builtInMethod.Global)
                {
                    globalScope.AddNativeMethod(builtInMethod);
                }
            }

            globalScope.AddNativeMethod(new Lambda.WaitAsyncFunction());
            return(globalScope);
        }
Beispiel #2
0
        public void GetMeta()
        {
            // Floor
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Floor",
                Documentation = "Rounds the provided number down to the nearest integer.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Down)
            }.GetMethod());
            // Ceil
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Ceil",
                Documentation = "Return the ceiling of the provided number.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Up)
            }.GetMethod());
            // Round
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Round",
                Documentation = "Returns the provided number rounded to the nearest integer.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Nearest)
            }.GetMethod());
            // Absolute value
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Abs",
                Documentation = "Returns the absolute value of the provided number. Also known as the value's distance to 0.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.Abs(actionSet.CurrentObject)
            }.GetMethod());

            Operations.AddTypeOperation(new TypeOperation[] {
                new TypeOperation(TypeOperator.Add, this, this),                                  // Number + number
                new TypeOperation(TypeOperator.Subtract, this, this),                             // Number - number
                new TypeOperation(TypeOperator.Multiply, this, this),                             // Number * number
                new TypeOperation(TypeOperator.Divide, this, this),                               // Number / number
                new TypeOperation(TypeOperator.Modulo, this, this),                               // Number % number
                new TypeOperation(TypeOperator.Pow, this, this),
                new TypeOperation(TypeOperator.Multiply, _supplier.Vector(), _supplier.Vector()), // Number * vector
                new TypeOperation(TypeOperator.LessThan, this, _supplier.Boolean()),              // Number < number
                new TypeOperation(TypeOperator.LessThanOrEqual, this, _supplier.Boolean()),       // Number <= number
                new TypeOperation(TypeOperator.GreaterThanOrEqual, this, _supplier.Boolean()),    // Number >= number
                new TypeOperation(TypeOperator.GreaterThan, this, _supplier.Boolean()),           // Number > number
            });
            Operations.AddTypeOperation(AssignmentOperation.GetNumericOperations(this));
        }
 private void AddConditionalFunction <T>(string name, string description, CodeType returnType, string parameterDescription = "The condition that is evaluated for each element of the specified array.") where T : Element, new()
 {
     _scope.AddNativeMethod(new ConditionalArrayFunction <T>(
                                name,
                                description,
                                this,
                                parameterDescription,
                                returnType
                                ));
 }
        public void Add(Scope addToScope, ITypeSupplier supplier)
        {
            // value => ...
            var noIndex = GetFuncMethod();

            noIndex.Parameters = new CodeParameter[] {
                new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType))
            };
            noIndex.Action = (actionSet, methodCall) =>
                             Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv));

            // (value, index) => ...
            var withIndex = GetFuncMethod();

            withIndex.Parameters = new CodeParameter[] {
                new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType, supplier.Number()))
            };
            withIndex.Action = (actionSet, methodCall) =>
                               Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv, Element.ArrayIndex()));

            addToScope.AddNativeMethod(new FuncMethod(noIndex));
            addToScope.AddNativeMethod(new FuncMethod(withIndex));
        }
 public void AddStaticBasedScope(IMethod function) => _staticScope.AddNativeMethod(function);
 public void AddObjectBasedScope(IMethod function) => _objectScope.AddNativeMethod(function);
Beispiel #7
0
 private void Func(FuncMethodBuilder builder)
 {
     _scope.AddNativeMethod(new FuncMethod(builder));
 }
        public void ResolveElements()
        {
            X = CreateInternalVar("X", "The X component of the vector.");
            Y = CreateInternalVar("Y", "The Y component of the vector.");
            Z = CreateInternalVar("Z", "The Z component of the vector.");
            HorizontalAngle = CreateInternalVar("HorizontalAngle", "The horizontal angle of the vector.");
            VerticalAngle   = CreateInternalVar("VerticalAngle", "The vertical angle of the vector.");
            Zero            = CreateInternalVar("Zero", "Equal to `Vector(0, 0, 0)`.", true);

            objectScope.AddNativeMethod(DistanceTo);
            objectScope.AddNativeMethod(CrossProduct);
            objectScope.AddNativeMethod(DotProduct);
            objectScope.AddNativeMethod(Normalize);
            objectScope.AddNativeMethod(DirectionTowards);
            objectScope.AddNativeMethod(FarthestPlayer);
            objectScope.AddNativeMethod(ClosestPlayer);
            objectScope.AddNativeMethod(IsInLineOfSight);
            objectScope.AddNativeMethod(Towards);
            objectScope.AddNativeMethod(AsLocalVector);
            objectScope.AddNativeMethod(AsWorldVector);
        }
        public void GetMeta()
        {
            X = CreateInternalVar("X", "The X component of the vector.", _typeSupplier.Number());
            Y = CreateInternalVar("Y", "The Y component of the vector.", _typeSupplier.Number());
            Z = CreateInternalVar("Z", "The Z component of the vector.", _typeSupplier.Number());
            HorizontalAngle = CreateInternalVar("HorizontalAngle", "The horizontal angle of the vector.", _typeSupplier.Number());
            VerticalAngle   = CreateInternalVar("VerticalAngle", "The vertical angle of the vector.", _typeSupplier.Number());
            Magnitude       = CreateInternalVar("Magnitude", "The magnitude of the vector.", _typeSupplier.Number());
            Zero            = CreateInternalVar("Zero", "Equal to `Vector(0, 0, 0)`.", _typeSupplier.Vector(), Element.Vector(0, 0, 0), true);

            _deltinScript.GetComponent <StaticVariableCollection>().AddVariable(Zero.GetDefaultInstance(this));

            objectScope.AddNativeMethod(DistanceTo);
            objectScope.AddNativeMethod(CrossProduct);
            objectScope.AddNativeMethod(DotProduct);
            objectScope.AddNativeMethod(Normalize);
            objectScope.AddNativeMethod(DirectionTowards);
            objectScope.AddNativeMethod(FarthestPlayer);
            objectScope.AddNativeMethod(ClosestPlayer);
            objectScope.AddNativeMethod(IsInLineOfSight);
            objectScope.AddNativeMethod(Towards);
            objectScope.AddNativeMethod(AsLocalVector);
            objectScope.AddNativeMethod(AsWorldVector);

            Operations.AddTypeOperation(new TypeOperation[] {
                new TypeOperation(TypeOperator.Add, this, this),                        // Vector + vector
                new TypeOperation(TypeOperator.Subtract, this, this),                   // Vector - vector
                new TypeOperation(TypeOperator.Multiply, this, this),                   // Vector * vector
                new TypeOperation(TypeOperator.Divide, this, this),                     // Vector / vector
                new TypeOperation(TypeOperator.Multiply, _typeSupplier.Number(), this), // Vector * number
                new TypeOperation(TypeOperator.Divide, _typeSupplier.Number(), this),   // Vector / number
            });
            Operations.AddTypeOperation(new[] {
                new AssignmentOperation(AssignmentOperator.AddEqual, this),                        // += vector
                new AssignmentOperation(AssignmentOperator.SubtractEqual, this),                   // -= vector
                new AssignmentOperation(AssignmentOperator.MultiplyEqual, this),                   // *= vector
                new AssignmentOperation(AssignmentOperator.DivideEqual, this),                     // /= vector
                new AssignmentOperation(AssignmentOperator.MultiplyEqual, _typeSupplier.Number()), // *= number
                new AssignmentOperation(AssignmentOperator.DivideEqual, _typeSupplier.Number())    // /= number
            });
        }
Beispiel #10
0
 private void AddFunc(FuncMethodBuilder builder) => _objectScope.AddNativeMethod(new FuncMethod(builder));
Beispiel #11
0
 void AddSharedFunctionsToScope(Scope scope)
 {
     scope.AddNativeMethod(Teleport);
     scope.AddNativeMethod(SetMoveSpeed);
     scope.AddNativeMethod(SetMaxHealth);
     scope.AddNativeMethod(AllowButton);
     scope.AddNativeMethod(SetAbilityEnabled("Ability 1"));
     scope.AddNativeMethod(SetAbilityEnabled("Ability 2"));
     scope.AddNativeMethod(SetAbilityEnabled("Primary Fire"));
     scope.AddNativeMethod(SetAbilityEnabled("Secondary Fire"));
     scope.AddNativeMethod(SetAbilityEnabled("Ultimate Ability"));
     scope.AddNativeMethod(SetAbilityEnabled("Crouch"));
     scope.AddNativeMethod(SetAbilityEnabled("Melee"));
     scope.AddNativeMethod(SetAbilityEnabled("Jump"));
     scope.AddNativeMethod(SetAbilityEnabled("Reload"));
 }
 void IScopeAppender.AddStaticBasedScope(IMethod function)
 {
     _operationalStaticScope.AddNativeMethod(function);
     _conflictScope.AddNative(function);
 }
 void IScopeAppender.AddObjectBasedScope(IMethod function)
 {
     _operationalObjectScope.AddNativeMethod(function);
     _conflictScope.AddNative(function);
 }