From 8dc2f1f49d27b1b994ed2b872e4488211d836c23 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 19 Jan 2024 20:49:17 +0900 Subject: [PATCH] wip --- locales/index.d.ts | 2 + locales/ja-JP.yml | 2 + .../backend/src/core/GlobalEventService.ts | 1 + packages/backend/src/core/ReversiService.ts | 33 +++ packages/frontend/src/components/MkRadios.vue | 3 + .../frontend/src/pages/reversi/game.board.vue | 89 ++----- .../src/pages/reversi/game.setting.vue | 53 ++-- packages/frontend/src/pages/reversi/index.vue | 239 ++++++++---------- .../misskey-js/src/autogen/apiClientJSDoc.ts | 2 +- packages/misskey-js/src/autogen/endpoint.ts | 2 +- packages/misskey-js/src/autogen/entities.ts | 2 +- packages/misskey-js/src/autogen/models.ts | 2 +- packages/misskey-js/src/autogen/types.ts | 5 +- 13 files changed, 204 insertions(+), 231 deletions(-) diff --git a/locales/index.d.ts b/locales/index.d.ts index 06e52717d1..85e0c6b244 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -2665,6 +2665,8 @@ export interface Locale extends ILocale { "isLlotheo": string; "loopedMap": string; "canPutEverywhere": string; + "freeMatch": string; + "lookingForPlayer": string; }; } declare const locales: { diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 7efb400f34..6c8a453023 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2539,3 +2539,5 @@ _reversi: isLlotheo: "石の少ない方が勝ち(ロセオ)" loopedMap: "ループマップ" canPutEverywhere: "どこでも置けるモード" + freeMatch: "フリーマッチ" + lookingForPlayer: "対戦相手を探しています" diff --git a/packages/backend/src/core/GlobalEventService.ts b/packages/backend/src/core/GlobalEventService.ts index 96fae46729..11a8935be2 100644 --- a/packages/backend/src/core/GlobalEventService.ts +++ b/packages/backend/src/core/GlobalEventService.ts @@ -175,6 +175,7 @@ export interface ReversiGameEventTypes { user2: boolean; }; updateSettings: { + userId: MiUser['id']; key: string; value: any; }; diff --git a/packages/backend/src/core/ReversiService.ts b/packages/backend/src/core/ReversiService.ts index b030d6896e..cd990ba775 100644 --- a/packages/backend/src/core/ReversiService.ts +++ b/packages/backend/src/core/ReversiService.ts @@ -101,6 +101,38 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { @bindThis public async matchAnyUser(me: MiUser): Promise { + //#region まず自分宛ての招待を探す + const invitations = await this.redisClient.zrange( + `reversi:matchSpecific:${me.id}`, + Date.now() - MATCHING_TIMEOUT_MS, + '+inf', + 'BYSCORE'); + + if (invitations.length > 0) { + const invitorId = invitations[Math.floor(Math.random() * invitations.length)]; + await this.redisClient.zrem(`reversi:matchSpecific:${me.id}`, invitorId); + + const game = await this.reversiGamesRepository.insert({ + id: this.idService.gen(), + user1Id: invitorId, + user2Id: me.id, + user1Ready: false, + user2Ready: false, + isStarted: false, + isEnded: false, + logs: [], + map: Reversi.maps.eighteight.data, + bw: 'random', + isLlotheo: false, + }).then(x => this.reversiGamesRepository.findOneByOrFail(x.identifiers[0])); + + const packed = await this.reversiGameEntityService.packDetail(game, { id: invitorId }); + this.globalEventService.publishReversiStream(invitorId, 'matched', { game: packed }); + + return game; + } + //#endregion + const matchings = await this.redisClient.zrange( 'reversi:matchAny', Date.now() - MATCHING_TIMEOUT_MS, @@ -270,6 +302,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { }); this.globalEventService.publishReversiGameStream(game.id, 'updateSettings', { + userId: user.id, key: key, value: value, }); diff --git a/packages/frontend/src/components/MkRadios.vue b/packages/frontend/src/components/MkRadios.vue index d9178f3362..22e7ed1ef7 100644 --- a/packages/frontend/src/components/MkRadios.vue +++ b/packages/frontend/src/components/MkRadios.vue @@ -18,6 +18,9 @@ export default defineComponent({ watch(value, () => { context.emit('update:modelValue', value.value); }); + watch(() => props.modelValue, v => { + value.value = v; + }); if (!context.slots.default) return null; let options = context.slots.default(); const label = context.slots.label && context.slots.label(); diff --git a/packages/frontend/src/pages/reversi/game.board.vue b/packages/frontend/src/pages/reversi/game.board.vue index 71bad546a4..18fd74427c 100644 --- a/packages/frontend/src/pages/reversi/game.board.vue +++ b/packages/frontend/src/pages/reversi/game.board.vue @@ -5,26 +5,26 @@ SPDX-License-Identifier: AGPL-3.0-only @@ -191,7 +195,7 @@ if (game.value.isStarted && !game.value.isEnded) { props.connection.send('syncState', { crc32: crc32, }); - }, 3000, { immediate: false, afterMounted: true }); + }, 5000, { immediate: false, afterMounted: true }); } function putStone(pos) { @@ -422,40 +426,3 @@ $gap: 4px; } } - - diff --git a/packages/frontend/src/pages/reversi/game.setting.vue b/packages/frontend/src/pages/reversi/game.setting.vue index d118205b99..301a177de1 100644 --- a/packages/frontend/src/pages/reversi/game.setting.vue +++ b/packages/frontend/src/pages/reversi/game.setting.vue @@ -6,10 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only