Skip to content

Commit

Permalink
Merge pull request #56 from eugene-serb/dev
Browse files Browse the repository at this point in the history
Release 1.15.0
  • Loading branch information
eugene-serb authored Dec 24, 2023
2 parents f19c4e6 + eacbcc0 commit 424e2a7
Showing 13 changed files with 100 additions and 71 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wavelovers",
"version": "1.14.0",
"version": "1.15.0",
"description": "Wavelovers is a tool that can turn your gamepad into a vibration massager or simply a gamepad vibration and buttons test tool.",
"keywords": [
"wavelovers",
14 changes: 7 additions & 7 deletions public/sitemap-internal.xml
Original file line number Diff line number Diff line change
@@ -2,43 +2,43 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://wavelovers.ru/</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/custom</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/manual</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/diagnostic</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/faq</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/about</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://wavelovers.ru/donate</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
2 changes: 1 addition & 1 deletion public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://wavelovers.ru/sitemap-internal.xml</loc>
<lastmod>2023-12-24</lastmod>
<lastmod>2023-12-25</lastmod>
</sitemap>
</sitemapindex>
26 changes: 5 additions & 21 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
<script setup lang="ts">
import { defineComponent, onMounted, onUnmounted } from 'vue';
import { RouterView } from 'vue-router';
import { useLayouts } from '@/composables/useLayouts';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useLayouts } from '@/composables';
import { useGamepadsStore } from '@/store';
defineComponent({
name: 'App',
});
const { layout } = useLayouts();
const { addGamepad, deleteGamepad } = useGamepadsStore();
const { initialize, terminate } = useGamepadsStore();
/**
* Добавить слушатели событий.
*/
function addEventListeners(): void {
window.addEventListener('gamepadconnected', addGamepad);
window.addEventListener('gamepaddisconnected', deleteGamepad);
}
/**
* Убрать слушатели событий.
*/
function removeEventListeners(): void {
window.removeEventListener('gamepadconnected', addGamepad);
window.removeEventListener('gamepaddisconnected', deleteGamepad);
}
onMounted(() => addEventListeners());
onUnmounted(() => removeEventListeners());
onMounted(() => initialize());
onUnmounted(() => terminate());
</script>

<template>
2 changes: 1 addition & 1 deletion src/components/organisms/OCustom.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { defineComponent, ref } from 'vue';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useGamepadsStore } from '@/store';
defineComponent({
name: 'OCustom',
2 changes: 1 addition & 1 deletion src/components/organisms/ODiagnostic.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { defineComponent } from 'vue';
import { storeToRefs } from 'pinia';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useGamepadsStore } from '@/store';
import { MDiagnosticItem } from '@/components/molecules';
defineComponent({
2 changes: 1 addition & 1 deletion src/components/organisms/OManual.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { defineComponent, ref, onMounted, onUnmounted } from 'vue';
import { storeToRefs } from 'pinia';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useGamepadsStore } from '@/store';
import type { TVibrator } from '@/models';
2 changes: 1 addition & 1 deletion src/components/organisms/OPatterns.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { defineComponent } from 'vue';
import { storeToRefs } from 'pinia';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useGamepadsStore } from '@/store';
import { AMessage } from '@/components/atoms';
import { MPatternList } from '@/components/molecules';
1 change: 1 addition & 0 deletions src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useLayouts';
2 changes: 1 addition & 1 deletion src/layouts/LGamepad.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { defineComponent } from 'vue';
import { storeToRefs } from 'pinia';
import { useGamepadsStore } from '@/store/useGamepadsStore';
import { useGamepadsStore } from '@/store';
import { AMessage } from '@/components/atoms';
import { MHeader, MFooter, MToolsNav, MGamepadList } from '@/components/molecules';
1 change: 1 addition & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useGamepadsStore';
111 changes: 77 additions & 34 deletions src/store/useGamepadsStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { ref, computed } from 'vue';
import { defineStore } from 'pinia';
import { Vibrator } from '@/models';
import patterns from '@/assets/patterns.json';
@@ -27,21 +27,21 @@ export const useGamepadsStore = defineStore('gamepads', () => {
const timestamp = ref<number>(0);

/**
* Геймпады.
* Интервал.
*
* @description Просто массив с геймпадами. Нужен для того,
* чтобы на его основе получить обновлённый список геймпадов.
* @see gamepads
* @private
*/
const _gamepads = ref<TVibrator[]>([]);
const _interval = ref<number>(0);

/**
* Интервал.
* Геймпады.
*
* @description Просто массив с геймпадами. Нужен для того,
* чтобы на его основе получить обновлённый список геймпадов.
* @see gamepads
* @private
*/
const _interval = ref<number>(0);
const _gamepads = ref<TVibrator[]>([]);

/**
* Геймпады.
@@ -77,12 +77,47 @@ export const useGamepadsStore = defineStore('gamepads', () => {
}
}

/**
* Воспроизвести дорожку вибрации.
*
* @param pattern Дорожка шаблонов вибраций.
*/
function loop(pattern: GamepadEffectParameters[]): void {
_gamepads.value.forEach((gamepad) => gamepad.loop(pattern));
}

/**
* Запустить вибрацию.
*
* @param pattern Шаблон вибрации.
*/
function vibrate(pattern: GamepadEffectParameters): void {
_gamepads.value.forEach((gamepad) => gamepad.vibrate(pattern));
}

/**
* Отключить вибрацию.
*/
function reset(): void {
_gamepads.value.forEach((gamepad) => gamepad.reset());
}

/**
* Обновить временную метку.
*
* @private
*/
function _updateTimestamp(): void {
timestamp.value = Date.now();
}

/**
* Добавить геймпад.
*
* @private
* @param event Событие геймпада.
*/
function addGamepad(event: GamepadEvent): void {
function _addGamepad(event: GamepadEvent): void {
if (_gamepads.value.length >= 1) {
return;
}
@@ -93,59 +128,67 @@ export const useGamepadsStore = defineStore('gamepads', () => {
/**
* Удалить геймпад.
*
* @private
* @param event Событие геймпада.
*/
function deleteGamepad(event: GamepadEvent): void {
function _deleteGamepad(event: GamepadEvent): void {
_gamepads.value = _gamepads.value.filter((gamepad) => gamepad.device.id !== event.gamepad.id);
}

/**
* Воспроизвести дорожку вибрации.
* Добавить слушатели событий.
*
* @param pattern Дорожка шаблонов вибраций.
* @private
*/
function loop(pattern: GamepadEffectParameters[]): void {
_gamepads.value.forEach((gamepad) => gamepad.loop(pattern));
function _addEventListeners(): void {
window.addEventListener('gamepadconnected', _addGamepad);
window.addEventListener('gamepaddisconnected', _deleteGamepad);
}

/**
* Запустить вибрацию.
* Убрать слушатели событий.
*
* @param pattern Шаблон вибрации.
* @private
*/
function vibrate(pattern: GamepadEffectParameters): void {
_gamepads.value.forEach((gamepad) => gamepad.vibrate(pattern));
function _removeEventListeners(): void {
window.removeEventListener('gamepadconnected', _addGamepad);
window.removeEventListener('gamepaddisconnected', _deleteGamepad);
}

/**
* Отключить вибрацию.
* Запустить работу приложения.
*
* @description Запускает слушатели событий для добавления и удаления геймпадов,
* а также, их обновления.
*/
function reset(): void {
_gamepads.value.forEach((gamepad) => gamepad.reset());
function initialize() {
_addEventListeners();
_interval.value = window.setInterval(_updateTimestamp, 1);
}

/**
* Обновить временную метку.
* Завершить работу приложения.
*
* @description Удаляет слушатели событий для добавления и удаления геймпадов,
* а также, их обновления.
*/
function updateTimestamp(): void {
timestamp.value = Date.now();
function terminate() {
_removeEventListeners();
_interval.value = window.setInterval(_updateTimestamp, 1);
}

onMounted(() => (_interval.value = window.setInterval(updateTimestamp, 1)));
onUnmounted(() => clearInterval(_interval.value));

return {
loop,
reset,
change,
vibrate,
gamepads,
isActive,
patterns,
isActive,
timestamp,
addGamepad,
patternMode,
deleteGamepad,
loop,
change,
vibrate,
reset,
terminate,
initialize,
};
});

0 comments on commit 424e2a7

Please sign in to comment.