From 98f09ad16c8dbdfedfb1a517203f84e584fb0bee Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 11 Mar 2018 07:07:17 +0900 Subject: [PATCH] :v: --- src/api/models/othello-game.ts | 2 + src/api/stream/othello-game.ts | 76 ++++++ .../common/views/components/othello.room.vue | 230 +++++++++++++----- 3 files changed, 253 insertions(+), 55 deletions(-) diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts index a8c302510..ab90cffa4 100644 --- a/src/api/models/othello-game.ts +++ b/src/api/models/othello-game.ts @@ -33,6 +33,8 @@ export interface IGame { can_put_everywhere: boolean; looped_board: boolean; }; + form1: any; + form2: any; } /** diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 5f61f0cc2..888c59933 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -31,6 +31,21 @@ export default function(request: websocket.request, connection: websocket.connec updateSettings(msg.settings); break; + case 'init-form': + if (msg.body == null) return; + initForm(msg.body); + break; + + case 'update-form': + if (msg.id == null || msg.value === undefined) return; + updateForm(msg.id, msg.value); + break; + + case 'message': + if (msg.body == null) return; + message(msg.body); + break; + case 'set': if (msg.pos == null) return; set(msg.pos); @@ -55,6 +70,67 @@ export default function(request: websocket.request, connection: websocket.connec publishOthelloGameStream(gameId, 'update-settings', settings); } + async function initForm(form) { + const game = await Game.findOne({ _id: gameId }); + + if (game.is_started) return; + if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; + + const set = game.user1_id.equals(user._id) ? { + form1: form + } : { + form2: form + }; + + await Game.update({ _id: gameId }, { + $set: set + }); + + publishOthelloGameStream(gameId, 'init-form', { + user_id: user._id, + form + }); + } + + async function updateForm(id, value) { + const game = await Game.findOne({ _id: gameId }); + + if (game.is_started) return; + if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; + + const form = game.user1_id.equals(user._id) ? game.form2 : game.form1; + + const item = form.find(i => i.id == id); + + if (item == null) return; + + item.value = value; + + const set = game.user1_id.equals(user._id) ? { + form2: form + } : { + form1: form + }; + + await Game.update({ _id: gameId }, { + $set: set + }); + + publishOthelloGameStream(gameId, 'update-form', { + user_id: user._id, + id, + value + }); + } + + async function message(message) { + message.id = Math.random(); + publishOthelloGameStream(gameId, 'message', { + user_id: user._id, + message + }); + } + async function accept(accept: boolean) { const game = await Game.findOne({ _id: gameId }); diff --git a/src/web/app/common/views/components/othello.room.vue b/src/web/app/common/views/components/othello.room.vue index dfdc43ef9..bdefcdc49 100644 --- a/src/web/app/common/views/components/othello.room.vue +++ b/src/web/app/common/views/components/othello.room.vue @@ -2,37 +2,77 @@
{{ game.user1.name }} vs {{ game.user2.name }}
-

ゲームの設定

+
+

ゲームの設定

- - - - - {{ m.name }} - (by {{ m.author }}) - - - + +
+ + + + + {{ m.name }} + (by {{ m.author }}) + + + +
+
+
+ + +
+
+
-
-
- - -
-
- -
- - - -
+ +
+ 先手/後手 +
ランダム {{ game.user1.name }}が黒 {{ game.user2.name }}が黒 -
+ + + +
+ ルール +
+ + + +
+ + +
+ Botの設定 +
+ + +