Skip to content

Commit 26f4ffc

Browse files
author
Bot
committed
various bug fixes
1 parent 4920afa commit 26f4ffc

File tree

12 files changed

+76
-72
lines changed

12 files changed

+76
-72
lines changed

public/exampleResults.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,18 +1911,21 @@
19111911
"oneThirdCharsCount": 103,
19121912
"oneThirdTime": 34888,
19131913
"lastThirdCharsCount": 53,
1914-
"lastThirdStartTime": 61622,
1914+
"lastThirdStartTime": 50622,
19151915
"timeFromFirstInput": 61782,
1916-
"codeLength": 216,
19171916
"correctLines": 12,
19181917
"mode": 0,
1919-
"file": {
1920-
"languageName": "R",
1921-
"languageIndex": 20,
1922-
"index": 0,
1918+
"codeInfo": {
1919+
"language": {
1920+
"name": "R",
1921+
"index": 20,
1922+
"ext": "r"
1923+
},
1924+
"fileIndex": 0,
19231925
"name": "factorial_of_a_number",
19241926
"source": "datamentor.io",
19251927
"tabSize": 2,
1926-
"lines": 12
1928+
"lines": 12,
1929+
"length": 216
19271930
}
19281931
}

src/components/CodeEditor.vue

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ref="codemirror"
1010
v-model="codeText"
1111
class="codemirror"
12-
:class="{showInvisibles: language.name === 'Whitespace'}"
12+
:class="{showInvisibles: codeInfo.language.name === 'Whitespace'}"
1313
:options="cmOptions"
1414
@ready="onCmReady"
1515
@blur="onUnFocus"
@@ -84,13 +84,13 @@ export default {
8484
};
8585
},
8686
computed: {
87-
...mapGetters(['language', 'options', 'codeInfo', 'customCode', 'room']),
87+
...mapGetters(['options', 'codeInfo', 'customCode', 'room']),
8888
cmOptions() {
8989
return {
90-
showInvisibles: this.language.name === 'Whitespace',
90+
showInvisibles: this.codeInfo.language.name === 'Whitespace',
9191
maxInvisibles: 2,
9292
undoDepth: 0,
93-
tabSize: this.tabWidth,
93+
tabSize: this.codeInfo.tabSize,
9494
styleActiveLine: false,
9595
lineNumbers: this.options.lineNumbers,
9696
styleSelectedText: true,
@@ -109,9 +109,6 @@ export default {
109109
readOnly: true,
110110
};
111111
},
112-
tabWidth() {
113-
return this.customCode.tabSize ? this.customCode.tabSize : this.codeInfo.tabSize;
114-
},
115112
roomPlace() {
116113
if (this.room.connected && this.isCompleted) {
117114
const { place } = this.room.players[this.room.myName];
@@ -159,6 +156,7 @@ export default {
159156
160157
const handleEnter = () => {
161158
const expectedText = this.cm.getLine(this.currentLine);
159+
162160
if (this.correctCharsInLine === expectedText.length) {
163161
this.cm.execCommand('goCharRight');
164162
this.currentLine += 1;
@@ -190,6 +188,14 @@ export default {
190188
this.stats.lastThirdStartTime = this.timeElapsed();
191189
}
192190
191+
console.blue(this.currentLine);
192+
console.red(this.cm.getLine(this.currentLine));
193+
if (this.currentLine + 1 === this.codeInfo.lines && this.cm.getLine(this.currentLine).trim().length === 0) {
194+
console.red('Last line is empty');
195+
this.stats.history.push(this.currentChange);
196+
this.completed();
197+
}
198+
193199
if (this.options.autoIndent) {
194200
this.cm.execCommand('goLineStartSmart');
195201
this.currentChar = this.cm.getCursor().ch;
@@ -200,8 +206,8 @@ export default {
200206
}
201207
if (this.options.underScore) {
202208
let underScoreWidth = 1;
203-
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(0, this.tabWidth) === Array(this.tabWidth).fill(' ').join('')) {
204-
underScoreWidth = this.tabWidth;
209+
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(0, this.codeInfo.tabSize) === Array(this.codeInfo.tabSize).fill(' ').join('')) {
210+
underScoreWidth = this.codeInfo.tabSize;
205211
}
206212
this.cm.markText(
207213
{ line: this.currentLine, ch: this.currentChar },
@@ -229,11 +235,11 @@ export default {
229235
let text = key;
230236
231237
if (key === 'Tab') {
232-
text = Array(this.tabWidth).fill(' ').join('');
238+
text = Array(this.codeInfo.tabSize).fill(' ').join('');
233239
// console.log(`tabText: '${text}'`);
234240
235-
if (expectedText === ' ' && this.language.name !== 'Whitespace') {
236-
if (lineText.slice(this.currentChar, this.currentChar + this.tabWidth) === text) {
241+
if (expectedText === ' ' && this.codeInfo.language.name !== 'Whitespace') {
242+
if (lineText.slice(this.currentChar, this.currentChar + this.codeInfo.tabSize) === text) {
237243
console.log('tab exception');
238244
expectedText = text;
239245
}
@@ -284,8 +290,8 @@ export default {
284290
} else if (this.options.underScore) {
285291
if (this.currentChar !== lineText.length) {
286292
let underScoreWidth = 1;
287-
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(this.currentChar, this.tabWidth + this.currentChar) === Array(this.tabWidth).fill(' ').join('')) {
288-
underScoreWidth = this.tabWidth;
293+
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(this.currentChar, this.codeInfo.tabSize + this.currentChar) === Array(this.codeInfo.tabSize).fill(' ').join('')) {
294+
underScoreWidth = this.codeInfo.tabSize;
289295
}
290296
this.cm.markText(
291297
{ line: this.currentLine, ch: this.currentChar },
@@ -449,8 +455,8 @@ export default {
449455
450456
if (this.options.underScore) {
451457
let underScoreWidth = 1;
452-
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(this.currentChar, this.tabWidth + this.currentChar) === Array(this.tabWidth).fill(' ').join('')) {
453-
underScoreWidth = this.tabWidth;
458+
if (!this.options.autoIndent && this.cm.getLine(this.currentLine).slice(this.currentChar, this.codeInfo.tabSize + this.currentChar) === Array(this.codeInfo.tabSize).fill(' ').join('')) {
459+
underScoreWidth = this.codeInfo.tabSize;
454460
}
455461
this.cm.markText(
456462
{ line: this.currentLine, ch: this.currentChar },
@@ -515,7 +521,7 @@ export default {
515521
if (!this.codeInfo.name) {
516522
return this.customCode.text;
517523
}
518-
const url = `/code/${this.language.name.replace('#', '_sharp')}/${this.codeInfo.name}.${this.language.ext}`;
524+
const url = `/code/${this.codeInfo.language.name.replace('#', '_sharp')}/${this.codeInfo.name}.${this.codeInfo.language.ext}`;
519525
try {
520526
const resp = await axios.get(url);
521527
return resp.data;
@@ -572,7 +578,7 @@ export default {
572578
}
573579
}, DEV ? 10 : 500);
574580
575-
Promise.all([this.getCode(), loadTheme(this.options.selectedTheme), loadMode(this.cm, this.language.mode, this.language.mime)])
581+
Promise.all([this.getCode(), loadTheme(this.options.selectedTheme), loadMode(this.cm, this.codeInfo.language.mode, this.codeInfo.language.mime)])
576582
.then((resp) => {
577583
[this.codeText] = resp;
578584
this.cmReady = true;
@@ -589,7 +595,7 @@ export default {
589595
});
590596
},
591597
async completed(devStats = false) {
592-
if (this.$route.path === '/results' || (!devStats && this.stats.history.length < 10)) {
598+
if (this.$route.path === '/results' || (!devStats && !this.codeInfo.fileIndex !== -1 && this.stats.history.length < 10)) {
593599
// TODO: disable Finish now button in Run component
594600
return;
595601
}
@@ -619,9 +625,11 @@ export default {
619625
this.stats = {
620626
...this.stats,
621627
timeFromFirstInput: this.timeElapsed(),
622-
codeLength: this.codeText.length,
623628
correctLines: this.currentLine + 1,
624-
file: this.codeInfo,
629+
codeInfo: {
630+
...this.codeInfo,
631+
length: this.codeText.length,
632+
},
625633
mode: this.options.selectedMode,
626634
complete,
627635
};

src/components/LanguagesList.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,15 @@ export default {
166166
167167
this.$nextTick(() => {
168168
const gridComputedStyle = window.getComputedStyle(this.$refs.languagesList);
169-
console.warn(gridComputedStyle.getPropertyValue('grid-template-columns'));
170169
171170
const columns = gridComputedStyle.getPropertyValue('grid-template-columns')
172-
.replace(/ 0px/g, '') // webkit bug return 0px for non existing columns
171+
.replace(/ 0px/g, '') // webkit bug returns 0px for non existing columns
173172
.split(' ').length;
174173
175-
console.log(`cells: ${this.filteredList.length + 1}`);
176-
console.log(`columns: ${columns}`);
177-
178174
const mod = (this.filteredList.length + 1) % columns;
179-
console.log(`mod: ${mod}`);
180175
181176
if (mod) {
182177
const emptyCells = columns - mod;
183-
console.blue(emptyCells);
184178
185179
this.randomBtnColSpan = emptyCells + 1;
186180
}

src/components/NavBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default {
7575
};
7676
},
7777
computed: {
78-
...mapGetters(['room', 'language', 'userLanguage']),
78+
...mapGetters(['room', 'language']),
7979
},
8080
watch: {
8181
showCopyConfirmation(current) {

src/components/RoomPanel.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export default {
261261
this.$store.commit('SET_ROOM_PROPERTY', ['name', '']);
262262
this.$store.commit('SET_ROOM_PROPERTY', ['owner', false]);
263263
this.$store.commit('SET_ROOM_PROPERTY', ['newGameRequest', false]);
264+
this.$store.commit('SET_ROOM_PROPERTY', ['players', {}]);
264265
if (action) {
265266
this.askForPlayerName = false;
266267
this.roomName = '';

src/components/charts/MixedChart.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ export default {
3030
return [{ x: 0, y: avg }, { x: this.stats.timeFromFirstInput, y: avg }];
3131
},
3232
wpmPoints() {
33-
const oneThirdTime = this.format(this.stats.oneThirdTime, 0);
33+
const oneThirdTime = this.format(this.stats.oneThirdTime);
3434
const oneThirdWPM = this.stats.oneThirdCharsCount / oneThirdTime * 60 / 5;
3535
36-
const halfCharsCount = this.stats.codeLength - this.stats.oneThirdCharsCount - this.stats.lastThirdCharsCount;
37-
const halfTime = this.format(this.stats.lastThirdStartTime - this.stats.oneThirdTime, 0);
36+
const halfCharsCount = this.stats.codeInfo.length - this.stats.oneThirdCharsCount - this.stats.lastThirdCharsCount;
37+
const halfTime = this.format(this.stats.lastThirdStartTime - this.stats.oneThirdTime, 2, 1);
3838
const halfWPM = halfCharsCount / halfTime * 60 / 5;
3939
40-
const lastThirdTime = this.format(this.stats.timeFromFirstInput - this.stats.lastThirdStartTime, 0);
40+
const lastThirdTime = this.format(this.stats.timeFromFirstInput - this.stats.lastThirdStartTime);
4141
const lastThirdWPM = this.stats.lastThirdCharsCount / lastThirdTime * 60 / 5;
4242
4343
return [
4444
{ x: 0, y: this.format(oneThirdWPM, 1, 1) },
45-
{ x: this.format(this.stats.timeFromFirstInput / 2, 0, 1), y: this.format(halfWPM, 1, 1) },
45+
{ x: this.format(this.stats.timeFromFirstInput / 2, 0, 1), y: this.format(halfWPM) },
4646
{ x: this.stats.timeFromFirstInput, y: this.format(lastThirdWPM, 1, 1) },
4747
];
4848
},

src/store/modules/misc.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,20 @@ const actions = {
4444
});
4545
},
4646
generateCodeInfo: ({ state, rootState, commit }, fileIndex) => {
47-
let codeInfo = {};
47+
let codeInfo = { language: rootState.options.language }; // copy without reference
48+
delete codeInfo.files;
49+
4850
if (fileIndex === -1) {
49-
codeInfo.tabSize = state.customCode.lines;
51+
codeInfo.tabSize = state.customCode.tabSize;
5052
codeInfo.lines = state.customCode.lines;
5153
codeInfo.short = state.customCode.short;
5254
} else {
53-
codeInfo = rootState.options.language.files[fileIndex];
55+
codeInfo = {
56+
...codeInfo,
57+
...rootState.options.language.files[fileIndex],
58+
};
5459
}
55-
codeInfo.index = fileIndex;
56-
codeInfo.languageIndex = rootState.options.language.index;
57-
codeInfo.languageName = rootState.options.language.name;
60+
codeInfo.fileIndex = fileIndex;
5861

5962
commit('SET_CODE_INFO', codeInfo);
6063
},

src/store/modules/options.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getField, updateField } from 'vuex-map-fields';
22

33
const state = {
4-
userLanguage: false,
54
language: {
65
index: null,
76
name: '',
@@ -17,7 +16,6 @@ const state = {
1716
};
1817

1918
const getters = {
20-
userLanguage: (state) => state.userLanguage,
2119
language: (state) => state.language,
2220
options: (state) => state.options,
2321
getLanguage: (state) => getField(state),
@@ -27,9 +25,6 @@ const getters = {
2725
const actions = {};
2826

2927
const mutations = {
30-
USER_LANGUAGE: (state) => {
31-
state.userLanguage = !state.userLanguage;
32-
},
3328
SET_LANGUAGE: (state, languageObj) => {
3429
state.language = languageObj;
3530
},

src/store/modules/room.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ const getters = {
1818
const actions = {
1919
socket_playerDisconnected({ commit }, msg) {
2020
if (msg.owner) {
21-
commit('SET_ROOM_PROPERTY', ['connected', false]);
22-
2321
console.log('admin disconnected');
2422
this._vm.$socket.client.disconnect();
23+
commit('SET_ROOM_PROPERTY', ['connected', false]);
24+
commit('SET_ROOM_PROPERTY', ['name', '']);
25+
commit('SET_ROOM_PROPERTY', ['owner', false]);
26+
commit('SET_ROOM_PROPERTY', ['newGameRequest', false]);
27+
commit('SET_ROOM_PROPERTY', ['players', {}]);
2528
}
2629

2730
commit('PLAYER_LOST_CONNECTION', {

src/views/Results.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</template>
4949
<template v-else>
5050
<p>You made a mistake after {{ correctInputs }} correct characters</p>
51-
<p>{{ stats.file.lines - stats.correctLines }} lines left</p>
51+
<p>{{ stats.codeInfo.lines - stats.correctLines }} lines left</p>
5252
<p>{{ percentCompleted }}% completed</p>
5353
</template>
5454
</div>
@@ -132,7 +132,7 @@ export default {
132132
return this.CPM / 5;
133133
},
134134
percentCompleted() {
135-
return this.format(this.correctLines / this.stats.file.lines, 1, 100);
135+
return this.format(this.correctLines / this.stats.codeInfo.lines, 1, 100);
136136
},
137137
mostMistakesInARow() {
138138
return this.mistakes.map((obj) => obj.fixQueuePos)
@@ -182,8 +182,8 @@ export default {
182182
correct: this.correctInputs,
183183
});
184184
185-
// if (this.stats.file.index !== -1) {
186-
if (this.$route.path !== '/about' && !this.stats.file.short) {
185+
// if (this.stats.codeInfo.index !== -1) {
186+
if (this.$route.path !== '/about' && !this.stats.codeInfo.short) {
187187
this.sendStats();
188188
}
189189
// }
@@ -212,9 +212,9 @@ export default {
212212
}
213213
const data = {
214214
main: {
215-
languageIndex: this.stats.file.languageIndex,
216-
languageName: this.stats.file.languageName,
217-
fileIndex: this.stats.file.index,
215+
languageIndex: this.stats.codeInfo.language.index,
216+
languageName: this.stats.codeInfo.language.name,
217+
fileIndex: this.stats.codeInfo.fileIndex,
218218
wpm: this.format(this.WPM, 0, 1),
219219
percentCompleted: this.percentCompleted,
220220
},

0 commit comments

Comments
 (0)