wip
This commit is contained in:
parent
58f4d5d790
commit
1259fabd7f
33
locales/index.d.ts
vendored
33
locales/index.d.ts
vendored
|
@ -2625,6 +2625,39 @@ export interface Locale {
|
|||
"description": string;
|
||||
};
|
||||
};
|
||||
"_reversi": {
|
||||
"reversi": string;
|
||||
"gameSettings": string;
|
||||
"chooseBoard": string;
|
||||
"blackOrWhite": string;
|
||||
"blackIs": string;
|
||||
"rules": string;
|
||||
"thisGameIsStartedSoon": string;
|
||||
"waitingForOther": string;
|
||||
"waitingForMe": string;
|
||||
"waitingBoth": string;
|
||||
"ready": string;
|
||||
"cancelReady": string;
|
||||
"opponentTurn": string;
|
||||
"myTurn": string;
|
||||
"turnOf": string;
|
||||
"pastTurnOf": string;
|
||||
"surrender": string;
|
||||
"surrendered": string;
|
||||
"drawn": string;
|
||||
"won": string;
|
||||
"black": string;
|
||||
"white": string;
|
||||
"total": string;
|
||||
"turnCount": string;
|
||||
"myGames": string;
|
||||
"allGames": string;
|
||||
"ended": string;
|
||||
"playing": string;
|
||||
"isLlotheo": string;
|
||||
"loopedMap": string;
|
||||
"canPutEverywhere": string;
|
||||
};
|
||||
}
|
||||
declare const locales: {
|
||||
[lang: string]: Locale;
|
||||
|
|
|
@ -2505,3 +2505,36 @@ _dataSaver:
|
|||
_code:
|
||||
title: "コードハイライト"
|
||||
description: "MFMなどでコードハイライト記法が使われている場合、タップするまで読み込まれなくなります。コードハイライトではハイライトする言語ごとにその定義ファイルを読み込む必要がありますが、それらが自動で読み込まれなくなるため、通信量の削減が見込めます。"
|
||||
|
||||
_reversi:
|
||||
reversi: "リバーシ"
|
||||
gameSettings: "対局の設定"
|
||||
chooseBoard: "ボードを選択"
|
||||
blackOrWhite: "先行/後攻"
|
||||
blackIs: "{name}が黒(先行)"
|
||||
rules: "ルール"
|
||||
thisGameIsStartedSoon: "対局はまもなく開始されます"
|
||||
waitingForOther: "相手の準備が完了するのを待っています"
|
||||
waitingForMe: "あなたの準備が完了するのを待っています"
|
||||
waitingBoth: "準備してください"
|
||||
ready: "準備完了"
|
||||
cancelReady: "準備を再開"
|
||||
opponentTurn: "相手のターンです"
|
||||
myTurn: "あなたのターンです"
|
||||
turnOf: "{name}のターンです"
|
||||
pastTurnOf: "{name}のターン"
|
||||
surrender: "投了"
|
||||
surrendered: "投了により"
|
||||
drawn: "引き分け"
|
||||
won: "{name}の勝ち"
|
||||
black: "黒"
|
||||
white: "白"
|
||||
total: "合計"
|
||||
turnCount: "{count}ターン目"
|
||||
myGames: "自分の対局"
|
||||
allGames: "みんなの対局"
|
||||
ended: "終了"
|
||||
playing: "対局中"
|
||||
isLlotheo: "石の少ない方が勝ち(ロセオ)"
|
||||
loopedMap: "ループマップ"
|
||||
canPutEverywhere: "どこでも置けるモード"
|
||||
|
|
|
@ -162,7 +162,7 @@ export interface AdminEventTypes {
|
|||
|
||||
export interface ReversiEventTypes {
|
||||
matched: {
|
||||
game: Packed<'ReversiGame'>;
|
||||
game: Packed<'ReversiGameDetailed'>;
|
||||
};
|
||||
invited: {
|
||||
game: Packed<'ReversiMatching'>;
|
||||
|
@ -180,18 +180,21 @@ export interface ReversiGameEventTypes {
|
|||
key: string;
|
||||
value: any;
|
||||
};
|
||||
putStone: {
|
||||
pos: number;
|
||||
};
|
||||
putStone: {
|
||||
at: Date;
|
||||
color: boolean;
|
||||
pos: number;
|
||||
next: boolean;
|
||||
};
|
||||
syncState: {
|
||||
crc32: string;
|
||||
};
|
||||
started: {
|
||||
game: Packed<'ReversiGame'>;
|
||||
game: Packed<'ReversiGameDetailed'>;
|
||||
};
|
||||
ended: {
|
||||
winnerId: MiUser['id'] | null;
|
||||
game: Packed<'ReversiGame'>;
|
||||
game: Packed<'ReversiGameDetailed'>;
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
|
|
|
@ -86,7 +86,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
|
|||
isLlotheo: false,
|
||||
}).then(x => this.reversiGamesRepository.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
const packed = await this.reversiGameEntityService.pack(game, { id: exist.parentId });
|
||||
const packed = await this.reversiGameEntityService.packDetail(game, { id: exist.parentId });
|
||||
this.globalEventService.publishReversiStream(exist.parentId, 'matched', { game: packed });
|
||||
|
||||
return game;
|
||||
|
@ -202,13 +202,13 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
|
|||
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'ended', {
|
||||
winnerId: winner,
|
||||
game: await this.reversiGameEntityService.pack(game.id, user),
|
||||
game: await this.reversiGameEntityService.packDetail(game.id, user),
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'started', {
|
||||
game: await this.reversiGameEntityService.pack(game.id, user),
|
||||
game: await this.reversiGameEntityService.packDetail(game.id, user),
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
|
@ -288,14 +288,14 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
|
|||
logs: game.logs,
|
||||
});
|
||||
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'set', Object.assign(log, {
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'putStone', Object.assign(log, {
|
||||
next: o.turn,
|
||||
}));
|
||||
|
||||
if (o.isEnded) {
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'ended', {
|
||||
winnerId: winner,
|
||||
game: await this.reversiGameEntityService.pack(game.id, user),
|
||||
game: await this.reversiGameEntityService.packDetail(game.id, user),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
|
|||
|
||||
this.globalEventService.publishReversiGameStream(game.id, 'ended', {
|
||||
winnerId: winnerId,
|
||||
game: await this.reversiGameEntityService.pack(game.id, user),
|
||||
game: await this.reversiGameEntityService.packDetail(game.id, user),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -27,14 +27,10 @@ export class ReversiGameEntityService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
public async packDetail(
|
||||
src: MiReversiGame['id'] | MiReversiGame,
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean;
|
||||
skipHide?: boolean;
|
||||
},
|
||||
): Promise<Packed<'ReversiGame'>> {
|
||||
): Promise<Packed<'ReversiGameDetailed'>> {
|
||||
const game = typeof src === 'object' ? src : await this.reversiGamesRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return await awaitAll({
|
||||
|
@ -59,23 +55,61 @@ export class ReversiGameEntityService {
|
|||
isLlotheo: game.isLlotheo,
|
||||
canPutEverywhere: game.canPutEverywhere,
|
||||
loopedBoard: game.loopedBoard,
|
||||
...(options?.detail ? {
|
||||
logs: game.logs.map(log => ({
|
||||
at: log.at.toISOString(),
|
||||
color: log.color,
|
||||
pos: log.pos,
|
||||
})),
|
||||
map: game.map,
|
||||
} : {}),
|
||||
logs: game.logs.map(log => ({
|
||||
at: log.at.toISOString(),
|
||||
color: log.color,
|
||||
pos: log.pos,
|
||||
})),
|
||||
map: game.map,
|
||||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packMany(
|
||||
public packDetailMany(
|
||||
xs: MiReversiGame[],
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
) {
|
||||
return Promise.all(xs.map(x => this.pack(x, me)));
|
||||
return Promise.all(xs.map(x => this.packDetail(x, me)));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packLite(
|
||||
src: MiReversiGame['id'] | MiReversiGame,
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
): Promise<Packed<'ReversiGameLite'>> {
|
||||
const game = typeof src === 'object' ? src : await this.reversiGamesRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return await awaitAll({
|
||||
id: game.id,
|
||||
createdAt: this.idService.parse(game.id).date.toISOString(),
|
||||
startedAt: game.startedAt && game.startedAt.toISOString(),
|
||||
isStarted: game.isStarted,
|
||||
isEnded: game.isEnded,
|
||||
form1: game.form1,
|
||||
form2: game.form2,
|
||||
user1Accepted: game.user1Accepted,
|
||||
user2Accepted: game.user2Accepted,
|
||||
user1Id: game.user1Id,
|
||||
user2Id: game.user2Id,
|
||||
user1: this.userEntityService.pack(game.user1Id, me),
|
||||
user2: this.userEntityService.pack(game.user2Id, me),
|
||||
winnerId: game.winnerId,
|
||||
winner: game.winnerId ? this.userEntityService.pack(game.winnerId, me) : null,
|
||||
surrendered: game.surrendered,
|
||||
black: game.black,
|
||||
bw: game.bw,
|
||||
isLlotheo: game.isLlotheo,
|
||||
canPutEverywhere: game.canPutEverywhere,
|
||||
loopedBoard: game.loopedBoard,
|
||||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packLiteMany(
|
||||
xs: MiReversiGame[],
|
||||
me?: { id: MiUser['id'] } | null | undefined,
|
||||
) {
|
||||
return Promise.all(xs.map(x => this.packLite(x, me)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
|
|||
import { packedSigninSchema } from '@/models/json-schema/signin.js';
|
||||
import { packedRoleLiteSchema, packedRoleSchema } from '@/models/json-schema/role.js';
|
||||
import { packedAdSchema } from '@/models/json-schema/ad.js';
|
||||
import { packedReversiGameSchema } from '@/models/json-schema/reversi-game.js';
|
||||
import { packedReversiGameLiteSchema, packedReversiGameDetailedSchema } from '@/models/json-schema/reversi-game.js';
|
||||
import { packedReversiMatchingSchema } from '@/models/json-schema/reversi-matching.js';
|
||||
|
||||
export const refs = {
|
||||
|
@ -80,7 +80,8 @@ export const refs = {
|
|||
Signin: packedSigninSchema,
|
||||
RoleLite: packedRoleLiteSchema,
|
||||
Role: packedRoleSchema,
|
||||
ReversiGame: packedReversiGameSchema,
|
||||
ReversiGameLite: packedReversiGameLiteSchema,
|
||||
ReversiGameDetailed: packedReversiGameDetailedSchema,
|
||||
ReversiMatching: packedReversiMatchingSchema,
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,107 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export const packedReversiGameSchema = {
|
||||
export const packedReversiGameLiteSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'date-time',
|
||||
},
|
||||
startedAt: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
format: 'date-time',
|
||||
},
|
||||
isStarted: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
isEnded: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
form1: {
|
||||
type: 'any',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
form2: {
|
||||
type: 'any',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
user1Accepted: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
user2Accepted: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
user1Id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
user2Id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
user1: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'User',
|
||||
},
|
||||
user2: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'User',
|
||||
},
|
||||
winnerId: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
format: 'id',
|
||||
},
|
||||
winner: {
|
||||
type: 'object',
|
||||
optional: false, nullable: true,
|
||||
ref: 'User',
|
||||
},
|
||||
surrendered: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
format: 'id',
|
||||
},
|
||||
black: {
|
||||
type: 'number',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
bw: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
isLlotheo: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
canPutEverywhere: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
loopedBoard: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const packedReversiGameDetailedSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
|
@ -102,10 +202,10 @@ export const packedReversiGameSchema = {
|
|||
},
|
||||
logs: {
|
||||
type: 'array',
|
||||
optional: true, nullable: false,
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'object',
|
||||
optional: true, nullable: false,
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
at: {
|
||||
type: 'string',
|
||||
|
@ -125,7 +225,7 @@ export const packedReversiGameSchema = {
|
|||
},
|
||||
map: {
|
||||
type: 'array',
|
||||
optional: true, nullable: false,
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
|
|
|
@ -17,7 +17,7 @@ export const meta = {
|
|||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
items: { ref: 'ReversiGame' },
|
||||
items: { ref: 'ReversiGameLite' },
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
@ -55,7 +55,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
const games = await query.take(ps.limit).getMany();
|
||||
|
||||
return await this.reversiGameEntityService.packMany(games, me);
|
||||
return await this.reversiGameEntityService.packLiteMany(games, me);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
if (game == null) return;
|
||||
|
||||
return await this.reversiGameEntityService.pack(game, me);
|
||||
return await this.reversiGameEntityService.packDetail(game, me);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ export const meta = {
|
|||
res: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'ReversiGame',
|
||||
ref: 'ReversiGameDetailed',
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
@ -48,7 +48,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.noSuchGame);
|
||||
}
|
||||
|
||||
return await this.reversiGameEntityService.pack(game, me);
|
||||
return await this.reversiGameEntityService.packDetail(game, me);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ class ReversiGameChannel extends Channel {
|
|||
if (!game.isStarted) return;
|
||||
|
||||
if (crc32.toString() !== game.crc32) {
|
||||
this.send('rescue', await this.reversiGameEntityService.pack(game, this.user));
|
||||
this.send('rescue', await this.reversiGameEntityService.packDetail(game, this.user));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
534
packages/frontend/src/pages/reversi/game.board.vue
Normal file
534
packages/frontend/src/pages/reversi/game.board.vue
Normal file
|
@ -0,0 +1,534 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div class="xqnhankfuuilcwvhgsopeqncafzsquya">
|
||||
<header><b><MkA :to="userPage(blackUser)"><MkUserName :user="blackUser"/></MkA></b>({{ i18n.ts._reversi.black }}) vs <b><MkA :to="userPage(whiteUser)"><MkUserName :user="whiteUser"/></MkA></b>({{ i18n.ts._reversi.white }})</header>
|
||||
|
||||
<div style="overflow: hidden; line-height: 28px;">
|
||||
<p v-if="!iAmPlayer && !game.isEnded" class="turn">
|
||||
<Mfm :key="'turn:' + turnUser().name" :text="$t('_reversi.turnOf', { name: turnUser().name })" :plain="true" :customEmojis="turnUser().emojis"/>
|
||||
<MkEllipsis/>
|
||||
</p>
|
||||
<p v-if="logPos != logs.length" class="turn">
|
||||
<Mfm :key="'past-turn-of:' + turnUser().name" :text="$t('_reversi.pastTurnOf', { name: turnUser().name })" :plain="true" :customEmojis="turnUser().emojis"/>
|
||||
</p>
|
||||
<p v-if="iAmPlayer && !game.isEnded && !isMyTurn()" class="turn1">{{ i18n.ts._reversi.opponentTurn }}<MkEllipsis/></p>
|
||||
<p v-if="iAmPlayer && !game.isEnded && isMyTurn()" class="turn2" style="animation: tada 1s linear infinite both;">{{ i18n.ts._reversi.myTurn }}</p>
|
||||
<p v-if="game.isEnded && logPos == logs.length" class="result">
|
||||
<template v-if="game.winner">
|
||||
<Mfm :key="'won'" :text="$t('_reversi.won', { name: game.winner.name })" :plain="true" :customEmojis="game.winner.emojis"/>
|
||||
<span v-if="game.surrendered != null"> ({{ i18n.ts._reversi.surrendered }})</span>
|
||||
</template>
|
||||
<template v-else>{{ i18n.ts._reversi.drawn }}</template>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="board">
|
||||
<div v-if="$store.state.gamesReversiShowBoardLabels" class="labels-x">
|
||||
<span v-for="i in game.map[0].length">{{ String.fromCharCode(64 + i) }}</span>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<div v-if="$store.state.gamesReversiShowBoardLabels" class="labels-y">
|
||||
<div v-for="i in game.map.length">{{ i }}</div>
|
||||
</div>
|
||||
<div class="cells" :style="cellsStyle">
|
||||
<div
|
||||
v-for="(stone, i) in o.board"
|
||||
:class="{ empty: stone == null, none: o.map[i] == 'null', isEnded: game.isEnded, myTurn: !game.isEnded && isMyTurn(), can: turnUser() ? o.canPut(turnUser().id == blackUser.id, i) : null, prev: o.prevPos == i }"
|
||||
:title="`${String.fromCharCode(65 + o.transformPosToXy(i)[0])}${o.transformPosToXy(i)[1] + 1}`"
|
||||
@click="set(i)"
|
||||
>
|
||||
<template v-if="$store.state.gamesReversiUseAvatarStones || true">
|
||||
<img v-if="stone === true" :src="blackUser.avatarUrl" alt="black">
|
||||
<img v-if="stone === false" :src="whiteUser.avatarUrl" alt="white">
|
||||
</template>
|
||||
<template v-else>
|
||||
<i v-if="stone === true" class="fas fa-circle"></i>
|
||||
<i v-if="stone === false" class="far fa-circle"></i>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="$store.state.gamesReversiShowBoardLabels" class="labels-y">
|
||||
<div v-for="i in game.map.length">{{ i }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="$store.state.gamesReversiShowBoardLabels" class="labels-x">
|
||||
<span v-for="i in game.map[0].length">{{ String.fromCharCode(64 + i) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="status"><b>{{ $t('_reversi.turnCount', { count: logPos }) }}</b> {{ i18n.ts._reversi.black }}:{{ o.blackCount }} {{ i18n.ts._reversi.white }}:{{ o.whiteCount }} {{ i18n.ts._reversi.total }}:{{ o.blackCount + o.whiteCount }}</p>
|
||||
|
||||
<div v-if="!game.isEnded && iAmPlayer" class="actions">
|
||||
<MkButton inline @click="surrender">{{ i18n.ts._reversi.surrender }}</MkButton>
|
||||
</div>
|
||||
|
||||
<div v-if="game.isEnded" class="player">
|
||||
<span>{{ logPos }} / {{ logs.length }}</span>
|
||||
<div v-if="!autoplaying" class="buttons">
|
||||
<MkButton inline :disabled="logPos == 0" @click="logPos = 0"><i class="fas fa-angle-double-left"></i></MkButton>
|
||||
<MkButton inline :disabled="logPos == 0" @click="logPos--"><i class="fas fa-angle-left"></i></MkButton>
|
||||
<MkButton inline :disabled="logPos == logs.length" @click="logPos++"><i class="fas fa-angle-right"></i></MkButton>
|
||||
<MkButton inline :disabled="logPos == logs.length" @click="logPos = logs.length"><i class="fas fa-angle-double-right"></i></MkButton>
|
||||
</div>
|
||||
<MkButton :disabled="autoplaying" style="margin: var(--margin) auto 0 auto;" @click="autoplay()"><i class="fas fa-play"></i></MkButton>
|
||||
</div>
|
||||
|
||||
<div class="info">
|
||||
<p v-if="game.isLlotheo">{{ i18n.ts._reversi.isLlotheo }}</p>
|
||||
<p v-if="game.loopedBoard">{{ i18n.ts._reversi.loopedMap }}</p>
|
||||
<p v-if="game.canPutEverywhere">{{ i18n.ts._reversi.canPutEverywhere }}</p>
|
||||
</div>
|
||||
|
||||
<div class="watchers">
|
||||
<MkAvatar v-for="user in watchers" :key="user.id" :user="user" class="avatar"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import * as CRC32 from 'crc-32';
|
||||
import Reversi, { Color } from '@/scripts/games/reversi/core';
|
||||
import { url } from '@/config';
|
||||
import MkButton from '@/components/ui/button.vue';
|
||||
import { userPage } from '@/filters/user';
|
||||
import * as os from '@/os';
|
||||
import * as sound from '@/scripts/sound';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkButton,
|
||||
},
|
||||
|
||||
props: {
|
||||
initGame: {
|
||||
type: Object,
|
||||
require: true,
|
||||
},
|
||||
connection: {
|
||||
type: Object,
|
||||
require: true,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
game: JSON.parse(JSON.stringify(this.initGame)),
|
||||
o: null as Reversi,
|
||||
logs: [],
|
||||
logPos: 0,
|
||||
watchers: [],
|
||||
pollingClock: null,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
iAmPlayer(): boolean {
|
||||
if (!this.$i) return false;
|
||||
return this.game.user1Id == this.$i.id || this.game.user2Id == this.$i.id;
|
||||
},
|
||||
|
||||
myColor(): Color {
|
||||
if (!this.iAmPlayer) return null;
|
||||
if (this.game.user1Id == this.$i.id && this.game.black == 1) return true;
|
||||
if (this.game.user2Id == this.$i.id && this.game.black == 2) return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
opColor(): Color {
|
||||
if (!this.iAmPlayer) return null;
|
||||
return this.myColor === true ? false : true;
|
||||
},
|
||||
|
||||
blackUser(): any {
|
||||
return this.game.black == 1 ? this.game.user1 : this.game.user2;
|
||||
},
|
||||
|
||||
whiteUser(): any {
|
||||
return this.game.black == 1 ? this.game.user2 : this.game.user1;
|
||||
},
|
||||
|
||||
cellsStyle(): any {
|
||||
return {
|
||||
'grid-template-rows': `repeat(${this.game.map.length}, 1fr)`,
|
||||
'grid-template-columns': `repeat(${this.game.map[0].length}, 1fr)`,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
logPos(v) {
|
||||
if (!this.game.isEnded) return;
|
||||
const o = new Reversi(this.game.map, {
|
||||
isLlotheo: this.game.isLlotheo,
|
||||
canPutEverywhere: this.game.canPutEverywhere,
|
||||
loopedBoard: this.game.loopedBoard,
|
||||
});
|
||||
for (const log of this.logs.slice(0, v)) {
|
||||
o.put(log.color, log.pos);
|
||||
}
|
||||
this.o = o;
|
||||
//this.$forceUpdate();
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
this.o = new Reversi(this.game.map, {
|
||||
isLlotheo: this.game.isLlotheo,
|
||||
canPutEverywhere: this.game.canPutEverywhere,
|
||||
loopedBoard: this.game.loopedBoard,
|
||||
});
|
||||
|
||||
for (const log of this.game.logs) {
|
||||
this.o.put(log.color, log.pos);
|
||||
}
|
||||
|
||||
this.logs = this.game.logs;
|
||||
this.logPos = this.logs.length;
|
||||
|
||||
// 通信を取りこぼしてもいいように定期的にポーリングさせる
|
||||
if (this.game.isStarted && !this.game.isEnded) {
|
||||
this.pollingClock = setInterval(() => {
|
||||
if (this.game.isEnded) return;
|
||||
const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join(''));
|
||||
this.connection.send('check', {
|
||||
crc32: crc32,
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.connection.on('set', this.onSet);
|
||||
this.connection.on('rescue', this.onRescue);
|
||||
this.connection.on('ended', this.onEnded);
|
||||
this.connection.on('watchers', this.onWatchers);
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.connection.off('set', this.onSet);
|
||||
this.connection.off('rescue', this.onRescue);
|
||||
this.connection.off('ended', this.onEnded);
|
||||
this.connection.off('watchers', this.onWatchers);
|
||||
|
||||
clearInterval(this.pollingClock);
|
||||
},
|
||||
|
||||
methods: {
|
||||
userPage,
|
||||
|
||||
// this.o がリアクティブになった折にはcomputedにできる
|
||||
turnUser(): any {
|
||||
if (this.o.turn === true) {
|
||||
return this.game.black == 1 ? this.game.user1 : this.game.user2;
|
||||
} else if (this.o.turn === false) {
|
||||
return this.game.black == 1 ? this.game.user2 : this.game.user1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
// this.o がリアクティブになった折にはcomputedにできる
|
||||
isMyTurn(): boolean {
|
||||
if (!this.iAmPlayer) return false;
|
||||
if (this.turnUser() == null) return false;
|
||||
return this.turnUser().id == this.$i.id;
|
||||
},
|
||||
|
||||
set(pos) {
|
||||
if (this.game.isEnded) return;
|
||||
if (!this.iAmPlayer) return;
|
||||
if (!this.isMyTurn()) return;
|
||||
if (!this.o.canPut(this.myColor, pos)) return;
|
||||
|
||||
this.o.put(this.myColor, pos);
|
||||
|
||||
// サウンドを再生する
|
||||
sound.play(this.myColor ? 'reversiPutBlack' : 'reversiPutWhite');
|
||||
|
||||
this.connection.send('set', {
|
||||
pos: pos,
|
||||
});
|
||||
|
||||
this.checkEnd();
|
||||
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
||||
onSet(x) {
|
||||
this.logs.push(x);
|
||||
this.logPos++;
|
||||
this.o.put(x.color, x.pos);
|
||||
this.checkEnd();
|
||||
this.$forceUpdate();
|
||||
|
||||
// サウンドを再生する
|
||||
if (x.color !== this.myColor) {
|
||||
sound.play(x.color ? 'reversiPutBlack' : 'reversiPutWhite');
|
||||
}
|
||||
},
|
||||
|
||||
onEnded(x) {
|
||||
this.game = JSON.parse(JSON.stringify(x.game));
|
||||
},
|
||||
|
||||
checkEnd() {
|
||||
this.game.isEnded = this.o.isEnded;
|
||||
if (this.game.isEnded) {
|
||||
if (this.o.winner === true) {
|
||||
this.game.winnerId = this.game.black == 1 ? this.game.user1Id : this.game.user2Id;
|
||||
this.game.winner = this.game.black == 1 ? this.game.user1 : this.game.user2;
|
||||
} else if (this.o.winner === false) {
|
||||
this.game.winnerId = this.game.black == 1 ? this.game.user2Id : this.game.user1Id;
|
||||
this.game.winner = this.game.black == 1 ? this.game.user2 : this.game.user1;
|
||||
} else {
|
||||
this.game.winnerId = null;
|
||||
this.game.winner = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 正しいゲーム情報が送られてきたとき
|
||||
onRescue(game) {
|
||||
this.game = JSON.parse(JSON.stringify(game));
|
||||
|
||||
this.o = new Reversi(this.game.map, {
|
||||
isLlotheo: this.game.isLlotheo,
|
||||
canPutEverywhere: this.game.canPutEverywhere,
|
||||
loopedBoard: this.game.loopedBoard,
|
||||
});
|
||||
|
||||
for (const log of this.game.logs) {
|
||||
this.o.put(log.color, log.pos, true);
|
||||
}
|
||||
|
||||
this.logs = this.game.logs;
|
||||
this.logPos = this.logs.length;
|
||||
|
||||
this.checkEnd();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
||||
onWatchers(users) {
|
||||
this.watchers = users;
|
||||
},
|
||||
|
||||
surrender() {
|
||||
os.api('games/reversi/games/surrender', {
|
||||
gameId: this.game.id,
|
||||
});
|
||||
},
|
||||
|
||||
autoplay() {
|
||||
this.autoplaying = true;
|
||||
this.logPos = 0;
|
||||
|
||||
setTimeout(() => {
|
||||
this.logPos = 1;
|
||||
|
||||
let i = 1;
|
||||
let previousLog = this.game.logs[0];
|
||||
const tick = () => {
|
||||
const log = this.game.logs[i];
|
||||
const time = new Date(log.at).getTime() - new Date(previousLog.at).getTime();
|
||||
setTimeout(() => {
|
||||
i++;
|
||||
this.logPos++;
|
||||
previousLog = log;
|
||||
|
||||
if (i < this.game.logs.length) {
|
||||
tick();
|
||||
} else {
|
||||
this.autoplaying = false;
|
||||
}
|
||||
}, time);
|
||||
};
|
||||
|
||||
tick();
|
||||
}, 1000);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@use "sass:math";
|
||||
|
||||
.xqnhankfuuilcwvhgsopeqncafzsquya {
|
||||
text-align: center;
|
||||
|
||||
> .go-index {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
width: 42px;
|
||||
height :42px;
|
||||
}
|
||||
|
||||
> header {
|
||||
padding: 8px;
|
||||
border-bottom: dashed 1px var(--divider);
|
||||
}
|
||||
|
||||
> .board {
|
||||
width: calc(100% - 16px);
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
|
||||
$label-size: 16px;
|
||||
$gap: 4px;
|
||||
|
||||
> .labels-x {
|
||||
height: $label-size;
|
||||
padding: 0 $label-size;
|
||||
display: flex;
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.8em;
|
||||
|
||||
&:first-child {
|
||||
margin-left: -(math.div($gap, 2));
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-right: -(math.div($gap, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .flex {
|
||||
display: flex;
|
||||
|
||||
> .labels-y {
|
||||
width: $label-size;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
|
||||
&:first-child {
|
||||
margin-top: -(math.div($gap, 2));
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: -(math.div($gap, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .cells {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-gap: $gap;
|
||||
|
||||
> div {
|
||||
background: transparent;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
|
||||
* {
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
&.empty {
|
||||
border: solid 2px var(--divider);
|
||||
}
|
||||
|
||||
&.empty.can {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
&.empty.myTurn {
|
||||
border-color: var(--divider);
|
||||
|
||||
&.can {
|
||||
border-color: var(--accent);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--accent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.prev {
|
||||
box-shadow: 0 0 0 4px var(--accent);
|
||||
}
|
||||
|
||||
&.isEnded {
|
||||
border-color: var(--divider);
|
||||
}
|
||||
|
||||
&.none {
|
||||
border-color: transparent !important;
|
||||
}
|
||||
|
||||
> svg, > img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .status {
|
||||
margin: 0;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
> .actions {
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
> .player {
|
||||
padding: 0 16px 32px 16px;
|
||||
margin: 0 auto;
|
||||
max-width: 500px;
|
||||
|
||||
> span {
|
||||
display: inline-block;
|
||||
margin: 0 8px;
|
||||
min-width: 70px;
|
||||
}
|
||||
|
||||
> .buttons {
|
||||
display: flex;
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .watchers {
|
||||
padding: 0 0 16px 0;
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
> .avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
185
packages/frontend/src/pages/reversi/game.setting.vue
Normal file
185
packages/frontend/src/pages/reversi/game.setting.vue
Normal file
|
@ -0,0 +1,185 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div class="urbixznjwwuukfsckrwzwsqzsxornqij">
|
||||
<header><b><MkUserName :user="game.user1"/></b> vs <b><MkUserName :user="game.user2"/></b></header>
|
||||
|
||||
<div>
|
||||
<p>{{ i18n.ts._reversi.gameSettings }}</p>
|
||||
|
||||
<div class="card map _panel">
|
||||
<header>
|
||||
<select v-model="mapName" :placeholder="i18n.ts._reversi.chooseBoard" @change="onMapChange">
|
||||
<option v-if="mapName == '-Custom-'" label="-Custom-" :value="mapName"/>
|
||||
<option :label="i18n.ts.random" :value="null"/>
|
||||
<optgroup v-for="c in mapCategories" :key="c" :label="c">
|
||||
<option v-for="m in Object.values(Reversi.maps).filter(m => m.category == c)" :key="m.name" :label="m.name" :value="m.name">{{ m.name }}</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<div v-if="game.map == null" class="random"><i class="ti ti-dice"></i></div>
|
||||
<div v-else class="board" :style="{ 'grid-template-rows': `repeat(${ game.map.length }, 1fr)`, 'grid-template-columns': `repeat(${ game.map[0].length }, 1fr)` }">
|
||||
<div v-for="(x, i) in game.map.join('')" :class="{ none: x == ' ' }" @click="onMapCellClick(i, x)">
|
||||
<i v-if="x === 'b'" class="ti ti-circle-filled"></i>
|
||||
<i v-if="x === 'w'" class="ti ti-circle"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card _panel">
|
||||
<header>
|
||||
<span>{{ i18n.ts._reversi.blackOrWhite }}</span>
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<MkRadio v-model="game.bw" value="random" @update:modelValue="updateSettings('bw')">{{ i18n.ts.random }}</MkRadio>
|
||||
<MkRadio v-model="game.bw" :value="'1'" @update:modelValue="updateSettings('bw')">
|
||||
<I18n :src="i18n.ts._reversi.blackIs" tag="span">
|
||||
<template #name>
|
||||
<b><MkUserName :user="game.user1"/></b>
|
||||
</template>
|
||||
</I18n>
|
||||
</MkRadio>
|
||||
<MkRadio v-model="game.bw" :value="'2'" @update:modelValue="updateSettings('bw')">
|
||||
<I18n :src="i18n.ts._reversi.blackIs" tag="span">
|
||||
<template #name>
|
||||
<b><MkUserName :user="game.user2"/></b>
|
||||
</template>
|
||||
</I18n>
|
||||
</MkRadio>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card _panel">
|
||||
<header>
|
||||
<span>{{ i18n.ts._reversi.rules }}</span>
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<MkSwitch v-model="game.isLlotheo" @update:modelValue="updateSettings('isLlotheo')">{{ i18n.ts._reversi.isLlotheo }}</MkSwitch>
|
||||
<MkSwitch v-model="game.loopedBoard" @update:modelValue="updateSettings('loopedBoard')">{{ i18n.ts._reversi.loopedMap }}</MkSwitch>
|
||||
<MkSwitch v-model="game.canPutEverywhere" @update:modelValue="updateSettings('canPutEverywhere')">{{ i18n.ts._reversi.canPutEverywhere }}</MkSwitch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="_acrylic">
|
||||
<p class="status">
|
||||
<template v-if="isAccepted && isOpAccepted">{{ i18n.ts._reversi.thisGameIsStartedSoon }}<MkEllipsis/></template>
|
||||
<template v-if="isAccepted && !isOpAccepted">{{ i18n.ts._reversi.waitingForOther }}<MkEllipsis/></template>
|
||||
<template v-if="!isAccepted && isOpAccepted">{{ i18n.ts._reversi.waitingForMe }}</template>
|
||||
<template v-if="!isAccepted && !isOpAccepted">{{ i18n.ts._reversi.waitingBoth }}<MkEllipsis/></template>
|
||||
</p>
|
||||
|
||||
<div class="actions">
|
||||
<MkButton inline @click="exit">{{ i18n.ts.cancel }}</MkButton>
|
||||
<MkButton v-if="!isAccepted" inline primary @click="accept">{{ i18n.ts._reversi.ready }}</MkButton>
|
||||
<MkButton v-if="isAccepted" inline primary @click="cancel">{{ i18n.ts._reversi.cancelReady }}</MkButton>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, watch, ref, onMounted, shallowRef, onUnmounted } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import * as Reversi from 'misskey-reversi';
|
||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||
import { useStream } from '@/stream.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { signinRequired } from '@/account.js';
|
||||
|
||||
const $i = signinRequired();
|
||||
|
||||
const mapCategories = Array.from(new Set(Object.values(Reversi.maps).map(x => x.category)));
|
||||
|
||||
const props = defineProps<{
|
||||
game: Misskey.entities.ReversiGameDetailed;
|
||||
connection: Misskey.ChannelConnection;
|
||||
}>();
|
||||
|
||||
const game = ref<Misskey.entities.ReversiGameDetailed>(props.game);
|
||||
const isLlotheo = ref<boolean>(false);
|
||||
const mapName = ref<string>(Reversi.maps.eighteight.name!);
|
||||
const isAccepted = computed(() => {
|
||||
if (game.value.user1Id === $i.id && game.value.user1Accepted) return true;
|
||||
if (game.value.user2Id === $i.id && game.value.user2Accepted) return true;
|
||||
return false;
|
||||
});
|
||||
const isOpAccepted = computed(() => {
|
||||
if (game.value.user1Id !== $i.id && game.value.user1Accepted) return true;
|
||||
if (game.value.user2Id !== $i.id && game.value.user2Accepted) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
function exit() {
|
||||
props.connection.send('exit', {});
|
||||
}
|
||||
|
||||
function accept() {
|
||||
props.connection.send('accept', {});
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
props.connection.send('cancelAccept', {});
|
||||
}
|
||||
|
||||
function onChangeAcceptingStates(acceptingStates) {
|
||||
game.value.user1Accepted = acceptingStates.user1;
|
||||
game.value.user2Accepted = acceptingStates.user2;
|
||||
}
|
||||
|
||||
function updateSettings(key: keyof Misskey.entities.ReversiGameDetailed) {
|
||||
props.connection.send('updateSettings', {
|
||||
key: key,
|
||||
value: game.value[key],
|
||||
});
|
||||
}
|
||||
|
||||
function onUpdateSettings({ key, value }: { key: keyof Misskey.entities.ReversiGameDetailed; value: any; }) {
|
||||
game.value[key] = value;
|
||||
if (game.value.map == null) {
|
||||
mapName.value = null;
|
||||
} else {
|
||||
const found = Object.values(Reversi.maps).find(x => x.data.join('') === game.value.map.join(''));
|
||||
mapName.value = found ? found.name! : '-Custom-';
|
||||
}
|
||||
}
|
||||
|
||||
function onMapChange() {
|
||||
if (mapName.value == null) {
|
||||
game.value.map = null;
|
||||
} else {
|
||||
game.value.map = Object.values(Reversi.maps).find(x => x.name === mapName.value)!.data;
|
||||
}
|
||||
updateSettings('map');
|
||||
}
|
||||
|
||||
function onMapCellClick(pos: number, pixel: string) {
|
||||
const x = pos % game.value.map[0].length;
|
||||
const y = Math.floor(pos / game.value.map[0].length);
|
||||
const newPixel =
|
||||
pixel === ' ' ? '-' :
|
||||
pixel === '-' ? 'b' :
|
||||
pixel === 'b' ? 'w' :
|
||||
' ';
|
||||
const line = game.value.map[y].split('');
|
||||
line[x] = newPixel;
|
||||
game.value.map[y] = line.join('');
|
||||
updateSettings('map');
|
||||
}
|
||||
|
||||
props.connection.on('changeAcceptingStates', onChangeAcceptingStates);
|
||||
props.connection.on('updateSettings', onUpdateSettings);
|
||||
|
||||
onUnmounted(() => {
|
||||
props.connection.off('changeAcceptingStates', onChangeAcceptingStates);
|
||||
props.connection.off('updateSettings', onUpdateSettings);
|
||||
});
|
||||
</script>
|
|
@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
-->
|
||||
|
||||
<template>
|
||||
<div v-if="game == null"><MkLoading/></div>
|
||||
<div v-if="game == null || connection == null"><MkLoading/></div>
|
||||
<GameSetting v-else-if="!game.isStarted" :initGame="game" :connection="connection"/>
|
||||
<GameBoard v-else :initGame="game" :connection="connection"/>
|
||||
</template>
|
||||
|
@ -22,7 +22,7 @@ const props = defineProps<{
|
|||
gameId: string;
|
||||
}>();
|
||||
|
||||
const game = shallowRef<Misskey.entities.ReversiGame | null>(null);
|
||||
const game = shallowRef<Misskey.entities.ReversiGameDetailed | null>(null);
|
||||
const connection = shallowRef<Misskey.ChannelConnection | null>(null);
|
||||
|
||||
watch(() => props.gameId, () => {
|
||||
|
|
284
packages/frontend/src/pages/reversi/index.vue
Normal file
284
packages/frontend/src/pages/reversi/index.vue
Normal file
|
@ -0,0 +1,284 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div v-if="!matching" class="bgvwxkhb">
|
||||
<h1>Misskey {{ i18n.ts._reversi.reversi }}</h1>
|
||||
|
||||
<div class="play">
|
||||
<MkButton primary round style="margin: var(--margin) auto 0 auto;" @click="match">{{ i18n.ts.invite }}</MkButton>
|
||||
</div>
|
||||
|
||||
<div class="_section">
|
||||
<MkFolder v-if="invitations.length > 0">
|
||||
<template #header>{{ i18n.ts.invitations }}</template>
|
||||
<div class="nfcacttm">
|
||||
<button v-for="invitation in invitations" class="invitation _panel _button" tabindex="-1" @click="accept(invitation)">
|
||||
<MkAvatar class="avatar" :user="invitation.parent" :showIndicator="true"/>
|
||||
<span class="name"><b><MkUserName :user="invitation.parent"/></b></span>
|
||||
<span class="username">@{{ invitation.parent.username }}</span>
|
||||
<MkTime :time="invitation.createdAt" class="time"/>
|
||||
</button>
|
||||
</div>
|
||||
</MkFolder>
|
||||
|
||||
<MkFolder v-if="myGames.length > 0">
|
||||
<template #header>{{ i18n.ts._reversi.myGames }}</template>
|
||||
<div class="knextgwz">
|
||||
<MkA v-for="g in myGames" :key="g.id" class="game _panel" tabindex="-1" :to="`/games/reversi/${g.id}`">
|
||||
<div class="players">
|
||||
<MkAvatar class="avatar" :user="g.user1"/><b><MkUserName :user="g.user1"/></b> vs <b><MkUserName :user="g.user2"/></b><MkAvatar class="avatar" :user="g.user2"/>
|
||||
</div>
|
||||
<footer><span class="state" :class="{ playing: !g.isEnded }">{{ g.isEnded ? i18n.ts._reversi.ended : i18n.ts._reversi.playing }}</span><MkTime class="time" :time="g.createdAt"/></footer>
|
||||
</MkA>
|
||||
</div>
|
||||
</MkFolder>
|
||||
|
||||
<MkFolder v-if="games.length > 0">
|
||||
<template #header>{{ i18n.ts._reversi.allGames }}</template>
|
||||
<div class="knextgwz">
|
||||
<MkA v-for="g in games" :key="g.id" class="game _panel" tabindex="-1" :to="`/games/reversi/${g.id}`">
|
||||
<div class="players">
|
||||
<MkAvatar class="avatar" :user="g.user1"/><b><MkUserName :user="g.user1"/></b> vs <b><MkUserName :user="g.user2"/></b><MkAvatar class="avatar" :user="g.user2"/>
|
||||
</div>
|
||||
<footer><span class="state" :class="{ playing: !g.isEnded }">{{ g.isEnded ? i18n.ts._reversi.ended : i18n.ts._reversi.playing }}</span><MkTime class="time" :time="g.createdAt"/></footer>
|
||||
</MkA>
|
||||
</div>
|
||||
</MkFolder>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="sazhgisb">
|
||||
<h1>
|
||||
<I18n :src="i18n.ts.waitingFor" tag="span">
|
||||
<template #x>
|
||||
<b><MkUserName :user="matching"/></b>
|
||||
</template>
|
||||
</I18n>
|
||||
<MkEllipsis/>
|
||||
</h1>
|
||||
<div class="cancel">
|
||||
<MkButton inline round @click="cancel">{{ i18n.ts.cancel }}</MkButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, markRaw } from 'vue';
|
||||
import * as os from '@/os';
|
||||
import MkButton from '@/components/ui/button.vue';
|
||||
import MkFolder from '@/components/ui/folder.vue';
|
||||
import * as symbols from '@/symbols';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkButton, MkFolder,
|
||||
},
|
||||
|
||||
inject: ['navHook'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
[symbols.PAGE_INFO]: {
|
||||
title: this.i18n.ts._reversi.reversi,
|
||||
icon: 'fas fa-gamepad',
|
||||
},
|
||||
games: [],
|
||||
gamesFetching: true,
|
||||
gamesMoreFetching: false,
|
||||
myGames: [],
|
||||
matching: null,
|
||||
invitations: [],
|
||||
connection: null,
|
||||
pingClock: null,
|
||||
};
|
||||
},
|
||||
|
||||
mounted() {
|
||||
if (this.$i) {
|
||||
this.connection = markRaw(os.stream.useChannel('gamesReversi'));
|
||||
|
||||
this.connection.on('invited', this.onInvited);
|
||||
|
||||
this.connection.on('matched', this.onMatched);
|
||||
|
||||
this.pingClock = setInterval(() => {
|
||||
if (this.matching) {
|
||||
this.connection.send('ping', {
|
||||
id: this.matching.id,
|
||||
});
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
os.api('games/reversi/games', {
|
||||
my: true,
|
||||
}).then(games => {
|
||||
this.myGames = games;
|
||||
});
|
||||
|
||||
os.api('games/reversi/invitations').then(invitations => {
|
||||
this.invitations = this.invitations.concat(invitations);
|
||||
});
|
||||
}
|
||||
|
||||
os.api('games/reversi/games').then(games => {
|
||||
this.games = games;
|
||||
this.gamesFetching = false;
|
||||
});
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
if (this.connection) {
|
||||
this.connection.dispose();
|
||||
clearInterval(this.pingClock);
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
go(game) {
|
||||
const url = '/games/reversi/' + game.id;
|
||||
if (this.navHook) {
|
||||
this.navHook(url);
|
||||
} else {
|
||||
this.$router.push(url);
|
||||
}
|
||||
},
|
||||
|
||||
async match() {
|
||||
const user = await os.selectUser({ local: true });
|
||||
if (user == null) return;
|
||||
os.api('games/reversi/match', {
|
||||
userId: user.id,
|
||||
}).then(res => {
|
||||
if (res == null) {
|
||||
this.matching = user;
|
||||
} else {
|
||||
this.go(res);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.matching = null;
|
||||
os.api('games/reversi/match/cancel');
|
||||
},
|
||||
|
||||
accept(invitation) {
|
||||
os.api('games/reversi/match', {
|
||||
userId: invitation.parent.id,
|
||||
}).then(game => {
|
||||
if (game) {
|
||||
this.go(game);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onMatched(game) {
|
||||
this.go(game);
|
||||
},
|
||||
|
||||
onInvited(invite) {
|
||||
this.invitations.unshift(invite);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.bgvwxkhb {
|
||||
> h1 {
|
||||
margin: 0;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
font-size: 1.5em;
|
||||
background: linear-gradient(0deg, #43c583, #438881);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
> .play {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.sazhgisb {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.nfcacttm {
|
||||
> .invitation {
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
padding: 16px;
|
||||
line-height: 32px;
|
||||
text-align: left;
|
||||
|
||||
> .avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
> .name {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
> .username {
|
||||
margin-right: 8px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
> .time {
|
||||
margin-left: auto;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.knextgwz {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
||||
grid-gap: var(--margin);
|
||||
|
||||
> .game {
|
||||
> .players {
|
||||
text-align: center;
|
||||
padding: 16px;
|
||||
line-height: 32px;
|
||||
|
||||
> .avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
||||
&:first-child {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-left: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> footer {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
border-top: solid 0.5px var(--divider);
|
||||
padding: 6px 8px;
|
||||
font-size: 0.9em;
|
||||
|
||||
> .state {
|
||||
&.playing {
|
||||
color: var(--accent);
|
||||
}
|
||||
}
|
||||
|
||||
> .time {
|
||||
margin-left: auto;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -1670,7 +1670,8 @@ declare namespace entities {
|
|||
Signin,
|
||||
RoleLite,
|
||||
Role,
|
||||
ReversiGame,
|
||||
ReversiGameLite,
|
||||
ReversiGameDetailed,
|
||||
ReversiMatching
|
||||
}
|
||||
}
|
||||
|
@ -2612,7 +2613,10 @@ type RetentionResponse = operations['retention']['responses']['200']['content'][
|
|||
type ReversiCancelMatchResponse = operations['reversi/cancel-match']['responses']['200']['content']['application/json'];
|
||||
|
||||
// @public (undocumented)
|
||||
type ReversiGame = components['schemas']['ReversiGame'];
|
||||
type ReversiGameDetailed = components['schemas']['ReversiGameDetailed'];
|
||||
|
||||
// @public (undocumented)
|
||||
type ReversiGameLite = components['schemas']['ReversiGameLite'];
|
||||
|
||||
// @public (undocumented)
|
||||
type ReversiGamesRequest = operations['reversi/games']['requestBody']['content']['application/json'];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* version: 2023.12.2
|
||||
* generatedAt: 2024-01-18T11:02:35.535Z
|
||||
* generatedAt: 2024-01-18T11:53:06.433Z
|
||||
*/
|
||||
|
||||
import type { SwitchCaseResponseType } from '../api.js';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* version: 2023.12.2
|
||||
* generatedAt: 2024-01-18T11:02:35.533Z
|
||||
* generatedAt: 2024-01-18T11:53:06.431Z
|
||||
*/
|
||||
|
||||
import type {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* version: 2023.12.2
|
||||
* generatedAt: 2024-01-18T11:02:35.532Z
|
||||
* generatedAt: 2024-01-18T11:53:06.430Z
|
||||
*/
|
||||
|
||||
import { operations } from './types.js';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* version: 2023.12.2
|
||||
* generatedAt: 2024-01-18T11:02:35.530Z
|
||||
* generatedAt: 2024-01-18T11:53:06.429Z
|
||||
*/
|
||||
|
||||
import { components } from './types.js';
|
||||
|
@ -41,5 +41,6 @@ export type Flash = components['schemas']['Flash'];
|
|||
export type Signin = components['schemas']['Signin'];
|
||||
export type RoleLite = components['schemas']['RoleLite'];
|
||||
export type Role = components['schemas']['Role'];
|
||||
export type ReversiGame = components['schemas']['ReversiGame'];
|
||||
export type ReversiGameLite = components['schemas']['ReversiGameLite'];
|
||||
export type ReversiGameDetailed = components['schemas']['ReversiGameDetailed'];
|
||||
export type ReversiMatching = components['schemas']['ReversiMatching'];
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/*
|
||||
* version: 2023.12.2
|
||||
* generatedAt: 2024-01-18T11:02:35.451Z
|
||||
* generatedAt: 2024-01-18T11:53:06.350Z
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -4458,7 +4458,7 @@ export type components = {
|
|||
};
|
||||
usersCount: number;
|
||||
});
|
||||
ReversiGame: {
|
||||
ReversiGameLite: {
|
||||
/** Format: id */
|
||||
id: string;
|
||||
/** Format: date-time */
|
||||
|
@ -4487,13 +4487,43 @@ export type components = {
|
|||
isLlotheo: boolean;
|
||||
canPutEverywhere: boolean;
|
||||
loopedBoard: boolean;
|
||||
logs?: {
|
||||
};
|
||||
ReversiGameDetailed: {
|
||||
/** Format: id */
|
||||
id: string;
|
||||
/** Format: date-time */
|
||||
createdAt: string;
|
||||
/** Format: date-time */
|
||||
startedAt: string | null;
|
||||
isStarted: boolean;
|
||||
isEnded: boolean;
|
||||
form1: Record<string, never> | null;
|
||||
form2: Record<string, never> | null;
|
||||
user1Accepted: boolean;
|
||||
user2Accepted: boolean;
|
||||
/** Format: id */
|
||||
user1Id: string;
|
||||
/** Format: id */
|
||||
user2Id: string;
|
||||
user1: components['schemas']['User'];
|
||||
user2: components['schemas']['User'];
|
||||
/** Format: id */
|
||||
winnerId: string | null;
|
||||
winner: components['schemas']['User'] | null;
|
||||
/** Format: id */
|
||||
surrendered: string | null;
|
||||
black: number | null;
|
||||
bw: string;
|
||||
isLlotheo: boolean;
|
||||
canPutEverywhere: boolean;
|
||||
loopedBoard: boolean;
|
||||
logs: {
|
||||
/** Format: date-time */
|
||||
at: string;
|
||||
color: boolean;
|
||||
pos: number;
|
||||
}[];
|
||||
map?: string[];
|
||||
map: string[];
|
||||
};
|
||||
ReversiMatching: {
|
||||
/** Format: id */
|
||||
|
@ -25716,7 +25746,7 @@ export type operations = {
|
|||
/** @description OK (with results) */
|
||||
200: {
|
||||
content: {
|
||||
'application/json': components['schemas']['ReversiGame'][];
|
||||
'application/json': components['schemas']['ReversiGameLite'][];
|
||||
};
|
||||
};
|
||||
/** @description Client error */
|
||||
|
@ -25878,7 +25908,7 @@ export type operations = {
|
|||
/** @description OK (with results) */
|
||||
200: {
|
||||
content: {
|
||||
'application/json': components['schemas']['ReversiGame'];
|
||||
'application/json': components['schemas']['ReversiGameDetailed'];
|
||||
};
|
||||
};
|
||||
/** @description Client error */
|
||||
|
|
Loading…
Reference in a new issue