Sharkey/src/client/app/common/views/components/games/reversi/reversi.room.vue

347 lines
9.5 KiB
Vue
Raw Normal View History

2018-03-08 10:57:57 +02:00
<template>
2018-08-02 18:36:29 +03:00
<div class="urbixznjwwuukfsckrwzwsqzsxornqij">
2018-08-02 03:52:47 +03:00
<header><b>{{ game.user1 | userName }}</b> vs <b>{{ game.user2 | userName }}</b></header>
2018-03-08 10:57:57 +02:00
2018-03-11 00:07:17 +02:00
<div>
2018-08-02 01:36:25 +03:00
<p>%i18n:@settings-of-the-game%</p>
2018-03-11 00:07:17 +02:00
2018-08-02 18:36:29 +03:00
<div class="card map">
2018-08-02 16:54:52 +03:00
<header>
2018-08-02 18:36:29 +03:00
<select v-model="mapName" placeholder="%i18n:@choose-map%" @change="onMapChange">
<option label="-Custom-" :value="mapName" v-if="mapName == '-Custom-'"/>
<option label="%i18n:@random%" :value="null"/>
<optgroup v-for="c in mapCategories" :key="c" :label="c">
<option v-for="m in maps" v-if="m.category == c" :key="m.name" :label="m.name" :value="m.name">{{ m.name }}</option>
</optgroup>
</select>
2018-08-02 16:54:52 +03:00
</header>
<div>
2018-08-03 09:59:24 +03:00
<div class="random" v-if="game.settings.map == null">%fa:dice%</div>
<div class="board" v-else :style="{ 'grid-template-rows': `repeat(${ game.settings.map.length }, 1fr)`, 'grid-template-columns': `repeat(${ game.settings.map[0].length }, 1fr)` }">
2018-08-02 16:54:52 +03:00
<div v-for="(x, i) in game.settings.map.join('')"
:data-none="x == ' '"
@click="onPixelClick(i, x)">
2018-08-03 09:59:24 +03:00
<template v-if="x == 'b'"><template v-if="$store.state.device.darkmode">%fa:circle R%</template><template v-else>%fa:circle%</template></template>
<template v-if="x == 'w'"><template v-if="$store.state.device.darkmode">%fa:circle%</template><template v-else>%fa:circle R%</template></template>
2018-08-02 16:54:52 +03:00
</div>
2018-03-11 00:07:17 +02:00
</div>
</div>
2018-08-02 16:54:52 +03:00
</div>
2018-03-11 00:07:17 +02:00
2018-08-02 16:54:52 +03:00
<div class="card">
<header>
2018-08-02 01:36:25 +03:00
<span>%i18n:@black-or-white%</span>
2018-08-02 16:54:52 +03:00
</header>
<div>
2018-08-03 03:39:03 +03:00
<form-radio v-model="game.settings.bw" value="random" @change="updateSettings">%i18n:@random%</form-radio>
2018-08-03 09:59:24 +03:00
<form-radio v-model="game.settings.bw" :value="1" @change="updateSettings">{{ '%i18n:@black-is%'.split('{}')[0] }}<b>{{ game.user1 | userName }}</b>{{ '%i18n:@black-is%'.split('{}')[1] }}</form-radio>
<form-radio v-model="game.settings.bw" :value="2" @change="updateSettings">{{ '%i18n:@black-is%'.split('{}')[0] }}<b>{{ game.user2 | userName }}</b>{{ '%i18n:@black-is%'.split('{}')[1] }}</form-radio>
2018-03-11 00:07:17 +02:00
</div>
2018-08-02 16:54:52 +03:00
</div>
2018-03-11 00:07:17 +02:00
2018-08-02 16:54:52 +03:00
<div class="card">
<header>
2018-08-02 01:36:25 +03:00
<span>%i18n:@rules%</span>
2018-08-02 16:54:52 +03:00
</header>
<div>
<mk-switch v-model="game.settings.isLlotheo" @change="updateSettings" text="%i18n:@is-llotheo%"/>
<mk-switch v-model="game.settings.loopedBoard" @change="updateSettings" text="%i18n:@looped-map%"/>
<mk-switch v-model="game.settings.canPutEverywhere" @change="updateSettings" text="%i18n:@can-put-everywhere%"/>
2018-03-11 00:07:17 +02:00
</div>
2018-08-02 16:54:52 +03:00
</div>
2018-03-11 00:07:17 +02:00
2018-08-02 16:54:52 +03:00
<div class="card" v-if="form">
<header>
2018-08-02 01:36:25 +03:00
<span>%i18n:@settings-of-the-bot%</span>
2018-08-02 16:54:52 +03:00
</header>
<div>
<el-alert v-for="message in messages"
:title="message.text"
:type="message.type"
:key="message.id"/>
<template v-for="item in form">
<mk-switch v-if="item.type == 'button'" v-model="item.value" :key="item.id" :text="item.label" @change="onChangeForm($event, item)">{{ item.desc || '' }}</mk-switch>
<div class="card" v-if="item.type == 'radio'" :key="item.id">
<header>
<span>{{ item.label }}</span>
</header>
<div>
<el-radio v-for="(r, i) in item.items" :key="item.id + ':' + i" v-model="item.value" :label="r.value" @change="onChangeForm($event, item)">{{ r.label }}</el-radio>
</div>
2018-03-11 00:07:17 +02:00
</div>
2018-08-02 16:54:52 +03:00
<div class="card" v-if="item.type == 'textbox'" :key="item.id">
<header>
<span>{{ item.label }}</span>
</header>
<div>
<el-input v-model="item.value" @change="onChangeForm($event, item)"/>
</div>
2018-03-11 00:07:17 +02:00
</div>
2018-08-02 16:54:52 +03:00
</template>
</div>
</div>
2018-03-08 10:57:57 +02:00
</div>
2018-03-08 15:11:08 +02:00
<footer>
<p class="status">
2018-08-03 17:01:55 +03:00
<template v-if="isAccepted && isOpAccepted">%i18n:@this-game-is-started-soon%<mk-ellipsis/></template>
2018-08-02 01:36:25 +03:00
<template v-if="isAccepted && !isOpAccepted">%i18n:@waiting-for-other%<mk-ellipsis/></template>
<template v-if="!isAccepted && isOpAccepted">%i18n:@waiting-for-me%</template>
<template v-if="!isAccepted && !isOpAccepted">%i18n:@waiting-for-both%<mk-ellipsis/></template>
2018-03-08 15:11:08 +02:00
</p>
<div class="actions">
2018-08-03 03:39:03 +03:00
<form-button @click="exit">%i18n:@cancel%</form-button>
<form-button primary @click="accept" v-if="!isAccepted">%i18n:@ready%</form-button>
<form-button primary @click="cancel" v-if="isAccepted">%i18n:@cancel-ready%</form-button>
2018-03-08 15:11:08 +02:00
</div>
</footer>
2018-03-08 10:57:57 +02:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-07-11 07:47:01 +03:00
import * as maps from '../../../../../../../games/reversi/maps';
2018-03-08 10:57:57 +02:00
export default Vue.extend({
props: ['game', 'connection'],
data() {
return {
o: null,
isLlotheo: false,
mapName: maps.eighteight.name,
2018-03-11 00:07:17 +02:00
maps: maps,
form: null,
messages: []
2018-03-08 10:57:57 +02:00
};
},
computed: {
2018-03-08 15:11:08 +02:00
mapCategories(): string[] {
2018-07-23 08:04:53 +03:00
const categories = Object.values(maps).map(x => x.category);
2018-03-08 15:11:08 +02:00
return categories.filter((item, pos) => categories.indexOf(item) == pos);
},
2018-03-08 10:57:57 +02:00
isAccepted(): boolean {
2018-05-27 07:49:09 +03:00
if (this.game.user1Id == this.$store.state.i.id && this.game.user1Accepted) return true;
if (this.game.user2Id == this.$store.state.i.id && this.game.user2Accepted) return true;
2018-03-08 10:57:57 +02:00
return false;
2018-03-08 11:30:28 +02:00
},
isOpAccepted(): boolean {
2018-05-27 07:49:09 +03:00
if (this.game.user1Id != this.$store.state.i.id && this.game.user1Accepted) return true;
if (this.game.user2Id != this.$store.state.i.id && this.game.user2Accepted) return true;
2018-03-08 11:30:28 +02:00
return false;
2018-03-08 10:57:57 +02:00
}
},
created() {
this.connection.on('change-accepts', this.onChangeAccepts);
this.connection.on('update-settings', this.onUpdateSettings);
2018-03-11 00:07:17 +02:00
this.connection.on('init-form', this.onInitForm);
this.connection.on('message', this.onMessage);
2018-05-27 07:49:09 +03:00
if (this.game.user1Id != this.$store.state.i.id && this.game.settings.form1) this.form = this.game.settings.form1;
if (this.game.user2Id != this.$store.state.i.id && this.game.settings.form2) this.form = this.game.settings.form2;
2018-03-08 10:57:57 +02:00
},
beforeDestroy() {
this.connection.off('change-accepts', this.onChangeAccepts);
this.connection.off('update-settings', this.onUpdateSettings);
2018-03-11 00:07:17 +02:00
this.connection.off('init-form', this.onInitForm);
this.connection.off('message', this.onMessage);
2018-03-08 10:57:57 +02:00
},
methods: {
exit() {
},
accept() {
this.connection.send({
type: 'accept'
});
},
cancel() {
this.connection.send({
type: 'cancel-accept'
});
},
onChangeAccepts(accepts) {
2018-03-29 08:48:47 +03:00
this.game.user1Accepted = accepts.user1;
this.game.user2Accepted = accepts.user2;
2018-03-08 10:57:57 +02:00
this.$forceUpdate();
},
2018-03-10 05:48:41 +02:00
updateSettings() {
2018-03-08 10:57:57 +02:00
this.connection.send({
type: 'update-settings',
settings: this.game.settings
});
},
2018-03-10 05:48:41 +02:00
onUpdateSettings(settings) {
this.game.settings = settings;
2018-03-10 06:42:26 +02:00
if (this.game.settings.map == null) {
this.mapName = null;
} else {
2018-07-23 08:04:53 +03:00
const found = Object.values(maps).find(x => x.data.join('') == this.game.settings.map.join(''));
this.mapName = found ? found.name : '-Custom-';
2018-03-10 06:42:26 +02:00
}
2018-03-10 05:48:41 +02:00
},
2018-03-11 00:07:17 +02:00
onInitForm(x) {
2018-05-27 07:49:09 +03:00
if (x.userId == this.$store.state.i.id) return;
2018-03-11 00:07:17 +02:00
this.form = x.form;
},
onMessage(x) {
2018-05-27 07:49:09 +03:00
if (x.userId == this.$store.state.i.id) return;
2018-03-11 00:07:17 +02:00
this.messages.unshift(x.message);
},
onChangeForm(v, item) {
this.connection.send({
type: 'update-form',
id: item.id,
value: v
});
},
2018-08-02 18:36:29 +03:00
onMapChange() {
if (this.mapName == null) {
2018-03-10 06:42:26 +02:00
this.game.settings.map = null;
} else {
2018-08-02 18:36:29 +03:00
this.game.settings.map = Object.values(maps).find(x => x.name == this.mapName).data;
2018-03-10 06:42:26 +02:00
}
2018-03-08 10:57:57 +02:00
this.$forceUpdate();
2018-03-10 05:48:41 +02:00
this.updateSettings();
},
2018-03-10 05:48:41 +02:00
onPixelClick(pos, pixel) {
const x = pos % this.game.settings.map[0].length;
const y = Math.floor(pos / this.game.settings.map[0].length);
const newPixel =
pixel == ' ' ? '-' :
2018-07-23 08:04:53 +03:00
pixel == '-' ? 'b' :
pixel == 'b' ? 'w' :
' ';
2018-03-10 05:48:41 +02:00
const line = this.game.settings.map[y].split('');
line[x] = newPixel;
this.$set(this.game.settings.map, y, line.join(''));
this.$forceUpdate();
2018-03-10 05:48:41 +02:00
this.updateSettings();
2018-03-08 10:57:57 +02:00
}
}
});
</script>
<style lang="stylus" scoped>
@import '~const.styl'
2018-08-03 03:39:03 +03:00
root(isDark)
2018-03-08 10:57:57 +02:00
text-align center
2018-08-03 09:59:24 +03:00
background isDark ? #191b22 : #f9f9f9
2018-03-08 10:57:57 +02:00
> header
padding 8px
border-bottom dashed 1px #c4cdd4
2018-03-11 00:07:17 +02:00
> div
padding 0 16px
2018-03-08 10:57:57 +02:00
2018-08-02 16:54:52 +03:00
> .card
2018-03-11 00:07:17 +02:00
margin 0 auto 16px auto
2018-03-08 15:11:08 +02:00
2018-08-02 18:36:29 +03:00
&.map
> header
> select
width 100%
2018-08-03 09:59:24 +03:00
padding 12px 14px
background isDark ? #282C37 : #fff
border 1px solid isDark ? #6a707d : #dcdfe6
2018-08-02 18:36:29 +03:00
border-radius 4px
2018-08-03 09:59:24 +03:00
color isDark ? #fff : #606266
cursor pointer
2018-08-02 18:36:29 +03:00
transition border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1)
&:hover
2018-08-03 09:59:24 +03:00
border-color isDark ? #a7aebd : #c0c4cc
2018-08-02 18:36:29 +03:00
&:focus
&:active
border-color $theme-color
2018-08-03 09:59:24 +03:00
> div
> .random
padding 32px 0
font-size 64px
color isDark ? #4e5961 : #d8d8d8
> .board
display grid
grid-gap 4px
width 300px
height 300px
margin 0 auto
color isDark ? #fff : #444
> div
background transparent
border solid 2px isDark ? #6a767f : #ddd
border-radius 6px
overflow hidden
cursor pointer
*
pointer-events none
user-select none
width 100%
height 100%
&[data-none]
border-color transparent
2018-08-02 16:54:52 +03:00
.card
max-width 400px
border-radius 4px
2018-08-03 03:39:03 +03:00
background isDark ? #282C37 : #fff
2018-08-03 09:59:24 +03:00
color isDark ? #fff : #303133
2018-08-02 16:54:52 +03:00
box-shadow 0 2px 12px 0 rgba(#000, 0.1)
> header
padding 18px 20px
2018-08-03 09:59:24 +03:00
border-bottom 1px solid isDark ? #1c2023 : #ebeef5
2018-08-02 16:54:52 +03:00
> div
padding 20px
2018-08-03 09:59:24 +03:00
color isDark ? #fff : #606266
2018-08-02 16:54:52 +03:00
2018-03-08 15:11:08 +02:00
> footer
position sticky
bottom 0
padding 16px
2018-08-03 09:59:24 +03:00
background rgba(isDark ? #191b22 : #fff, 0.9)
border-top solid 1px isDark ? #606266 : #c4cdd4
2018-03-08 10:57:57 +02:00
2018-03-08 15:11:08 +02:00
> .status
margin 0 0 16px 0
2018-08-03 03:39:03 +03:00
.urbixznjwwuukfsckrwzwsqzsxornqij[data-darkmode]
root(true)
.urbixznjwwuukfsckrwzwsqzsxornqij:not([data-darkmode])
root(false)
2018-03-08 10:57:57 +02:00
</style>