- made mixin ComputedGamepads.

- added mixin ComputedGamepads to AppDiagnostic.
- added mixin ComputedGamepads to AppManual.
- updated version.
This commit is contained in:
Eugene Serb 2022-08-28 14:17:14 +03:00
parent b2ad331909
commit 3c892aa372
4 changed files with 42 additions and 49 deletions

View File

@ -2,7 +2,7 @@
"name": "wavelovers",
"description": "Wavelovers. Use your device vibration correctly. Make a massager out of a gamepad.",
"keywords": [ "wavelovers", "gamepad-vibrator", "gamepad-test-tool", "gamepad-vibration-test-tool" ],
"version": "1.0.5",
"version": "1.0.6",
"license": "GNU GPL v3",
"homepage": "https://wavelovers.ru/",
"author": {

View File

@ -13,48 +13,21 @@
<script lang="ts">
import { defineComponent } from 'vue';
import store from '@/store/index';
import NavigationList from '@/components/NavigationList.vue';
import GamepadList from '@/components/GamepadList.vue';
import MessageItem from '@/components/MessageItem.vue';
import DiagnosticItem from '@/components/DiagnosticItem.vue';
import Vibrator from '@/models/Vibrator';
import ComputedGamepads from '@/mixins/ComputedGamepads.vue';
export default defineComponent({
name: 'AppDiagnostic',
mixins: [ComputedGamepads],
components: {
DiagnosticItem: DiagnosticItem,
NavigationList: NavigationList,
GamepadList: GamepadList,
MessageItem: MessageItem,
},
data: () => {
return {
timestamp: 0 as number,
interval: 0 as number,
};
},
computed: {
gamepads: function (): Vibrator[] {
const timestamp: number = this.timestamp;
const result: Vibrator[] = store.getters.gamepads as Vibrator[];
result.forEach((item) => {
item.interval = timestamp;
});
return result;
},
},
methods: {
updateComputed: function (): void {
this.timestamp = Date.now();
},
},
mounted() {
this.interval = setInterval(this.updateComputed, 1);
},
unmounted() {
clearInterval(this.interval);
},
});
</script>

View File

@ -47,12 +47,14 @@
import NavigationList from '@/components/NavigationList.vue';
import GamepadList from '@/components/GamepadList.vue';
import MessageItem from '@/components/MessageItem.vue';
import ComputedGamepads from '@/mixins/ComputedGamepads.vue';
import Vibrator from '@/models/Vibrator';
import TPatternUnit from '@/models/TPatternUnit';
import PatternUnit from '@/models/PatternUnit';
export default defineComponent({
name: 'AppCustom',
mixins: [ComputedGamepads],
components: {
NavigationList: NavigationList,
GamepadList: GamepadList,
@ -60,8 +62,6 @@
},
data: () => {
return {
timestamp: 0 as number,
interval: 0 as number,
mode: 0 as number,
lock: false as boolean,
startDelay: 0 as number,
@ -70,16 +70,6 @@
strongMagnitude: 0 as number,
};
},
computed: {
gamepads: function (): Vibrator[] {
const timestamp: number = this.timestamp;
const result: Vibrator[] = store.getters.gamepads as Vibrator[];
result.forEach((item) => {
item.interval = timestamp;
})
return result;
},
},
methods: {
start: function (): void {
const pattern: TPatternUnit = new PatternUnit(
@ -101,9 +91,6 @@
this.updatePattern();
this.handle();
},
updateComputed: function (): void {
this.timestamp = Date.now();
},
updateMode: function (): void {
if (this.gamepads.length > 0) {
if (this.gamepads[0].unit.buttons[1].pressed === true) {
@ -142,7 +129,7 @@
},
handle: function (): void {
if (this.gamepads.length > 0) {
this.gamepads.forEach((gamepad) => {
this.gamepads.forEach((gamepad: Vibrator) => {
if (gamepad.unit.buttons[7].value > 0 || this.lock === true) {
this.start();
} else {
@ -155,9 +142,6 @@
mounted() {
this.interval = setInterval(this.eventLoop, 250);
},
unmounted() {
clearInterval(this.interval);
},
});
</script>

View File

@ -0,0 +1,36 @@
<script lang="ts">
import { defineComponent } from 'vue';
import store from '@/store/index';
import Vibrator from '@/models/Vibrator';
export default defineComponent({
name: 'ComputedGamepads',
data: () => {
return {
timestamp: 0 as number,
interval: 0 as number,
};
},
computed: {
gamepads: function (): Vibrator[] {
const timestamp: number = this.timestamp;
const result: Vibrator[] = store.getters.gamepads as Vibrator[];
result.forEach((item) => {
item.interval = timestamp;
});
return result;
},
},
methods: {
updateComputed: function (): void {
this.timestamp = Date.now();
},
},
mounted() {
this.interval = setInterval(this.updateComputed, 1);
},
unmounted() {
clearInterval(this.interval);
},
});
</script>