guess-the-year-web-component 3.0.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -5
- package/custom-elements.json +2 -2
- package/dist/guess-the-year.d.ts +4 -1
- package/dist/guess-the-year.d.ts.map +1 -1
- package/dist/guess-the-year.js +44 -21
- package/dist/guess-the-year.js.map +1 -1
- package/dist/index.html +2 -2
- package/dist/lib/ApiService.d.ts +2 -1
- package/dist/lib/ApiService.d.ts.map +1 -1
- package/dist/lib/ApiService.js +5 -1
- package/dist/lib/ApiService.js.map +1 -1
- package/dist/lib/Incident.d.ts.map +1 -1
- package/dist/lib/Incident.js +1 -0
- package/dist/lib/Incident.js.map +1 -1
- package/dist/lib/Util.d.ts +1 -0
- package/dist/lib/Util.d.ts.map +1 -1
- package/dist/lib/Util.js +25 -0
- package/dist/lib/Util.js.map +1 -1
- package/dist/lib/i18n/EN.d.ts.map +1 -1
- package/dist/lib/i18n/EN.js +5 -0
- package/dist/lib/i18n/EN.js.map +1 -1
- package/dist/lib/i18n/NL.d.ts.map +1 -1
- package/dist/lib/i18n/NL.js +7 -1
- package/dist/lib/i18n/NL.js.map +1 -1
- package/dist/main.js +35 -31
- package/package.json +1 -1
- package/src/guess-the-year.ts +49 -25
- package/src/index.html +2 -2
- package/src/lib/ApiService.ts +6 -1
- package/src/lib/Incident.ts +1 -0
- package/src/lib/Util.ts +25 -5
- package/src/lib/i18n/EN.ts +5 -0
- package/src/lib/i18n/NL.ts +7 -1
- package/todo.txt +0 -6
package/package.json
CHANGED
package/src/guess-the-year.ts
CHANGED
|
@@ -13,13 +13,20 @@ import stylesheet from "./scss/main.scss";
|
|
|
13
13
|
import { QuestionScoreController } from "./lib/controller/scorecontroller";
|
|
14
14
|
|
|
15
15
|
const SPLASH_DELAY: number = 1000;
|
|
16
|
-
const MIN_YEAR: number = 1950;
|
|
17
|
-
const MAX_YEAR: number = 2024;
|
|
18
16
|
const MAX_QUESTIONS: number = 10;
|
|
19
17
|
const HINT_COST: number = 2;
|
|
18
|
+
const MIN_YEAR: number = 1950;
|
|
19
|
+
const MAX_YEAR: number = parseInt(dayjs().format('YYYY'), 10);
|
|
20
|
+
const GTY_FROM_YEAR_VAR = 'gty-from-year';
|
|
21
|
+
const GTY_TO_YEAR_VAR = 'gty-to-year';
|
|
22
|
+
const GTY_NUM_QUESTIONS_VAR = 'gty-number-of-questions';
|
|
23
|
+
const MAX_DOB: number = 1915;
|
|
24
|
+
const MIN_DOB: number = parseInt(dayjs().format('YYYY'), 10) - 10;
|
|
25
|
+
const GTY_PLAYER_DOB_VAR = 'gty-player-dob';
|
|
20
26
|
|
|
21
27
|
@customElement("guess-the-year")
|
|
22
28
|
export class GuessTheYear extends LitElement {
|
|
29
|
+
|
|
23
30
|
private sources: Array<string> = [];
|
|
24
31
|
private _loading = false;
|
|
25
32
|
|
|
@@ -75,7 +82,7 @@ export class GuessTheYear extends LitElement {
|
|
|
75
82
|
},
|
|
76
83
|
},
|
|
77
84
|
})
|
|
78
|
-
from: Dayjs = dayjs(`${MIN_YEAR}-01-01`, "YYYY-MM-DD");
|
|
85
|
+
from: Dayjs = dayjs(`${window.localStorage.getItem(GTY_FROM_YEAR_VAR) || MIN_YEAR}-01-01`, "YYYY-MM-DD");
|
|
79
86
|
|
|
80
87
|
@property({
|
|
81
88
|
type: Dayjs,
|
|
@@ -98,7 +105,7 @@ export class GuessTheYear extends LitElement {
|
|
|
98
105
|
},
|
|
99
106
|
},
|
|
100
107
|
})
|
|
101
|
-
to: Dayjs = dayjs()
|
|
108
|
+
to: Dayjs = dayjs(`${window.localStorage.getItem(GTY_TO_YEAR_VAR) || MAX_YEAR}-01-01`, "YYYY-MM-DD");
|
|
102
109
|
|
|
103
110
|
@property({ type: String, attribute: "no-image-src" })
|
|
104
111
|
noImageSrc: string = "";
|
|
@@ -110,9 +117,11 @@ export class GuessTheYear extends LitElement {
|
|
|
110
117
|
maxHints: number = 3;
|
|
111
118
|
|
|
112
119
|
@property({ type: Number, attribute: "number-of-questions", reflect: true })
|
|
113
|
-
numberOfQuestions: number = 10;
|
|
120
|
+
numberOfQuestions: number = parseInt(window.localStorage.getItem(GTY_NUM_QUESTIONS_VAR) || MAX_QUESTIONS + '', 10);
|
|
114
121
|
private _numberOfQuestionsSeen: number = 0;
|
|
115
122
|
|
|
123
|
+
private _playerDob: number = parseInt(window.localStorage.getItem(GTY_PLAYER_DOB_VAR) || 0 + '', 10);
|
|
124
|
+
|
|
116
125
|
@state()
|
|
117
126
|
private _incident: Incident | undefined = undefined;
|
|
118
127
|
|
|
@@ -259,12 +268,12 @@ export class GuessTheYear extends LitElement {
|
|
|
259
268
|
|
|
260
269
|
// renders a selector for a year
|
|
261
270
|
// TODO: set type of selector
|
|
262
|
-
private
|
|
271
|
+
private _renderYearStepXSelectOptions(from: number, to: number, step: number, selectedValue: string): TemplateResult {
|
|
263
272
|
const selected = parseInt(selectedValue, 10);
|
|
264
273
|
// pre-render year options
|
|
265
274
|
// and mark selected when they match
|
|
266
275
|
const selectYearOptions = [];
|
|
267
|
-
for (let i =
|
|
276
|
+
for (let i = from; i <= to; i += step) {
|
|
268
277
|
selectYearOptions.push(html`
|
|
269
278
|
<option value="${i}" ?selected=${selected == i}>${i}</option>
|
|
270
279
|
`);
|
|
@@ -311,21 +320,21 @@ export class GuessTheYear extends LitElement {
|
|
|
311
320
|
|
|
312
321
|
<div class="game-settings">
|
|
313
322
|
<p>
|
|
323
|
+
${this.i18n.translate("game-settings-p0")}
|
|
324
|
+
<select @change="${this._setPlayerDob}">
|
|
325
|
+
${this._renderYearStepXSelectOptions(MAX_DOB, MIN_DOB, 1, this._playerDob + '')}
|
|
326
|
+
</select>
|
|
314
327
|
${this.i18n.translate("game-settings-p1")}
|
|
315
|
-
<select
|
|
316
|
-
@change="${(event: any) => {
|
|
317
|
-
this.numberOfQuestions = Number(event.target.value);
|
|
318
|
-
}}"
|
|
319
|
-
>
|
|
328
|
+
<select @change="${this._setNumberOfQuestions}">
|
|
320
329
|
${selectQuestionOptions}
|
|
321
330
|
</select>
|
|
322
331
|
${this.i18n.translate("game-settings-p2")}
|
|
323
332
|
<select @change="${this._setFromDate}">
|
|
324
|
-
${this.
|
|
333
|
+
${this._renderYearStepXSelectOptions(MIN_YEAR, MAX_YEAR, 5, this.from.format("YYYY"))}
|
|
325
334
|
</select>
|
|
326
335
|
${this.i18n.translate("game-settings-p3")}
|
|
327
336
|
<select @change="${this._setToDate}">
|
|
328
|
-
${this.
|
|
337
|
+
${this._renderYearStepXSelectOptions(MIN_YEAR, MAX_YEAR, 5, this.to.format("YYYY"))}
|
|
329
338
|
</select>
|
|
330
339
|
${this.i18n.translate("game-settings-p4")}
|
|
331
340
|
</p>
|
|
@@ -337,13 +346,24 @@ export class GuessTheYear extends LitElement {
|
|
|
337
346
|
</div>
|
|
338
347
|
`;
|
|
339
348
|
}
|
|
349
|
+
private _setPlayerDob(event: any): void {
|
|
350
|
+
this._playerDob = Number(event.target.value);
|
|
351
|
+
window.localStorage.setItem(GTY_PLAYER_DOB_VAR, this._playerDob + '');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private _setNumberOfQuestions(event: any): void {
|
|
355
|
+
this.numberOfQuestions = Number(event.target.value);
|
|
356
|
+
window.localStorage.setItem(GTY_NUM_QUESTIONS_VAR, this.numberOfQuestions + '');
|
|
357
|
+
}
|
|
340
358
|
|
|
341
359
|
private _setFromDate(event: any): void {
|
|
342
360
|
this.from = this.from.year(event.target.value);
|
|
361
|
+
window.localStorage.setItem(GTY_FROM_YEAR_VAR, this.from.format('YYYY') + '');
|
|
343
362
|
}
|
|
344
363
|
|
|
345
364
|
private _setToDate(event: any): void {
|
|
346
365
|
this.to = this.to.year(event.target.value);
|
|
366
|
+
window.localStorage.setItem(GTY_TO_YEAR_VAR, this.to.format('YYYY') + '');
|
|
347
367
|
}
|
|
348
368
|
|
|
349
369
|
// renders the actual game stage
|
|
@@ -407,7 +427,10 @@ export class GuessTheYear extends LitElement {
|
|
|
407
427
|
`;
|
|
408
428
|
}
|
|
409
429
|
|
|
410
|
-
|
|
430
|
+
// Preserve html structure to prevent the webcomponent to collapse.
|
|
431
|
+
return html`<div class="incident--image">
|
|
432
|
+
<img/>
|
|
433
|
+
</div>`;
|
|
411
434
|
}
|
|
412
435
|
|
|
413
436
|
// renders a list of possible answers
|
|
@@ -539,6 +562,11 @@ export class GuessTheYear extends LitElement {
|
|
|
539
562
|
|
|
540
563
|
this.totalScore += score;
|
|
541
564
|
|
|
565
|
+
// Fire-and-forget recallability feedback.
|
|
566
|
+
if (this._incident?.id) {
|
|
567
|
+
this._apiService.incidentRecallability(this._incident?.id, this._playerDob, is_correct);
|
|
568
|
+
}
|
|
569
|
+
|
|
542
570
|
if (is_correct) {
|
|
543
571
|
return html`
|
|
544
572
|
<div class="feedback">
|
|
@@ -599,8 +627,6 @@ export class GuessTheYear extends LitElement {
|
|
|
599
627
|
}
|
|
600
628
|
|
|
601
629
|
private renderGameEnd(): TemplateResult {
|
|
602
|
-
// clearInterval(this._scoreIntervalHandler);
|
|
603
|
-
|
|
604
630
|
console.debug("renderGameEnd");
|
|
605
631
|
return html`
|
|
606
632
|
${this._renderHeader("The end!")}
|
|
@@ -612,10 +638,6 @@ export class GuessTheYear extends LitElement {
|
|
|
612
638
|
`;
|
|
613
639
|
}
|
|
614
640
|
|
|
615
|
-
// private _incidentsStack = [];
|
|
616
|
-
|
|
617
|
-
// private _totalScore: number = 0;
|
|
618
|
-
|
|
619
641
|
private setupNewGame(): void {
|
|
620
642
|
console.debug("new game!");
|
|
621
643
|
|
|
@@ -628,14 +650,10 @@ export class GuessTheYear extends LitElement {
|
|
|
628
650
|
this.totalScore = 0;
|
|
629
651
|
this._numberOfQuestionsSeen = 0;
|
|
630
652
|
|
|
631
|
-
// this._question.load(this.from.format('YYYY'), this.to.format('YYYY'));
|
|
632
|
-
// this._question.init();
|
|
633
|
-
|
|
634
653
|
this._loadQuestion();
|
|
635
654
|
}
|
|
636
655
|
|
|
637
656
|
private _resetStage(): void {
|
|
638
|
-
// window.scrollTo(0, 0);
|
|
639
657
|
this.sources = [];
|
|
640
658
|
this._incident = undefined;
|
|
641
659
|
this._hints = [];
|
|
@@ -763,6 +781,12 @@ export class GuessTheYear extends LitElement {
|
|
|
763
781
|
hintTemplates[0]
|
|
764
782
|
).replace(/__TITLE__/, hintIncident.title || hintIncident.text);
|
|
765
783
|
break;
|
|
784
|
+
case Category.tvShowOrSeries:
|
|
785
|
+
hint = (
|
|
786
|
+
hintTemplates[Math.round(Math.random() * hintTemplates.length)] ||
|
|
787
|
+
hintTemplates[0]
|
|
788
|
+
).replace(/__TITLE__/, hintIncident.title || hintIncident.text);
|
|
789
|
+
break;
|
|
766
790
|
case Category.sports:
|
|
767
791
|
hint = (
|
|
768
792
|
hintTemplates[Math.round(Math.random() * hintTemplates.length)] ||
|
package/src/index.html
CHANGED
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
--guess-the-year-title-background-color: orange;
|
|
37
37
|
--guess-the-year-title-color: white;
|
|
38
38
|
/* --guess-the-year-text-position: static; */
|
|
39
|
-
--guess-the-year-text-
|
|
40
|
-
--guess-the-year-text-color:
|
|
39
|
+
/* --guess-the-year-text-color: white;
|
|
40
|
+
--guess-the-year-text-background-color: rgb(3, 78, 3); */
|
|
41
41
|
--guess-the-year-text-max-height: 200px;
|
|
42
42
|
--guess-the-year-tile-min-height: 500px;
|
|
43
43
|
--guess-the-year-tile-max-height: 90vh;
|
package/src/lib/ApiService.ts
CHANGED
|
@@ -127,7 +127,7 @@ export class ApiService {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// post feedback about an incident.
|
|
130
|
-
public async
|
|
130
|
+
public async postIncidentFeedback(incidentid: string, remark: string) {
|
|
131
131
|
const url = `${this.teeeApiUrl}/feedback/${incidentid}/remark`;
|
|
132
132
|
await fetch(url, {
|
|
133
133
|
method: "POST",
|
|
@@ -140,6 +140,11 @@ export class ApiService {
|
|
|
140
140
|
}),
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
// Post the recallability of this incident by the player.
|
|
145
|
+
public async incidentRecallability(incidentid: string, dob: number, is_correct: boolean) {
|
|
146
|
+
this.postIncidentFeedback(incidentid, `recall:absolute-year:${Util.dobToGeneration(dob)}:${is_correct}`);
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
export enum ContentFeedback {
|
package/src/lib/Incident.ts
CHANGED
package/src/lib/Util.ts
CHANGED
|
@@ -27,15 +27,35 @@ export class Util {
|
|
|
27
27
|
public static shuffleArray(array: Array<any>): Array<any> {
|
|
28
28
|
return array.sort(() => Math.random() - 0.5);
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
// The naming of the generations should conform to what the backend expects.
|
|
32
|
+
public static dobToGeneration(dob: number): string {
|
|
33
|
+
if (dob >= 2013) return 'generationalpha';
|
|
34
|
+
if (dob >= 1997) return 'generationz';
|
|
35
|
+
if (dob >= 1981) return 'generationy';
|
|
36
|
+
if (dob >= 1965) return 'generationx';
|
|
37
|
+
if (dob >= 1946) return 'babyboomers';
|
|
38
|
+
if (dob >= 1928) return 'silentgeneration';
|
|
39
|
+
if (dob >= 1901) return 'greatestgeneration';
|
|
40
|
+
return '';
|
|
41
|
+
// greatestgeneration: 1901-1927
|
|
42
|
+
// silentgeneration: 1928-1945
|
|
43
|
+
// babyboomers: 1946-1964
|
|
44
|
+
// generationx: 1965-1980
|
|
45
|
+
// generationy: 1981-1996
|
|
46
|
+
// generationz: 1997-2012
|
|
47
|
+
// generationalpha: 2013-2028
|
|
48
|
+
}
|
|
49
|
+
|
|
30
50
|
}
|
|
31
51
|
|
|
32
52
|
export interface IHash {
|
|
33
53
|
[Identifier: string | number]:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
| boolean
|
|
55
|
+
| number
|
|
56
|
+
| string
|
|
57
|
+
| string[]
|
|
58
|
+
| undefined;
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
export interface IStringArrayHash {
|
package/src/lib/i18n/EN.ts
CHANGED
|
@@ -15,6 +15,9 @@ export class EN implements i18n {
|
|
|
15
15
|
"Sports news: __TITLE__.",
|
|
16
16
|
"Sports fans were talking about '__TITLE__'.",
|
|
17
17
|
];
|
|
18
|
+
HintTemplates[Category.tvShowOrSeries] = [
|
|
19
|
+
"We watched '__TITLE__' on television.",
|
|
20
|
+
];
|
|
18
21
|
HintTemplates[Category.newsItem] = [
|
|
19
22
|
"The newspaper also mentioned '__TITLE__' this year.",
|
|
20
23
|
"'__TITLE__' was also in the news this year.",
|
|
@@ -101,6 +104,8 @@ export class EN implements i18n {
|
|
|
101
104
|
return "In __SECONDS__ second";
|
|
102
105
|
case "in-x-seconds":
|
|
103
106
|
return "In __SECONDS__ seconds";
|
|
107
|
+
case "game-settings-p0":
|
|
108
|
+
return " What year of birth?"
|
|
104
109
|
case "game-settings-p1":
|
|
105
110
|
return " Right. Oh hey, Biff, hey, guys, how are you doing? Look, there's a rhythmic"
|
|
106
111
|
case "game-settings-p2":
|
package/src/lib/i18n/NL.ts
CHANGED
|
@@ -18,6 +18,10 @@ export class NL implements i18n {
|
|
|
18
18
|
"Sportnieuws: __TITLE__.",
|
|
19
19
|
"Sportfanaten spraken over '__TITLE__'.",
|
|
20
20
|
];
|
|
21
|
+
HintTemplates[Category.tvShowOrSeries] = [
|
|
22
|
+
"Op tv was '__TITLE__'.",
|
|
23
|
+
"'s Avonds keken we naar '__TITLE__' op televisie.",
|
|
24
|
+
];
|
|
21
25
|
HintTemplates[Category.newsItem] = [
|
|
22
26
|
"In de krant stond dit jaar ook '__TITLE__'.",
|
|
23
27
|
"'__TITLE__' was dit jaar ook in het nieuws te lezen.",
|
|
@@ -59,7 +63,7 @@ export class NL implements i18n {
|
|
|
59
63
|
case "new-game":
|
|
60
64
|
return "nieuw spel";
|
|
61
65
|
case "end":
|
|
62
|
-
return "
|
|
66
|
+
return "Goed gedaan!";
|
|
63
67
|
case "next-question":
|
|
64
68
|
return "Volgende vraag";
|
|
65
69
|
case "quit":
|
|
@@ -104,6 +108,8 @@ export class NL implements i18n {
|
|
|
104
108
|
return "In __SECONDS__ seconde";
|
|
105
109
|
case "in-x-seconds":
|
|
106
110
|
return "In __SECONDS__ seconden";
|
|
111
|
+
case "game-settings-p0":
|
|
112
|
+
return " Welk geboortejaar?"
|
|
107
113
|
case "game-settings-p1":
|
|
108
114
|
return " Right. Oh hey, Biff, hey, guys, how are you doing? Look, there's a rhythmic"
|
|
109
115
|
case "game-settings-p2":
|