-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguageTimeObj.js
More file actions
119 lines (110 loc) · 3.22 KB
/
languageTimeObj.js
File metadata and controls
119 lines (110 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class word {
constructor(_r, _c, _l) {
this.name = "platt"
this.r = _r;
this.c = _c;
this.l = _l;
}
}
// Base class, derive all language specific classes from here.
// Needs to expose
// - the matrix (10 rows / 11 columns)
// - getWordsForTime(h, m)
// everything else is up to the class.
class LanguageTimeObj {
constructor () {
this.matrix = [
// 01234567890
" ",
" I ",
" ",
" AM ",
" ",
" A ",
" ",
" TEST ",
" ",
" ",
];
this.fillMatrixGaps(); // fills spaces with random characters
this.itIs = [new word(1, 5, 2), new word(3, 4, 2), new word(5, 5, 1), new word(7, 3, 4)];
this.before = [new word(0, 0, 0)];
this.after = [new word(0, 0, 0)];
this.half = [new word(0, 0, 0)];
this.oclock = [new word(0, 0, 0)];
this.minuteWords = [
[new word(0, 0, 0)], // Fünf (nach)
[new word(0, 0, 0)], // Zehn
[new word(0, 0, 0)], // Viertel
[new word(0, 0, 0)], // Zwanzig
[new word(0, 0, 0)], // Fünf (vor halb)
[new word(0, 0, 0)], // Halb
[new word(0, 0, 0)], // Fünf (nach halb)
[new word(0, 0, 0)], // Zwanzig (vor)
[new word(0, 0, 0)], // Viertel
[new word(0, 0, 0)], // Zehn
[new word(0, 0, 0)], // Fünf
];
this.hourWords = [
[new word(0, 0, 0)], // 12 at top (index=0)
[new word(0, 0, 0)], // 1
[new word(0, 0, 0)], // 2
[new word(0, 0, 0)], // 3
[new word(0, 0, 0)], // 4
[new word(0, 0, 0)], // 5
[new word(0, 0, 0)], // 6
[new word(0, 0, 0)], // 7
[new word(0, 0, 0)], // 8
[new word(0, 0, 0)], // 9
[new word(0, 0, 0)], // 10
[new word(0, 0, 0)] // 11
];
}
getWordsForTime(h, m) {
// The grammar to create the corrent wording for a given time
// returns an array of words (row, col, len) to be displayed
// this example is from german
let wordArr = [];
wordArr = wordArr.concat(this.itIs);
if (m >= 5) {
var mIndex = Math.floor(m / 5) - 1;
wordArr = wordArr.concat(this.minuteWords[mIndex]);
if (m < 25)
wordArr = wordArr.concat(this.after);
else if (m < 30)
wordArr = wordArr.concat(this.before);
else if (m >= 35 && m < 40)
wordArr = wordArr.concat(this.after);
else if (m >= 40)
wordArr = wordArr.concat(this.before);
if (m >= 25 && m < 40) wordArr = wordArr.concat(this.half);
}
var hIndex = h;
if (m < 25)
hIndex = h % 12;
else
hIndex = (h + 1) % 12;
wordArr = wordArr.concat(this.hourWords[hIndex]);
if (m < 5)
wordArr = wordArr.concat(this.oclock);
return wordArr;
}
fillMatrixGaps(fillword) {
if (fillword === undefined) fillword = "";
let gapCount = 0;
for (let i=0; i<this.matrix.length; i++) {
let word = "";
for (let j=0; j<this.matrix[i].length; j++) {
let c = this.matrix[i].substring(j, j+1);
if (c == " ") {
c = (gapCount < fillword.length
? fillword.substr(gapCount, gapCount+1)
: String.fromCharCode(65+Math.floor(Math.random() * 26)));
gapCount++;
}
word = word + c;
}
this.matrix[i] = word;
}
}
}