-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
94 lines (85 loc) · 2.2 KB
/
Copy pathutils.js
File metadata and controls
94 lines (85 loc) · 2.2 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
function getCharAtPos(x, y) {
// Move the cursor to position (x, y)
console.gotoxy(x, y);
// Calculate the index in the screen buffer
var index = (y - 1) * console.screen_columns + (x - 1);
// Get the character at that position
var charAtPosition = console.screen_buf[index];
return charAtPosition;
}
function loadMapToGrid(filename, grid) {
var file = new File(filename);
if (!file.open("r")) {
alert("Failed to open " + filename);
return;
}
var y = 0;
while (!file.eof && y < grid.length) {
var line = file.readln();
for (var x = 0; x < line.length && x < grid[y].length; x++) {
grid[y][x] = line.charAt(x);
}
y++;
}
file.close();
return grid;
}
function checkSingleCharacter(key) {
var commonKeys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 `~!@#$%^&*()-_=+[]{}|;:\'",.<>/?\\'.split('');
if (typeof key === 'string' && key.length === 1) {
var isCommonKey = false;
for (var i = 0; i < commonKeys.length; i++) {
if (commonKeys[i] === key) {
isCommonKey = true;
break;
}
}
if (!isCommonKey) {
return false;
}
return key;
}
return false;
}
function offScreenCursor() {
console.gotoxy(200, 200); // Move cursor off screen
}
function base64ToInt(str) {
// Base64 character set
const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Validate input
if (!str || str.length === 0) {
return 0;
}
var result = 0;
// Process each character
for (var i = 0; i < str.length; i++) {
const char = str[i];
const value = indexOf(base64Chars, char);
if (value === -1) {
return "Invalid base64 character"
}
result = (result << 6) | value;
}
return result;
}
function indexOf(array, searchElement) {
startIndex = 0;
if (startIndex >= array.length) {
return -1;
}
if (searchElement !== searchElement) {
for (var i = startIndex; i < array.length; i++) {
if (array[i] !== array[i]) {
return i;
}
}
return -1;
}
for (var i = startIndex; i < array.length; i++) {
if (array[i] === searchElement) {
return i;
}
}
return -1;
}