- 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.
This commit is contained in:
Eugene Serb
2022-08-11 13:59:33 +03:00
parent d340a6e81d
commit 34e3db0d02
5 changed files with 65 additions and 43 deletions

View File

@@ -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');

View File

@@ -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();
}

View File

@@ -0,0 +1,9 @@
interface IPatternUnit {
startDelay: number;
duration: number;
weakMagnitude: number;
strongMagnitude: number;
}
export default IPatternUnit;

22
src/models/PatternUnit.ts Normal file
View File

@@ -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;