-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
37 lines (34 loc) · 1.29 KB
/
utils.js
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
/* Utility functions */
/**
* Downloads the given object as a JSON file with the given filename.
* @param exportObj {Object} - Object to be downloaded.
* @param exportName {string} - Name of the file.
*/
window.downloadObjectAsJson = (exportObj, exportName) => {
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
let downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
/**
* Transforms the first character of the given string to upper case.
* @param a {string}
* @returns {string}
*/
window.strUcFirst = (a) => {
return (a+'').charAt(0).toUpperCase()+a.substr(1);
}
/**
* Draws the forbidden area in the off-screen forbidden canvas.
*/
window.draw_forbidden_area = () => {
forbidden_canvas.clear();
forbidden_canvas.stroke("#FF0000");
forbidden_canvas.strokeWeight(3);
forbidden_canvas.fill(255, 50, 0, 75);
let w = convertPosEnvToCanvas((INITIAL_TERRAIN_STARTPAD - 1) * TERRAIN_STEP, 0).x;
forbidden_canvas.rect(0, 0, w, RENDERING_VIEWER_H + 2 * SCROLL_Y_MAX);
}