mirror of
https://github.com/nullnyat/NullcatChan.git
synced 2025-08-04 09:46:26 +09:00
v10対応
This commit is contained in:
@ -73,11 +73,11 @@ class Session {
|
||||
|
||||
private onMessage = async (msg: any) => {
|
||||
switch (msg.type) {
|
||||
case '_init_': this.onInit(msg); break;
|
||||
case 'updateForm': this.onUpdateForn(msg); break;
|
||||
case 'started': this.onStarted(msg); break;
|
||||
case 'ended': this.onEnded(msg); break;
|
||||
case 'set': this.onSet(msg); break;
|
||||
case '_init_': this.onInit(msg.body); break;
|
||||
case 'updateForm': this.onUpdateForn(msg.body); break;
|
||||
case 'started': this.onStarted(msg.body); break;
|
||||
case 'ended': this.onEnded(msg.body); break;
|
||||
case 'set': this.onSet(msg.body); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,14 +92,14 @@ class Session {
|
||||
* フォームが更新されたとき
|
||||
*/
|
||||
private onUpdateForn = (msg: any) => {
|
||||
this.form.find(i => i.id == msg.body.id).value = msg.body.value;
|
||||
this.form.find(i => i.id == msg.id).value = msg.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 対局が始まったとき
|
||||
*/
|
||||
private onStarted = (msg: any) => {
|
||||
this.game = msg.body;
|
||||
this.game = msg;
|
||||
|
||||
// TLに投稿する
|
||||
this.postGameStarted().then(note => {
|
||||
@ -215,14 +215,14 @@ class Session {
|
||||
|
||||
let text: string;
|
||||
|
||||
if (msg.body.game.surrendered) {
|
||||
if (msg.game.surrendered) {
|
||||
if (this.isSettai) {
|
||||
text = serifs.reversi.settaiButYouSurrendered(this.userName);
|
||||
} else {
|
||||
text = serifs.reversi.youSurrendered(this.userName);
|
||||
}
|
||||
} else if (msg.body.winnerId) {
|
||||
if (msg.body.winnerId == this.account.id) {
|
||||
} else if (msg.winnerId) {
|
||||
if (msg.winnerId == this.account.id) {
|
||||
if (this.isSettai) {
|
||||
text = serifs.reversi.iWonButSettai(this.userName);
|
||||
} else {
|
||||
@ -252,9 +252,9 @@ class Session {
|
||||
* 打たれたとき
|
||||
*/
|
||||
private onSet = (msg: any) => {
|
||||
this.o.put(msg.body.color, msg.body.pos);
|
||||
this.o.put(msg.color, msg.pos);
|
||||
|
||||
if (msg.body.next === this.botColor) {
|
||||
if (msg.next === this.botColor) {
|
||||
this.think();
|
||||
}
|
||||
}
|
||||
|
@ -66,19 +66,13 @@ export default class ReversiModule implements IModule {
|
||||
}
|
||||
|
||||
private onReversiGameStart = (game: any) => {
|
||||
console.log('enter reversi game room');
|
||||
|
||||
// ゲームストリームに接続
|
||||
const gw = this.ai.connection.connectToChannel('gamesReversiGame', {
|
||||
game: game.id
|
||||
gameId: game.id
|
||||
});
|
||||
|
||||
function send(msg) {
|
||||
try {
|
||||
gw.send(JSON.stringify(msg));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
// フォーム
|
||||
const form = [{
|
||||
id: 'publish',
|
||||
@ -114,15 +108,16 @@ export default class ReversiModule implements IModule {
|
||||
// バックエンドプロセスに情報を渡す
|
||||
ai.send({
|
||||
type: '_init_',
|
||||
game,
|
||||
form,
|
||||
account: this.ai.account
|
||||
body: {
|
||||
game: game,
|
||||
form: form,
|
||||
account: this.ai.account
|
||||
}
|
||||
});
|
||||
|
||||
ai.on('message', msg => {
|
||||
if (msg.type == 'put') {
|
||||
send({
|
||||
type: 'set',
|
||||
gw.send('set', {
|
||||
pos: msg.pos
|
||||
});
|
||||
} else if (msg.type == 'ended') {
|
||||
@ -133,24 +128,19 @@ export default class ReversiModule implements IModule {
|
||||
});
|
||||
|
||||
// ゲームストリームから情報が流れてきたらそのままバックエンドプロセスに伝える
|
||||
gw.addEventListener('*', message => {
|
||||
gw.addListener('*', message => {
|
||||
ai.send(message);
|
||||
});
|
||||
//#endregion
|
||||
|
||||
// フォーム初期化
|
||||
setTimeout(() => {
|
||||
send({
|
||||
type: 'initForm',
|
||||
body: form
|
||||
});
|
||||
gw.send('initForm', form);
|
||||
}, 1000);
|
||||
|
||||
// どんな設定内容の対局でも受け入れる
|
||||
setTimeout(() => {
|
||||
send({
|
||||
type: 'accept'
|
||||
});
|
||||
gw.send('accept', {});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user