showing current config, fixed auto join

This commit is contained in:
Jack 2020-10-12 17:59:55 +01:00
parent 12fcfb96a5
commit 43cc2fd1c2
5 changed files with 198 additions and 16 deletions

View file

@ -2305,7 +2305,7 @@ key {
}
.lobby{
display: grid;
grid-template-areas: "currentsettings currentsettings"
grid-template-areas: "currentsettings lobbyButtons"
"chat userlist"
"inviteLink inviteLink";
gap: 2rem;
@ -2313,8 +2313,25 @@ key {
.title{
color: var(--sub-color);
}
.lobbyButtons{
grid-area: lobbyButtons;
}
.currentSettings{
grid-area: currentsettings;
.groups{
display: grid;
// grid-auto-flow: column;
justify-items: center;
grid-template-columns: 1fr 1fr 1fr 1fr;
.group{
padding: .5rem;
color: var(--text-color);
.fas,.far{
margin-right: .5rem;
color: var(--main-color);
}
}
}
}
.chat{
grid-area: chat;

View file

@ -3017,7 +3017,11 @@
</div>
<div class="lobby hidden">
<div class="currentSettings">
<div class="title"></div>
<div class="title">current settings</div>
<div class="groups"></div>
</div>
<div class="lobbyButtons">
<div class="button"><i class="fas fa-door-open"></i>Leave room</div>
</div>
<div class="chat">
<div class="title">chat</div>

View file

@ -256,11 +256,20 @@ firebase.auth().onAuthStateChanged(function (user) {
} else {
console.log('user is not logged in');
}
if (!MP.socket.connected) {
if (MP.state === -1) {
mp_init();
setTimeout(f => {
if (/\/tribe_.+/.test(window.location.pathname)) {
changePage('tribe');
let code = window.location.pathname.split('/')[1];
code = code.substring(5);
code = "room" + code;
MP.autoJoin = code;
}
}
if (!MP.socket.connected && MP.autoJoin != undefined) {
if (MP.state === -1) {
mp_init();
}
}
}, 250);
});
function getAccountDataAndInit() {

View file

@ -2836,7 +2836,7 @@ function changePage(page) {
pageTransition = false;
history.pushState("tribe", null, "tribe");
$(".page.pageTribe").addClass("active");
if (!MP.socket.connected && firebase.auth().currentUser !== null) {
if (!MP.socket.connected) {
if (MP.state === -1) {
mp_init();
}
@ -4883,11 +4883,7 @@ $(document).ready(() => {
history.replaceState("/", null, "/");
} else if (window.location.pathname !== "/") {
if (/\/tribe_.+/.test(window.location.pathname)) {
changePage('tribe');
let code = window.location.pathname.split('/')[1];
code = code.substring(5);
code = "room" + code;
MP.autoJoin = code;
} else {
let page = window.location.pathname.replace("/", "");
changePage(page);

View file

@ -36,6 +36,14 @@ function mp_resetLobby(){
}
function mp_applyRoomConfig(cfg) {
changeMode(cfg.mode);
if (cfg.mode === "time") {
changeTimeConfig(cfg.mode2);
} else if (cfg.mode === "words") {
changeWordCount(cfg.mode2);
} else if (cfg.mode === "quote") {
changeQuoteLength(cfg.mode2);
}
setDifficulty(cfg.difficulty, true);
setBlindMode(cfg.blindMode, true);
changeLanguage(cfg.language, true);
@ -44,6 +52,132 @@ function mp_applyRoomConfig(cfg) {
setConfidenceMode(cfg.confidenceMode, true);
}
function mp_refreshConfig() {
$(".pageTribe .lobby .currentSettings .groups").empty();
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Mode" data-balloon-pos="up">
<i class="fas fa-bars"></i>${MP.room.config.mode}
</div>
`);
if (MP.room.config.mode === "time") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Time" data-balloon-pos="up">
<i class="fas fa-clock"></i>${MP.room.config.mode2}
</div>
`);
} else if (MP.room.config.mode === "words") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Words" data-balloon-pos="up">
<i class="fas fa-font"></i>${MP.room.config.mode2}
</div>
`);
} else if (MP.room.config.mode === "quote") {
let qstring = "all";
let num = MP.room.config.mode2;
if (num == 0) {
qstring = "short";
} else if (num == 1) {
qstring = "medium";
} else if (num == 2) {
qstring = "long";
} else if (num == 3) {
qstring = "thicc";
}
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Quote length" data-balloon-pos="up">
<i class="fas fa-quote-right"></i>${qstring}
</div>
`);
}
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Language" data-balloon-pos="up">
<i class="fas fa-globe-americas"></i>${MP.room.config.language}
</div>
`);
if (MP.room.config.difficulty === "normal") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Difficulty" data-balloon-pos="up">
<i class="far fa-star"></i>normal
</div>
`);
} else if (MP.room.config.difficulty === "expert") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Difficulty" data-balloon-pos="up">
<i class="fas fa-star-half-alt"></i>expert
</div>
`);
} else if (MP.room.config.difficulty === "master"){
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Difficulty" data-balloon-pos="up">
<i class="fas fa-star"></i>master
</div>
`);
}
if (MP.room.config.blindMode) {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Blind mode" data-balloon-pos="up">
<i class="fas fa-eye-slash"></i>blind
</div>
`);
} else {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Blind mode" data-balloon-pos="up">
<i class="fas fa-eye-slash"></i>off
</div>
`);
}
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Funbox" data-balloon-pos="up">
<i class="fas fa-gamepad"></i>${MP.room.config.funbox}
</div>
`);
if (MP.room.config.confidenceMode === "off") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Confidence mode" data-balloon-pos="up">
<i class="fas fa-backspace"></i>off
</div>
`);
} else if (MP.room.config.confidenceMode === "on") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Confidence mode" data-balloon-pos="up">
<i class="fas fa-backspace"></i>confidence
</div>
`);
} else if (MP.room.config.confidenceMode === "max"){
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Confidence mode" data-balloon-pos="up">
<i class="fas fa-backspace"></i>max
</div>
`);
}
if (MP.room.config.stopOnError === "off") {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Stop on error" data-balloon-pos="up">
<i class="fas fa-hand-paper"></i>off
</div>
`);
} else {
$(".pageTribe .lobby .currentSettings .groups").append(`
<div class='group' aria-label="Stop on error" data-balloon-pos="up">
<i class="fas fa-hand-paper"></i>stop on ${MP.room.config.stopOnError}
</div>
`);
}
}
MP.socket.on('connect', (f) => {
MP.state = 1;
MP.reconnectionAttempts = 0;
@ -55,12 +189,15 @@ MP.socket.on('connect', (f) => {
MP.id = MP.socket.id;
MP.name = name;
MP.socket.emit("mp_system_name_set", { name: name });
$(".pageTribe .lobby div").removeClass('hidden');
$(".pageTribe .prelobby div").removeClass('hidden');
if (MP.autoJoin) {
MP.socket.emit("mp_room_join", { roomId: MP.autoJoin });
MP.autoJoin = undefined;
swapElements($(".pageTribe .preloader"), $(".pageTribe .lobby"), 250);
} else {
swapElements($(".pageTribe .preloader"), $(".pageTribe .prelobby"), 250);
}
$(".pageTribe .prelobby .button").removeClass('hidden');
swapElements($(".pageTribe .preloader"), $(".pageTribe .prelobby"), 250);
})
MP.socket.on('disconnect', (f) => {
@ -110,17 +247,26 @@ MP.socket.on('mp_room_joined', data => {
MP.room.isLeader = true;
}
mp_refreshUserList();
mp_applyRoomConfig(MP.room.config);
if (MP.state === 10) {
//user is already in the room and somebody joined
} else if(MP.state === 1) {
//user is in prelobby and joined a room
mp_applyRoomConfig(MP.room.config);
mp_refreshConfig();
let link = "www.monkey-type.com/tribe" + MP.room.id.substring(4);
$(".pageTribe .lobby .inviteLink").text(link);
swapElements($(".pageTribe .prelobby"), $(".pageTribe .lobby"), 250, () => {MP.state = 10});
swapElements($(".pageTribe .prelobby"), $(".pageTribe .lobby"), 250, () => {
MP.state = 10;
// $(".pageTribe .prelobby").addClass('hidden');
});
}
})
MP.socket.on('mp_room_user_left', data => {
MP.room = data.room;
mp_refreshUserList();
})
MP.socket.on('mp_chat_message', data => {
let cls = "message";
let author = '';
@ -144,8 +290,18 @@ $(".pageTribe #createPrivateRoom").click(f => {
activateFunbox("none");
changeLanguage("english");
changeMode("quote");
let mode2;
if (config.mode === "time") {
mode2 = config.time;
} else if (config.mode === "words") {
mode2 = config.words;
} else if (config.mode === "quote") {
mode2 = config.quoteLength === undefined ? "-1" : config.quoteLength;
}
MP.socket.emit("mp_room_create", {
config: {
mode: config.mode,
mode2: mode2,
difficulty: config.difficulty,
blindMode: config.blindMode,
language: config.language,