This commit is contained in:
syuilo 2018-03-07 17:48:32 +09:00
parent 6c495268ae
commit 161fd4afab
37 changed files with 747 additions and 219 deletions

View file

@ -1,21 +1,53 @@
<template>
<div>
<div class="mk-othello">
<div v-if="game">
<x-game :game="game"/>
</div>
<div v-if="matching">
<div class="matching" v-else-if="matching">
<h1><b>{{ matching.name }}</b>を待っています<mk-ellipsis/></h1>
<div class="cancel">
<el-button round @click="cancel">キャンセル</el-button>
</div>
</div>
<div v-else>
<h1>Misskey Othello</h1>
<p>他のMisskeyユーザーとオセロで対戦しよう</p>
<button>フリーマッチ(準備中)</button>
<button @click="match">指名</button>
<section>
<h2>対局の招待があります:</h2>
<div class="index" v-else>
<h1>Misskey %fa:circle%thell%fa:circle R%</h1>
<p>他のMisskeyユーザーとオセロで対戦しよう</p>
<div class="play">
<el-button round>フリーマッチ(準備中)</el-button>
<el-button type="primary" round @click="match">指名</el-button>
<details>
<summary>遊び方</summary>
<div>
<p>オセロは相手と交互に石をボードに置いてゆき相手の石を挟んでひっくり返しながら最終的に残った石が多い方が勝ちというボードゲームです</p>
<dl>
<dt><b>フリーマッチ</b></dt>
<dd>ランダムなユーザーと対戦するモードです</dd>
<dt><b>指名</b></dt>
<dd>指定したユーザーと対戦するモードです</dd>
</dl>
</div>
</details>
</div>
<section v-if="invitations.length > 0">
<h2>対局の招待があります:</h2>
<div class="invitation" v-for="i in invitations" tabindex="-1" @click="accept(i)">
<img :src="`${i.parent.avatar_url}?thumbnail&size=32`" alt="">
<span class="name"><b>{{ i.parent.name }}</b></span>
<span class="username">@{{ i.parent.username }}</span>
<mk-time :time="i.created_at"/>
</div>
</section>
<section v-if="myGames.length > 0">
<h2>自分の対局</h2>
<div class="game" v-for="g in myGames" tabindex="-1" @click="game = g">
<img :src="`${g.black_user.avatar_url}?thumbnail&size=32`" alt="">
<img :src="`${g.white_user.avatar_url}?thumbnail&size=32`" alt="">
<span><b>{{ g.black_user.name }}</b> vs <b>{{ g.white_user.name }}</b></span>
<span class="state">{{ g.winner ? '終了' : '進行中' }}</span>
</div>
</section>
<section>
<h2>過去の対局</h2>
<h2>みんなの対局</h2>
</section>
</div>
</div>
@ -35,7 +67,8 @@ export default Vue.extend({
games: [],
gamesFetching: true,
gamesMoreFetching: false,
matching: false,
myGames: [],
matching: null,
invitations: [],
connection: null,
connectionId: null
@ -45,9 +78,15 @@ export default Vue.extend({
this.connection = (this as any).os.streams.othelloStream.getConnection();
this.connectionId = (this as any).os.streams.othelloStream.use();
this.connection.on('macthed', this.onMatched);
this.connection.on('matched', this.onMatched);
this.connection.on('invited', this.onInvited);
(this as any).api('othello/games', {
my: true
}).then(games => {
this.myGames = games;
});
(this as any).api('othello/games').then(games => {
this.games = games;
this.gamesFetching = false;
@ -58,9 +97,9 @@ export default Vue.extend({
});
},
beforeDestroy() {
this.connection.off('macthed', this.onMatched);
this.connection.off('matched', this.onMatched);
this.connection.off('invited', this.onInvited);
(this as any).streams.othelloStream.dispose(this.connectionId);
(this as any).os.streams.othelloStream.dispose(this.connectionId);
},
methods: {
match() {
@ -82,6 +121,19 @@ export default Vue.extend({
});
});
},
cancel() {
this.matching = null;
(this as any).api('othello/match/cancel');
},
accept(invitation) {
(this as any).api('othello/match', {
user_id: invitation.parent.id
}).then(game => {
if (game) {
this.game = game;
}
});
},
onMatched(game) {
this.game = game;
},
@ -92,3 +144,126 @@ export default Vue.extend({
});
</script>
<style lang="stylus" scoped>
@import '~const.styl'
.mk-othello
color #677f84
> .matching
> h1
margin 0
padding 24px
font-size 20px
text-align center
font-weight normal
> .cancel
margin 0 auto
padding 24px 0 0 0
max-width 200px
text-align center
border-top dashed 1px #c4cdd4
> .index
> h1
margin 0
padding 24px
font-size 24px
text-align center
font-weight normal
color #fff
background linear-gradient(to bottom, #8bca3e, #d6cf31)
& + p
margin 0
padding 12px
margin-bottom 12px
text-align center
font-size 14px
border-bottom solid 1px #d3d9dc
> .play
margin 0 auto
padding 0 16px
max-width 500px
text-align center
> details
margin 8px 0
> div
padding 16px
font-size 14px
text-align left
background #f5f5f5
border-radius 8px
> section
margin 0 auto
padding 0 16px 16px 16px
max-width 500px
border-top solid 1px #d3d9dc
> h2
margin 0
padding 16px 0 8px 0
font-size 16px
font-weight bold
.invitation
margin 8px 0
padding 8px
border solid 1px #e1e5e8
border-radius 6px
cursor pointer
*
pointer-events none
user-select none
&:focus
border-color $theme-color
&:hover
background #f5f5f5
&:active
background #eee
> img
vertical-align bottom
border-radius 100%
> span
margin 0 8px
line-height 32px
.game
margin 8px 0
padding 8px
border solid 1px #e1e5e8
border-radius 6px
cursor pointer
*
pointer-events none
user-select none
&:focus
border-color $theme-color
&:hover
background #f5f5f5
&:active
background #eee
> img
vertical-align bottom
border-radius 100%
> span
margin 0 8px
line-height 32px
</style>