2020-10-27 10:11:41 +01:00
|
|
|
<template>
|
|
|
|
<div class="bgvwxkhb" v-if="!matching">
|
2020-12-26 02:47:36 +01:00
|
|
|
<h1>Misskey {{ $ts._reversi.reversi }}</h1>
|
2020-10-27 10:11:41 +01:00
|
|
|
|
|
|
|
<div class="play">
|
2020-12-26 02:47:36 +01:00
|
|
|
<MkButton primary round @click="match" style="margin: var(--margin) auto 0 auto;">{{ $ts.invite }}</MkButton>
|
2020-10-27 10:11:41 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="_section">
|
|
|
|
<MkFolder v-if="invitations.length > 0">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #header>{{ $ts.invitations }}</template>
|
2020-10-27 10:11:41 +01:00
|
|
|
<div class="nfcacttm">
|
|
|
|
<button class="invitation _panel _button" v-for="invitation in invitations" tabindex="-1" @click="accept(invitation)">
|
2021-04-17 16:52:54 +02:00
|
|
|
<MkAvatar class="avatar" :user="invitation.parent" :show-indicator="true"/>
|
2020-10-27 10:11:41 +01:00
|
|
|
<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">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #header>{{ $ts._reversi.myGames }}</template>
|
2020-10-27 10:11:41 +01:00
|
|
|
<div class="knextgwz">
|
|
|
|
<MkA class="game _panel" v-for="g in myGames" tabindex="-1" :to="`/games/reversi/${g.id}`" :key="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>
|
2020-12-26 02:47:36 +01:00
|
|
|
<footer><span class="state" :class="{ playing: !g.isEnded }">{{ g.isEnded ? $ts._reversi.ended : $ts._reversi.playing }}</span><MkTime class="time" :time="g.createdAt"/></footer>
|
2020-10-27 10:11:41 +01:00
|
|
|
</MkA>
|
|
|
|
</div>
|
|
|
|
</MkFolder>
|
|
|
|
|
|
|
|
<MkFolder v-if="games.length > 0">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #header>{{ $ts._reversi.allGames }}</template>
|
2020-10-27 10:11:41 +01:00
|
|
|
<div class="knextgwz">
|
|
|
|
<MkA class="game _panel" v-for="g in games" tabindex="-1" :to="`/games/reversi/${g.id}`" :key="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>
|
2020-12-26 02:47:36 +01:00
|
|
|
<footer><span class="state" :class="{ playing: !g.isEnded }">{{ g.isEnded ? $ts._reversi.ended : $ts._reversi.playing }}</span><MkTime class="time" :time="g.createdAt"/></footer>
|
2020-10-27 10:11:41 +01:00
|
|
|
</MkA>
|
|
|
|
</div>
|
|
|
|
</MkFolder>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="sazhgisb" v-else>
|
|
|
|
<h1>
|
2020-12-26 02:47:36 +01:00
|
|
|
<I18n :src="$ts.waitingFor" tag="span">
|
2020-10-27 10:11:41 +01:00
|
|
|
<template #x>
|
|
|
|
<b><MkUserName :user="matching"/></b>
|
|
|
|
</template>
|
2020-12-26 02:01:32 +01:00
|
|
|
</I18n>
|
2020-10-27 10:11:41 +01:00
|
|
|
<MkEllipsis/>
|
|
|
|
</h1>
|
|
|
|
<div class="cancel">
|
2020-12-26 02:47:36 +01:00
|
|
|
<MkButton inline round @click="cancel">{{ $ts.cancel }}</MkButton>
|
2020-10-27 10:11:41 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-07-26 04:12:06 +02:00
|
|
|
import { defineComponent, markRaw } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkFolder from '@/components/ui/folder.vue';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-10-27 10:11:41 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkButton, MkFolder,
|
|
|
|
},
|
|
|
|
|
|
|
|
inject: ['navHook'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._reversi.reversi,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-gamepad'
|
2020-10-27 10:11:41 +01:00
|
|
|
},
|
|
|
|
games: [],
|
|
|
|
gamesFetching: true,
|
|
|
|
gamesMoreFetching: false,
|
|
|
|
myGames: [],
|
|
|
|
matching: null,
|
|
|
|
invitations: [],
|
|
|
|
connection: null,
|
|
|
|
pingClock: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2020-12-19 02:55:52 +01:00
|
|
|
if (this.$i) {
|
2021-07-26 04:12:06 +02:00
|
|
|
this.connection = markRaw(os.stream.useChannel('gamesReversi'));
|
2020-10-27 10:11:41 +01:00
|
|
|
|
|
|
|
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;
|
2021-04-10 05:40:50 +02:00
|
|
|
border-top: solid 0.5px var(--divider);
|
2020-10-27 10:11:41 +01:00
|
|
|
padding: 6px 8px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
|
|
|
> .state {
|
|
|
|
&.playing {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .time {
|
|
|
|
margin-left: auto;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|