Skip to content

Commit a803ec5

Browse files
committed
cleaned up Classic.ts, removed RoleList class, regenerated documentation
1 parent bf5783e commit a803ec5

25 files changed

+2855
-3257
lines changed

Core/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
export { Server } from "./server";
1717
export { Game, MessageRoom } from "./game";
1818
export { User } from "./user";
19-
export { Utils, Color as Colors, Stopwatch, RoleList } from "./utils";
19+
export { Utils, Colors, Stopwatch } from "./utils";

Core/game.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Socket } from "../node_modules/@types/socket.io";
1717
import { Server } from "./server";
1818
import { User, Message } from "./user";
1919
import {
20-
Color,
20+
Colors,
2121
NameColorPair,
2222
Stopwatch,
2323
UserColorArray,
@@ -218,7 +218,7 @@ export abstract class Game {
218218
}
219219
user.color = this.colorPool[0];
220220
user.headerSend([
221-
{ text: "Welcome, ", color: Color.white },
221+
{ text: "Welcome, ", color: Colors.white },
222222
{ text: user.username, color: user.color },
223223
]);
224224
this.colorPool.splice(0, 1);
@@ -246,8 +246,8 @@ export abstract class Game {
246246
}
247247
public broadcast(
248248
msg: string | Message,
249-
textColor?: Color,
250-
backgroundColor?: Color,
249+
textColor?: Colors,
250+
backgroundColor?: Colors,
251251
) {
252252
for (let i = 0; i < this._users.length; i++) {
253253
this._users[i].send(msg, textColor, backgroundColor);
@@ -277,7 +277,7 @@ export abstract class Game {
277277
user.title = "OpenWerewolf";
278278
this.broadcast(user.username + " has disconnected");
279279
}
280-
protected headerBroadcast(array: Array<{ text: string; color: Color }>) {
280+
protected headerBroadcast(array: Array<{ text: string; color: Colors }>) {
281281
for (let i = 0; i < this._users.length; i++) {
282282
this._users[i].headerSend(array);
283283
}
@@ -289,14 +289,14 @@ export abstract class Game {
289289
}
290290
this._inPlay = true;
291291
this._server.markGameStatusInLobby(this, "IN PLAY");
292-
this.broadcast("*** NEW GAME ***", Color.brightGreen);
292+
this.broadcast("*** NEW GAME ***", Colors.brightGreen);
293293
this.broadcast(this.title + " by " + this.author);
294294
this.broadcast("License: " + this.license);
295295
this.broadcast(
296296
"You can create your own games! Take a look at the github repository.",
297297
);
298298
this.headerBroadcast([
299-
{ text: "*** NEW GAME ***", color: Color.brightGreen },
299+
{ text: "*** NEW GAME ***", color: Colors.brightGreen },
300300
]);
301301
}
302302
protected afterEnd() {
@@ -370,54 +370,54 @@ export abstract class Game {
370370
if (!this.inPlay) {
371371
if (Utils.isCommand(msg, "!stop")) {
372372
this.startClock.stop();
373-
user.send("Countdown stopped", undefined, Color.green);
373+
user.send("Countdown stopped", undefined, Colors.green);
374374
} else if (Utils.isCommand(msg, "!start")) {
375375
if (this._registeredPlayerCount >= this._minPlayerCount) {
376376
this.start();
377377
} else {
378-
user.send("Not enough players to start game", Color.brightRed);
378+
user.send("Not enough players to start game", Colors.brightRed);
379379
}
380380
} else if (Utils.isCommand(msg, "!resume")) {
381381
this.startClock.start();
382-
user.send("Countdown resumed", undefined, Color.green);
382+
user.send("Countdown resumed", undefined, Colors.green);
383383
} else if (Utils.isCommand(msg, "!restart")) {
384384
this.startClock.restart();
385-
user.send("Countdown restarted", undefined, Color.green);
385+
user.send("Countdown restarted", undefined, Colors.green);
386386
} else if (Utils.isCommand(msg, "!time")) {
387387
user.send(this.startClock.time.toString());
388388
} else if (Utils.isCommand(msg, "!hold")) {
389389
user.send(
390390
"The vote to start has been halted.",
391391
undefined,
392-
Color.green,
392+
Colors.green,
393393
);
394394
this.holdVote = true;
395395
} else if (Utils.isCommand(msg, "!release")) {
396396
user.send(
397397
"The vote to start has been resumed",
398398
undefined,
399-
Color.green,
399+
Colors.green,
400400
);
401401
this.holdVote = false;
402402
} else if (Utils.isCommand(msg, "!help")) {
403403
user.send(
404404
"!stop, !start, !resume, !restart, !time, !hold, !release, !yell, !help",
405405
undefined,
406-
Color.green,
406+
Colors.green,
407407
);
408408
user.send(
409409
"Use !gamehelp for game-specific commands.",
410410
undefined,
411-
Color.green,
411+
Colors.green,
412412
);
413413
} else {
414414
this.customAdminReceive(user, msg);
415415
}
416-
}
416+
}
417417
if (Utils.isCommand(msg, "!yell")) {
418-
this.broadcast("ADMIN:" + msg.slice(5), Color.brightGreen);
418+
this.broadcast("ADMIN:" + msg.slice(5), Colors.brightGreen);
419419
} else {
420-
this.customAdminReceive(user, msg);
420+
this.customAdminReceive(user, msg);
421421
}
422422
}
423423
}
@@ -471,8 +471,8 @@ class MessageRoomMember {
471471
}
472472
public send(
473473
message: string | Message,
474-
textColor?: Color,
475-
backgroundColor?: Color,
474+
textColor?: Colors,
475+
backgroundColor?: Colors,
476476
): void {
477477
this._member.send(message, textColor, backgroundColor);
478478
}
@@ -493,8 +493,8 @@ export class MessageRoom {
493493
public receive(
494494
sender: User,
495495
msg: string | Message,
496-
textColor?: Color,
497-
backgroundColor?: Color,
496+
textColor?: Colors,
497+
backgroundColor?: Colors,
498498
) {
499499
//if id passed in, find the sender within the message room
500500
let messageRoomSender = this.getMemberById(sender.id);
@@ -510,8 +510,8 @@ export class MessageRoom {
510510
}
511511
public broadcast(
512512
msg: string | Message,
513-
textColor?: Color,
514-
backgroundColor?: Color,
513+
textColor?: Colors,
514+
backgroundColor?: Colors,
515515
) {
516516
for (let i = 0; i < this._members.length; i++) {
517517
if (!this._members[i].deafened) {

Core/player.ts

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { User, Message } from "./user";
2-
import { Color } from "./utils";
3-
41
/*
52
Copyright 2017-2018 James V. Craster
63
Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,31 +11,14 @@ import { Color } from "./utils";
1411
limitations under the License.
1512
*/
1613

14+
import { User } from "./user";
15+
1716
export class Player {
1817
protected _user: User;
1918
constructor(user: User) {
2019
this._user = user;
2120
}
22-
/*public canVote() {
23-
return this._user.canVote();
24-
}
25-
public cannotVote() {
26-
this._user.cannotVote();
27-
}*/
2821
get user() {
2922
return this._user;
3023
}
31-
/*public headerSend(message: Message) {
32-
this._user.headerSend(message);
33-
}
34-
public leftSend(message: string, textColor?: Color, backgroundColor?: Color) {
35-
this._user.leftSend(message, textColor, backgroundColor);
36-
}
37-
public send(text: Message | string,
38-
textColor?: Color,
39-
backgroundColor?: Color,
40-
usernameColor?: Color,){
41-
this._user.send()
42-
43-
}*/
4424
}

Core/server.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import { Socket } from "../node_modules/@types/socket.io";
1717
import { User, Message } from "./user";
1818
import { Game } from "./game";
19-
import { Utils, Color } from "./utils";
20-
import { thisExpression } from "../node_modules/@types/babel-types";
19+
import { Utils, Colors } from "./utils";
2120
const grawlix = require("grawlix");
2221

2322
export class Server {
@@ -257,7 +256,7 @@ export class Server {
257256
socket.emit(
258257
"lineThroughPlayer",
259258
this._users[i].deadCache[j],
260-
Color.brightRed,
259+
Colors.brightRed,
261260
);
262261
}
263262
}
@@ -319,7 +318,7 @@ export class Server {
319318
user.send(
320319
"You're already playing a game in a different tab, so you cannot join this one.",
321320
undefined,
322-
Color.red,
321+
Colors.red,
323322
);
324323
user.banFromRegistering();
325324
return;
@@ -357,13 +356,13 @@ export class Server {
357356
for (let i = 0; i < this._users.length; i++) {
358357
this._users[i].lobbyMessage(
359358
user.username + " : " + msg,
360-
Color.standardWhite,
359+
Colors.standardWhite,
361360
);
362361
}
363362
this._lobbyChatCache.push([
364363
{
365364
text: user.username + " : " + msg,
366-
color: Color.standardWhite,
365+
color: Colors.standardWhite,
367366
},
368367
]);
369368
if (this._lobbyChatCache.length > 50) {
@@ -384,7 +383,7 @@ export class Server {
384383
user.send(
385384
"You have been granted administrator access",
386385
undefined,
387-
Color.green,
386+
Colors.green,
388387
);
389388
}
390389
if (user.admin) {
@@ -447,7 +446,7 @@ export class Server {
447446
this._users[i].markGameStatusInLobby(game, status);
448447
}
449448
}
450-
public listPlayerInLobby(username: string, color: Color, game: Game) {
449+
public listPlayerInLobby(username: string, color: Colors, game: Game) {
451450
for (let i = 0; i < this._users.length; i++) {
452451
this._users[i].addListingToGame(username, color, game);
453452
//if the player is viewing the game, add joiner to their right bar

Core/user.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/user.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"use strict";
1515

1616
import { Socket } from "socket.io";
17-
import { NameColorPair, Stopwatch, Color } from "./utils";
17+
import { NameColorPair, Stopwatch, Colors } from "./utils";
1818
import { Game } from "./game";
1919
//set this to what the admin password should be
2020
const password = "goat";
2121

2222
export interface Phrase {
2323
text: string;
24-
color?: Color;
25-
backgroundColor?: Color;
24+
color?: Colors;
25+
backgroundColor?: Colors;
2626
italic?: boolean;
2727
}
2828

@@ -41,13 +41,13 @@ export class User {
4141
private _admin: boolean = false;
4242
private _startVote: boolean = false;
4343
//username color
44-
private _color: Color = Color.none;
44+
private _color: Colors = Colors.none;
4545
private _gameClickedLast: string = "";
4646
private _session: string = "";
4747
//true if already playing in another tab
4848
private _cannotRegister: boolean = false;
4949
private _id: string;
50-
private _cache: Array<{ msg: Message; color?: Color }> = [];
50+
private _cache: Array<{ msg: Message; color?: Colors }> = [];
5151
private _leftMessageCache: Array<Message> = [];
5252
private _time: number = 0;
5353
private _stopwatch: Stopwatch;
@@ -77,7 +77,7 @@ export class User {
7777
this._game = undefined;
7878
this._inGame = false;
7979
this._startVote = false;
80-
this._color = Color.none;
80+
this._color = Colors.none;
8181
this.gameClickedLast = "";
8282
this._cache = [];
8383
this._leftMessageCache = [];
@@ -112,7 +112,7 @@ export class User {
112112
| string[]
113113
| boolean
114114
| undefined
115-
| Array<{ text: string; color: string | Color }>
115+
| Array<{ text: string; color: string | Colors }>
116116
| Message
117117
>
118118
) {
@@ -213,9 +213,9 @@ export class User {
213213

214214
public send(
215215
text: Message | string,
216-
textColor?: Color,
217-
backgroundColor?: Color,
218-
usernameColor?: Color,
216+
textColor?: Colors,
217+
backgroundColor?: Colors,
218+
usernameColor?: Colors,
219219
) {
220220
if (typeof text == "string") {
221221
this.emit(
@@ -255,8 +255,8 @@ export class User {
255255
//These functions manipulate the two boxes either side of the central chatbox
256256
public rightSend(
257257
msg: string | Message,
258-
textColor?: Color,
259-
backgroundColor?: Color,
258+
textColor?: Colors,
259+
backgroundColor?: Colors,
260260
): void {
261261
if (typeof msg == "string") {
262262
this.emit("rightMessage", [
@@ -268,8 +268,8 @@ export class User {
268268
}
269269
public leftSend(
270270
message: string,
271-
textColor?: Color,
272-
backgroundColor?: Color,
271+
textColor?: Colors,
272+
backgroundColor?: Colors,
273273
): void {
274274
this.emit("leftMessage", [
275275
{ text: message, color: textColor, backgroundColor: backgroundColor },
@@ -315,7 +315,11 @@ export class User {
315315
public get deadCache(): Array<string> {
316316
return this._deadCache;
317317
}
318-
public lobbyMessage(msg: string, textColor: Color, backgroundColor?: Color) {
318+
public lobbyMessage(
319+
msg: string,
320+
textColor: Colors,
321+
backgroundColor?: Colors,
322+
) {
319323
this.emit("lobbyMessage", [
320324
{ text: msg, color: textColor, backgroundColor: backgroundColor },
321325
]);
@@ -339,7 +343,7 @@ export class User {
339343
set startVote(startVote: boolean) {
340344
this._startVote = startVote;
341345
}
342-
set color(color: Color) {
346+
set color(color: Colors) {
343347
this._color = color;
344348
}
345349
get color() {

0 commit comments

Comments
 (0)