mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-02 05:24:50 +08:00
completed merge
This commit is contained in:
parent
e274a5120c
commit
3c6cfaf15d
14 changed files with 852 additions and 514 deletions
|
|
@ -13,6 +13,7 @@ import * as AllTimeStats from "./all-time-stats";
|
|||
import * as DB from "./db";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as UI from "./ui";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
var gmailProvider = new firebase.auth.GoogleAuthProvider();
|
||||
|
||||
|
|
@ -308,6 +309,10 @@ firebase.auth().onAuthStateChanged(function (user) {
|
|||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$("#menu .icon-button.account .text").text(displayName);
|
||||
|
||||
try {
|
||||
Tribe.setName(displayName);
|
||||
} catch {}
|
||||
|
||||
// showFavouriteThemesAtTheTop();
|
||||
CommandlineLists.updateThemeCommands();
|
||||
|
||||
|
|
@ -349,6 +354,20 @@ firebase.auth().onAuthStateChanged(function (user) {
|
|||
ChallengeController.setup(challengeName);
|
||||
}, 1000);
|
||||
}
|
||||
if (/\/tribe/.test(window.location.pathname)) {
|
||||
if (/\/tribe_.+/.test(window.location.pathname)) {
|
||||
let code = window.location.pathname.split("/")[1];
|
||||
code = code.substring(5);
|
||||
code = "room" + code;
|
||||
Tribe.setAutoJoin(code);
|
||||
}
|
||||
UI.changePage("tribe");
|
||||
}
|
||||
if (!Tribe.socket.connected && Tribe.autoJoin != undefined) {
|
||||
if (Tribe.state === -1) {
|
||||
Tribe.init();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(".pageLogin .register input").keyup((e) => {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,32 @@ export function getDataAndInit() {
|
|||
snap.name = user.displayName;
|
||||
DB.setSnapshot(snap);
|
||||
DB.updateName(user.uid, user.displayName);
|
||||
} else {
|
||||
//invalid, get new
|
||||
// Notifications.add("Invalid name", 0);
|
||||
let promptVal = null;
|
||||
let cdnVal = undefined;
|
||||
|
||||
while (
|
||||
promptVal === null ||
|
||||
cdnVal === undefined ||
|
||||
cdnVal.data.status < 0
|
||||
) {
|
||||
promptVal = prompt(
|
||||
"Your name is either invalid or unavailable (you also need to do this if you used Google Sign Up). Please provide a new display name (cannot be longer than 14 characters, can only contain letters, numbers, underscores, dots and dashes):"
|
||||
);
|
||||
cdnVal = await CloudFunctions.changeDisplayName({
|
||||
uid: user.uid,
|
||||
name: promptVal,
|
||||
});
|
||||
if (cdnVal.data.status === 1) {
|
||||
alert("Name updated", 1);
|
||||
location.reload();
|
||||
} else if (cdnVal.data.status < 0) {
|
||||
alert(cdnVal.data.message, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (snap.refactored === false) {
|
||||
CloudFunctions.removeSmallTests({ uid: user.uid });
|
||||
|
|
|
|||
136
src/js/config.js
136
src/js/config.js
|
|
@ -15,6 +15,7 @@ import * as LanguagePicker from "./language-picker";
|
|||
import * as TestLogic from "./test-logic";
|
||||
import * as PaceCaret from "./pace-caret";
|
||||
import * as UI from "./ui";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
export let cookieConfig = null;
|
||||
export let dbConfigLoaded = false;
|
||||
|
|
@ -143,7 +144,10 @@ export async function saveToCookie(noDbCheck = false) {
|
|||
}
|
||||
|
||||
//numbers
|
||||
export function setNumbers(numb, nosave) {
|
||||
export function setNumbers(numb, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (config.mode === "quote") {
|
||||
numb = false;
|
||||
}
|
||||
|
|
@ -153,10 +157,14 @@ export function setNumbers(numb, nosave) {
|
|||
} else {
|
||||
$("#top .config .numbersMode .text-button").addClass("active");
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function toggleNumbers() {
|
||||
if (!Tribe.checkIfCanChangeConfig(false)) {
|
||||
return;
|
||||
}
|
||||
config.numbers = !config.numbers;
|
||||
if (config.mode === "quote") {
|
||||
config.numbers = false;
|
||||
|
|
@ -166,11 +174,15 @@ export function toggleNumbers() {
|
|||
} else {
|
||||
$("#top .config .numbersMode .text-button").removeClass("active");
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
saveToCookie();
|
||||
}
|
||||
|
||||
//punctuation
|
||||
export function setPunctuation(punc, nosave) {
|
||||
export function setPunctuation(punc, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (config.mode === "quote") {
|
||||
punc = false;
|
||||
}
|
||||
|
|
@ -180,10 +192,14 @@ export function setPunctuation(punc, nosave) {
|
|||
} else {
|
||||
$("#top .config .punctuationMode .text-button").addClass("active");
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function togglePunctuation() {
|
||||
if (!Tribe.checkIfCanChangeConfig(false)) {
|
||||
return;
|
||||
}
|
||||
config.punctuation = !config.punctuation;
|
||||
if (config.mode === "quote") {
|
||||
config.punctuation = false;
|
||||
|
|
@ -193,11 +209,15 @@ export function togglePunctuation() {
|
|||
} else {
|
||||
$("#top .config .punctuationMode .text-button").removeClass("active");
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
saveToCookie();
|
||||
}
|
||||
|
||||
export function setMode(mode, nosave) {
|
||||
export function setMode(mode, nosave, mp = false) {
|
||||
if (TestUI.testRestarting) return;
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (mode !== "words" && Funbox.active === "memory") {
|
||||
Notifications.add("Memory funbox can only be used with words mode.", 0);
|
||||
return;
|
||||
|
|
@ -267,6 +287,7 @@ export function setMode(mode, nosave) {
|
|||
}
|
||||
// setPaceCaret("off", true);
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +316,10 @@ export function togglePlaySoundOnError() {
|
|||
}
|
||||
|
||||
//difficulty
|
||||
export function setDifficulty(diff, nosave) {
|
||||
export function setDifficulty(diff, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(diff !== "normal" && diff !== "expert" && diff !== "master") ||
|
||||
diff == undefined
|
||||
|
|
@ -303,8 +327,9 @@ export function setDifficulty(diff, nosave) {
|
|||
diff = "normal";
|
||||
}
|
||||
config.difficulty = diff;
|
||||
if (!nosave) TestLogic.restart(false, nosave);
|
||||
if (!nosave) TestLogic.restart(false, nosave, mp);
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -324,15 +349,20 @@ export function toggleBlindMode() {
|
|||
}
|
||||
config.blindMode = blind;
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
saveToCookie();
|
||||
}
|
||||
|
||||
export function setBlindMode(blind, nosave) {
|
||||
export function setBlindMode(blind, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (blind == undefined) {
|
||||
blind = false;
|
||||
}
|
||||
config.blindMode = blind;
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -392,7 +422,10 @@ export function setChartStyle(chartStyle, nosave) {
|
|||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function setStopOnError(soe, nosave) {
|
||||
export function setStopOnError(soe, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (soe == undefined || soe === true || soe === false) {
|
||||
soe = "off";
|
||||
}
|
||||
|
|
@ -401,6 +434,7 @@ export function setStopOnError(soe, nosave) {
|
|||
config.confidenceMode = "off";
|
||||
}
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -491,38 +525,54 @@ export function setPaceCaretCustomSpeed(val, nosave) {
|
|||
}
|
||||
|
||||
//min wpm
|
||||
export function setMinWpm(minwpm, nosave) {
|
||||
export function setMinWpm(minwpm, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (minwpm == undefined) {
|
||||
minwpm = "off";
|
||||
}
|
||||
config.minWpm = minwpm;
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function setMinWpmCustomSpeed(val, nosave) {
|
||||
export function setMinWpmCustomSpeed(val, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (val == undefined || Number.isNaN(parseInt(val))) {
|
||||
val = 100;
|
||||
}
|
||||
config.minWpmCustomSpeed = val;
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
//min acc
|
||||
export function setMinAcc(min, nosave) {
|
||||
export function setMinAcc(min, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (min == undefined) {
|
||||
min = "off";
|
||||
}
|
||||
config.minAcc = min;
|
||||
TestUI.updateModesNotice();
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function setMinAccCustom(val, nosave) {
|
||||
export function setMinAccCustom(val, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (val == undefined || Number.isNaN(parseInt(val))) {
|
||||
val = 90;
|
||||
}
|
||||
config.minAccCustom = val;
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -835,6 +885,10 @@ export function setTimerStyle(style, nosave) {
|
|||
if (style == null || style == undefined) {
|
||||
style = "bar";
|
||||
}
|
||||
if (Tribe.state >= 10 && style != "mini") {
|
||||
Notifications.add("You can only use the mini timer style in Tribe", 0);
|
||||
return;
|
||||
}
|
||||
config.timerStyle = style;
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
|
@ -910,12 +964,15 @@ export function toggleKeyTips() {
|
|||
}
|
||||
|
||||
//mode
|
||||
export function setTimeConfig(time, nosave) {
|
||||
export function setTimeConfig(time, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (time === null || isNaN(time) || time < 0) {
|
||||
time = 15;
|
||||
}
|
||||
time = parseInt(time);
|
||||
if (!nosave) setMode("time", nosave);
|
||||
if (!nosave) setMode("time", nosave, mp);
|
||||
config.time = time;
|
||||
$("#top .config .time .text-button").removeClass("active");
|
||||
if (![15, 30, 60, 120].includes(time)) {
|
||||
|
|
@ -924,11 +981,15 @@ export function setTimeConfig(time, nosave) {
|
|||
$("#top .config .time .text-button[timeConfig='" + time + "']").addClass(
|
||||
"active"
|
||||
);
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
//quote length
|
||||
export function setQuoteLength(len, nosave, multipleMode) {
|
||||
export function setQuoteLength(len, nosave, multipleMode, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(len)) {
|
||||
//config load
|
||||
if (len.length === 1 && len[0] === -1) len = [1];
|
||||
|
|
@ -952,15 +1013,19 @@ export function setQuoteLength(len, nosave, multipleMode) {
|
|||
"#top .config .quoteLength .text-button[quoteLength='" + ql + "']"
|
||||
).addClass("active");
|
||||
});
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function setWordCount(wordCount, nosave) {
|
||||
export function setWordCount(wordCount, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (wordCount === null || isNaN(wordCount) || wordCount < 0) {
|
||||
wordCount = 10;
|
||||
}
|
||||
wordCount = parseInt(wordCount);
|
||||
if (!nosave) setMode("words", nosave);
|
||||
if (!nosave) setMode("words", nosave, mp);
|
||||
config.words = wordCount;
|
||||
$("#top .config .wordCount .text-button").removeClass("active");
|
||||
if (![10, 25, 50, 100, 200].includes(wordCount)) {
|
||||
|
|
@ -969,6 +1034,7 @@ export function setWordCount(wordCount, nosave) {
|
|||
$(
|
||||
"#top .config .wordCount .text-button[wordCount='" + wordCount + "']"
|
||||
).addClass("active");
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -1115,7 +1181,10 @@ export function toggleFreedomMode() {
|
|||
saveToCookie();
|
||||
}
|
||||
|
||||
export function setConfidenceMode(cm, nosave) {
|
||||
export function setConfidenceMode(cm, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (cm == undefined) {
|
||||
cm = "off";
|
||||
}
|
||||
|
|
@ -1124,7 +1193,7 @@ export function setConfidenceMode(cm, nosave) {
|
|||
config.freedomMode = false;
|
||||
config.stopOnError = "off";
|
||||
}
|
||||
|
||||
Tribe.syncConfig();
|
||||
TestUI.updateModesNotice();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
|
@ -1194,7 +1263,10 @@ export function setCustomThemeColors(colors, nosave) {
|
|||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
export function setLanguage(language, nosave) {
|
||||
export function setLanguage(language, nosave, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (language == null || language == undefined) {
|
||||
language = "english";
|
||||
}
|
||||
|
|
@ -1206,6 +1278,7 @@ export function setLanguage(language, nosave) {
|
|||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
||||
|
|
@ -1310,12 +1383,13 @@ export function setFontSize(fontSize, nosave) {
|
|||
}
|
||||
config.fontSize = fontSize;
|
||||
$("#words").removeClass("size125");
|
||||
$("#caret, #paceCaret").removeClass("size125");
|
||||
$("#words").removeClass("size15");
|
||||
$("#caret, #paceCaret").removeClass("size15");
|
||||
$("#words").removeClass("size2");
|
||||
$("#caret, #paceCaret").removeClass("size2");
|
||||
$("#words").removeClass("size3");
|
||||
|
||||
$("#caret, #paceCaret").removeClass("size125");
|
||||
$("#caret, #paceCaret").removeClass("size15");
|
||||
$("#caret, #paceCaret").removeClass("size2");
|
||||
$("#caret, #paceCaret").removeClass("size3");
|
||||
|
||||
$("#miniTimerAndLiveWpm").removeClass("size125");
|
||||
|
|
@ -1323,22 +1397,40 @@ export function setFontSize(fontSize, nosave) {
|
|||
$("#miniTimerAndLiveWpm").removeClass("size2");
|
||||
$("#miniTimerAndLiveWpm").removeClass("size3");
|
||||
|
||||
$("#typingTest .tribePlayers").removeClass("size125");
|
||||
$("#typingTest .tribePlayers").removeClass("size15");
|
||||
$("#typingTest .tribePlayers").removeClass("size2");
|
||||
$("#typingTest .tribePlayers").removeClass("size3");
|
||||
|
||||
$("#tribeDiff").removeClass("size125");
|
||||
$("#tribeDiff").removeClass("size15");
|
||||
$("#tribeDiff").removeClass("size2");
|
||||
$("#tribeDiff").removeClass("size3");
|
||||
|
||||
if (fontSize == 125) {
|
||||
$("#words").addClass("size125");
|
||||
$("#caret, #paceCaret").addClass("size125");
|
||||
$("#miniTimerAndLiveWpm").addClass("size125");
|
||||
$("#typingTest .tribePlayers").addClass("size125");
|
||||
$("#tribeDiff").addClass("size125");
|
||||
} else if (fontSize == 15) {
|
||||
$("#words").addClass("size15");
|
||||
$("#caret, #paceCaret").addClass("size15");
|
||||
$("#miniTimerAndLiveWpm").addClass("size15");
|
||||
$("#typingTest .tribePlayers").addClass("size15");
|
||||
$("#tribeDiff").addClass("size15");
|
||||
} else if (fontSize == 2) {
|
||||
$("#words").addClass("size2");
|
||||
$("#caret, #paceCaret").addClass("size2");
|
||||
$("#miniTimerAndLiveWpm").addClass("size2");
|
||||
$("#typingTest .tribePlayers").addClass("size2");
|
||||
$("#tribeDiff").addClass("size2");
|
||||
} else if (fontSize == 3) {
|
||||
$("#words").addClass("size3");
|
||||
$("#caret, #paceCaret").addClass("size3");
|
||||
$("#miniTimerAndLiveWpm").addClass("size3");
|
||||
$("#typingTest .tribePlayers").addClass("size3");
|
||||
$("#tribeDiff").addClass("size3");
|
||||
}
|
||||
if (!nosave) saveToCookie();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ global.getuid = Misc.getuid;
|
|||
|
||||
//these exports are just for debugging in the browser
|
||||
|
||||
global.MP = MP;
|
||||
global.addnotif = Notifications.add;
|
||||
global.Tribe = Tribe;
|
||||
|
||||
global.snapshot = DB.getSnapshot;
|
||||
global.config = Config;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
import Chart from "chart.js";
|
||||
import chartTrendline from "chartjs-plugin-trendline";
|
||||
import chartAnnotation from "chartjs-plugin-annotation";
|
||||
import seedrandom from "seedrandom";
|
||||
|
||||
Chart.plugins.register(chartTrendline);
|
||||
Chart.plugins.register(chartAnnotation);
|
||||
|
|
@ -14,6 +13,7 @@ import * as ResultFilters from "./result-filters";
|
|||
import Config from "./config";
|
||||
import * as SimplePopups from "./simple-popups";
|
||||
import * as AccountController from "./account-controller";
|
||||
import * as Tribe from "./tribe";
|
||||
import "./caps-warning";
|
||||
import "./support-popup";
|
||||
import "./version-popup";
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import * as TimerProgress from "./timer-progress";
|
|||
import * as TestTimer from "./test-timer";
|
||||
import * as Focus from "./focus";
|
||||
import * as ShiftTracker from "./shift-tracker";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
$("#wordsInput").keypress((event) => {
|
||||
event.preventDefault();
|
||||
|
|
@ -51,6 +52,10 @@ function handleTab(event) {
|
|||
// $("#customTextPopup .textarea").val() + "\t"
|
||||
// );
|
||||
return;
|
||||
} else if (Tribe.state >= 10) {
|
||||
if (Tribe.state < 28) {
|
||||
event.preventDefault();
|
||||
}
|
||||
} else if (
|
||||
$(".pageTest").hasClass("active") &&
|
||||
!TestUI.resultCalculating &&
|
||||
|
|
@ -324,6 +329,23 @@ function handleSpace(event, isEnter) {
|
|||
}
|
||||
} //end of line wrap
|
||||
|
||||
let wpmAndRaw = TestLogic.calculateWpmAndRaw();
|
||||
|
||||
let acc = Misc.roundTo2(TestStats.calculateAccuracy());
|
||||
|
||||
let progress = 0;
|
||||
if (Config.mode === "time") {
|
||||
progress = 100 - ((TestTimer.time + 1) / Config.time) * 100;
|
||||
} else {
|
||||
let outof = TestLogic.words.length;
|
||||
if (Config.mode === "words") {
|
||||
outof = Config.words;
|
||||
}
|
||||
progress = Math.floor((TestLogic.currentWordIndex / (outof - 1)) * 100);
|
||||
}
|
||||
|
||||
Tribe.sendTestProgress(wpmAndRaw.wpm, wpmAndRaw.raw, acc, progress);
|
||||
|
||||
Caret.updatePosition();
|
||||
|
||||
if (Config.keymapMode === "react") {
|
||||
|
|
@ -754,6 +776,11 @@ $(document).keydown(function (event) {
|
|||
// if (Config.showOutOfFocusWarning) return;
|
||||
}
|
||||
|
||||
if (Tribe.state == 20) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
//tab
|
||||
if (
|
||||
(event.key == "Tab" && !Config.swapEscAndTab) ||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import * as Misc from "./misc";
|
|||
import * as Notifications from "./notifications";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as WordFilterPopup from "./word-filter-popup";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
let wrapper = "#customTextPopupWrapper";
|
||||
let popup = "#customTextPopup";
|
||||
|
|
@ -154,6 +155,7 @@ $("#customTextPopup .apply").click(() => {
|
|||
ManualRestart.set();
|
||||
TestLogic.restart();
|
||||
hide();
|
||||
Tribe.syncConfig();
|
||||
});
|
||||
|
||||
$("#customTextPopup .wordfilter").click(() => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import * as Misc from "./misc";
|
|||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import Config, * as UpdateConfig from "./config";
|
||||
import * as Settings from "./settings";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
export let active = "none";
|
||||
let memoryTimer = null;
|
||||
|
|
@ -70,8 +71,11 @@ export function toggleScript(...params) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function activate(funbox, mode) {
|
||||
if (TestLogic.active || TestUI.resultVisible) {
|
||||
export async function activate(funbox, mode, mp = false) {
|
||||
if (!Tribe.checkIfCanChangeConfig(mp)) {
|
||||
return;
|
||||
}
|
||||
if (TestLogic.active || (TestUI.resultVisible && Tribe.state < 10)) {
|
||||
Notifications.add(
|
||||
"You can only change the funbox before starting a test.",
|
||||
0
|
||||
|
|
@ -97,7 +101,7 @@ export async function activate(funbox, mode) {
|
|||
$("#wordsWrapper").removeClass("hidden");
|
||||
// }
|
||||
|
||||
if (mode === null || mode === undefined) {
|
||||
if ((mode === null || mode === undefined) && funbox !== "none") {
|
||||
let list = await Misc.getFunboxList();
|
||||
mode = list.filter((f) => f.name === funbox)[0].type;
|
||||
}
|
||||
|
|
@ -159,6 +163,7 @@ export async function activate(funbox, mode) {
|
|||
Settings.groups.layout.updateButton();
|
||||
}
|
||||
}
|
||||
Tribe.syncConfig();
|
||||
TestUI.updateModesNotice();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import * as DB from "./db";
|
|||
import * as ThemeColors from "./theme-colors";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
import * as TestLeaderboards from "./test-leaderboards";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
export let notSignedInLastResult = null;
|
||||
|
||||
|
|
@ -578,7 +579,13 @@ export async function init() {
|
|||
// }
|
||||
}
|
||||
|
||||
export function restart(withSameWordset = false, nosave = false, event) {
|
||||
export function restart(
|
||||
withSameWordset = false,
|
||||
nosave = false,
|
||||
event,
|
||||
tribe = false
|
||||
) {
|
||||
if (Tribe.state >= 10 && !tribe) return;
|
||||
if (TestUI.testRestarting || TestUI.resultCalculating) {
|
||||
try {
|
||||
event.preventDefault();
|
||||
|
|
@ -904,7 +911,7 @@ export function addWord() {
|
|||
TestUI.addWord(randomWord);
|
||||
}
|
||||
|
||||
export function finish(difficultyFailed = false) {
|
||||
export function finish(difficultyFailed = false, mp_outOfTime = false) {
|
||||
if (!active) return;
|
||||
if (Config.mode == "zen" && input.current.length != 0) {
|
||||
input.pushHistory();
|
||||
|
|
@ -950,6 +957,29 @@ export function finish(difficultyFailed = false) {
|
|||
|
||||
ChartController.result.options.annotation.annotations = [];
|
||||
|
||||
if (Tribe.state >= 10) {
|
||||
$(".pageTest #nextTestButton").addClass("hidden");
|
||||
$(".pageTest #backToLobbyButton").addClass("hidden");
|
||||
$(".pageTest #readyButton").removeClass("hidden");
|
||||
$(".pageTest #restartTestButtonWithSameWordset").addClass("hidden");
|
||||
$(".pageTest #goBackToLobbyButton").removeClass("hidden");
|
||||
$(".pageTest #practiseMissedWordsButton").addClass("hidden");
|
||||
$(".pageTest #result .tribeResultChat").removeClass("hidden");
|
||||
if (Tribe.room.isLeader) {
|
||||
// $(".pageTest #backToLobbyButton").removeClass("hidden");
|
||||
// $(".pageTest #nextTestButton").removeClass("hidden");
|
||||
$(".pageTest #readyButton").addClass("hidden");
|
||||
}
|
||||
} else {
|
||||
$(".pageTest #nextTestButton").removeClass("hidden");
|
||||
$(".pageTest #backToLobbyButton").addClass("hidden");
|
||||
$(".pageTest #readyButton").addClass("hidden");
|
||||
$(".pageTest #restartTestButtonWithSameWordset").removeClass("hidden");
|
||||
$(".pageTest #goBackToLobbyButton").addClass("hidden");
|
||||
$(".pageTest #practiseMissedWordsButton").removeClass("hidden");
|
||||
$(".pageTest #result .tribeResultChat").addClass("hidden");
|
||||
}
|
||||
|
||||
$("#result #resultWordsHistory").addClass("hidden");
|
||||
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
|
|
@ -1204,6 +1234,8 @@ export function finish(difficultyFailed = false) {
|
|||
Notifications.add("Test invalid - AFK detected", 0);
|
||||
} else if (isRepeated) {
|
||||
Notifications.add("Test invalid - repeated", 0);
|
||||
} else if (mp_outOfTime) {
|
||||
Notifications.add("Test failed - out of time", 0);
|
||||
} else if (
|
||||
(Config.mode === "time" && mode2 < 15 && mode2 > 0) ||
|
||||
(Config.mode === "time" && mode2 == 0 && testtime < 15) ||
|
||||
|
|
@ -1671,6 +1703,9 @@ export function finish(difficultyFailed = false) {
|
|||
if (difficultyFailed) {
|
||||
otherText += "<br>failed";
|
||||
}
|
||||
if (mp_outOfTime) {
|
||||
otherText += "<br>out of time";
|
||||
}
|
||||
if (afkDetected) {
|
||||
otherText += "<br>afk detected";
|
||||
}
|
||||
|
|
@ -1717,10 +1752,30 @@ export function finish(difficultyFailed = false) {
|
|||
TestUI.setResultCalculating(false);
|
||||
$("#words").empty();
|
||||
ChartController.result.resize();
|
||||
Tribe.scrollChat();
|
||||
if (Config.alwaysShowWordsHistory) {
|
||||
TestUI.toggleResultWords();
|
||||
}
|
||||
});
|
||||
Tribe.testFinished({
|
||||
wpm: stats.wpm,
|
||||
acc: stats.acc,
|
||||
raw: stats.wpmRaw,
|
||||
char: `${stats.correctChars + stats.correctSpaces}/${
|
||||
stats.incorrectChars
|
||||
}/${stats.extraChars}/${stats.missedChars}`,
|
||||
con: consistency,
|
||||
duration: testtime,
|
||||
invalid: TestStats.invalid,
|
||||
failed: difficultyFailed,
|
||||
outOfTime: mp_outOfTime,
|
||||
afk: afkDetected,
|
||||
chartData: {
|
||||
wpm: TestStats.wpmHistory,
|
||||
raw: rawWpmPerSecond,
|
||||
err: errorsArray,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function fail() {
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ export function calculateStats() {
|
|||
5
|
||||
);
|
||||
let acc = Misc.roundTo2(TestStats.calculateAccuracy());
|
||||
if (isNaN(acc)) acc = 0;
|
||||
return {
|
||||
wpm: isNaN(wpm) ? 0 : wpm,
|
||||
wpmRaw: isNaN(wpmraw) ? 0 : wpmraw,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import * as Funbox from "./funbox";
|
|||
import * as TestLogic from "./test-logic";
|
||||
import * as Caret from "./caret";
|
||||
import * as Keymap from "./keymap";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
export let time = 0;
|
||||
let timer = null;
|
||||
|
|
@ -24,6 +25,10 @@ export function start() {
|
|||
(function loop(expectedStepEnd) {
|
||||
const delay = expectedStepEnd - performance.now();
|
||||
timer = setTimeout(function () {
|
||||
if (!TestLogic.active) {
|
||||
clearTimeout(timer);
|
||||
return;
|
||||
}
|
||||
time++;
|
||||
$(".pageTest #premidSecondsLeft").text(Config.time - time);
|
||||
if (
|
||||
|
|
@ -40,6 +45,31 @@ export function start() {
|
|||
|
||||
let acc = Misc.roundTo2(TestStats.calculateAccuracy());
|
||||
|
||||
let progress = 0;
|
||||
|
||||
if (Config.mode === "time") {
|
||||
progress = 100 - ((time + 1) / Config.time) * 100;
|
||||
} else {
|
||||
let outof = TestLogic.words.length;
|
||||
if (Config.mode === "words") {
|
||||
outof = Config.words;
|
||||
}
|
||||
progress = Math.floor((TestLogic.currentWordIndex / (outof - 1)) * 100);
|
||||
}
|
||||
|
||||
Tribe.sendTestProgress(wpmAndRaw.wpm, wpmAndRaw.raw, acc, progress);
|
||||
Tribe.updateTribeDiff(wpmAndRaw.wpm);
|
||||
|
||||
if (
|
||||
Tribe.state >= 21 &&
|
||||
Tribe.state <= 28 &&
|
||||
time >= 5 &&
|
||||
TestLogic.input.current === "" &&
|
||||
TestLogic.input.getHistory().length === 0
|
||||
) {
|
||||
TestLogic.finish();
|
||||
}
|
||||
|
||||
if (Funbox.active === "layoutfluid" && Config.mode === "time") {
|
||||
const layouts = ["qwerty", "dvorak", "colemak"];
|
||||
let index = 0;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import * as Commandline from "./commandline";
|
|||
import * as OutOfFocus from "./out-of-focus";
|
||||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import * as PractiseMissed from "./practise-missed";
|
||||
import * as Tribe from "./tribe";
|
||||
import * as UI from "./ui";
|
||||
|
||||
export let currentWordElementIndex = 0;
|
||||
export let resultVisible = false;
|
||||
|
|
@ -885,13 +887,21 @@ $(document.body).on("click", "#practiseMissedWordsButton", () => {
|
|||
|
||||
$(document).on("keypress", "#nextTestButton", (event) => {
|
||||
if (event.keyCode == 13) {
|
||||
TestLogic.restart();
|
||||
if (Tribe.state >= 10) {
|
||||
Tribe.startTest();
|
||||
} else {
|
||||
TestLogic.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document.body).on("click", "#nextTestButton", () => {
|
||||
ManualRestart.set();
|
||||
TestLogic.restart();
|
||||
if (Tribe.state >= 10) {
|
||||
Tribe.startTest();
|
||||
} else {
|
||||
TestLogic.restart();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("keypress", "#showWordHistoryButton", (event) => {
|
||||
|
|
@ -926,3 +936,11 @@ $(document).on("keypress", "#restartTestButtonWithSameWordset", (event) => {
|
|||
$("#wordsWrapper").on("click", () => {
|
||||
focusWords();
|
||||
});
|
||||
|
||||
$(document).on("keypress", "#goBackToLobbyButton", (event) => {
|
||||
UI.changePage("tribe");
|
||||
});
|
||||
|
||||
$(document.body).on("click", "#goBackToLobbyButton", (event) => {
|
||||
UI.changePage("tribe");
|
||||
});
|
||||
|
|
|
|||
998
src/js/tribe.js
998
src/js/tribe.js
File diff suppressed because it is too large
Load diff
30
src/js/ui.js
30
src/js/ui.js
|
|
@ -14,6 +14,7 @@ import * as ManualRestart from "./manual-restart-tracker";
|
|||
import * as Settings from "./settings";
|
||||
import * as Account from "./account";
|
||||
import * as Leaderboards from "./leaderboards";
|
||||
import * as Tribe from "./tribe";
|
||||
|
||||
export let pageTransition = false;
|
||||
|
||||
|
|
@ -109,12 +110,21 @@ export function swapElements(
|
|||
|
||||
export function changePage(page) {
|
||||
if (pageTransition) {
|
||||
Notifications.add("Not changing page, page transition true", 0, 0, "DEBUG");
|
||||
return;
|
||||
}
|
||||
let activePage = $(".page.active");
|
||||
$(".page").removeClass("active");
|
||||
$("#wordsInput").focusout();
|
||||
if (page == "test" || page == "") {
|
||||
if (
|
||||
Tribe.state >= 20 &&
|
||||
Tribe.state <= 29 &&
|
||||
!Tribe.room.isTyping &&
|
||||
!Tribe.room.isReady &&
|
||||
!Tribe.room.isLeader
|
||||
)
|
||||
return;
|
||||
setPageTransition(true);
|
||||
swapElements(
|
||||
activePage,
|
||||
|
|
@ -193,6 +203,26 @@ export function changePage(page) {
|
|||
TestConfig.hide();
|
||||
SignOutButton.hide();
|
||||
}
|
||||
} else if (page == "tribe") {
|
||||
if (Tribe.state === 20 || Tribe.state === 21) {
|
||||
changePage("test");
|
||||
} else {
|
||||
pageTransition = true;
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageTribe"), 250, () => {
|
||||
pageTransition = false;
|
||||
Tribe.scrollChat();
|
||||
Tribe.showTestConfig();
|
||||
$(".pageTribe .lobby .chat .input input").focus();
|
||||
history.pushState("tribe", null, "tribe");
|
||||
$(".page.pageTribe").addClass("active");
|
||||
if (!Tribe.socket.connected) {
|
||||
if (Tribe.state === -1) {
|
||||
Tribe.init();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue