mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-26 04:24:22 +02:00
* fix * navhookをbootに移動 * サーバーサイドのbootも分けるように * 埋め込みページかどうかの判定は最初の一回だけに * tooltipは出せるように * fix design * 埋め込み独自のtooltipを削除 * ロジックの分岐が多かったMkNoteDetailedを分離 * fix indent * プレビュー用iframeにフォーカスが当たるのを修正 * popupの制御を出す側で行うように * パラメータが逆になっていたのを修正 * Update MkEmbedCodeGenDialog.vue * fix * eliminate misskey-js lint warns * fix * add appropriate attributes to embed html * enhance: サーバーサイドのembed系をさらに分離 * enhance: embed routerを分離(route定義をboot時に変更できるようにする改修を含む) * type * lint * fix indent * server-side styleを完全に分離 * Revert "refactor: 画面サイズのしきい値をconstにまとめる" This reverts commit05ca36f400. * fix * revert all changes in base.pug * embedドメインをまとめた * embedドメインをまとめた * prevent calling contextmenu in embed page by stopping at the caller * fix import * fix import * improve directory structure * fix import * register timeline ui as a container * wa- * rename * wa- * Update EmMediaList.vue * Update EmMediaList.vue * Update EmMediaList.vue * Update EmMediaImage.vue * Update EmNote.vue * revert mkmedialist changes * 戻し漏れ * wip * tweak embed media ui * revert original media components * Update boot.embed.js * rename * wip * Update MkNote.vue * wip * Update MkSubNoteContent.vue * Update EmNote.vue * Update packages/frontend/src/router/definition.ts * Revert "Update packages/frontend/src/router/definition.ts" This reverts commit937ae44521. * refactor EmMediaImage * fix import * remove unused imports * Update router.ts * wip * Update boot.ts * wip * wip * wip * wip * Update EmNote.vue * Update EmNote.vue * Create EmA.vue * Create EmAvatar.vue * Update EmAvatar.vue * wip * wip * wip * Create EmImgWithBlurhash.vue * Update EmImgWithBlurhash.vue * Create EmPagination.vue * wip * Update boot.ts * wip * wip * wi@p * wip * wip * wiop * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update boot.ts * wip * Update MkMisskeyFlavoredMarkdown.ts * wip * wip * wip * wip * wip * Update post-message.ts * wip * Update EmNoteDetailed.vue * Update EmNoteDetailed.vue * Create instance.ts * Update EmNoteDetailed.vue * wip * Update EmNoteDetailed.vue * wip * wip * wip * Update pnpm-lock.yaml * wip * wip * wp * wip * Update ClientServerService.ts * wip * Update boot.ts * Update vite.config.local-dev.ts * Update vite.config.ts * Create index.html * wa- * wip * Update boot.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * Create EmLink.vue * Create EmMention.vue * Update EmMfm.ts * wip * wip * wip * wip * Update vite.config.ts * Update boot.ts * Update EmA.vue * うぃp * wip * wip * Create EmError.vue * wip * Update MkEmbedCodeGenDialog.vue * Update EmNote.vue * wip * wip * Update user-timeline.vue * Update check-spdx-license-id.yml * wip * wip * style(frontend-shared): lint fixes on build.js * fix(frontend-shared): include `*.{js,json}` files in js-built * wip * use alias * refactor * refactor * Update scroll.ts * refactor * refactor * refactor * wip * wip * wip * wip * Update roles.vue * Update branding.vue * wip * wip * wip * Update page.vue * wip * fix import * add missing css variables * 絵文字をtwemojiに変更 クライアントデフォルトにあわせるため * force empoll readonly * fix compiler error * fix broken imports * tweak button style * run api extractor * fix storybook theme preloads * fix storybook instance imports * Update preview.ts * Update preview.ts * Update preview.ts * Revert "Update preview.ts" This reverts commit12bab1c6fb. * Revert "Update preview.ts" This reverts commit5c0ce01dbd. * Revert "Update preview.ts" This reverts commitf4863524d7. * Revert "fix storybook instance imports" This reverts commited8eabb246. * Revert "wip" This reverts commitd3c1926519. * Revert "Update page.vue" This reverts commit27c7900b0c. * Revert "Update branding.vue" This reverts commitc08ccb65ba. * Revert "Update roles.vue" This reverts commit1488b67066. * Revert "wip" This reverts commitaab1c76981. * refactor: use common media proxy * fix imports * fix * fix: MediaProxyの初期化を保証する(storybook対策?) * enhance(frontend-embed): improve embedParams provide * fix(backend): MK_DEV_PREFER=backendのときにembed viteが読み込めないのを修正 * fix * embed-pageを共通化 * fix import * fix import * fix import * const.jsを共通化 (たぶんrevertしすぎた) * fix type error * fix duplicated import * fix lint * fix * コメントとして残す * sharedとembedをlint対象にする * lint * attempt to fix eslint (frontend-shared) * lint fixes --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: zyoshoka <107108195+zyoshoka@users.noreply.github.com>
354 lines
10 KiB
Vue
354 lines
10 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<MkSpacer v-if="!matchingAny && !matchingUser" :contentMax="600">
|
|
<div class="_gaps">
|
|
<div>
|
|
<img src="/client-assets/reversi/logo.png" style="display: block; max-width: 100%; max-height: 200px; margin: auto;"/>
|
|
</div>
|
|
|
|
<div class="_panel _gaps" style="padding: 16px;">
|
|
<div class="_buttonsCenter">
|
|
<MkButton primary gradate rounded @click="matchAny">{{ i18n.ts._reversi.freeMatch }}</MkButton>
|
|
<MkButton primary gradate rounded @click="matchUser">{{ i18n.ts.invite }}</MkButton>
|
|
</div>
|
|
<div style="font-size: 90%; opacity: 0.7; text-align: center;"><i class="ti ti-music"></i> {{ i18n.ts.soundWillBePlayed }}</div>
|
|
</div>
|
|
|
|
<MkFolder v-if="invitations.length > 0" :defaultOpen="true">
|
|
<template #label>{{ i18n.ts.invitations }}</template>
|
|
<div class="_gaps_s">
|
|
<button v-for="user in invitations" :key="user.id" v-panel :class="$style.invitation" class="_button" tabindex="-1" @click="accept(user)">
|
|
<MkAvatar style="width: 32px; height: 32px; margin-right: 8px;" :user="user" :showIndicator="true"/>
|
|
<span style="margin-right: 8px;"><b><MkUserName :user="user"/></b></span>
|
|
<span>@{{ user.username }}</span>
|
|
</button>
|
|
</div>
|
|
</MkFolder>
|
|
|
|
<MkFolder v-if="$i" :defaultOpen="true">
|
|
<template #label>{{ i18n.ts._reversi.myGames }}</template>
|
|
<MkPagination :pagination="myGamesPagination" :disableAutoLoad="true">
|
|
<template #default="{ items }">
|
|
<div :class="$style.gamePreviews">
|
|
<MkA v-for="g in items" :key="g.id" v-panel :class="[$style.gamePreview, !g.isStarted && !g.isEnded && $style.gamePreviewWaiting, g.isStarted && !g.isEnded && $style.gamePreviewActive]" tabindex="-1" :to="`/reversi/g/${g.id}`">
|
|
<div :class="$style.gamePreviewPlayers">
|
|
<span v-if="g.winnerId === g.user1Id" style="margin-right: 0.75em; color: var(--accent); font-weight: bold;"><i class="ti ti-trophy"></i></span>
|
|
<span v-if="g.winnerId === g.user2Id" style="margin-right: 0.75em; visibility: hidden;"><i class="ti ti-x"></i></span>
|
|
<MkAvatar :class="$style.gamePreviewPlayersAvatar" :user="g.user1"/>
|
|
<span style="margin: 0 1em;">vs</span>
|
|
<MkAvatar :class="$style.gamePreviewPlayersAvatar" :user="g.user2"/>
|
|
<span v-if="g.winnerId === g.user1Id" style="margin-left: 0.75em; visibility: hidden;"><i class="ti ti-x"></i></span>
|
|
<span v-if="g.winnerId === g.user2Id" style="margin-left: 0.75em; color: var(--accent); font-weight: bold;"><i class="ti ti-trophy"></i></span>
|
|
</div>
|
|
<div :class="$style.gamePreviewFooter">
|
|
<span v-if="g.isStarted && !g.isEnded" :class="$style.gamePreviewStatusActive">{{ i18n.ts._reversi.playing }}</span>
|
|
<span v-else-if="!g.isEnded" :class="$style.gamePreviewStatusWaiting"><MkEllipsis/></span>
|
|
<span v-else>{{ i18n.ts._reversi.ended }}</span>
|
|
<MkTime style="margin-left: auto; opacity: 0.7;" :time="g.createdAt"/>
|
|
</div>
|
|
</MkA>
|
|
</div>
|
|
</template>
|
|
</MkPagination>
|
|
</MkFolder>
|
|
|
|
<MkFolder :defaultOpen="true">
|
|
<template #label>{{ i18n.ts._reversi.allGames }}</template>
|
|
<MkPagination :pagination="gamesPagination" :disableAutoLoad="true">
|
|
<template #default="{ items }">
|
|
<div :class="$style.gamePreviews">
|
|
<MkA v-for="g in items" :key="g.id" v-panel :class="[$style.gamePreview, !g.isStarted && !g.isEnded && $style.gamePreviewWaiting, g.isStarted && !g.isEnded && $style.gamePreviewActive]" tabindex="-1" :to="`/reversi/g/${g.id}`">
|
|
<div :class="$style.gamePreviewPlayers">
|
|
<span v-if="g.winnerId === g.user1Id" style="margin-right: 0.75em; color: var(--accent); font-weight: bold;"><i class="ti ti-trophy"></i></span>
|
|
<span v-if="g.winnerId === g.user2Id" style="margin-right: 0.75em; visibility: hidden;"><i class="ti ti-x"></i></span>
|
|
<MkAvatar :class="$style.gamePreviewPlayersAvatar" :user="g.user1"/>
|
|
<span style="margin: 0 1em;">vs</span>
|
|
<MkAvatar :class="$style.gamePreviewPlayersAvatar" :user="g.user2"/>
|
|
<span v-if="g.winnerId === g.user1Id" style="margin-left: 0.75em; visibility: hidden;"><i class="ti ti-x"></i></span>
|
|
<span v-if="g.winnerId === g.user2Id" style="margin-left: 0.75em; color: var(--accent); font-weight: bold;"><i class="ti ti-trophy"></i></span>
|
|
</div>
|
|
<div :class="$style.gamePreviewFooter">
|
|
<span v-if="g.isStarted && !g.isEnded" :class="$style.gamePreviewStatusActive">{{ i18n.ts._reversi.playing }}</span>
|
|
<span v-else-if="!g.isEnded" :class="$style.gamePreviewStatusWaiting"><MkEllipsis/></span>
|
|
<span v-else>{{ i18n.ts._reversi.ended }}</span>
|
|
<MkTime style="margin-left: auto; opacity: 0.7;" :time="g.createdAt"/>
|
|
</div>
|
|
</MkA>
|
|
</div>
|
|
</template>
|
|
</MkPagination>
|
|
</MkFolder>
|
|
</div>
|
|
</MkSpacer>
|
|
<MkSpacer v-else :contentMax="600">
|
|
<div :class="$style.waitingScreen">
|
|
<div v-if="matchingUser" :class="$style.waitingScreenTitle">
|
|
<I18n :src="i18n.ts.waitingFor" tag="span">
|
|
<template #x>
|
|
<b><MkUserName :user="matchingUser"/></b>
|
|
</template>
|
|
</I18n>
|
|
<MkEllipsis/>
|
|
</div>
|
|
<div v-else :class="$style.waitingScreenTitle">
|
|
{{ i18n.ts._reversi.lookingForPlayer }}<MkEllipsis/>
|
|
</div>
|
|
<div class="cancel">
|
|
<MkButton inline rounded @click="cancelMatching">{{ i18n.ts.cancel }}</MkButton>
|
|
</div>
|
|
</div>
|
|
</MkSpacer>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { onDeactivated, onMounted, onUnmounted, ref } from 'vue';
|
|
import * as Misskey from 'misskey-js';
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
import { useStream } from '@/stream.js';
|
|
import MkButton from '@/components/MkButton.vue';
|
|
import MkFolder from '@/components/MkFolder.vue';
|
|
import { i18n } from '@/i18n.js';
|
|
import { $i } from '@/account.js';
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
import { useRouter } from '@/router/supplier.js';
|
|
import * as os from '@/os.js';
|
|
import { useInterval } from '@@/js/use-interval.js';
|
|
import { pleaseLogin } from '@/scripts/please-login.js';
|
|
import * as sound from '@/scripts/sound.js';
|
|
|
|
const myGamesPagination = {
|
|
endpoint: 'reversi/games' as const,
|
|
limit: 10,
|
|
params: {
|
|
my: true,
|
|
},
|
|
};
|
|
|
|
const gamesPagination = {
|
|
endpoint: 'reversi/games' as const,
|
|
limit: 10,
|
|
};
|
|
|
|
const router = useRouter();
|
|
|
|
if ($i) {
|
|
const connection = useStream().useChannel('reversi');
|
|
|
|
connection.on('matched', x => {
|
|
if (matchingUser.value != null || matchingAny.value) {
|
|
startGame(x.game);
|
|
}
|
|
});
|
|
|
|
connection.on('invited', invitation => {
|
|
if (invitations.value.some(x => x.id === invitation.user.id)) return;
|
|
invitations.value.unshift(invitation.user);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
connection.dispose();
|
|
});
|
|
}
|
|
|
|
const invitations = ref<Misskey.entities.UserLite[]>([]);
|
|
const matchingUser = ref<Misskey.entities.UserLite | null>(null);
|
|
const matchingAny = ref<boolean>(false);
|
|
const noIrregularRules = ref<boolean>(false);
|
|
|
|
function startGame(game: Misskey.entities.ReversiGameDetailed) {
|
|
matchingUser.value = null;
|
|
matchingAny.value = false;
|
|
|
|
sound.playUrl('/client-assets/reversi/matched.mp3', {
|
|
volume: 1,
|
|
playbackRate: 1,
|
|
});
|
|
|
|
router.push(`/reversi/g/${game.id}`);
|
|
}
|
|
|
|
async function matchHeatbeat() {
|
|
if (matchingUser.value) {
|
|
const res = await misskeyApi('reversi/match', {
|
|
userId: matchingUser.value.id,
|
|
});
|
|
|
|
if (res != null) {
|
|
startGame(res);
|
|
}
|
|
} else if (matchingAny.value) {
|
|
const res = await misskeyApi('reversi/match', {
|
|
userId: null,
|
|
noIrregularRules: noIrregularRules.value,
|
|
});
|
|
|
|
if (res != null) {
|
|
startGame(res);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function matchUser() {
|
|
pleaseLogin();
|
|
|
|
const user = await os.selectUser({ includeSelf: false, localOnly: true });
|
|
if (user == null) return;
|
|
|
|
matchingUser.value = user;
|
|
|
|
matchHeatbeat();
|
|
}
|
|
|
|
function matchAny(ev: MouseEvent) {
|
|
pleaseLogin();
|
|
|
|
os.popupMenu([{
|
|
text: i18n.ts._reversi.allowIrregularRules,
|
|
action: () => {
|
|
noIrregularRules.value = false;
|
|
matchingAny.value = true;
|
|
matchHeatbeat();
|
|
},
|
|
}, {
|
|
text: i18n.ts._reversi.disallowIrregularRules,
|
|
action: () => {
|
|
noIrregularRules.value = true;
|
|
matchingAny.value = true;
|
|
matchHeatbeat();
|
|
},
|
|
}], ev.currentTarget ?? ev.target);
|
|
}
|
|
|
|
function cancelMatching() {
|
|
if (matchingUser.value) {
|
|
misskeyApi('reversi/cancel-match', { userId: matchingUser.value.id });
|
|
matchingUser.value = null;
|
|
} else if (matchingAny.value) {
|
|
misskeyApi('reversi/cancel-match', { userId: null });
|
|
matchingAny.value = false;
|
|
}
|
|
}
|
|
|
|
async function accept(user) {
|
|
const game = await misskeyApi('reversi/match', {
|
|
userId: user.id,
|
|
});
|
|
if (game) {
|
|
startGame(game);
|
|
}
|
|
}
|
|
|
|
useInterval(matchHeatbeat, 1000 * 5, { immediate: false, afterMounted: true });
|
|
|
|
onMounted(() => {
|
|
misskeyApi('reversi/invitations').then(_invitations => {
|
|
invitations.value = _invitations;
|
|
});
|
|
|
|
window.addEventListener('beforeunload', cancelMatching);
|
|
});
|
|
|
|
onDeactivated(() => {
|
|
cancelMatching();
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
cancelMatching();
|
|
});
|
|
|
|
definePageMetadata(() => ({
|
|
title: 'Reversi',
|
|
icon: 'ti ti-device-gamepad',
|
|
}));
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
@keyframes blink {
|
|
0% { opacity: 1; }
|
|
50% { opacity: 0.2; }
|
|
}
|
|
|
|
.invitation {
|
|
display: flex;
|
|
box-sizing: border-box;
|
|
width: 100%;
|
|
padding: 16px;
|
|
line-height: 32px;
|
|
text-align: left;
|
|
}
|
|
|
|
.gamePreviews {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
|
grid-gap: var(--margin);
|
|
}
|
|
|
|
.gamePreview {
|
|
font-size: 90%;
|
|
border-radius: 8px;
|
|
overflow: clip;
|
|
}
|
|
|
|
.gamePreviewActive {
|
|
box-shadow: inset 0 0 8px 0px var(--accent);
|
|
}
|
|
|
|
.gamePreviewWaiting {
|
|
box-shadow: inset 0 0 8px 0px var(--warn);
|
|
}
|
|
|
|
.gamePreviewPlayers {
|
|
text-align: center;
|
|
padding: 16px;
|
|
line-height: 32px;
|
|
}
|
|
|
|
.gamePreviewPlayersAvatar {
|
|
width: 32px;
|
|
height: 32px;
|
|
|
|
&:first-child {
|
|
margin-right: 8px;
|
|
}
|
|
|
|
&:last-child {
|
|
margin-left: 8px;
|
|
}
|
|
}
|
|
|
|
.gamePreviewFooter {
|
|
display: flex;
|
|
align-items: baseline;
|
|
border-top: solid 0.5px var(--divider);
|
|
padding: 6px 10px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.gamePreviewStatusActive {
|
|
color: var(--accent);
|
|
font-weight: bold;
|
|
animation: blink 2s infinite;
|
|
}
|
|
|
|
.gamePreviewStatusWaiting {
|
|
color: var(--warn);
|
|
font-weight: bold;
|
|
animation: blink 2s infinite;
|
|
}
|
|
|
|
.waitingScreen {
|
|
text-align: center;
|
|
}
|
|
|
|
.waitingScreenTitle {
|
|
font-size: 1.5em;
|
|
margin-bottom: 16px;
|
|
margin-top: 32px;
|
|
}
|
|
</style>
|