From 34e3db0d021cf41a967c9324940dce3aebeb644e Mon Sep 17 00:00:00 2001 From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:59:33 +0300 Subject: [PATCH] - added interface IPatternUnit and his implementation PatternUnit. - deleted createPatternUnit-function in AppCustom and AppManual, used now class PatternUnit to create. - deleted consoles in AppManual. - updated dependencies. --- package-lock.json | 24 ++++++++++++------------ src/components/AppCustom.vue | 18 ++++++++---------- src/components/AppManual.vue | 35 ++++++++++++++--------------------- src/models/IPatternUnit.ts | 9 +++++++++ src/models/PatternUnit.ts | 22 ++++++++++++++++++++++ 5 files changed, 65 insertions(+), 43 deletions(-) create mode 100644 src/models/IPatternUnit.ts create mode 100644 src/models/PatternUnit.ts diff --git a/package-lock.json b/package-lock.json index fea7bde..78b4d3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2219,9 +2219,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.6.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", - "integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==", + "version": "18.7.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.1.tgz", + "integrity": "sha512-GKX1Qnqxo4S+Z/+Z8KKPLpH282LD7jLHWJcVryOflnsnH+BtSDfieR6ObwBMwpnNws0bUK8GI7z0unQf9bARNQ==", "dev": true }, "node_modules/@types/normalize-package-data": { @@ -5186,9 +5186,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.213", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.213.tgz", - "integrity": "sha512-+3DbGHGOCHTVB/Ms63bGqbyC1b8y7Fk86+7ltssB8NQrZtSCvZG6eooSl9U2Q0yw++fL2DpHKOdTU0NVEkFObg==", + "version": "1.4.215", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.215.tgz", + "integrity": "sha512-vqZxT8C5mlDZ//hQFhneHmOLnj1LhbzxV0+I1yqHV8SB1Oo4Y5Ne9+qQhwHl7O1s9s9cRuo2l5CoLEHdhMTwZg==", "dev": true }, "node_modules/emoji-regex": { @@ -13592,9 +13592,9 @@ "dev": true }, "@types/node": { - "version": "18.6.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", - "integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==", + "version": "18.7.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.1.tgz", + "integrity": "sha512-GKX1Qnqxo4S+Z/+Z8KKPLpH282LD7jLHWJcVryOflnsnH+BtSDfieR6ObwBMwpnNws0bUK8GI7z0unQf9bARNQ==", "dev": true }, "@types/normalize-package-data": { @@ -15802,9 +15802,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.4.213", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.213.tgz", - "integrity": "sha512-+3DbGHGOCHTVB/Ms63bGqbyC1b8y7Fk86+7ltssB8NQrZtSCvZG6eooSl9U2Q0yw++fL2DpHKOdTU0NVEkFObg==", + "version": "1.4.215", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.215.tgz", + "integrity": "sha512-vqZxT8C5mlDZ//hQFhneHmOLnj1LhbzxV0+I1yqHV8SB1Oo4Y5Ne9+qQhwHl7O1s9s9cRuo2l5CoLEHdhMTwZg==", "dev": true }, "emoji-regex": { diff --git a/src/components/AppCustom.vue b/src/components/AppCustom.vue index aaafb73..b2a81b9 100644 --- a/src/components/AppCustom.vue +++ b/src/components/AppCustom.vue @@ -37,6 +37,7 @@ import { defineComponent } from 'vue'; import store from '@/store/index'; import TPatternUnit from '@/models/TPatternUnit'; + import PatternUnit from '@/models/PatternUnit'; export default defineComponent({ name: 'AppCustom', @@ -49,17 +50,14 @@ }; }, methods: { - createPatternUnit: function (): TPatternUnit[] { - const patternUnit: TPatternUnit[] = [{ - startDelay: this.startDelay, - duration: this.duration, - weakMagnitude: this.weakMagnitude, - strongMagnitude: this.strongMagnitude, - }]; - return patternUnit as TPatternUnit[]; - }, start: function (): void { - store.dispatch('startCustom', this.createPatternUnit()); + const patterns: TPatternUnit[] = [new PatternUnit( + this.startDelay, + this.duration, + this.weakMagnitude, + this.strongMagnitude, + )]; + store.dispatch('startCustom', patterns); }, stop: function (): void { store.dispatch('reset'); diff --git a/src/components/AppManual.vue b/src/components/AppManual.vue index 74ad772..073dfc3 100644 --- a/src/components/AppManual.vue +++ b/src/components/AppManual.vue @@ -42,19 +42,20 @@ import store from '@/store/index'; import Vibrator from '@/models/Vibrator'; import TPatternUnit from '@/models/TPatternUnit'; + import PatternUnit from '@/models/PatternUnit'; export default defineComponent({ name: 'AppCustom', data: () => { return { - startDelay: 0 as number, - duration: 260 as number, - weakMagnitude: 0 as number, - strongMagnitude: 0 as number, timestamp: 0 as number, interval: 0 as number, mode: 0 as number, lock: false as boolean, + startDelay: 0 as number, + duration: 260 as number, + weakMagnitude: 0 as number, + strongMagnitude: 0 as number, }; }, computed: { @@ -68,17 +69,14 @@ }, }, methods: { - createPatternUnit: function (): TPatternUnit { - const patternUnit: TPatternUnit = { - startDelay: this.startDelay, - duration: this.duration, - weakMagnitude: this.weakMagnitude, - strongMagnitude: this.strongMagnitude, - }; - return patternUnit as TPatternUnit; - }, start: function (): void { - store.dispatch('startCustom', this.createPatternUnit()); + const pattern: TPatternUnit = new PatternUnit( + this.startDelay, + this.duration, + this.weakMagnitude, + this.strongMagnitude, + ); + store.dispatch('vibrate', pattern); }, stop: function (): void { store.dispatch('setIsActive', false); @@ -98,20 +96,16 @@ if (this.gamepads.length > 0) { if (this.gamepads[0].unit.buttons[1].pressed === true) { this.lock = !this.lock; - console.log('B', this.lock); } if (this.lock === false) { if (this.gamepads[0].unit.buttons[0].pressed === true) { this.mode = 0; - console.log('A', this.mode); } if (this.gamepads[0].unit.buttons[2].pressed === true) { this.mode = 1; - console.log('X', this.mode); } if (this.gamepads[0].unit.buttons[3].pressed === true) { this.mode = 2; - console.log('Y', this.mode); } } } @@ -137,9 +131,8 @@ handle: function (): void { if (this.gamepads.length > 0) { this.gamepads.forEach((gamepad) => { - if (gamepad.unit.buttons[7].value > 0 - || this.lock === true) { - gamepad.unit.vibrationActuator.playEffect('dual-rumble', this.createPatternUnit()); + if (gamepad.unit.buttons[7].value > 0 || this.lock === true) { + this.start(); } else { this.stop(); } diff --git a/src/models/IPatternUnit.ts b/src/models/IPatternUnit.ts new file mode 100644 index 0000000..663f794 --- /dev/null +++ b/src/models/IPatternUnit.ts @@ -0,0 +1,9 @@ +interface IPatternUnit { + startDelay: number; + duration: number; + weakMagnitude: number; + strongMagnitude: number; +} + +export default IPatternUnit; + diff --git a/src/models/PatternUnit.ts b/src/models/PatternUnit.ts new file mode 100644 index 0000000..c1825cd --- /dev/null +++ b/src/models/PatternUnit.ts @@ -0,0 +1,22 @@ +import IPatternUnit from "@/models/IPatternUnit"; + +class PatternUnit implements IPatternUnit { + + startDelay: number; + duration: number; + weakMagnitude: number; + strongMagnitude: number; + + constructor( + startDelay: number, duration: number, + weakMagnitude: number, strongMagnitude: number + ) { + this.startDelay = startDelay; + this.duration = duration; + this.weakMagnitude = weakMagnitude; + this.strongMagnitude = strongMagnitude; + } +} + +export default PatternUnit; +