Example #1
0
    override public void Update()
    {
        GlobalVariable[0].source = Rotation;
        GlobalVariable[1].source = CurrentAnchor != null;
        if (CurrentAnchor != null)
        {
            GlobalVariable[2].source = CurrentAnchor.GetComponentInChildren <WInteractable>().Name;
        }
        else
        {
            GlobalVariable[2].source = string.Empty;
        }

        for (int i = 0; i < FunctionCall.Count; i++)
        {
            FunctionCaller fc = FunctionCall[FunctionCall.Count - 1];
            FunctionCall.RemoveAt(0);
            int pr = i;
            i = 0;
            if (fc.Name == "GripNearestAnchor")
            {
                Undock();

                Dock(DetectedAnchor);
            }
            else if (fc.Name == "SetRotation")
            {
                SetRotation((int)fc.parameters[0].source);
            }
            else if (fc.Name == "UngripAnchor")
            {
                Undock();
            }
        }
    }
    void Start()
    {
        _functionCaller = new FunctionCaller(); //[TO DO]: Avoid "new" (D in SOLID)
        _taskLogic      = new TaskLogic();      //[TO DO]: Avoid "new" (D in SOLID)
        _taskLogic.LoadNumbers();

        StartCoroutine(_functionCaller.CallFunctionAfterDelay(0.5f, GenerateTask)); //give time to read file
    }
    override public void Update()
    {
        if (CanExecuteCode())
        {
            GlobalVariable[0].source = ParentRotor.localEulerAngles.y;

            for (int i = 0; i < FunctionCall.Count; i++)
            {
                FunctionCaller fc = FunctionCall[FunctionCall.Count - 1];
                FunctionCall.RemoveAt(0);
                int pr = i;
                i = 0;
                if (fc.Name == "SetSpecificRotation")
                {
                    Goto    = Mathf.Clamp((float)fc.parameters[0].source, 0f, 1f);
                    AtSpeed = Mathf.Clamp((float)fc.parameters[1].source, -1f, 1f);

                    if (AtSpeed < 0)
                    {
                        Goto = -Goto;
                    }
                    StartRot = ParentRotor.localEulerAngles;
                    cRot     = ParentRotor.localEulerAngles.y;
                }
                else if (fc.Name == "ExecuteRotation")
                {
                    Goto    = ParentRotor.localEulerAngles.y / 360f + (float)fc.parameters[0].source;
                    AtSpeed = Mathf.Clamp((float)fc.parameters[1].source, -1f, 1f);

                    if (AtSpeed < 0)
                    {
                        Goto = -Goto;
                    }
                    StartRot = ParentRotor.localEulerAngles;
                    cRot     = ParentRotor.localEulerAngles.y;
                }
                else if (fc.Name == "SetConstantSpeed")
                {
                    Goto    = Mathf.Infinity;
                    AtSpeed = Mathf.Clamp((float)fc.parameters[0].source, -1f, 1f);
                }
                i = pr;
            }

            PPSComsumption = AtSpeed * 6.0f;

            if (AtSpeed != 0f && Goto != Mathf.Infinity && Goto != Mathf.NegativeInfinity)
            {
                ParentRotor.localEulerAngles = new Vector3(0f, Mathf.Clamp(cRot + (AtSpeed * EnginSpeed) * Time.deltaTime, StartRot.y, Goto * 360f), 0f);
                cRot = Mathf.Clamp(cRot + (AtSpeed * EnginSpeed) * Time.deltaTime, StartRot.y, Goto * 360f);
            }
            else if (Goto == Mathf.Infinity || Goto == Mathf.NegativeInfinity)
            {
                ParentRotor.localEulerAngles += Vector3.up * (AtSpeed * EnginSpeed) * Time.deltaTime;
            }
        }
    }
 public void SendInteractableFunctionCall(string InteractableName, FunctionCaller caller)
 {
     for (int i = 0; i < sources.Count; i++)
     {
         if (sources[i].Name == InteractableName)
         {
             sources[i].FunctionCall.Add(caller);
             break;
         }
     }
 }
    public void OnValueChangedDropDown()
    {
        DestroyChildren();
        FunctionCaller function = GetFunction();

        function.parameters.ForEach(param =>
        {
            GameObject instance  = Instantiate(parameterPrefab);
            var placeholderText  = instance.transform.Find("Placeholder").GetComponent <Text>();
            placeholderText.text = param;
            instance.transform.SetParent(parameters.transform);
        });
    }
    public void OnClickExecute()
    {
        FunctionCaller function = GetFunction();
        string         param1, param2, param3, param4;

        switch (function.parameters.Count)
        {
        case 1:
            param1 = parameters.transform.GetChild(0).Find("Text").GetComponent <Text>().text;
            function.function1Param.Invoke(param1);
            break;

        case 2:
            param1 = parameters.transform.GetChild(0).Find("Text").GetComponent <Text>().text;
            param2 = parameters.transform.GetChild(1).Find("Text").GetComponent <Text>().text;
            function.function2Params.Invoke(param1, param2);
            break;

        case 3:
            param1 = parameters.transform.GetChild(0).Find("Text").GetComponent <Text>().text;
            param2 = parameters.transform.GetChild(1).Find("Text").GetComponent <Text>().text;
            param3 = parameters.transform.GetChild(2).Find("Text").GetComponent <Text>().text;
            function.function3Params.Invoke(param1, param2, param3);
            break;

        case 4:
            param1 = parameters.transform.GetChild(0).Find("Text").GetComponent <Text>().text;
            param2 = parameters.transform.GetChild(1).Find("Text").GetComponent <Text>().text;
            param3 = parameters.transform.GetChild(2).Find("Text").GetComponent <Text>().text;
            param4 = parameters.transform.GetChild(3).Find("Text").GetComponent <Text>().text;
            function.function4Params.Invoke(param1, param2, param3, param4);
            break;

        default:
            function.functionNoParams.Invoke();
            break;
        }
    }
    private void LoadApiDictionary()
    {
        apiDictionary = new Dictionary <string, FunctionCaller>();

        FunctionCaller loginGuest = new FunctionCaller()
        {
        };

        loginGuest.functionNoParams = authentication.Login;
        apiDictionary.Add("Login as guest", loginGuest);

        FunctionCaller loginUser = new FunctionCaller();

        loginUser.function2Params = (username, password) => authentication.Login(username, password);
        loginUser.parameters.Add("Username");
        loginUser.parameters.Add("Password");
        apiDictionary.Add("Login user with id", loginUser);

        FunctionCaller createAccount = new FunctionCaller();

        createAccount.function3Params = (email, username, password) => authentication.CreateAccount(email, username, password);
        createAccount.parameters.Add("Email");
        createAccount.parameters.Add("Username");
        createAccount.parameters.Add("Password");
        apiDictionary.Add("Create account with email", createAccount);

        FunctionCaller changeBackgroundColor = new FunctionCaller();

        changeBackgroundColor.functionNoParams = () => backgroundColorChanger.ChangeBackgroundColor();
        apiDictionary.Add("Change background color", changeBackgroundColor);

        FunctionCaller saveBackgroundColor = new FunctionCaller();

        saveBackgroundColor.functionNoParams = () => backgroundColorChanger.SaveBackgroundColor();
        apiDictionary.Add("Save background color", saveBackgroundColor);

        FunctionCaller getBackgroundColor = new FunctionCaller();

        getBackgroundColor.functionNoParams = () => backgroundColorChanger.GetBackgroundColor();
        apiDictionary.Add("Get background color", getBackgroundColor);

        FunctionCaller createGroup = new FunctionCaller();

        createGroup.function3Params = (adminUsername, password, groupName) => groupController.CreateGroup(adminUsername, password, groupName);
        createGroup.parameters.Add("Admin Username");
        createGroup.parameters.Add("Password");
        createGroup.parameters.Add("Group Name");
        apiDictionary.Add("Create group", createGroup);

        FunctionCaller invitePlayerToGroup = new FunctionCaller();

        invitePlayerToGroup.function4Params =
            (adminUsername, password, groupName, usernameToInvite) =>
            groupController.InvitePlayerToGroup(adminUsername, password, groupName, usernameToInvite);
        invitePlayerToGroup.parameters.Add("Admin Username");
        invitePlayerToGroup.parameters.Add("Password");
        invitePlayerToGroup.parameters.Add("Group Name");
        invitePlayerToGroup.parameters.Add("Username To Invite");
        apiDictionary.Add("Invite player to group", invitePlayerToGroup);

        FunctionCaller acceptInvitationToGroup = new FunctionCaller();

        acceptInvitationToGroup.function3Params =
            (usernameToAccept, password, groupName) =>
            groupController.AcceptInvitationToGroup(usernameToAccept, password, groupName);
        acceptInvitationToGroup.parameters.Add("Username To Accept");
        acceptInvitationToGroup.parameters.Add("Password");
        acceptInvitationToGroup.parameters.Add("Group Name");
        apiDictionary.Add("Accept invitation to group", acceptInvitationToGroup);

        FunctionCaller fetchApiPolicy = new FunctionCaller();

        fetchApiPolicy.functionNoParams = () => apiAccessPolicyController.FetchApiPolicy();
        apiDictionary.Add("Fetch API access policy", fetchApiPolicy);

        FunctionCaller readDropTableData = new FunctionCaller();

        readDropTableData.function1Param = (tableId) => dropTableController.ReadDropTableData(tableId);
        readDropTableData.parameters.Add("Drop table id");
        apiDictionary.Add("Read drop table data", readDropTableData);

        FunctionCaller grantRandomItemToUser = new FunctionCaller();

        grantRandomItemToUser.function4Params =
            (adminUsername, password, usernameReceivingItem, dropTableId) =>
            dropTableController.GrantRandomItemToUser(adminUsername, password, usernameReceivingItem, dropTableId);
        grantRandomItemToUser.parameters.Add("Admin Username");
        grantRandomItemToUser.parameters.Add("Password");
        grantRandomItemToUser.parameters.Add("Username Receiving Item");
        grantRandomItemToUser.parameters.Add("Drop Table Id");
        apiDictionary.Add("Grant user random item", grantRandomItemToUser);

        FunctionCaller purchaseItem = new FunctionCaller();

        purchaseItem.function4Params =
            (username, password, itemId, price) =>
            playerInventoryController.PurchaseItem(username, password, itemId, price);
        purchaseItem.parameters.Add("Username");
        purchaseItem.parameters.Add("Password");
        purchaseItem.parameters.Add("Item Id");
        purchaseItem.parameters.Add("Price");
        apiDictionary.Add("Purchase item", purchaseItem);

        FunctionCaller getInventory = new FunctionCaller();

        getInventory.function2Params = (username, password) => playerInventoryController.GetInventory(username, password);
        getInventory.parameters.Add("Username");
        getInventory.parameters.Add("Password");
        apiDictionary.Add("Get inventory", getInventory);

        FunctionCaller consumeItem = new FunctionCaller();

        consumeItem.function3Params = (username, password, itemId) => playerInventoryController.ConsumeItem(username, password, itemId);
        consumeItem.parameters.Add("Username");
        consumeItem.parameters.Add("Password");
        consumeItem.parameters.Add("Item Id");
        apiDictionary.Add("Consume item", consumeItem);

        FunctionCaller redeemCoupon = new FunctionCaller();

        redeemCoupon.function3Params = (username, password, couponCode) => couponController.RedeemCoupon(username, password, couponCode);
        redeemCoupon.parameters.Add("Username");
        redeemCoupon.parameters.Add("Password");
        redeemCoupon.parameters.Add("Coupon Code");
        apiDictionary.Add("Redeem Coupon", redeemCoupon);

        FunctionCaller updatePlayerStatistic = new FunctionCaller();

        updatePlayerStatistic.function2Params = (username, password) => statisticsController.UpdatePlayerStatistics(username, password);
        updatePlayerStatistic.parameters.Add("Username");
        updatePlayerStatistic.parameters.Add("Password");
        apiDictionary.Add("Update player statistic", updatePlayerStatistic);
    }
Example #8
0
 public virtual bool VisitFunctionCaller(FunctionCaller functionCaller)
 {
     return(true);
 }
Example #9
0
    // Update is called once per frame
    override public void Update()
    {
        if (PowerSource != null)
        {
            Capacity += Mathf.Clamp(PowerSource.PPSPool, 0.0f, (float)GlobalVariable[3].source * Time.deltaTime);
            Capacity  = Mathf.Min(MaxCap * (float)GlobalVariable[6].source, Capacity);

            if (Capacity / MaxCap >= 1f)
            {
                renderers[0].material = mats[1];
                renderers[1].material = mats[1];
                renderers[2].material = mats[1];
                renderers[3].material = mats[1];
            }
            else if (Capacity / MaxCap > 0.75f)
            {
                renderers[0].material = mats[0];
                renderers[1].material = mats[1];
                renderers[2].material = mats[1];
                renderers[3].material = mats[1];
            }
            else if (Capacity / MaxCap > 0.5f)
            {
                renderers[0].material = mats[0];
                renderers[1].material = mats[0];
                renderers[2].material = mats[1];
                renderers[3].material = mats[1];
            }
            else if (Capacity / MaxCap > 0f)
            {
                renderers[0].material = mats[0];
                renderers[1].material = mats[0];
                renderers[2].material = mats[0];
                renderers[3].material = mats[1];
            }
            else if (Capacity / MaxCap <= 0f)
            {
                renderers[0].material = mats[0];
                renderers[1].material = mats[0];
                renderers[2].material = mats[0];
                renderers[3].material = mats[0];
            }
        }
        GlobalVariable[0].source = Capacity;
        GlobalVariable[1].source = Capacity / MaxCap;

        GlobalVariable[4].source = Capacity == MaxCap;
        GlobalVariable[5].source = Capacity == 0f;

        PPSPool = Mathf.Clamp(Capacity, 0.0f, (float)GlobalVariable[1].source);

        for (int i = 0; i < FunctionCall.Count; i++)
        {
            FunctionCaller fc = FunctionCall[FunctionCall.Count - 1];
            FunctionCall.RemoveAt(0);
            int pr = i;
            i = 0;
            if (fc.Name == "SetMaxPPSFlowValues")
            {
                GlobalVariable[2].source = Mathf.Clamp((float)fc.parameters[0].source, 0.0f, 2000f);
                GlobalVariable[3].source = Mathf.Clamp((float)fc.parameters[1].source, 0.0f, 2000f);
            }
            if (fc.Name == "SetMaxFillingCapacity")
            {
                GlobalVariable[6].source = Mathf.Clamp((float)fc.parameters[0].source, 0.0f, 1.0f);
            }
        }
    }
        public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,SLOT resultSlot,
                                          object callbacker,
                                          object stackframe,
                                          SourceToken token,RunTimeScope scope)
        {
            //base.executeAsync(thisObj, argements, resultSlot, callbacker, stackframe, token, scope);

            var thisArg = argements[0].getValue();


            rtFunction func    = (rtFunction)((rtObjectBase)thisObj).value.memberData[0].getValue();
            rtFunction toApply = (rtFunction)func;            //.Clone();


            if (!func.ismethod)             //方法无法更改this
            {
                if (!(thisArg is rtObjectBase))
                {
                    var player  = ((StackFrame)stackframe).player;
                    var objtype = thisArg.rtType;
                    if (objtype < RunTimeDataType.unknown
                        &&
                        player.swc.primitive_to_class_table[objtype] != null
                        )
                    {
                        FunctionCaller toInsertStack = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token);
                        toInsertStack.callbacker = (IBlockCallBack)callbacker;
                        toInsertStack.SetFunction(toApply);
                        toInsertStack._tempSlot  = ((StackFrame)stackframe)._tempSlot1;
                        toInsertStack.returnSlot = resultSlot;
                        toInsertStack.tag        = argements;

                        stackCallers.Push(toInsertStack);

                        //***转换为对象***
                        OpCast.Primitive_to_Object(thisArg,(StackFrame)stackframe,token,scope,
                                                   ((StackFrame)stackframe)._tempSlot1,
                                                   null,_primitive_toObj);


                        return;
                    }
                    else
                    {
                        var fd    = player.swc.functions[toApply.functionId];
                        var block = player.swc.blocks[fd.blockid];
                        //if (block.isoutclass )将this复位
                        {
                            var oc = player.outpackage_runtimescope[block.define_class_id];
                            toApply.setThis(oc.this_pointer);
                        }
                        //else
                        //{
                        //    caller.function.setThis(null);
                        //}
                    }
                }
                else
                {
                    toApply.setThis((rtObjectBase)thisArg);
                }
            }

            FunctionCaller caller = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token);

            caller.callbacker = (IBlockCallBack)callbacker;
            caller.SetFunction(toApply);
            caller._tempSlot  = ((StackFrame)stackframe)._tempSlot1;
            caller.returnSlot = resultSlot;

            caller.loadDefineFromFunction();
            if (!caller.createParaScope())
            {
                return;
            }



            if (argements[1].getValue().rtType == RunTimeDataType.rt_array)
            {
                rtArray argArray = (rtArray)argements[1].getValue();
                for (int i = 0; i < argArray.innerArray.Count; i++)
                {
                    bool success;
                    caller.pushParameter(argArray.innerArray[i],i,out success);
                }
            }


            caller.call();
        }
Example #11
0
    override public void Update()
    {
        if (CanExecuteCode())
        {
            for (int i = 0; i < FunctionCall.Count; i++)
            {
                FunctionCaller fc = FunctionCall[FunctionCall.Count - 1];
                FunctionCall.RemoveAt(0);
                int pr = i;
                i = 0;
                if (fc.Name == "Fill")
                {
                    Color color = new Color {
                        r = (float)fc.parameters[0].source,
                        g = (float)fc.parameters[1].source,
                        b = (float)fc.parameters[2].source,
                        a = 1f
                    };

                    Color[] colors = display.GetPixels();
                    for (int c = 0; c < colors.Length; c++)
                    {
                        colors[c] = color;
                    }

                    display.SetPixels(colors);
                    UpdateScreen();
                }
                else
                if (fc.Name == "SetColor")
                {
                    CurrentColor = new Color {
                        r = (float)fc.parameters[0].source,
                        g = (float)fc.parameters[1].source,
                        b = (float)fc.parameters[2].source,
                        a = 1f
                    };
                }
                else
                if (fc.Name == "SetTextCursor")
                {
                    TextCursorX = (int)fc.parameters[0].source;
                    TextCursorY = (int)fc.parameters[1].source;
                }
                else
                if (fc.Name == "DrawText")
                {
                    Color[] colors = display.GetPixels();
                    string  text   = (string)fc.parameters[0].source;
                    for (int t = 0; t < text.Length; t++)
                    {
                        byte b = (byte)(Converter.IndexOf(char.ToUpper(text[t])));
                        if (b > 127)
                        {
                            b = 0;
                        }
                        int readb = 2 + b * 3;

                        byte width  = BitmapFont[0];
                        byte height = BitmapFont[1];

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                if ((BitmapFont[readb + x] >> y & 1) == 1)
                                {
                                    if ((TextCursorX + x + (width + 1) * t) < display.width)
                                    {
                                        colors[(TextCursorX + x + (width + 1) * t) + (display.height - (TextCursorY + y)) * display.width] = CurrentColor;
                                    }
                                }
                            }
                        }
                    }
                    display.SetPixels(colors);
                    UpdateScreen();
                }
                else
                if (fc.Name == "DrawPixel")
                {
                    display.SetPixel(
                        (int)fc.parameters[0].source,
                        display.height - (int)fc.parameters[1].source,
                        CurrentColor
                        );
                    UpdateScreen();
                }
                else
                if (fc.Name == "DrawFilledRect")
                {
                    Color[] colors = display.GetPixels();
                    for (int x = (int)fc.parameters[0].source; x < (int)fc.parameters[2].source; x++)
                    {
                        for (int y = (int)fc.parameters[1].source; y < (int)fc.parameters[3].source; y++)
                        {
                            if (x < display.width)
                            {
                                colors[x + (display.height - y - 1) * display.width] = CurrentColor;
                            }
                        }
                    }
                    display.SetPixels(colors);
                    UpdateScreen();
                }
                else
                if (fc.Name == "DrawRect")
                {
                    Color[] colors = display.GetPixels();
                    for (int x = (int)fc.parameters[0].source; x < (int)fc.parameters[2].source; x++)
                    {
                        for (int y = (int)fc.parameters[1].source; y < (int)fc.parameters[3].source; y++)
                        {
                            if (x == (int)fc.parameters[0].source || x == (int)fc.parameters[2].source - 1 || y == (int)fc.parameters[1].source || y == (int)fc.parameters[3].source - 1)
                            {
                                if (x < display.width)
                                {
                                    colors[x + (display.height - y - 1) * display.width] = CurrentColor;
                                }
                            }
                        }
                    }
                    display.SetPixels(colors);
                    UpdateScreen();
                }
                else
                if (fc.Name == "DrawLine")
                {
                    display.SetPixels(DrawLine(
                                          (int)fc.parameters[0].source,
                                          (int)fc.parameters[1].source,
                                          (int)fc.parameters[2].source,
                                          (int)fc.parameters[3].source,
                                          display.GetPixels(),
                                          display.width,
                                          display.height,
                                          CurrentColor
                                          ));
                    UpdateScreen();
                }
                i = pr;
            }
        }

        int tactileX = Mathf.FloorToInt(TouchUVs.x * display.width);
        int tactileY = display.height - Mathf.FloorToInt(TouchUVs.y * display.height);

        GlobalVariable[2].source = tactileX;
        GlobalVariable[3].source = tactileY;
        GlobalVariable[4].source = MouseDown;
        GlobalVariable[5].source = MousePress;
        GlobalVariable[6].source = MouseUp;

        MouseDown  = false;
        MousePress = false;
        MouseUp    = false;
    }
Example #12
0
 public static int RvExtensionArgs(StringBuilder output, int outputSize,
                                   [MarshalAs(UnmanagedType.LPStr)] string function,
                                   [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] args, int argCount)
 {
     return(FunctionCaller.Call(function, output, args));
 }
Example #13
0
 public static void RvExtension(StringBuilder output, int outputSize,
                                [MarshalAs(UnmanagedType.LPStr)] string function)
 {
     FunctionCaller.Call(function, output);
 }
Example #14
0
        private object ConstructScope(IWebConnection constructWebConnection)
        {
            log.Debug("Constructing Javascript scope for " + FileContainer.FullPath);

            CacheIDsByKey = new Dictionary<object, KeyValuePair<object, DateTime>>();

            _SubProcess.RegisterParentFunctionDelegate(ScopeId, CallParentFunction);
            FunctionCallers = new Dictionary<string, FunctionCaller>();

            SubProcess.CreateScopeResults data = FunctionCaller.UseTemporaryCaller<SubProcess.CreateScopeResults>(
                this, FileContainer, constructWebConnection, delegate()
                {
                    return _SubProcess.CreateScope(
                        ScopeId,
                        ParentScope.ParentScopeId,
                        Thread.CurrentThread.ManagedThreadId,
                        CreateMetadata(FileHandlerFactoryLocator, FileContainer));
                });

            // Initialize each function caller
            foreach (KeyValuePair<string, SubProcess.CreateScopeFunctionInfo> functionKVP in data.Functions)
            {
                string functionName = functionKVP.Key;
                SubProcess.CreateScopeFunctionInfo functionInfo = functionKVP.Value;
                Dictionary<string, object> properties = functionInfo.Properties;

                // ... and it's marked as webCallable, create a FunctionCaller
                if (properties.ContainsKey("webCallable"))
                {
                    FunctionCaller functionCaller = new FunctionCaller(this, FileContainer, functionName, functionInfo);

                    // ... and if the function caller supports the calling convention, then cache it!

                    if (null != functionCaller.WebDelegate)
                        FunctionCallers[functionName] = functionCaller;
                }
            }

            return data.Results[data.Results.Length - 2];
        }