Repository navigation
Expand file tree
/
Copy pathinterface.js
More file actions
301 lines (256 loc) · 12.9 KB
/
Copy pathinterface.js
File metadata and controls
301 lines (256 loc) · 12.9 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
if (!("scramble" in Array.prototype)) {
Object.defineProperty(Array.prototype, "scramble", {
enumerable: false,
value: function () {
var o, i, ln = this.length;
while (ln--) {
i = Math.random() * (ln + 1) | 0;
o = this[ln];
this[ln] = this[i];
this[i] = o;
}
return this;
}
});
}
var rs = require("readline-sync")
var temp = 0, temp2 = 0
class Hud {
//TODO: test all fillspaces to their function name
static fillSpacesRight(input = "", size) {
size -= input.length
while (size > 0) {
input = input + ' '
size--;
}
// console.log(input.length);
return input
}
static fillSpacesLeft(input = "", size) {
size -= input.length
while (size >= 0) {
input = ' ' + input
size--;
}
return input
}
static fillSpacesCentered(input = "", size) {
size -= input.length
// console.log(input.length);
let flipflop = false
flipflop = false
while (size > 0) {
if (flipflop) {
input = input + ' ';
flipflop = false
}
else {
input = ' ' + input;
flipflop = true
}
size--
}
// console.log(input.length);
return input
}
static cutString(string = "", Max_length) {
for (let index = Max_length; index >= 0; index--)
if (string[index] == '\n' || string[index] == ' ')
return [string.substring(0, index), index];
}
static cutStringTwice(string = "", Start, Max_length) {
for (let index = Max_length; index >= 0; index--)
if ((Start + index) < string.length)
if (string[Start + index] == '\n' || string[Start + index] == ' ')
return [string.substring(Start, Start + index), Start + index];
//at htis point we are at the end of the string, i mark this with -1 ...
return ["", -1]
}
// const hud = new Hud();
// for (let index = 0; index < array.length; index++) {
// const element = array[index];
// }
// the final part that shows the dialogue and image and gets the user input
static showScreenDialogue(CName, dialogue,
image = ["", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "", ""]) {
let LineLength = 152, lastprintedchar = 1, texttobeprinted = ""
dialogue = this.fillSpacesRight(' ' + dialogue, LineLength * 9)
console.log(this.fillSpacesRight(image[0], LineLength))
console.log(this.fillSpacesRight(image[1], LineLength))
console.log(this.fillSpacesRight(image[2], LineLength))
console.log(this.fillSpacesRight(image[3], LineLength))
console.log(this.fillSpacesRight(image[4], LineLength))
console.log(this.fillSpacesRight(image[5], LineLength))
console.log(this.fillSpacesRight(image[6], LineLength))
console.log(this.fillSpacesRight(image[7], LineLength))
console.log(this.fillSpacesRight(image[8], LineLength))
console.log(this.fillSpacesRight(image[9], LineLength))
console.log(this.fillSpacesRight(image[10], LineLength))
console.log(this.fillSpacesRight(image[11], LineLength))
console.log(this.fillSpacesRight(image[12], LineLength))
console.log(this.fillSpacesRight(image[13], LineLength))
console.log(this.fillSpacesRight(image[14], LineLength))
console.log(this.fillSpacesRight(image[15], LineLength))
console.log(this.fillSpacesRight(image[16], LineLength))
console.log(this.fillSpacesRight(image[17], LineLength))
console.log(this.fillSpacesRight(image[18], LineLength))
console.log(this.fillSpacesRight(image[19], LineLength))
console.log(this.fillSpacesRight(image[20], LineLength))
console.log(this.fillSpacesRight(image[21], LineLength))
if (null == CName) {
console.log(this.fillSpacesRight(image[22], LineLength))
console.log(this.fillSpacesRight(image[23], LineLength))
console.log(this.fillSpacesRight(image[24], LineLength))
console.log(this.fillSpacesRight(image[25], LineLength))
console.log(this.fillSpacesRight(image[26], LineLength))
console.log(" ________________________________________________________________________________________________________________________________________________________ ")
} else {
console.log(" _________________________ " + this.fillSpacesRight(image[22].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[23].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[24].substring(28), LineLength - 24))
console.log(" |" + this.fillSpacesCentered(CName, 25) + '|' + this.fillSpacesRight(image[25].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[26].substring(28), LineLength - 24))
console.log(" |_________________________|______________________________________________________________________________________________________________________________ ")
}
//this ensures good line wrapping(, hopefully, havent tested it yet)
for (let Line = 0; Line <= 8; Line++) {
// ... so that i can intercept it later
if (lastprintedchar) {
[texttobeprinted, lastprintedchar] = this.cutStringTwice(dialogue, lastprintedchar, LineLength);
console.log(" |" + this.fillSpacesRight(texttobeprinted, LineLength) + "| ");
// skip the ' ' at which we just cut of
lastprintedchar++
} else
console.log(" |" + this.fillSpacesRight("", LineLength) + "| ")
}
console.log(" |________________________________________________________________________________________________________________________________________________________| ")
console.log(" ")
rs.question("continue")
}
static something() {
/*function cutStringTwice(string, Start, Max_length ) {
for (let index = Max_length; index >= 0; index--)
if ((Start + index) < string.length)
if (string[Start + index] == '\n' || string[Start + index] == ' ')
return [string.substring(Start, Start + index), Start + index];
//at htis point we are at the end of the string, i mark this with -1 ...
return ["", -1]
}
dialogue = ' ' + dialogue + ' '
for (let Line = 0; Line <= 8; Line++) {
// ... so that i can intercept it later
if (lastprintedchar) {
[texttobeprinted, lastprintedchar] = cutStringTwice(dialogue, lastprintedchar, LineLength);
console.log(" |"+ fillSpacesRight(texttobeprinted, LineLength)+"| ");
// skip the ' ' at which we just cut of
lastprintedchar++
}else
console.log(" |"+ fillSpacesRight("", LineLength)+"| ")
}*/
/*let Max_length = 69, string = "sASDFASDasdfssadjfkladsjflkajsdfasdfkljasdfakldshfdashasd fasdf argbys fbwrsb", printString = ""
function cutString(Max_length, string) {
for (let index = Max_length; index >= 0; index--)
if (string[index] == '\n' || string[index] == ' ' )
return string.substring(0, index);
}*/
}
static showScreenQuestion(CName, options = ["", "", "", ""], image = ["", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "", ""], question) {
let LineLength = 152, printedLineCount = 0 /*lastprintedchar = 1, texttobeprinted = ""*/
console.log(this.fillSpacesRight(image[0], LineLength))
console.log(this.fillSpacesRight(image[1], LineLength))
console.log(this.fillSpacesRight(image[2], LineLength))
console.log(this.fillSpacesRight(image[3], LineLength))
console.log(this.fillSpacesRight(image[4], LineLength))
console.log(this.fillSpacesRight(image[5], LineLength))
console.log(this.fillSpacesRight(image[6], LineLength))
console.log(this.fillSpacesRight(image[7], LineLength))
console.log(this.fillSpacesRight(image[8], LineLength))
console.log(this.fillSpacesRight(image[9], LineLength))
console.log(this.fillSpacesRight(image[10], LineLength))
console.log(this.fillSpacesRight(image[11], LineLength))
console.log(this.fillSpacesRight(image[12], LineLength))
console.log(this.fillSpacesRight(image[13], LineLength))
console.log(this.fillSpacesRight(image[14], LineLength))
console.log(this.fillSpacesRight(image[15], LineLength))
console.log(this.fillSpacesRight(image[16], LineLength))
console.log(this.fillSpacesRight(image[17], LineLength))
console.log(this.fillSpacesRight(image[18], LineLength))
console.log(this.fillSpacesRight(image[19], LineLength))
console.log(this.fillSpacesRight(image[20], LineLength))
console.log(this.fillSpacesRight(image[21], LineLength))
if (null == CName) {
console.log(this.fillSpacesRight(image[22], LineLength))
console.log(this.fillSpacesRight(image[23], LineLength))
console.log(this.fillSpacesRight(image[24], LineLength))
console.log(this.fillSpacesRight(image[25], LineLength))
console.log(this.fillSpacesRight(image[26], LineLength))
console.log(" ________________________________________________________________________________________________________________________________________________________ ")
} else {
console.log(" _________________________ " + this.fillSpacesRight(image[22].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[23].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[24].substring(28), LineLength - 24))
console.log(" |" + this.fillSpacesCentered(CName, 25) + '|' + this.fillSpacesRight(image[25].substring(28), LineLength - 24))
console.log(" | |" + this.fillSpacesRight(image[26].substring(28), LineLength - 24))
console.log(" |_________________________|______________________________________________________________________________________________________________________________ ")
}
// let opForPrinting = options
// for (let index = 9; index > 0; index--)
// opForPrinting.scramble()
console.log(" |" + this.fillSpacesRight("", LineLength) + "| ");
console.log(" |" + this.fillSpacesRight("", LineLength) + "| ");
console.log(" |" + this.fillSpacesRight(this.fillSpacesLeft(question, 20),LineLength) + "| ");
console.log(" |" + this.fillSpacesRight("", LineLength) + "| ");
let op = []
for (let index in options) {
console.log(" |" + this.fillSpacesCentered(this.fillSpacesRight(String.fromCharCode(97 + Number(index)) +" "+ options[index]+" ", 100), LineLength) + "|");
++printedLineCount
// console.log(String.fromCharCode(97 + Number(index)) + "aaaa");
op.push(String.fromCharCode(97 + Number(index)))
}
while (printedLineCount++ < 5)
console.log(" |" + this.fillSpacesRight("", LineLength) + "| ");
console.log(" |________________________________________________________________________________________________________________________________________________________| ")
console.log(" ")
let choice = rs.question("what option will you chose? ").toLowerCase()
while (true) {
// console.log(op);
// console.log(options);
// console.log(choice);
if (op.includes(choice)){
console.log(op.indexOf(choice));
return op.indexOf(choice)
}else {
// this process still adds another line while deleting the last line, but i cant be bothered to fix that rn
process.stdout.moveCursor(0, -1)
process.stdout.write("\r\x1b[K");
choice = rs.question("please give a valid answer ");
}
}
}
}
/*(CName, options = ["", "", "", ""], image = ["", "", "", "", "", ""], question)*/
// Hud.showScreenQuestion("jannes", ["aaa", "bbb", "ccc"],
// [
// "01", "02", "03", "04", "05", "06", "07",
// "08", "09", "10", "11", "12", "13", "14",
// "15", "16", "17", "18", "19", "20", "21", "22", "000000000000000000000000000000000000000023",
// "0000000000000000000000000000000000000000000024", "00000000000000000000000000000000000000000025",
// "0000000000000000000000000000000000000000026", "000000000000000000000000000000000000027"
// ],
// "whaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat?")
// Hud.showScreenDialogue("meeee", "aaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccc ddddddddddddddddddddddd eeeeeeeeeeeeeeeee ffffffffffffffffffffff gggggggggggggggggggggg",
// ["01", "02", "03", "04", "05", "06", "07","08", "09", "10", "11", "12", "13", "14",
// "15", "16", "17", "18", "19", "20", "21", "22", "000000000000000000000000000000000000000023",
// "0000000000000000000000000000000000000000000024", "00000000000000000000000000000000000000000025",
// "0000000000000000000000000000000000000000026", "000000000000000000000000000000000000027"
// ],"haaaalllloooo?")
module.exports = Hud
// aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccc ddddddddddddddddddddddd eeeeeeeeeeeeeeeee ffffffffffffffffffffff gggggggggggggggggggggg