Skip to content

Commit 183a21e

Browse files
authored
Merge pull request #51 from encap/dev
Dev
2 parents 6ccb258 + f7199ee commit 183a21e

File tree

12 files changed

+115
-59
lines changed

12 files changed

+115
-59
lines changed

public/code/Python/UrlParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@property
1+
@property
22
def port(self):
33
port = self._hostinfo[1]
44
if port is not None:

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default {
3232
computed: {
3333
...mapGetters(['room', 'trackedContainers', 'smallScreen']),
3434
isThin() {
35-
console.log('UPDATE');
3635
const { path } = this.$route;
37-
return path === '/run' || (this.innerWidth < 1300 && !this.room.connected && path !== '/');
36+
// newGameRequest exception because of webkit bug with position: fixed and transfrom http://code.google.com/p/chromium/issues/detail?id=20574
37+
return !this.room.newGameRequest && (path === '/run' || (this.innerWidth < 1300 && !this.room.connected && path !== '/'));
3838
},
3939
},
4040
created() {

src/components/CodeEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@blur="onUnFocus"
1616
/>
1717
</div>
18-
<div class="pop-up" :class="{hidden: !showPopUp, clickable: popUpClickable, 'small-font': popUpText.length > 15}">
18+
<div class="pop-up" :class="{hidden: !showPopUp || room.newGameRequest, clickable: popUpClickable && !room.newGameRequest, 'small-font': popUpText.length > 15}">
1919
<div>
2020
<p v-show="popUpText === 'Try again'" class="hardcore-info">
2121
We can't generate accurate results from this round.

src/components/LanguagesList.vue

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
type="text"
77
placeholder="Search"
88
class="searchInput"
9+
:disabled="room.connected && !room.admin"
910
maxlength="12"
1011
autofocus
1112
@keydown.enter.stop="selectFirstFromSearch"
@@ -26,8 +27,9 @@
2627
>
2728
<button
2829
:disabled="room.connected && !room.owner"
29-
class="language random"
30+
class="language random-btn"
3031
:class="{'selected': language.index === null}"
32+
:style="{'--col-span': randomBtnColSpan}"
3133
@click="selectRandom"
3234
>
3335
<span class="language-name">
@@ -70,6 +72,7 @@ export default {
7072
return {
7173
searchText: '',
7274
forceStats: false,
75+
randomBtnColSpan: 1,
7376
};
7477
},
7578
computed: {
@@ -81,9 +84,13 @@ export default {
8184
const filtered = this.languagesList
8285
.filter((language) => language.name.toLowerCase().includes(search))
8386
.sort((a, b) => (b.name.toLowerCase().startsWith(search) ? 1 : -1));
84-
return filtered.length > 0 ? filtered : this.languagesList;
87+
return filtered.length === 0 ? this.languagesList : filtered;
8588
}
86-
return [...Array(29)].map(() => ({ name: 'Loading...' }));
89+
return [...Array(33)].map(() => ({ name: '...' }));
90+
},
91+
fillEmptyCellsReference() {
92+
// .bind spawns new reference and will not work with removeEventListener without saving it here
93+
return this.fillEmptyCells.bind(this);
8794
},
8895
},
8996
watch: {
@@ -106,12 +113,18 @@ export default {
106113
}
107114
},
108115
},
116+
filteredList() {
117+
this.fillEmptyCells();
118+
},
109119
},
110120
activated() {
111121
this.$store.commit('ADD_TRACKED_CONTAINER', this.$refs.languagesList);
122+
window.addEventListener('resize', this.fillEmptyCellsReference);
112123
},
113124
deactivated() {
114125
this.$store.commit('REMOVE_TRACKED_CONTAINER', this.$refs.languagesList.className);
126+
console.log('DEACTIVATED');
127+
window.removeEventListener('resize', this.fillEmptyCellsReference);
115128
},
116129
methods: {
117130
clear() {
@@ -147,6 +160,32 @@ export default {
147160
this.$nextTick(() => this.$socket.client.emit('languageChange', ev.target.getAttribute('data-index')));
148161
}
149162
},
163+
fillEmptyCells() {
164+
// randomBtn prevents shrinking
165+
this.randomBtnColSpan = 1;
166+
167+
this.$nextTick(() => {
168+
const gridComputedStyle = window.getComputedStyle(this.$refs.languagesList);
169+
console.warn(gridComputedStyle.getPropertyValue('grid-template-columns'));
170+
171+
const columns = gridComputedStyle.getPropertyValue('grid-template-columns')
172+
.replace(/ 0px/g, '') // webkit bug return 0px for non existing columns
173+
.split(' ').length;
174+
175+
console.log(`cells: ${this.filteredList.length + 1}`);
176+
console.log(`columns: ${columns}`);
177+
178+
const mod = (this.filteredList.length + 1) % columns;
179+
console.log(`mod: ${mod}`);
180+
181+
if (mod) {
182+
const emptyCells = columns - mod;
183+
console.blue(emptyCells);
184+
185+
this.randomBtnColSpan = emptyCells + 1;
186+
}
187+
});
188+
},
150189
toggleStats() {
151190
this.forceStats = !this.forceStats;
152191
},
@@ -211,12 +250,15 @@ export default {
211250
.language-radio
212251
display: none
213252
214-
.showStats .language:hover:not(.random), .forceStats .language:not(.random)
253+
.showStats .language:hover:not(.random-btn), .forceStats .language:not(.random-btn)
215254
& > .language-name
216255
transform: translateX(-25%)
217256
& > .stat
218257
opacity: 1
219258
259+
.random-btn
260+
grid-column-start: span var(--col-span)
261+
220262
.language
221263
display: flex
222264
align-items: center

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: 29 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) {
@@ -266,6 +260,7 @@ export default {
266260
this.$store.commit('SET_ROOM_PROPERTY', ['connected', false]);
267261
this.$store.commit('SET_ROOM_PROPERTY', ['name', '']);
268262
this.$store.commit('SET_ROOM_PROPERTY', ['owner', false]);
263+
this.$store.commit('SET_ROOM_PROPERTY', ['newGameRequest', false]);
269264
if (action) {
270265
this.askForPlayerName = false;
271266
this.roomName = '';
@@ -281,7 +276,7 @@ export default {
281276
this.roomInfoMsg = '';
282277
},
283278
acceptNewGame() {
284-
this.requestNewGame = false;
279+
this.$store.commit('SET_ROOM_PROPERTY', ['newGameRequest', false]);
285280
this.$router.push('/');
286281
},
287282
},
@@ -312,33 +307,33 @@ input
312307
313308
314309
.popUp
310+
display: flex
311+
align-items: center
312+
justify-content: space-around
313+
position: fixed
314+
top: 0
315+
bottom: 0
316+
left: 0
317+
right: 0
318+
background-color: rgba($navy-grey, .7)
319+
transition: opacity 2s ease-in-out
320+
z-index: 10
321+
user-select: none
322+
pointer-events: all
323+
324+
&.hide-popUp
325+
opacity: 0
326+
327+
.wrapper
315328
display: flex
316329
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
330+
flex-direction: column
331+
flex-wrap: wrap
332+
text-align: center
333+
width: 50vw
334+
335+
h2
336+
font-size: 2.5rem
342337
343338
344339
.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 = {

0 commit comments

Comments
 (0)