create widget handler

This commit is contained in:
dank074 2021-11-15 21:12:05 -06:00
parent 03b140c289
commit bc0c1b0562
5 changed files with 195 additions and 0 deletions

View File

@ -0,0 +1,110 @@
import { IQuestion } from '@nitrots/nitro-renderer';
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
export class RoomWidgetWordQuizUpdateEvent extends RoomWidgetUpdateEvent
{
public static readonly NEW_QUESTION = 'RWPUW_NEW_QUESTION';
public static readonly QUESTION_FINISHED = 'RWPUW_QUESION_FINSIHED';
public static readonly QUESTION_ANSWERED = 'RWPUW_QUESTION_ANSWERED';
private _id: number = -1;
private _pollType: string = null;
private _pollId: number = -1;
private _questionId: number = -1;
private _duration: number = -1;
private _question: IQuestion = null;
private _userId: number = -1;
private _value: string;
private _answerCounts: Map<string, number>;
constructor(type: string, id: number)
{
super(type);
this._id = id;
}
public get id(): number
{
return this._id;
}
public get pollType(): string
{
return this._pollType;
}
public set pollType(k: string)
{
this._pollType = k;
}
public get pollId(): number
{
return this._pollId;
}
public set pollId(k: number)
{
this._pollId = k;
}
public get questionId(): number
{
return this._questionId;
}
public set questionId(k: number)
{
this._questionId = k;
}
public get duration(): number
{
return this._duration;
}
public set duration(k: number)
{
this._duration = k;
}
public get question(): IQuestion
{
return this._question;
}
public set question(k: IQuestion)
{
this._question = k;
}
public get userId(): number
{
return this._userId;
}
public set userId(k: number)
{
this._userId = k;
}
public get value(): string
{
return this._value;
}
public set value(k: string)
{
this._value = k;
}
public get answerCounts(): Map<string, number>
{
return this._answerCounts;
}
public set answerCounts(k: Map<string, number>)
{
this._answerCounts = k;
}
}

View File

@ -0,0 +1,75 @@
import { AvatarAction, NitroEvent, RoomSessionWordQuizEvent, RoomWidgetEnum } from '@nitrots/nitro-renderer';
import { RoomWidgetHandler } from '.';
import { GetRoomEngine } from '../../GetRoomEngine';
import { RoomWidgetUpdateEvent } from '../events';
import { RoomWidgetWordQuizUpdateEvent } from '../events/RoomWidgetWordQuizUpdateEvent';
import { RoomWidgetMessage } from '../messages';
export class WordQuizWidgetHandler extends RoomWidgetHandler
{
public processEvent(event: NitroEvent): void
{
const roomQuizEvent = (event as RoomSessionWordQuizEvent);
let widgetEvent: RoomWidgetWordQuizUpdateEvent;
switch(event.type)
{
case RoomSessionWordQuizEvent.ANSWERED:
const roomId = this.container.roomSession.roomId;
const userData = this.container.roomSession.userDataManager.getUserData(roomQuizEvent.userId);
if(!userData) return;
widgetEvent = new RoomWidgetWordQuizUpdateEvent(RoomWidgetWordQuizUpdateEvent.QUESTION_ANSWERED, roomQuizEvent.id);
widgetEvent.value = roomQuizEvent.value;
widgetEvent.userId = roomQuizEvent.userId;
widgetEvent.answerCounts = roomQuizEvent.answerCounts;
if(widgetEvent.value === '0')
{
GetRoomEngine().updateRoomObjectUserGesture(roomId, userData.roomIndex, AvatarAction.getGestureId(AvatarAction.GESTURE_SAD));
}
else
{
GetRoomEngine().updateRoomObjectUserGesture(roomId, userData.roomIndex, AvatarAction.getGestureId(AvatarAction.GESTURE_SMILE));
}
break;
case RoomSessionWordQuizEvent.FINISHED:
widgetEvent = new RoomWidgetWordQuizUpdateEvent(RoomWidgetWordQuizUpdateEvent.QUESTION_FINISHED, roomQuizEvent.id);
widgetEvent.pollId = roomQuizEvent.pollId;
widgetEvent.questionId = roomQuizEvent.questionId;
widgetEvent.answerCounts = roomQuizEvent.answerCounts;
break;
case RoomSessionWordQuizEvent.QUESTION:
widgetEvent = new RoomWidgetWordQuizUpdateEvent(RoomWidgetWordQuizUpdateEvent.NEW_QUESTION, roomQuizEvent.id);
widgetEvent.question = roomQuizEvent.question;
widgetEvent.duration = roomQuizEvent.duration;
widgetEvent.pollType = roomQuizEvent.pollType;
widgetEvent.questionId = roomQuizEvent.questionId;
widgetEvent.pollId = roomQuizEvent.pollId;
break;
}
if(!widgetEvent) return;
this.container.eventDispatcher.dispatchEvent(widgetEvent);
}
public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent
{
return null;
}
public get type(): string
{
return RoomWidgetEnum.WORD_QUIZZ;
}
public get eventTypes(): string[]
{
return [RoomSessionWordQuizEvent.ANSWERED, RoomSessionWordQuizEvent.FINISHED, RoomSessionWordQuizEvent.QUESTION];
}
public get messageTypes(): string[]
{
return [];
}
}

View File

@ -2,6 +2,7 @@ import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector
import { FC, useEffect, useRef, useState } from 'react';
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
import { FurnitureYoutubeDisplayWidgetHandler } from '../../api/nitro/room/widgets/handlers/FurnitureYoutubeDisplayWidgetHandler';
import { WordQuizWidgetHandler } from '../../api/nitro/room/widgets/handlers/WordQuizWidgetHandler';
import { RoomContextProvider } from './context/RoomContext';
import { RoomColorView } from './RoomColorView';
import { RoomViewProps } from './RoomView.types';
@ -37,6 +38,7 @@ export const RoomView: FC<RoomViewProps> = props =>
widgetHandlerManager.registerHandler(new RoomWidgetChatHandler());
widgetHandlerManager.registerHandler(new UserChooserWidgetHandler());
widgetHandlerManager.registerHandler(new DoorbellWidgetHandler());
widgetHandlerManager.registerHandler(new WordQuizWidgetHandler());
widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler());
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());

View File

@ -16,6 +16,7 @@ import { InfoStandWidgetView } from './infostand/InfoStandWidgetView';
import { RoomThumbnailWidgetView } from './room-thumbnail/RoomThumbnailWidgetView';
import { RoomToolsWidgetView } from './room-tools/RoomToolsWidgetView';
import { RoomWidgetViewProps } from './RoomWidgets.types';
import { WordQuizWidgetView } from './word-quiz/WordQuizWidgetView';
export const RoomWidgetsView: FC<RoomWidgetViewProps> = props =>
{
const { roomSession = null, eventDispatcher = null, widgetHandler = null } = useRoomContext();
@ -349,6 +350,7 @@ export const RoomWidgetsView: FC<RoomWidgetViewProps> = props =>
<RoomThumbnailWidgetView />
<FurniChooserWidgetView />
<UserChooserWidgetView />
<WordQuizWidgetView />
</>
);
}

View File

@ -0,0 +1,6 @@
import { FC } from 'react';
export const WordQuizWidgetView: FC<{}> = props =>
{
return null;
}