You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { QuestionAnsweredEvent, QuestionEvent, QuestionFinishedEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionWordQuizEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class WordQuizHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new QuestionEvent(this.onQuestionEvent.bind(this)));
|
||||
connection.addMessageEvent(new QuestionAnsweredEvent(this.onQuestionAnsweredEvent.bind(this)));
|
||||
connection.addMessageEvent(new QuestionFinishedEvent(this.onQuestionFinishedEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onQuestionEvent(event: QuestionEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.QUESTION, session, parser.pollId);
|
||||
|
||||
quizEvent.question = parser.question;
|
||||
quizEvent.duration = parser.duration;
|
||||
quizEvent.pollType = parser.pollType;
|
||||
quizEvent.questionId = parser.questionId;
|
||||
quizEvent.pollId = parser.pollId;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
|
||||
private onQuestionAnsweredEvent(event: QuestionAnsweredEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.ANSWERED, session, parser.userId);
|
||||
|
||||
quizEvent.value = parser.value;
|
||||
quizEvent.userId = parser.userId;
|
||||
quizEvent.answerCounts = parser.answerCounts;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
|
||||
private onQuestionFinishedEvent(event: QuestionFinishedEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.FINISHED, session);
|
||||
quizEvent.questionId = parser.questionId;
|
||||
quizEvent.answerCounts = parser.answerCounts;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user