-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.inc.js
executable file
·107 lines (68 loc) · 1.87 KB
/
library.inc.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
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
export function is_touch_device() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
};
export function width(array, prev_frames) {
var erg = 0;
for(var i = 0; i <= prev_frames; i++) {
erg += array[i].margin;
if(i < prev_frames)
erg += array[i].width;
}
return erg;
};
export let in_array = function(needle, haystack) {
for(var a = 0; a < haystack.length; a++)
if(haystack[a] === needle)
return true;
return false
};
export let get_array_key = function (needle, haystack) {
for(var a = 0; a < haystack.length; a++)
if(haystack[a] == needle)
return a;
};
export let change_size = function (selector, width, height) {
$(selector).css('width' , width+'px');
$(selector).css('height' , height+'px');
};
export let round = function (somenum) {
return (0.5 + somenum) << 0;
};
export let floor = function (somenum) {
return ~~somenum;
};
// TODO Not used, eventually remove
export let filter_fps_lag = function() {
return (window.cfg.elapsed_time / window.cfg.fps_sim) * 1.2;
};
// function flipHorizontal(array:Array):Array
// {
// var transformedArray:Array = new Array();
// for ( var i:int = 0; i < array.length; i++ )
// {
// transformedArray[i] = new Array();
// var index:int = 0;
// for ( var j:int = array[0].length - 1; j > -1; j-- )
// {
// transformedArray[i][index] = array[i][j];
// index++;
// }
// }
// return transformedArray;
// }
export let flipArrayHorizontal = function(ar) {
var transformedArray = [];
// for(var i = 0; i < ar.length; i++) {
var index = 0;
for(var j= ar.length-1; j > -1; j--) {
transformedArray[index] = ar[j];
index++;
}
// }
return transformedArray;
};