public void BindPlain() { var obj = new BindingObject <String>(); obj.SetBinding(_bindingPlain); obj.CheckValue("Plain"); }
public void TestWeakDelegate1() { var target = new BindingObject(); target.WeakDelegate1 = new MyProtocol(); target.CallDelegate1Method(); }
public void TestStringArrayMethod() { var targetObj = new BindingObject (); var arrayResult = targetObj.StringArrayMethod (); Assert.NotNull (arrayResult); Assert.AreEqual (1, arrayResult.Length); Assert.AreEqual ("return of string array method.", arrayResult [0]); }
public override bool HasBinding(ScriptValue name) { var foundBinding = BindingObject.HasProperty(name); if (!foundBinding) { return(false); } if (!withEnvironment) { return(true); } var unscopables = BindingObject.Get(Symbol.Unscopables); if (unscopables.IsObject) { var blocked = Agent.ToBoolean(((ScriptObject)unscopables).Get(name)); if (blocked) { return(false); } } return(true); }
public void BindObservable() { var obj = new BindingObject <String>(); obj.SetBinding(_bindingObservable); obj.CheckValue("Observable"); }
/// <summary> /// Sets the lifetimes of the given binding object. /// </summary> /// <param name="bindingObj">binding object</param> /// <param name="preferred">preferred lifetime in ms</param> /// <param name="valid">valid lifetime in ms</param> protected void SetBindingObjectTimes(BindingObject bindingObj, long preferred, long valid) { if (_log.IsDebugEnabled) { _log.Debug("Updating binding times for address: " + bindingObj.GetIpAddress().ToString() + " preferred=" + preferred + ", valid=" + valid); } DateTime now = DateTime.Now; bindingObj.SetStartTime(now); if (preferred < 0) { // infinite lease bindingObj.SetPreferredEndTime(new DateTime(-1)); } else { bindingObj.SetPreferredEndTime(now.AddMilliseconds(preferred)); } if (valid < 0) { // infinite lease bindingObj.SetValidEndTime(now.AddDays(-1)); } else { bindingObj.SetValidEndTime(now.AddMilliseconds(valid)); } }
/// <summary> /// Builds the set of binding objects for the client request. /// </summary> /// <param name="clientLink">client link</param> /// <param name="inetAddrs">the list of IP addresses for the client binding</param> /// <param name="requestMsg">request message</param> /// <param name="state">binding state</param> /// <returns>the HashSet<binding object></returns> private HashSet <BindingObject> BuildBindingObjects(DhcpLink clientLink, List <IPAddress> inetAddrs, DhcpMessage requestMsg, byte state) { HashSet <BindingObject> bindingObjs = new HashSet <BindingObject>(); foreach (IPAddress inetAddr in inetAddrs) { if (_log.IsDebugEnabled) { _log.Debug("Building BindingObject for IP=" + inetAddr.ToString()); } BindingObject bindingObj = BuildBindingObject(inetAddr, clientLink, requestMsg); if (bindingObj != null) { bindingObj.SetState(state); bindingObjs.Add(bindingObj); } else { _log.Warn("Failed to build BindingObject for IP=" + inetAddr.ToString()); } } return(bindingObjs); }
public void TestDelegate2() { var target = new BindingObject(); target.Delegate2 = new MyProtocol(); target.CallDelegate2Method(); }
/// <summary> /// Update an existing static binding. /// </summary> /// <param name="binding">existing client binding</param> /// <param name="clientLink">link for the client request message</param> /// <param name="duid">DUID of the client</param> /// <param name="iatype">IA type of the client request</param> /// <param name="iaid">IAID of the client request</param> /// <param name="staticBinding">static binding</param> /// <param name="requestMsg">client request message</param> /// <returns>updated Binding</returns> protected Binding UpdateStaticBinding(Binding binding, DhcpLink clientLink, byte[] duid, byte iatype, long iaid, StaticBinding staticBinding, DhcpMessage requestMsg) { List <IaAddress> addIaAddresses = null; List <IaAddress> updateIaAddresses = null; List <IaAddress> delIaAddresses = null; // not used currently if (staticBinding != null) { _log.Info("Updating static binding: " + binding); HashSet <BindingObject> bindingObjs = binding.GetBindingObjects(); if ((bindingObjs != null) && bindingObjs.Count > 0) { foreach (BindingObject bindingObj in bindingObjs) { if (bindingObj.GetIpAddress().Equals(staticBinding.GetIpAddress())) { SetBindingObjectTimes(bindingObj, staticBinding.GetPreferredLifetimeMs(), staticBinding.GetPreferredLifetimeMs()); break; } //TODO: what about bindingObjs that do NOT match the static binding? } // the existing IaAddress binding objects will be updated updateIaAddresses = binding.GetIaAddresses(); } else { IPAddress inetAddr = staticBinding.GetInetAddress(); if (inetAddr != null) { BindingObject bindingObj = BuildStaticBindingObject(inetAddr, staticBinding); bindingObjs = new HashSet <BindingObject>(); bindingObjs.Add(bindingObj); binding.SetBindingObjects(bindingObjs); // this new IaAddress binding object will be added addIaAddresses = binding.GetIaAddresses(); } } } else { _log.Error("StaticBindingObject is null"); } binding.SetState(IaAddress.STATIC); try { iaMgr.UpdateIA(binding, addIaAddresses, updateIaAddresses, delIaAddresses); return(binding); // if we get here, it worked } catch (Exception ex) { _log.Error("Failed to update binding"); return(null); } }
public void TestStringArrayCategoryMethod() { var bindObj = new BindingObject (); //var catObj = new Extension (); var strArrCatResult = bindObj.StringArrayCategoryMethod (); Assert.AreEqual (1, strArrCatResult.Length); Assert.AreEqual ("return of string array category method", strArrCatResult [0]); }
public void TestStringMethod() { var targetObj = new BindingObject(); var stringResult = targetObj.StringMethod(); Assert.IsNotNull(stringResult); Assert.AreEqual("return of string method.", stringResult); }
public void TestStringCategoryMethod() { var bindObj = new BindingObject (); //var catObj = new Extension (); var strCatResult = bindObj.StringCategoryMethod(); Assert.IsNotNull (strCatResult); Assert.AreEqual ("return of string category method", strCatResult); }
public void TestStringArrayMethod() { var targetObj = new BindingObject(); var arrayResult = targetObj.StringArrayMethod(); Assert.NotNull(arrayResult); Assert.AreEqual(1, arrayResult.Length); Assert.AreEqual("return of string array method.", arrayResult [0]); }
public void TestStringCategoryMethod() { var bindObj = new BindingObject(); //var catObj = new Extension (); var strCatResult = bindObj.StringCategoryMethod(); Assert.IsNotNull(strCatResult); Assert.AreEqual("return of string category method", strCatResult); }
public void TestStringArrayCategoryMethod() { var bindObj = new BindingObject(); //var catObj = new Extension (); var strArrCatResult = bindObj.StringArrayCategoryMethod(); Assert.AreEqual(1, strArrCatResult.Length); Assert.AreEqual("return of string array category method", strArrCatResult [0]); }
/** * Adds the v4 binding to reply. * * @param clientLink the client link * @param binding the binding */ protected void AddBindingToReply(DhcpLink clientLink, Binding binding) { HashSet <BindingObject> bindingObjs = binding.GetBindingObjects(); if ((bindingObjs != null) && bindingObjs.Count > 0) { if (bindingObjs.Count == 1) { BindingObject bindingObj = bindingObjs.First(); IPAddress inetAddr = bindingObj.GetIpAddress(); if (inetAddr != null) { _replyMsg.SetYiAddr(inetAddr); // must be an DhcpV4OptionConfigObject for v4 binding DhcpV4OptionConfigObject configObj = (DhcpV4OptionConfigObject)bindingObj.GetConfigObj(); if (configObj != null) { long preferred = configObj.GetPreferredLifetime(); DhcpV4LeaseTimeOption dhcpV4LeaseTimeOption = new DhcpV4LeaseTimeOption(); dhcpV4LeaseTimeOption.SetUnsignedInt(preferred); _replyMsg.PutDhcpOption(dhcpV4LeaseTimeOption); PopulateV4Reply(clientLink, configObj); //TODO when do actually start the timer? currently, two get // created - one during advertise, one during reply // policy to allow real-time expiration? // bp.startExpireTimerTask(bindingAddr, iaAddrOption.getValidLifetime()); } else { log.Error("Null binding pool in binding: " + binding.ToString()); } } else { log.Error("Null address in binding: " + binding.ToString()); } } else { log.Error("Expected only one bindingObject in v4 Binding, but found " + bindingObjs.Count + "bindingObjects"); } } else { log.Error("No V4 bindings in binding object!"); } }
public override ScriptValue GetBindingValue(ScriptValue name, bool strict) { var value = BindingObject.HasProperty(name); if (!value) { if (strict) { throw BindingObject.Agent.CreateReferenceError(); } return(ScriptValue.Undefined); } return(BindingObject.Get(name, BindingObject)); }
private static void AddDistinctBind(List <BindingObject> lst, BindingObject bind) { bool found = false; foreach (BindingObject b in lst) { if (b.Name == bind.Name) { found = true; } } if (!found) { lst.Add(bind); } }
public static bool Bind(string KeyName, string FunctionName) { BindingObject NewBind = new BindingObject(KeyName); bool Found = false; if (WithArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(SteelInputWithArg), false).Length > 0); WithArgMethods = new List <WithArgInfo>(); foreach (MethodInfo Method in Methods) { WithArgMethods.Add( new WithArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(SteelInputWithArg)) as SteelInputWithArg ) ); } } foreach (WithArgInfo Method in WithArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithArg = Method.Tag.Function; break; } } if (WithoutArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(SteelInputWithoutArg), false).Length > 0); WithoutArgMethods = new List <WithoutArgInfo>(); foreach (MethodInfo Method in Methods) { WithoutArgMethods.Add( new WithoutArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(SteelInputWithoutArg)) as SteelInputWithoutArg ) ); } } foreach (WithoutArgInfo Method in WithoutArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithoutArg = Method.Tag.Function; break; } } if (!Found) { Console.ThrowPrint($"The specified function '{FunctionName}' does not exist as a bindable function"); return(false); } var ButtonValue = ButtonList.Left; var AxisDirection = DIRECTION.UP; var ControllerButtonValue = JoystickList.Axis0; uint Scancode = 0; switch (KeyName) //Checks custom string literals first then assumes Scancode { case ("MouseOne"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Left; break; } case ("MouseTwo"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Right; break; } case ("MouseThree"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Middle; break; } case ("WheelUp"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelUp; break; } case ("WheelDown"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelDown; break; } case ("MouseUp"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.UP; break; } case ("MouseDown"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.DOWN; break; } case ("MouseRight"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.RIGHT; break; } case ("MouseLeft"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.LEFT; break; } case ("LeftStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("LeftStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("RightStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("RightStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("XboxA"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxA; break; } case ("XboxB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxB; break; } case ("XboxX"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxX; break; } case ("XboxY"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxY; break; } case ("XboxLB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L; break; } case ("XboxRB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R; break; } case ("XboxLT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L2; break; } case ("XboxRT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R2; break; } case ("RightStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R3; break; } case ("LeftStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L3; break; } case ("DPadUp"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadUp; break; } case ("DPadDown"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadDown; break; } case ("DPadLeft"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadLeft; break; } case ("DPadRight"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadRight; break; } case ("XboxStart"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Start; break; } case ("XboxSelect"): { // Or Select. Or Share. Or The big thing in the middle of ps4 remotes. Or -. NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Select; break; } default: { //Does not match any custom string literal must either be a Scancode or is invalid uint LocalScancode = (uint)OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = TYPE.SCANCODE; Scancode = LocalScancode; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } break; } } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind InputMap.AddAction(KeyName); switch (NewBind.Type) { case (TYPE.SCANCODE): { InputEventKey Event = new InputEventKey { Scancode = Scancode }; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEBUTTON): case (TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton { ButtonIndex = (int)ButtonValue }; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion { Axis = (int)ControllerButtonValue }; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton { ButtonIndex = (int)ControllerButtonValue }; InputMap.ActionAddEvent(KeyName, Event); break; } } if (NewBind.FuncWithArg != null) { BindingsWithArg.Add(NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); } return(true); }
public static bool Bind(string actionName, string KeyName) { string FunctionName; actionName = actionName.ToLower(); // TODO - support multiple commands with semicolon string searchname = actionName.Split(" ")[0]; KeyName = KeyName.ToLower(); var kvp = _game.Commands.List.Where(e => e.Key.ToLower() == searchname).FirstOrDefault(); CommandInfo ci = kvp.Value; FunctionName = ci.FunctionName; BindingObject NewBind = new BindingObject(actionName, KeyName); bool Found = false; if (WithArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(InputWithArg), false).Length > 0); WithArgMethods = new List <WithArgInfo>(); foreach (MethodInfo Method in Methods) { WithArgMethods.Add( new WithArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(InputWithArg)) as InputWithArg ) ); } } foreach (WithArgInfo Method in WithArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithArg = Method.Tag.Function; break; } } if (WithoutArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(InputWithoutArg), false).Length > 0); WithoutArgMethods = new List <WithoutArgInfo>(); foreach (MethodInfo Method in Methods) { WithoutArgMethods.Add( new WithoutArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(InputWithoutArg)) as InputWithoutArg ) ); } } foreach (WithoutArgInfo Method in WithoutArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithoutArg = Method.Tag.Function; break; } } if (WithArgCommands == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(CommandWithArg), false).Length > 0); WithArgCommands = new List <WithArgCommandInfo>(); foreach (MethodInfo Method in Methods) { WithArgCommands.Add( new WithArgCommandInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(CommandWithArg)) as CommandWithArg ) ); } } foreach (WithArgCommandInfo Method in WithArgCommands) { if (Method.Name == FunctionName) { Found = true; NewBind.CommandWithArg = Method.Tag.Function; break; } } if (!Found) { Console.ThrowPrint($"The specified function '{FunctionName}' does not exist as a bindable function"); return(false); } var ButtonValue = ButtonList.Left; var AxisDirection = ButtonInfo.DIRECTION.UP; var ControllerButtonValue = JoystickList.Axis0; uint Scancode = 0; //Checks custom string literals first then assumes Scancode KeyType kt = null; KeyTypes.List.TryGetValue(KeyName, out kt); if (kt == null) { // scancodes uint LocalScancode = (uint)OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = ButtonInfo.TYPE.SCANCODE; Scancode = LocalScancode; } else if (KeyName == "`") // this fails on ubuntu 18.04 (scancode of 0 given back) { NewBind.Type = ButtonInfo.TYPE.SCANCODE; Scancode = 96; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } } else { NewBind.Type = kt.Type; ButtonValue = kt.ButtonValue; AxisDirection = kt.Direction; ControllerButtonValue = kt.ControllerButtonValue; } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind if (!InputMap.HasAction(actionName)) { InputMap.AddAction(actionName); } switch (NewBind.Type) { case (ButtonInfo.TYPE.SCANCODE): { InputEventKey Event = new InputEventKey { Scancode = Scancode }; InputMap.ActionAddEvent(actionName, Event); break; } case (ButtonInfo.TYPE.MOUSEBUTTON): case (ButtonInfo.TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton { ButtonIndex = (int)ButtonValue }; InputMap.ActionAddEvent(actionName, Event); break; } case (ButtonInfo.TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(actionName, Event); NewBind.AxisDirection = (ButtonInfo.DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (ButtonInfo.TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion { Axis = (int)ControllerButtonValue }; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (ButtonInfo.DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (ButtonInfo.DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (ButtonInfo.DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (ButtonInfo.DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(actionName, Event); NewBind.AxisDirection = (ButtonInfo.DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (ButtonInfo.TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton { ButtonIndex = (int)ControllerButtonValue }; InputMap.ActionAddEvent(actionName, Event); break; } } if (NewBind.FuncWithArg != null || NewBind.CommandWithArg != null) { BindingsWithArg.Add(NewBind); AddDistinctBind(BindingsWithArgDistinct, NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); AddDistinctBind(BindingsWithoutArgDistinct, NewBind); } return(true); }
public static void Bind(string FunctionName, string InputString) { BIND_TYPE Type = BIND_TYPE.SCANCODE; if (System.Array.IndexOf(MouseButtonList, InputString) >= 0) { Type = BIND_TYPE.MOUSEBUTTON; } if (System.Array.IndexOf(MouseWheelList, InputString) >= 0) { Type = BIND_TYPE.MOUSEWHEEL; } if (System.Array.IndexOf(AxisList, InputString) >= 0) { Type = BIND_TYPE.AXIS; } if (InputMap.HasAction(FunctionName)) { InputMap.EraseAction(FunctionName); foreach (BindingObject Bind in BindingList) { if (Bind.Name == FunctionName) { BindingList.Remove(Bind); break; } } } if (Type == BIND_TYPE.SCANCODE) { InputMap.AddAction(FunctionName); InputEventKey Event = new InputEventKey(); Event.Scancode = OS.FindScancodeFromString(InputString); InputMap.ActionAddEvent(FunctionName, Event); BindingList.Add(new BindingObject(FunctionName, Type)); } else if (Type == BIND_TYPE.MOUSEBUTTON) { InputMap.AddAction(FunctionName); InputEventMouseButton Event = new InputEventMouseButton(); switch (InputString) { case ("MouseOne"): Event.ButtonIndex = (int)ButtonList.Left; break; case ("MouseTwo"): Event.ButtonIndex = (int)ButtonList.Right; break; case ("MouseThree"): Event.ButtonIndex = (int)ButtonList.Middle; break; //No default as this else if will not run unless one of these string will match anyway } InputMap.ActionAddEvent(FunctionName, Event); BindingList.Add(new BindingObject(FunctionName, Type)); } else if (Type == BIND_TYPE.MOUSEWHEEL) { InputMap.AddAction(FunctionName); InputEventMouseButton Event = new InputEventMouseButton(); switch (InputString) { case ("WheelUp"): Event.ButtonIndex = (int)ButtonList.WheelUp; break; case ("WheelDown"): Event.ButtonIndex = (int)ButtonList.WheelDown; break; } InputMap.ActionAddEvent(FunctionName, Event); BindingList.Add(new BindingObject(FunctionName, Type)); } else if (Type == BIND_TYPE.AXIS) { InputMap.AddAction(FunctionName); InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(FunctionName, Event); BindingObject Bind = new BindingObject(FunctionName, Type); switch (InputString) { case ("MouseUp"): Bind.AxisDirection = BindingObject.DIRECTION.UP; break; case ("MouseDown"): Bind.AxisDirection = BindingObject.DIRECTION.DOWN; break; case ("MouseRight"): Bind.AxisDirection = BindingObject.DIRECTION.RIGHT; break; case ("MouseLeft"): Bind.AxisDirection = BindingObject.DIRECTION.LEFT; break; } BindingList.Add(Bind); } }
public static bool Bind(string KeyName, string FunctionName) { BindingObject NewBind = new BindingObject(KeyName); //We need to check that the function exitst and either takes no args or one float arg and get the Action try //First assume it takes a float argument { Sc.ScriptState State = Scripting.ConsoleState.ContinueWithAsync($"return new Action<float>(delegate(float x) {{ {FunctionName}(x); }} );").Result; NewBind.FuncWithArg = State.ReturnValue as Action <float>; } catch //Must either not exist or has different argument requirements { try //Next we assume that it exists but without an argument { Sc.ScriptState State = Scripting.ConsoleState.ContinueWithAsync($"return new Action(delegate() {{ {FunctionName}(); }} );").Result; NewBind.FuncWithoutArg = State.ReturnValue as Action; } catch //At this point we know it either does not exist or has incompatible argument requirements { Console.ThrowPrint($"The supplied function '{FunctionName}' does not exist, does not take a single float argument, or does not take zero arguments"); return(false); } } Nullable <ButtonList> ButtonValue = null; //Making it null by default prevents a compile warning further down Nullable <DIRECTION> AxisDirection = null; //Making it null by default prevents a compile warning further down Nullable <JoystickList> ControllerButtonValue = null; // Making a new variable for Controller buttons because int Scancode = 0; switch (KeyName) //Checks custom string literals first then assumes Scancode { case ("MouseOne"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Left; break; } case ("MouseTwo"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Right; break; } case ("MouseThree"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Middle; break; } case ("WheelUp"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelUp; break; } case ("WheelDown"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelDown; break; } case ("MouseUp"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.UP; break; } case ("MouseDown"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.DOWN; break; } case ("MouseRight"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.RIGHT; break; } case ("MouseLeft"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.LEFT; break; } case ("LeftStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("LeftStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("RightStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("RightStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("XboxA"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxA; break; } case ("XboxB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxB; break; } case ("XboxX"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxX; break; } case ("XboxY"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxY; break; } case ("XboxLB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L; break; } case ("XboxRB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R; break; } case ("XboxLT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L2; break; } case ("XboxRT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R2; break; } case ("RightStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R3; break; } case ("LeftStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L3; break; } case ("DPadUp"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadUp; break; } case ("DPadDown"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadDown; break; } case ("DPadLeft"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadLeft; break; } case ("DPadRight"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadRight; break; } case ("XboxStart"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Start; break; } case ("XboxSelect"): { // Or Select. Or Share. Or The big thing in the middle of ps4 remotes. Or -. NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Select; break; } default: { //Does not match any custom string literal must either be a Scancode or is invalid int LocalScancode = OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = TYPE.SCANCODE; Scancode = LocalScancode; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } break; } } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind InputMap.AddAction(KeyName); switch (NewBind.Type) { case (TYPE.SCANCODE): { InputEventKey Event = new InputEventKey(); Event.Scancode = Scancode; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEBUTTON): case (TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton(); Event.ButtonIndex = (int)ButtonValue; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion(); Event.Axis = (int)ControllerButtonValue; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton(); Event.SetButtonIndex((int)ControllerButtonValue); InputMap.ActionAddEvent(KeyName, Event); break; } } if (NewBind.FuncWithArg != null) { BindingsWithArg.Add(NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); } return(true); }
public override bool DeleteBinding(ScriptValue name) { //https://tc39.github.io/ecma262/#sec-object-environment-records-deletebinding-n return(BindingObject.Delete(name)); }
public bool Equals(BindingObject Other) { return(Name == Other.Name); }
public void TestStringMethod () { var targetObj = new BindingObject (); var stringResult = targetObj.StringMethod (); Assert.IsNotNull (stringResult); Assert.AreEqual ("return of string method.", stringResult); }