123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- import { Observable } from "../Misc/observable.js";
- import { Gamepad } from "./gamepad.js";
- /**
- * Defines supported buttons for DualShock compatible gamepads
- */
- export var DualShockButton;
- (function (DualShockButton) {
- /** Cross */
- DualShockButton[DualShockButton["Cross"] = 0] = "Cross";
- /** Circle */
- DualShockButton[DualShockButton["Circle"] = 1] = "Circle";
- /** Square */
- DualShockButton[DualShockButton["Square"] = 2] = "Square";
- /** Triangle */
- DualShockButton[DualShockButton["Triangle"] = 3] = "Triangle";
- /** L1 */
- DualShockButton[DualShockButton["L1"] = 4] = "L1";
- /** R1 */
- DualShockButton[DualShockButton["R1"] = 5] = "R1";
- /** Share */
- DualShockButton[DualShockButton["Share"] = 8] = "Share";
- /** Options */
- DualShockButton[DualShockButton["Options"] = 9] = "Options";
- /** Left stick */
- DualShockButton[DualShockButton["LeftStick"] = 10] = "LeftStick";
- /** Right stick */
- DualShockButton[DualShockButton["RightStick"] = 11] = "RightStick";
- })(DualShockButton || (DualShockButton = {}));
- /** Defines values for DualShock DPad */
- export var DualShockDpad;
- (function (DualShockDpad) {
- /** Up */
- DualShockDpad[DualShockDpad["Up"] = 12] = "Up";
- /** Down */
- DualShockDpad[DualShockDpad["Down"] = 13] = "Down";
- /** Left */
- DualShockDpad[DualShockDpad["Left"] = 14] = "Left";
- /** Right */
- DualShockDpad[DualShockDpad["Right"] = 15] = "Right";
- })(DualShockDpad || (DualShockDpad = {}));
- /**
- * Defines a DualShock gamepad
- */
- export class DualShockPad extends Gamepad {
- /**
- * Creates a new DualShock gamepad object
- * @param id defines the id of this gamepad
- * @param index defines its index
- * @param gamepad defines the internal HTML gamepad object
- */
- constructor(id, index, gamepad) {
- super(id.replace("STANDARD GAMEPAD", "SONY PLAYSTATION DUALSHOCK"), index, gamepad, 0, 1, 2, 3);
- this._leftTrigger = 0;
- this._rightTrigger = 0;
- /** Observable raised when a button is pressed */
- this.onButtonDownObservable = new Observable();
- /** Observable raised when a button is released */
- this.onButtonUpObservable = new Observable();
- /** Observable raised when a pad is pressed */
- this.onPadDownObservable = new Observable();
- /** Observable raised when a pad is released */
- this.onPadUpObservable = new Observable();
- this._buttonCross = 0;
- this._buttonCircle = 0;
- this._buttonSquare = 0;
- this._buttonTriangle = 0;
- this._buttonShare = 0;
- this._buttonOptions = 0;
- this._buttonL1 = 0;
- this._buttonR1 = 0;
- this._buttonLeftStick = 0;
- this._buttonRightStick = 0;
- this._dPadUp = 0;
- this._dPadDown = 0;
- this._dPadLeft = 0;
- this._dPadRight = 0;
- this.type = Gamepad.DUALSHOCK;
- }
- /**
- * Defines the callback to call when left trigger is pressed
- * @param callback defines the callback to use
- */
- onlefttriggerchanged(callback) {
- this._onlefttriggerchanged = callback;
- }
- /**
- * Defines the callback to call when right trigger is pressed
- * @param callback defines the callback to use
- */
- onrighttriggerchanged(callback) {
- this._onrighttriggerchanged = callback;
- }
- /**
- * Gets the left trigger value
- */
- get leftTrigger() {
- return this._leftTrigger;
- }
- /**
- * Sets the left trigger value
- */
- set leftTrigger(newValue) {
- if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {
- this._onlefttriggerchanged(newValue);
- }
- this._leftTrigger = newValue;
- }
- /**
- * Gets the right trigger value
- */
- get rightTrigger() {
- return this._rightTrigger;
- }
- /**
- * Sets the right trigger value
- */
- set rightTrigger(newValue) {
- if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {
- this._onrighttriggerchanged(newValue);
- }
- this._rightTrigger = newValue;
- }
- /**
- * Defines the callback to call when a button is pressed
- * @param callback defines the callback to use
- */
- onbuttondown(callback) {
- this._onbuttondown = callback;
- }
- /**
- * Defines the callback to call when a button is released
- * @param callback defines the callback to use
- */
- onbuttonup(callback) {
- this._onbuttonup = callback;
- }
- /**
- * Defines the callback to call when a pad is pressed
- * @param callback defines the callback to use
- */
- ondpaddown(callback) {
- this._ondpaddown = callback;
- }
- /**
- * Defines the callback to call when a pad is released
- * @param callback defines the callback to use
- */
- ondpadup(callback) {
- this._ondpadup = callback;
- }
- _setButtonValue(newValue, currentValue, buttonType) {
- if (newValue !== currentValue) {
- if (newValue === 1) {
- if (this._onbuttondown) {
- this._onbuttondown(buttonType);
- }
- this.onButtonDownObservable.notifyObservers(buttonType);
- }
- if (newValue === 0) {
- if (this._onbuttonup) {
- this._onbuttonup(buttonType);
- }
- this.onButtonUpObservable.notifyObservers(buttonType);
- }
- }
- return newValue;
- }
- _setDPadValue(newValue, currentValue, buttonType) {
- if (newValue !== currentValue) {
- if (newValue === 1) {
- if (this._ondpaddown) {
- this._ondpaddown(buttonType);
- }
- this.onPadDownObservable.notifyObservers(buttonType);
- }
- if (newValue === 0) {
- if (this._ondpadup) {
- this._ondpadup(buttonType);
- }
- this.onPadUpObservable.notifyObservers(buttonType);
- }
- }
- return newValue;
- }
- /**
- * Gets the value of the `Cross` button
- */
- get buttonCross() {
- return this._buttonCross;
- }
- /**
- * Sets the value of the `Cross` button
- */
- set buttonCross(value) {
- this._buttonCross = this._setButtonValue(value, this._buttonCross, DualShockButton.Cross);
- }
- /**
- * Gets the value of the `Circle` button
- */
- get buttonCircle() {
- return this._buttonCircle;
- }
- /**
- * Sets the value of the `Circle` button
- */
- set buttonCircle(value) {
- this._buttonCircle = this._setButtonValue(value, this._buttonCircle, DualShockButton.Circle);
- }
- /**
- * Gets the value of the `Square` button
- */
- get buttonSquare() {
- return this._buttonSquare;
- }
- /**
- * Sets the value of the `Square` button
- */
- set buttonSquare(value) {
- this._buttonSquare = this._setButtonValue(value, this._buttonSquare, DualShockButton.Square);
- }
- /**
- * Gets the value of the `Triangle` button
- */
- get buttonTriangle() {
- return this._buttonTriangle;
- }
- /**
- * Sets the value of the `Triangle` button
- */
- set buttonTriangle(value) {
- this._buttonTriangle = this._setButtonValue(value, this._buttonTriangle, DualShockButton.Triangle);
- }
- /**
- * Gets the value of the `Options` button
- */
- get buttonOptions() {
- return this._buttonOptions;
- }
- /**
- * Sets the value of the `Options` button
- */
- set buttonOptions(value) {
- this._buttonOptions = this._setButtonValue(value, this._buttonOptions, DualShockButton.Options);
- }
- /**
- * Gets the value of the `Share` button
- */
- get buttonShare() {
- return this._buttonShare;
- }
- /**
- * Sets the value of the `Share` button
- */
- set buttonShare(value) {
- this._buttonShare = this._setButtonValue(value, this._buttonShare, DualShockButton.Share);
- }
- /**
- * Gets the value of the `L1` button
- */
- get buttonL1() {
- return this._buttonL1;
- }
- /**
- * Sets the value of the `L1` button
- */
- set buttonL1(value) {
- this._buttonL1 = this._setButtonValue(value, this._buttonL1, DualShockButton.L1);
- }
- /**
- * Gets the value of the `R1` button
- */
- get buttonR1() {
- return this._buttonR1;
- }
- /**
- * Sets the value of the `R1` button
- */
- set buttonR1(value) {
- this._buttonR1 = this._setButtonValue(value, this._buttonR1, DualShockButton.R1);
- }
- /**
- * Gets the value of the Left joystick
- */
- get buttonLeftStick() {
- return this._buttonLeftStick;
- }
- /**
- * Sets the value of the Left joystick
- */
- set buttonLeftStick(value) {
- this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, DualShockButton.LeftStick);
- }
- /**
- * Gets the value of the Right joystick
- */
- get buttonRightStick() {
- return this._buttonRightStick;
- }
- /**
- * Sets the value of the Right joystick
- */
- set buttonRightStick(value) {
- this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, DualShockButton.RightStick);
- }
- /**
- * Gets the value of D-pad up
- */
- get dPadUp() {
- return this._dPadUp;
- }
- /**
- * Sets the value of D-pad up
- */
- set dPadUp(value) {
- this._dPadUp = this._setDPadValue(value, this._dPadUp, DualShockDpad.Up);
- }
- /**
- * Gets the value of D-pad down
- */
- get dPadDown() {
- return this._dPadDown;
- }
- /**
- * Sets the value of D-pad down
- */
- set dPadDown(value) {
- this._dPadDown = this._setDPadValue(value, this._dPadDown, DualShockDpad.Down);
- }
- /**
- * Gets the value of D-pad left
- */
- get dPadLeft() {
- return this._dPadLeft;
- }
- /**
- * Sets the value of D-pad left
- */
- set dPadLeft(value) {
- this._dPadLeft = this._setDPadValue(value, this._dPadLeft, DualShockDpad.Left);
- }
- /**
- * Gets the value of D-pad right
- */
- get dPadRight() {
- return this._dPadRight;
- }
- /**
- * Sets the value of D-pad right
- */
- set dPadRight(value) {
- this._dPadRight = this._setDPadValue(value, this._dPadRight, DualShockDpad.Right);
- }
- /**
- * Force the gamepad to synchronize with device values
- */
- update() {
- super.update();
- this.buttonCross = this.browserGamepad.buttons[0].value;
- this.buttonCircle = this.browserGamepad.buttons[1].value;
- this.buttonSquare = this.browserGamepad.buttons[2].value;
- this.buttonTriangle = this.browserGamepad.buttons[3].value;
- this.buttonL1 = this.browserGamepad.buttons[4].value;
- this.buttonR1 = this.browserGamepad.buttons[5].value;
- this.leftTrigger = this.browserGamepad.buttons[6].value;
- this.rightTrigger = this.browserGamepad.buttons[7].value;
- this.buttonShare = this.browserGamepad.buttons[8].value;
- this.buttonOptions = this.browserGamepad.buttons[9].value;
- this.buttonLeftStick = this.browserGamepad.buttons[10].value;
- this.buttonRightStick = this.browserGamepad.buttons[11].value;
- this.dPadUp = this.browserGamepad.buttons[12].value;
- this.dPadDown = this.browserGamepad.buttons[13].value;
- this.dPadLeft = this.browserGamepad.buttons[14].value;
- this.dPadRight = this.browserGamepad.buttons[15].value;
- }
- /**
- * Disposes the gamepad
- */
- dispose() {
- super.dispose();
- this.onButtonDownObservable.clear();
- this.onButtonUpObservable.clear();
- this.onPadDownObservable.clear();
- this.onPadUpObservable.clear();
- }
- }
- //# sourceMappingURL=dualShockGamepad.js.map
|