Best JavaScript code snippet using wpt
webxr-test.js
Source:webxr-test.js
...1475 if (supportedButtons == null || supportedButtons.length < 1) {1476 return;1477 }1478 const supported_button_map = {};1479 this.gamepad_ = this._getEmptyGamepad();1480 for (let i = 0; i < supportedButtons.length; i++) {1481 const buttonType = supportedButtons[i].buttonType;1482 this.supported_buttons_.push(buttonType);1483 supported_button_map[buttonType] = supportedButtons[i];1484 }1485 // Let's start by building the button state in order of priority:1486 // Primary button is index 0.1487 this.gamepad_.buttons.push({1488 pressed: this.primary_input_pressed_,1489 touched: this.primary_input_pressed_,1490 value: this.primary_input_pressed_ ? 1.0 : 0.01491 });1492 // Now add the rest of our buttons1493 this._addGamepadButton(supported_button_map['grip']);1494 this._addGamepadButton(supported_button_map['touchpad']);1495 this._addGamepadButton(supported_button_map['thumbstick']);1496 this._addGamepadButton(supported_button_map['optional-button']);1497 this._addGamepadButton(supported_button_map['optional-thumbstick']);1498 // Finally, back-fill placeholder buttons/axes1499 for (let i = 0; i < this.gamepad_.buttons.length; i++) {1500 if (this.gamepad_.buttons[i] == null) {1501 this.gamepad_.buttons[i] = {1502 pressed: false,1503 touched: false,1504 value: 01505 };1506 }1507 }1508 for (let i=0; i < this.gamepad_.axes.length; i++) {1509 if (this.gamepad_.axes[i] == null) {1510 this.gamepad_.axes[i] = 0;1511 }1512 }1513 }1514 updateButtonState(buttonState) {1515 if (this.supported_buttons_.indexOf(buttonState.buttonType) == -1) {1516 throw new Error("Tried to update state on an unsupported button");1517 }1518 const buttonIndex = this._getButtonIndex(buttonState.buttonType);1519 const axesStartIndex = this._getAxesStartIndex(buttonState.buttonType);1520 if (buttonIndex == -1) {1521 throw new Error("Unknown Button Type!");1522 }1523 // is this a 'squeeze' button?1524 if (buttonIndex === this._getButtonIndex('grip')) {1525 // squeeze1526 if (buttonState.pressed) {1527 this.primary_squeeze_pressed_ = true;1528 } else if (this.gamepad_.buttons[buttonIndex].pressed) {1529 this.primary_squeeze_clicked_ = true;1530 this.primary_squeeze_pressed_ = false;1531 } else {1532 this.primary_squeeze_clicked_ = false;1533 this.primary_squeeze_pressed_ = false;1534 }1535 }1536 this.gamepad_.buttons[buttonIndex].pressed = buttonState.pressed;1537 this.gamepad_.buttons[buttonIndex].touched = buttonState.touched;1538 this.gamepad_.buttons[buttonIndex].value = buttonState.pressedValue;1539 if (axesStartIndex != -1) {1540 this.gamepad_.axes[axesStartIndex] = buttonState.xValue == null ? 0.0 : buttonState.xValue;1541 this.gamepad_.axes[axesStartIndex + 1] = buttonState.yValue == null ? 0.0 : buttonState.yValue;1542 }1543 }1544 // DOM Overlay Extensions1545 setOverlayPointerPosition(x, y) {1546 this.overlay_pointer_position_ = {x: x, y: y};1547 }1548 // Helpers for Mojom1549 _getInputSourceState() {1550 const input_state = {};1551 input_state.sourceId = this.source_id_;1552 input_state.isAuxiliary = false;1553 input_state.primaryInputPressed = this.primary_input_pressed_;1554 input_state.primaryInputClicked = this.primary_input_clicked_;1555 input_state.primarySqueezePressed = this.primary_squeeze_pressed_;1556 input_state.primarySqueezeClicked = this.primary_squeeze_clicked_;1557 // Setting the input source's "clicked" state should generate one "select"1558 // event. Reset the input value to prevent it from continuously generating1559 // events.1560 this.primary_input_clicked_ = false;1561 // Setting the input source's "clicked" state should generate one "squeeze"1562 // event. Reset the input value to prevent it from continuously generating1563 // events.1564 this.primary_squeeze_clicked_ = false;1565 input_state.mojoFromInput = this.mojo_from_input_;1566 input_state.gamepad = this.gamepad_;1567 input_state.emulatedPosition = this.emulated_position_;1568 if (this.desc_dirty_) {1569 const input_desc = {};1570 switch (this.target_ray_mode_) {1571 case 'gaze':1572 input_desc.targetRayMode = vrMojom.XRTargetRayMode.GAZING;1573 break;1574 case 'tracked-pointer':1575 input_desc.targetRayMode = vrMojom.XRTargetRayMode.POINTING;1576 break;1577 case 'screen':1578 input_desc.targetRayMode = vrMojom.XRTargetRayMode.TAPPING;1579 break;1580 default:1581 throw new Error('Unhandled target ray mode ' + this.target_ray_mode_);1582 }1583 switch (this.handedness_) {1584 case 'left':1585 input_desc.handedness = vrMojom.XRHandedness.LEFT;1586 break;1587 case 'right':1588 input_desc.handedness = vrMojom.XRHandedness.RIGHT;1589 break;1590 default:1591 input_desc.handedness = vrMojom.XRHandedness.NONE;1592 break;1593 }1594 // Mojo requires us to send the pointerOrigin as relative to the grip1595 // space. If we don't have a grip space, we'll just assume that there1596 // is a grip at identity. This allows tests to simulate controllers that1597 // are really just a pointer with no tracked grip, though we will end up1598 // exposing that grip space.1599 let mojo_from_input = XRMathHelper.identity();1600 switch (this.target_ray_mode_) {1601 case 'gaze':1602 case 'screen':1603 // For gaze and screen space, we won't have a mojo_from_input; however1604 // the "input" position is just the viewer, so use mojo_from_viewer.1605 mojo_from_input = this.pairedDevice_._getMojoFromViewer();1606 break;1607 case 'tracked-pointer':1608 // If we have a tracked grip position (e.g. mojo_from_input), then use1609 // that. If we don't, then we'll just set the pointer offset directly,1610 // using identity as set above.1611 if (this.mojo_from_input_) {1612 mojo_from_input = this.mojo_from_input_.matrix;1613 }1614 break;1615 default:1616 throw new Error('Unhandled target ray mode ' + this.target_ray_mode_);1617 }1618 // To convert mojo_from_pointer to input_from_pointer, we need:1619 // input_from_pointer = input_from_mojo * mojo_from_pointer1620 // Since we store mojo_from_input, we need to invert it here before1621 // multiplying.1622 let input_from_mojo = XRMathHelper.inverse(mojo_from_input);1623 input_desc.inputFromPointer = {};1624 input_desc.inputFromPointer.matrix =1625 XRMathHelper.mul4x4(input_from_mojo, this.mojo_from_pointer_.matrix);1626 input_desc.profiles = this.profiles_;1627 input_state.description = input_desc;1628 this.desc_dirty_ = false;1629 }1630 // Pointer data for DOM Overlay, set by setOverlayPointerPosition()1631 if (this.overlay_pointer_position_) {1632 input_state.overlayPointerPosition = this.overlay_pointer_position_;1633 this.overlay_pointer_position_ = null;1634 }1635 return input_state;1636 }1637 _getEmptyGamepad() {1638 // Mojo complains if some of the properties on Gamepad are null, so set1639 // everything to reasonable defaults that tests can override.1640 const gamepad = {1641 connected: true,1642 id: [],1643 timestamp: 0n,1644 axes: [],1645 buttons: [],1646 mapping: GamepadMapping.GamepadMappingStandard,1647 displayId: 0,1648 };1649 switch (this.handedness_) {1650 case 'left':1651 gamepad.hand = GamepadHand.GamepadHandLeft;...
Using AI Code Generation
1var wptouchpad = require('wptouchpad');2var gamepad = wptouchpad._getEmptyGamepad();3var wptouchpad = require('wptouchpad');4var gamepad = wptouchpad._getEmptyGamepad();5gamepad.buttons[0] = 1;6gamepad.buttons[1] = 1;7gamepad.buttons[2] = 1;8gamepad.buttons[3] = 1;9gamepad.buttons[4] = 1;10gamepad.buttons[5] = 1;11gamepad.buttons[6] = 1;12gamepad.buttons[7] = 1;13gamepad.buttons[8] = 1;14gamepad.buttons[9] = 1;15gamepad.buttons[10] = 1;16gamepad.buttons[11] = 1;17gamepad.buttons[12] = 1;18gamepad.buttons[13] = 1;19gamepad.buttons[14] = 1;20gamepad.buttons[15] = 1;21gamepad.axes[0] = 1;22gamepad.axes[1] = 1;23gamepad.axes[2] = 1;24gamepad.axes[3] = 1;25console.log(gamepad);26var wptouchpad = require('wptouchpad');27var gamepad = wptouchpad._getEmptyGamepad();28gamepad.buttons[0] = 1;29gamepad.buttons[1] = 1;30gamepad.buttons[2] = 1;31gamepad.buttons[3] = 1;32gamepad.buttons[4] = 1;33gamepad.buttons[5] = 1;34gamepad.buttons[6] = 1;35gamepad.buttons[7] = 1;36gamepad.buttons[8] = 1;37gamepad.buttons[9] = 1;38gamepad.buttons[10] = 1;39gamepad.buttons[11] = 1;40gamepad.buttons[12] = 1;41gamepad.buttons[13] = 1;42gamepad.buttons[14] = 1;43gamepad.buttons[15] = 1;
Using AI Code Generation
1var gamepad = _getEmptyGamepad();2gamepad.buttons = [0, 0, 0, 0];3gamepad.axes = [0, 0];4navigator.getGamepads = function() {return [gamepad];};5var gamepadEvent = new GamepadEvent('gamepadconnected', {gamepad: gamepad});6window.dispatchEvent(gamepadEvent);7import os8import sys9import subprocess10import shutil11import json12import re13import time14def run_command(args, cwd=None):15 print " ".join(args)16 p = subprocess.Popen(args, cwd=cwd)17 p.wait()18 raise Exception("Command failed")19def run_command_output(args, cwd=None):20 print " ".join(args)21 p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE)22 p.wait()23 raise Exception("Command failed")24 return p.stdout.read()25def build_wpt():26 run_command(["./wpt", "build", "--no-prompt"])27def run_wpt():28 output = run_command_output(["./wpt", "run", "--no-prompt", "--log-wptreport", "test.html"])29 return json.loads(output)30def run_wpt_server():31 run_command(["./wpt", "serve", "--no-prompt"])32def main():33 build_wpt()34 run_wpt_server()35 run_wpt()36 main()
Using AI Code Generation
1var g = _getEmptyGamepad();2console.log(g);3var g = _getEmptyGamepad();4console.log(g);5g.id = "Custom Gamepad";6g.connected = true;7g.mapping = "standard";
Using AI Code Generation
1var gamepad = new wptGamepad();2gamepad._getEmptyGamepad();3 > + },4> + _getEmptyGamepad: function() {5> + return this._emptyGamepad;6> + },7> + _getGamepad: function() { 8Attachment #8837030 - Flags: review?(jdm) → review+
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!!