Best JavaScript code snippet using wpt
webxr-test.js
Source:webxr-test.js
...1462 touched: this.primary_input_pressed_,1463 value: this.primary_input_pressed_ ? 1.0 : 0.01464 });1465 // Now add the rest of our buttons1466 this._addGamepadButton(supported_button_map['grip']);1467 this._addGamepadButton(supported_button_map['touchpad']);1468 this._addGamepadButton(supported_button_map['thumbstick']);1469 this._addGamepadButton(supported_button_map['optional-button']);1470 this._addGamepadButton(supported_button_map['optional-thumbstick']);1471 // Finally, back-fill placeholder buttons/axes1472 for (let i = 0; i < this.gamepad_.buttons.length; i++) {1473 if (this.gamepad_.buttons[i] == null) {1474 this.gamepad_.buttons[i] = {1475 pressed: false,1476 touched: false,1477 value: 01478 };1479 }1480 }1481 for (let i=0; i < this.gamepad_.axes.length; i++) {1482 if (this.gamepad_.axes[i] == null) {1483 this.gamepad_.axes[i] = 0;1484 }1485 }1486 }1487 updateButtonState(buttonState) {1488 if (this.supported_buttons_.indexOf(buttonState.buttonType) == -1) {1489 throw new Error("Tried to update state on an unsupported button");1490 }1491 const buttonIndex = this._getButtonIndex(buttonState.buttonType);1492 const axesStartIndex = this._getAxesStartIndex(buttonState.buttonType);1493 if (buttonIndex == -1) {1494 throw new Error("Unknown Button Type!");1495 }1496 // is this a 'squeeze' button?1497 if (buttonIndex === this._getButtonIndex('grip')) {1498 // squeeze1499 if (buttonState.pressed) {1500 this.primary_squeeze_pressed_ = true;1501 } else if (this.gamepad_.buttons[buttonIndex].pressed) {1502 this.primary_squeeze_clicked_ = true;1503 this.primary_squeeze_pressed_ = false;1504 } else {1505 this.primary_squeeze_clicked_ = false;1506 this.primary_squeeze_pressed_ = false;1507 }1508 }1509 this.gamepad_.buttons[buttonIndex].pressed = buttonState.pressed;1510 this.gamepad_.buttons[buttonIndex].touched = buttonState.touched;1511 this.gamepad_.buttons[buttonIndex].value = buttonState.pressedValue;1512 if (axesStartIndex != -1) {1513 this.gamepad_.axes[axesStartIndex] = buttonState.xValue == null ? 0.0 : buttonState.xValue;1514 this.gamepad_.axes[axesStartIndex + 1] = buttonState.yValue == null ? 0.0 : buttonState.yValue;1515 }1516 }1517 // DOM Overlay Extensions1518 setOverlayPointerPosition(x, y) {1519 this.overlay_pointer_position_ = {x: x, y: y};1520 }1521 // Helpers for Mojom1522 _getInputSourceState() {1523 const input_state = {};1524 input_state.sourceId = this.source_id_;1525 input_state.isAuxiliary = false;1526 input_state.primaryInputPressed = this.primary_input_pressed_;1527 input_state.primaryInputClicked = this.primary_input_clicked_;1528 input_state.primarySqueezePressed = this.primary_squeeze_pressed_;1529 input_state.primarySqueezeClicked = this.primary_squeeze_clicked_;1530 // Setting the input source's "clicked" state should generate one "select"1531 // event. Reset the input value to prevent it from continuously generating1532 // events.1533 this.primary_input_clicked_ = false;1534 // Setting the input source's "clicked" state should generate one "squeeze"1535 // event. Reset the input value to prevent it from continuously generating1536 // events.1537 this.primary_squeeze_clicked_ = false;1538 input_state.mojoFromInput = this.mojo_from_input_;1539 input_state.gamepad = this.gamepad_;1540 input_state.emulatedPosition = this.emulated_position_;1541 if (this.desc_dirty_) {1542 const input_desc = {};1543 switch (this.target_ray_mode_) {1544 case 'gaze':1545 input_desc.targetRayMode = vrMojom.XRTargetRayMode.GAZING;1546 break;1547 case 'tracked-pointer':1548 input_desc.targetRayMode = vrMojom.XRTargetRayMode.POINTING;1549 break;1550 case 'screen':1551 input_desc.targetRayMode = vrMojom.XRTargetRayMode.TAPPING;1552 break;1553 default:1554 throw new Error('Unhandled target ray mode ' + this.target_ray_mode_);1555 }1556 switch (this.handedness_) {1557 case 'left':1558 input_desc.handedness = vrMojom.XRHandedness.LEFT;1559 break;1560 case 'right':1561 input_desc.handedness = vrMojom.XRHandedness.RIGHT;1562 break;1563 default:1564 input_desc.handedness = vrMojom.XRHandedness.NONE;1565 break;1566 }1567 // Mojo requires us to send the pointerOrigin as relative to the grip1568 // space. If we don't have a grip space, we'll just assume that there1569 // is a grip at identity. This allows tests to simulate controllers that1570 // are really just a pointer with no tracked grip, though we will end up1571 // exposing that grip space.1572 let mojo_from_input = XRMathHelper.identity();1573 switch (this.target_ray_mode_) {1574 case 'gaze':1575 case 'screen':1576 // For gaze and screen space, we won't have a mojo_from_input; however1577 // the "input" position is just the viewer, so use mojo_from_viewer.1578 mojo_from_input = this.pairedDevice_._getMojoFromViewer();1579 break;1580 case 'tracked-pointer':1581 // If we have a tracked grip position (e.g. mojo_from_input), then use1582 // that. If we don't, then we'll just set the pointer offset directly,1583 // using identity as set above.1584 if (this.mojo_from_input_) {1585 mojo_from_input = this.mojo_from_input_.matrix;1586 }1587 break;1588 default:1589 throw new Error('Unhandled target ray mode ' + this.target_ray_mode_);1590 }1591 // To convert mojo_from_pointer to input_from_pointer, we need:1592 // input_from_pointer = input_from_mojo * mojo_from_pointer1593 // Since we store mojo_from_input, we need to invert it here before1594 // multiplying.1595 let input_from_mojo = XRMathHelper.inverse(mojo_from_input);1596 input_desc.inputFromPointer = {};1597 input_desc.inputFromPointer.matrix =1598 XRMathHelper.mul4x4(input_from_mojo, this.mojo_from_pointer_.matrix);1599 input_desc.profiles = this.profiles_;1600 input_state.description = input_desc;1601 this.desc_dirty_ = false;1602 }1603 // Pointer data for DOM Overlay, set by setOverlayPointerPosition()1604 if (this.overlay_pointer_position_) {1605 input_state.overlayPointerPosition = this.overlay_pointer_position_;1606 this.overlay_pointer_position_ = null;1607 }1608 return input_state;1609 }1610 _getEmptyGamepad() {1611 // Mojo complains if some of the properties on Gamepad are null, so set1612 // everything to reasonable defaults that tests can override.1613 const gamepad = {1614 connected: true,1615 id: [],1616 timestamp: 0n,1617 axes: [],1618 buttons: [],1619 mapping: GamepadMapping.GamepadMappingStandard,1620 displayId: 0,1621 };1622 switch (this.handedness_) {1623 case 'left':1624 gamepad.hand = GamepadHand.GamepadHandLeft;1625 break;1626 case 'right':1627 gamepad.hand = GamepadHand.GamepadHandRight;1628 break;1629 default:1630 gamepad.hand = GamepadHand.GamepadHandNone;1631 break;1632 }1633 return gamepad;1634 }1635 _addGamepadButton(buttonState) {1636 if (buttonState == null) {1637 return;1638 }1639 const buttonIndex = this._getButtonIndex(buttonState.buttonType);1640 const axesStartIndex = this._getAxesStartIndex(buttonState.buttonType);1641 if (buttonIndex == -1) {1642 throw new Error("Unknown Button Type!");1643 }1644 this.gamepad_.buttons[buttonIndex] = {1645 pressed: buttonState.pressed,1646 touched: buttonState.touched,1647 value: buttonState.pressedValue1648 };1649 // Add x/y value if supported....
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3wp._addGamepadButton(1, 1, 1, 1, 1);4var wptoolkit = require('wptoolkit');5var wp = new wptoolkit();6wp._addGamepadButton(1, 1, 1, 1, 1);7var wptoolkit = require('wptoolkit');8var wp = new wptoolkit();9wp._addGamepadButton(1, 1, 1, 1, 1);10var wptoolkit = require('wptoolkit');11var wp = new wptoolkit();12wp._addGamepadButton(1, 1, 1, 1, 1);13var wptoolkit = require('wptoolkit');14var wp = new wptoolkit();15wp._addGamepadButton(1, 1, 1, 1, 1);16var wptoolkit = require('wptoolkit');17var wp = new wptoolkit();18wp._addGamepadButton(1, 1, 1, 1, 1);19var wptoolkit = require('wptoolkit');20var wp = new wptoolkit();21wp._addGamepadButton(1, 1, 1, 1, 1);22var wptoolkit = require('wptoolkit');23var wp = new wptoolkit();24wp._addGamepadButton(1, 1, 1, 1,
Using AI Code Generation
1var wptpad = require('./wptpad.js');2var gamepad = new wptpad();3gamepad._addGamepadButton(0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0);4gamepad._addGamepadButton(0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);5gamepad._addGamepadButton(0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);6gamepad._addGamepadButton(0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);7gamepad._addGamepadButton(0, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);8gamepad._addGamepadButton(0, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);9gamepad._addGamepadButton(0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);10gamepad._addGamepadButton(0, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);11gamepad._addGamepadButton(0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);12gamepad._addGamepadButton(0, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);13gamepad._addGamepadButton(0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Using AI Code Generation
1function addGamepadButton() {2 var button = document.createElement('button');3 button.id = 'wptouch-button-1';4 button.className = 'wptouch-button';5 button.innerHTML = 'Button 1';6 var gamepad = document.getElementById('wptouch-gamepad');7 gamepad.appendChild(button);8}9 function addGamepadButton() {10 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');11 }12 function addGamepadButton() {13 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');14 }15 function addGamepadButton() {16 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');17 }18 function addGamepadButton() {19 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');20 }21 function addGamepadButton() {22 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');23 }24 function addGamepadButton() {25 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');26 }27 function addGamepadButton() {28 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');29 }30 function addGamepadButton() {31 window.webkit.messageHandlers.wptouch.postMessage('_addGamepadButton');32 }
Using AI Code Generation
1var wptouch = require ( 'wptouch' ) ; 2 var gamepad = wptouch . _addGamepadButton ( 'left' ) ; 3 var gamepad = wptouch . _addGamepadButton ( 'right' ) ; 4 var gamepad = wptouch . _addGamepadButton ( 'up' ) ; 5 var gamepad = wptouch . _addGamepadButton ( 'down' ) ;6var wptouch = require ( 'wptouch' ) ; 7 var gamepad = wptouch . _addGamepadButton ( 'left' ) ; 8 var gamepad = wptouch . _addGamepadButton ( 'right' ) ; 9 var gamepad = wptouch . _addGamepadButton ( 'up' ) ; 10 var gamepad = wptouch . _addGamepadButton ( 'down' ) ;11This is a simple module that allows you to use the wptouch library with node.js. It is based on the work done by Jochen Karrer (
Using AI Code Generation
1var button = new wptouch._addGamepadButton("button1", "Button1", "button1");2button.ontouchstart = function(e) {3 console.log("button1 pressed");4}5button.ontouchend = function(e) {6 console.log("button1 released");7}8button.ontouchmove = function(e) {9 console.log("button1 moved");10}11var button2 = new wptouch._addGamepadButton("button2", "Button2", "button2");12button2.ontouchstart = function(e) {13 console.log("button2 pressed");14}15button2.ontouchend = function(e) {16 console.log("button2 released");17}18button2.ontouchmove = function(e) {19 console.log("button2 moved");20}21var button3 = new wptouch._addGamepadButton("button3", "Button3", "button3");22button3.ontouchstart = function(e) {23 console.log("button3 pressed");24}25button3.ontouchend = function(e) {26 console.log("button3 released");27}28button3.ontouchmove = function(e) {29 console.log("button3 moved");30}31var button4 = new wptouch._addGamepadButton("button4", "Button4", "button4");32button4.ontouchstart = function(e) {33 console.log("button4 pressed");34}35button4.ontouchend = function(e) {36 console.log("button4 released");37}38button4.ontouchmove = function(e) {39 console.log("button4 moved");40}41var button5 = new wptouch._addGamepadButton("button5", "Button5", "button5");42button5.ontouchstart = function(e) {43 console.log("button5 pressed");44}45button5.ontouchend = function(e) {46 console.log("button5 released");47}48button5.ontouchmove = function(e) {49 console.log("button5 moved");50}51var button6 = new wptouch._addGamepadButton("button6", "Button6", "button6");52button6.ontouchstart = function(e) {53 console.log("button6 pressed");54}55button6.ontouchend = function(e) {56 console.log("button6 released");57}58button6.ontouchmove = function(e) {
Using AI Code Generation
1var success = _removeGamepadButton(buttonID);2var success = _setGamepadButtonName(buttonID, "button2");3var success = _setGamepadButtonAction(buttonID, "alert('button pressed')");4var success = _setGamepadButtonAction(buttonID, function() {5 alert('button pressed');6});7var success = _setGamepadButtonAction(buttonID, function() {8 alert('button pressed');9});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!