feat(): add animation and call service & controllers (#259)

* feat(): add animation and call service & controllers

- run animations on interval so we don't lose animations when walking through doors
- move cl_call.ts to a class

* fix(animation/service): make everything private except for open/closePhone and start/endPhoneCall
This commit is contained in:
Dillon Skaggs authored and GitHub committed 2021-07-06 23:02:55 +02:00
1 parent 4ef89f679f
commit 398bfa2092
14 files changed
+412 -298

No files matched your search

+3 -3
View File
@@ -1,4 +1,4 @@
import { CallEvents } from '../../../typings/call';
import { CallEvents, CallRejectReasons } from '../../../typings/call';
import { getSource } from '../utils/miscUtils';
import CallService from './calls.service';
import { callLogger } from './calls.utils';
@@ -21,9 +21,9 @@ onNet(CallEvents.ACCEPT_CALL, (transmitterNumber: string) => {
);
});
onNet(CallEvents.REJECTED, (transmitterNumber: string) => {
onNet(CallEvents.REJECTED, (transmitterNumber: string, reason?: CallRejectReasons) => {
const src = getSource();
CallService.handleRejectCall(src, transmitterNumber).catch((e) =>
CallService.handleRejectCall(src, transmitterNumber, reason).catch((e) =>
callLogger.error(
`Error occured in rejectcall event (${transmitterNumber}), Error: ${e.message}`,
),
+12 -12
View File
@@ -1,5 +1,5 @@
import Collection from '@discordjs/collection';
import { CallEvents, CallHistoryItem } from '../../../typings/call';
import { CallEvents, CallHistoryItem, CallRejectReasons } from '../../../typings/call';
import CallsDB, { CallsRepo } from './calls.db';
import { v4 as uuidv4 } from 'uuid';
import PlayerService from '../players/player.service';
@@ -131,7 +131,7 @@ class CallsService {
emitNet(CallEvents.FETCH_CALLS, src, calls);
}
async handleRejectCall(src: number, transmitterNumber: string): Promise<void> {
async handleRejectCall(src: number, transmitterNumber: string, reason: CallRejectReasons): Promise<void> {
const currentCall = this.callMap.get(transmitterNumber);
const endCallTimeUnix = Math.floor(new Date().getTime() / 1000);
@@ -149,6 +149,13 @@ class CallsService {
// player who is calling and recieved the rejection.
emitNet(CallEvents.WAS_REJECTED, currentCall.transmitterSource);
if (reason && CallRejectReasons[reason]) {
emitNet(CallEvents.SEND_ALERT, src, {
message: `DIALER_${reason}`,
type: 'error',
});
}
await this.callsDB.updateCall(currentCall, false, endCallTimeUnix);
this.callMap.delete(transmitterNumber);
@@ -166,19 +173,12 @@ class CallsService {
return;
}
// player who is being called
emitNet(CallEvents.WAS_ENDED, currentCall.receiverSource);
if (currentCall.is_accepted) {
emitNet(CallEvents.WAS_ENDED, currentCall.receiverSource);
}
// player who is calling
emitNet(CallEvents.WAS_ENDED, currentCall.transmitterSource);
// ends animations if call is active
// TODO: This animation flow needs to be taken a look at. We should be able to
// to just attach this to the WAS_ENDED event without another net event.
if (currentCall.accepted) {
emitNet(CallEvents.SEND_HANGUP_ANIM, currentCall.receiverSource);
emitNet(CallEvents.SEND_HANGUP_ANIM, currentCall.transmitterSource);
}
await this.callsDB.updateCall(currentCall, true, endCallTimeUnix);
// Clear from memory