Skip to content

Commit

Permalink
move stuff into quizbowl/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Oct 1, 2024
1 parent 3cfdfd1 commit 7737925
Show file tree
Hide file tree
Showing 20 changed files with 407 additions and 470 deletions.
90 changes: 0 additions & 90 deletions client/singleplayer/TossupRoom.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/singleplayer/tossups/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Timer from '../../scripts/Timer.js';
import { arrayToRange, createTossupCard, rangeToArray } from '../../scripts/utilities/index.js';
import CategoryManager from '../../scripts/utilities/category-manager.js';
import { getDropdownValues } from '../../scripts/utilities/dropdown-checklist.js';
import { insertTokensIntoHTML } from '../../scripts/utilities/insert-tokens-into-html.js';
import { insertTokensIntoHTML } from '../../../quizbowl/insert-tokens-into-html.js';
import CategoryModal from '../../scripts/components/CategoryModal.min.js';
import DifficultyDropdown from '../../scripts/components/DifficultyDropdown.min.js';

Expand Down
2 changes: 1 addition & 1 deletion client/singleplayer/tossups/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 0 additions & 72 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,6 @@
const DEFAULT_QUERY_RETURN_LENGTH = 25;
const MAX_QUERY_RETURN_LENGTH = 10000;

const DEFAULT_MIN_YEAR = 2010;
const DEFAULT_MAX_YEAR = 2024;

const DIFFICULTIES = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const CATEGORIES = ['Literature', 'History', 'Science', 'Fine Arts', 'Religion', 'Mythology', 'Philosophy', 'Social Science', 'Current Events', 'Geography', 'Other Academic', 'Trash'];
const SUBCATEGORY_TO_CATEGORY = {
'American Literature': 'Literature',
'British Literature': 'Literature',
'Classical Literature': 'Literature',
'European Literature': 'Literature',
'World Literature': 'Literature',
'Other Literature': 'Literature',
'American History': 'History',
'Ancient History': 'History',
'European History': 'History',
'World History': 'History',
'Other History': 'History',
Biology: 'Science',
Chemistry: 'Science',
Physics: 'Science',
'Other Science': 'Science',
'Visual Fine Arts': 'Fine Arts',
'Auditory Fine Arts': 'Fine Arts',
'Other Fine Arts': 'Fine Arts',
Religion: 'Religion',
Mythology: 'Mythology',
Philosophy: 'Philosophy',
'Social Science': 'Social Science',
'Current Events': 'Current Events',
Geography: 'Geography',
'Other Academic': 'Other Academic',
Trash: 'Trash'
};
const SUBCATEGORIES_FLATTENED = Object.keys(SUBCATEGORY_TO_CATEGORY);

const ALTERNATE_SUBCATEGORY_TO_CATEGORY = {
Drama: 'Literature',
'Long Fiction': 'Literature',
Poetry: 'Literature',
'Short Fiction': 'Literature',
'Misc Literature': 'Literature',
Math: 'Science',
Astronomy: 'Science',
'Computer Science': 'Science',
'Earth Science': 'Science',
Engineering: 'Science',
'Misc Science': 'Science',
Architecture: 'Fine Arts',
Dance: 'Fine Arts',
Film: 'Fine Arts',
Jazz: 'Fine Arts',
Opera: 'Fine Arts',
Photography: 'Fine Arts',
'Misc Arts': 'Fine Arts',
Anthropology: 'Social Science',
Economics: 'Social Science',
Linguistics: 'Social Science',
Psychology: 'Social Science',
Sociology: 'Social Science',
'Other Social Science': 'Social Science'
};
const ALTERNATE_SUBCATEGORIES_FLATTENED = Object.keys(ALTERNATE_SUBCATEGORY_TO_CATEGORY);

const COOKIE_MAX_AGE = 1000 * 60 * 60 * 24 * 7; // 7 days
const WEBSOCKET_MAX_PAYLOAD = 1024 * 10 * 1; // 10 KB

Expand All @@ -73,14 +9,6 @@ const QBREADER_EMAIL_ADDRESS = 'noreply@qbreader.org';
export {
DEFAULT_QUERY_RETURN_LENGTH,
MAX_QUERY_RETURN_LENGTH,
DEFAULT_MIN_YEAR,
DEFAULT_MAX_YEAR,
DIFFICULTIES,
CATEGORIES,
SUBCATEGORY_TO_CATEGORY,
ALTERNATE_SUBCATEGORY_TO_CATEGORY,
ALTERNATE_SUBCATEGORIES_FLATTENED,
SUBCATEGORIES_FLATTENED,
COOKIE_MAX_AGE,
WEBSOCKET_MAX_PAYLOAD,
QBREADER_EMAIL_ADDRESS
Expand Down
2 changes: 1 addition & 1 deletion database/qbreader/get-frequency-list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bonuses, tossups } from './collections.js';
import { DIFFICULTIES } from '../../constants.js';
import { DIFFICULTIES } from '../../quizbowl/constants.js';
import mergeTwoSortedArrays from '../../server/merge-two-sorted-arrays.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion database/qbreader/get-random-bonuses.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bonuses } from './collections.js';

import { DIFFICULTIES, CATEGORIES, SUBCATEGORIES_FLATTENED, DEFAULT_MIN_YEAR, DEFAULT_MAX_YEAR } from '../../constants.js';
import { DIFFICULTIES, CATEGORIES, SUBCATEGORIES_FLATTENED, DEFAULT_MIN_YEAR, DEFAULT_MAX_YEAR } from '../../quizbowl/constants.js';

// eslint-disable-next-line no-unused-vars
import * as types from '../../types.js';
Expand Down
2 changes: 1 addition & 1 deletion database/qbreader/get-random-tossups.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tossups } from './collections.js';

import { DIFFICULTIES, CATEGORIES, SUBCATEGORIES_FLATTENED, DEFAULT_MIN_YEAR, DEFAULT_MAX_YEAR } from '../../constants.js';
import { DIFFICULTIES, CATEGORIES, SUBCATEGORIES_FLATTENED, DEFAULT_MIN_YEAR, DEFAULT_MAX_YEAR } from '../../quizbowl/constants.js';

// eslint-disable-next-line no-unused-vars
import * as types from '../../types.js';
Expand Down
2 changes: 1 addition & 1 deletion database/qbreader/get-set.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tossups, bonuses } from './collections.js';

import { CATEGORIES, SUBCATEGORIES_FLATTENED } from '../../constants.js';
import { CATEGORIES, SUBCATEGORIES_FLATTENED } from '../../quizbowl/constants.js';
// eslint-disable-next-line no-unused-vars
import * as types from '../../types.js';

Expand Down
2 changes: 1 addition & 1 deletion database/qbreader/update-subcategory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tossups, tossupData, bonuses, bonusData } from './collections.js';

import { SUBCATEGORY_TO_CATEGORY } from '../../constants.js';
import { SUBCATEGORY_TO_CATEGORY } from '../../quizbowl/constants.js';

/**
*
Expand Down
5 changes: 2 additions & 3 deletions server/multiplayer/Player.js → quizbowl/Player.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { USERNAME_MAX_LENGTH } from './constants.js';
import { USERNAME_MAX_LENGTH } from '../server/multiplayer/constants.js';

class Player {
constructor (userId) {
this.userId = userId;

this.username = '';
this.online = true;

this.powers = 0;
this.tens = 0;
Expand Down Expand Up @@ -71,7 +70,7 @@ class Player {
* @param {number} [maxLength=USERNAME_MAX_LENGTH]
* @returns {string} newUsername
*/
updateUsername (username, maxLength = USERNAME_MAX_LENGTH) {
safelySetUsername (username, maxLength = USERNAME_MAX_LENGTH) {
if (!username) { username = ''; }
username = username.substring(0, maxLength);
this.username = username;
Expand Down
58 changes: 58 additions & 0 deletions quizbowl/Room.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export default class Room {
/**
* @param {string} name - The name of the room
*/
constructor (name) {
this.name = name;

this.players = {};
this.sockets = {};
this.timer = {
interval: null,
timeRemaining: 0
};
}

async message (userId, message) { throw new Error('Not implemented'); }

/**
* Sends a message to all sockets
* @param {{}} message
*/
emitMessage (message) {
message = JSON.stringify(message);
for (const socket of Object.values(this.sockets)) {
socket.send(message);
}
}

/**
* Sends a message to a socket at a specific userId
* @param {string} userId
* @param {{}} message
*/
sendToSocket (userId, message) {
message = JSON.stringify(message);
this.sockets[userId].send(message);
}

/**
* @param {number} time - time in ticks, where 10 ticks = 1 second
* @param {(time: number) => void} ontick - called every tick
* @param {() => void} callback - called when timer is up
* @returns {void}
*/
startServerTimer (time, ontick, callback) {
clearInterval(this.timer.interval);
this.timer.timeRemaining = time;

this.timer.interval = setInterval(() => {
if (this.timer.timeRemaining <= 0) {
clearInterval(this.timer.interval);
callback();
}
ontick(this.timer.timeRemaining);
this.timer.timeRemaining--;
}, 100);
}
}
Loading

0 comments on commit 7737925

Please sign in to comment.