Skip to content

Commit b0f895f

Browse files
author
Bot
committed
various multiplayer mode bug fixes
1 parent 6ccb258 commit b0f895f

File tree

9 files changed

+66
-52
lines changed

9 files changed

+66
-52
lines changed

server/rooms.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,15 @@ module.exports = (http) => {
111111
});
112112

113113
socket.on('start', () => {
114+
rooms[roomName].playersCompleted = 0;
114115
io.in(roomName).emit('reset');
115116
socket.to(roomName).emit('start');
116117
});
117118

119+
socket.on('requestNewGame', () => {
120+
socket.to(roomName).emit('requestNewGame');
121+
});
122+
118123
socket.on('completed', () => {
119124
console.log(`player "${rooms[roomName].players[socket.id].name} completed`);
120125

@@ -143,8 +148,6 @@ module.exports = (http) => {
143148
});
144149

145150
socket.on('reset', () => {
146-
rooms[roomName].playersCompleted = 0;
147-
148151
if (rooms[roomName].players[socket.id].owner) {
149152
console.warn(`room "${roomName}" reset`);
150153
io.in(roomName).emit('reset');

src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default {
3434
isThin() {
3535
console.log('UPDATE');
3636
const { path } = this.$route;
37-
return path === '/run' || (this.innerWidth < 1300 && !this.room.connected && path !== '/');
37+
// newGameRequest exception because of webkit bug with position: fixed and transfrom http://code.google.com/p/chromium/issues/detail?id=20574
38+
return !this.room.newGameRequest && (path === '/run' || (this.innerWidth < 1300 && !this.room.connected && path !== '/'));
3839
},
3940
},
4041
created() {

src/components/NavBar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="sticky-container">
88
<div class="links" :class="{'room-connected': room.connected}">
99
<button class="link" @click="mainPage(true)">
10-
<fa :icon="['fas', 'play']" :class="{flip: $route.path === '/run'}" />
10+
<fa :icon="['fas', $route.path === '/' ? 'play' : 'home']" />
1111
<span class="btn-text">
1212
Start
1313
</span>
@@ -89,7 +89,7 @@ export default {
8989
methods: {
9090
mainPage(action = false) {
9191
if (this.$route.path === '/') {
92-
if (action && this.language.name && !this.room.connected) {
92+
if (action && this.language.name) {
9393
this.$emit('start');
9494
}
9595
} else {

src/components/PlayersList.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,22 @@ export default {
9595
// dont mutate original
9696
return [...this.playersArray].sort((p1, p2) => {
9797
console.log(p1.name, p2.name);
98-
if (p1.place && p2.place) {
99-
if (this.options.selectedMode === 0) {
100-
return p1.place - p2.place;
98+
if (this.$route.path === '/results') {
99+
if (p1.place && p2.place) {
100+
if (this.options.selectedMode === 0) {
101+
return p1.place - p2.place;
102+
}
103+
return p2.stats.correct - p1.stats.correct;
104+
}
105+
if (!p2.place) {
106+
return -1;
101107
}
102-
return p2.stats.correct - p1.stats.correct;
103108
}
104109
if (p1.owner) {
105110
console.log('owner');
106111
return -1;
107112
}
108-
if (this.$route.path === '/results') {
109-
return 1;
110-
}
113+
111114
return 0;
112115
});
113116
},

src/components/RoomPanel.vue

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
@keydown.enter="handleEnter"
5353
>
5454
</div>
55-
<p v-if="roomInfoMsg" class="info">
55+
<p v-if="roomInfoMsg && popUp" class="info">
5656
{{ roomInfoMsg }}
5757
</p>
5858
<div class="buttons">
@@ -117,7 +117,7 @@
117117

118118
<PlayersList v-if="room.connected && $route.path !== '/run'" class="playersList" />
119119

120-
<div v-if="requestNewGame && $route.path !== '/' && !room.owner" class="moveToLobby popUp">
120+
<div v-if="room.newGameRequest && !room.owner" class="moveToLobby popUp">
121121
<div class="wrapper">
122122
<h2>Room owner wants to start a new game.</h2>
123123
<h3>If you want to stay on current page {{ $route.path === '/results' ? 'and continue reading the results' : '' }} you have to leave the room. You can always join again later.</h3>
@@ -156,7 +156,6 @@ export default {
156156
origin: window.location.origin,
157157
popUp: false,
158158
hidePopUp: false,
159-
requestNewGame: false,
160159
};
161160
},
162161
computed: {
@@ -203,11 +202,6 @@ export default {
203202
console.error('PLAYER NAME TAKEN');
204203
this.roomInfoMsg = `Nick "${this.playerName}" is already taken.`;
205204
},
206-
reset() {
207-
if (this.$route.path === '/results' || this.$route.path === '/run') {
208-
this.requestNewGame = true;
209-
}
210-
},
211205
},
212206
mounted() {
213207
if (this.$route.params.roomName) {
@@ -281,7 +275,7 @@ export default {
281275
this.roomInfoMsg = '';
282276
},
283277
acceptNewGame() {
284-
this.requestNewGame = false;
278+
this.$store.commit('SET_ROOM_PROPERTY', ['newGameRequest', false]);
285279
this.$router.push('/');
286280
},
287281
},
@@ -312,33 +306,33 @@ input
312306
313307
314308
.popUp
309+
display: flex
310+
align-items: center
311+
justify-content: space-around
312+
position: fixed
313+
top: 0
314+
bottom: 0
315+
left: 0
316+
right: 0
317+
background-color: rgba($navy-grey, .7)
318+
transition: opacity 2s ease-in-out
319+
z-index: 10
320+
user-select: none
321+
pointer-events: all
322+
323+
&.hide-popUp
324+
opacity: 0
325+
326+
.wrapper
315327
display: flex
316328
align-items: center
317-
justify-content: space-around
318-
position: fixed
319-
top: 0
320-
bottom: 0
321-
left: 0
322-
right: 0
323-
background-color: rgba($navy-grey, .7)
324-
transition: opacity 2s ease-in-out
325-
z-index: 10
326-
user-select: none
327-
pointer-events: all
328-
329-
&.hide-popUp
330-
opacity: 0
331-
332-
.wrapper
333-
display: flex
334-
align-items: center
335-
flex-direction: column
336-
flex-wrap: wrap
337-
text-align: center
338-
width: 50vw
339-
340-
h2
341-
font-size: 2.5rem
329+
flex-direction: column
330+
flex-wrap: wrap
331+
text-align: center
332+
width: 50vw
333+
334+
h2
335+
font-size: 2.5rem
342336
343337
344338
.roomNotConnected

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FontAwesomeIcon, FontAwesomeLayers } from '@fortawesome/vue-fontawesome
66

77
// import only used icons to reduce bundle size
88
import {
9-
faUsers, faPlay, faInfo, faFileCode, faShareAlt, faTimes, faLink, faHeart, faServer, faUser, faSignOutAlt, faCopy, faUserCog, faCheck, faHourglassEnd, faSignal, faSlash, faCompressAlt, faExpandAlt,
9+
faUsers, faPlay, faHome, faInfo, faFileCode, faShareAlt, faTimes, faLink, faHeart, faServer, faUser, faSignOutAlt, faCopy, faUserCog, faCheck, faHourglassEnd, faSignal, faSlash, faCompressAlt, faExpandAlt,
1010
} from '@fortawesome/free-solid-svg-icons';
1111

1212
import {
@@ -17,7 +17,7 @@ import App from './App.vue';
1717
import router from './router';
1818
import store from './store';
1919

20-
library.add(faUsers, faPlay, faInfo, faFileCode, faShareAlt, faTimes, faLink, faFacebookF, faFacebookMessenger, faTwitter, faHeart, faServer, faUser, faSignOutAlt, faCopy, faUserCog, faCheck, faHourglassEnd, faSignal, faSlash, faCompressAlt, faExpandAlt);
20+
library.add(faUsers, faPlay, faHome, faInfo, faFileCode, faShareAlt, faTimes, faLink, faFacebookF, faFacebookMessenger, faTwitter, faHeart, faServer, faUser, faSignOutAlt, faCopy, faUserCog, faCheck, faHourglassEnd, faSignal, faSlash, faCompressAlt, faExpandAlt);
2121

2222
Vue.component('fa', FontAwesomeIcon);
2323
Vue.component('faStack', FontAwesomeLayers);

src/store/modules/room.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const actions = {
5151
commit('SET_ROOM_PROPERTY', ['players', playersObject]);
5252

5353
if (roomState.languageIndex) {
54-
commit('SET_LANGUAGE', rootState.other.languagesList[roomState.languageIndex]);
54+
commit('SET_LANGUAGE', rootState.misc.languagesList[roomState.languageIndex]);
5555
} else {
5656
commit('SET_LANGUAGE', {
5757
index: null,
@@ -84,7 +84,7 @@ const actions = {
8484
commit('SET_OPTION', option);
8585
},
8686
socket_languageChange({ commit, rootState }, languageIndex) {
87-
commit('SET_LANGUAGE', rootState.other.languagesList[languageIndex]);
87+
commit('SET_LANGUAGE', rootState.misc.languagesList[languageIndex]);
8888
},
8989
socket_fileIndex({ dispatch }, fileIndex) {
9090
dispatch('generateCodeInfo', fileIndex);
@@ -100,6 +100,11 @@ const actions = {
100100
commit('RESET_PLAYER', playerName);
101101
});
102102
},
103+
socket_requestNewGame({ commit, state }) {
104+
if (!state.room.players[state.room.myName].inLobby) {
105+
commit('SET_ROOM_PROPERTY', ['newGameRequest', true]);
106+
}
107+
},
103108
};
104109

105110
const mutations = {

src/views/Run.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export default {
106106
}
107107
},
108108
beforeRouteUpdate(to, from, next) {
109+
console.red('routeUpdate');
110+
109111
if (to.path === '/results') {
110112
setTimeout(() => {
111113
this.$refs.results.scrollIntoView({
@@ -122,6 +124,10 @@ export default {
122124
if (this.intervalId) {
123125
window.clearInterval(this.intervalId);
124126
}
127+
if (this.room.connected) {
128+
// reset players locally but let them finish and view results until admin clicks start again
129+
this.$store.dispatch('socket_reset');
130+
}
125131
},
126132
methods: {
127133
reset() {

src/views/Start.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export default {
174174
}
175175
176176
if (this.room.connected && !this.playersInLobby) {
177-
this.error = 'To start a new game all of the players must be in lobby';
178-
this.$socket.client.emit('reset');
177+
this.error = 'To start a new game all players must be in lobby';
178+
this.$socket.client.emit('requestNewGame');
179179
return;
180180
}
181181
@@ -276,6 +276,8 @@ export default {
276276
width: 150px
277277
height: 47px
278278
max-width: 250px
279+
&:disabled
280+
cursor: not-allowed
279281
280282
.start-btn, .ready-btn
281283
background: linear-gradient(to right, $purple, $dark-pink 50%, $navy-grey 50% 100%)

0 commit comments

Comments
 (0)