Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
238 lines (217 loc) · 5.43 KB
/
Copy pathindex.js
File metadata and controls
238 lines (217 loc) · 5.43 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
/**
* node-raylib
*
* https://github.com/robloach/node-raylib
*/
// Find the bindings.
const raylib = require('bindings')('node-raylib')
const {format} = require('util')
raylib.MAX_GAMEPADS = 4
raylib.MAX_GAMEPAD_AXIS = 8
raylib.MAX_GAMEPAD_BUTTONS = 32
raylib.MAX_TOUCH_POINTS = 10
raylib.MAX_KEY_PRESSED_QUEUE = 16
// Wrapped Functions
/**
* Text formatting with variables (sprintf style)
*/
raylib.TextFormat = format
/**
* Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR).
*
* @param {number} logType The type of message to present.
*/
raylib.TraceLog = function (logType, ...args) {
raylib.TraceLogWrap(logType, raylib.TextFormat(...args))
}
// Colors
raylib.Color = function (red, green, blue, alpha = 255) {
return {
r: red,
g: green,
b: blue,
a: alpha
}
}
raylib.LIGHTGRAY = raylib.Color(200, 200, 200, 255) // Light Gray
raylib.GRAY = raylib.Color(130, 130, 130, 255) // Gray
raylib.DARKGRAY = raylib.Color(80, 80, 80, 255) // Dark Gray
raylib.YELLOW = raylib.Color(253, 249, 0, 255) // Yellow
raylib.GOLD = raylib.Color(255, 203, 0, 255) // Gold
raylib.ORANGE = raylib.Color(255, 161, 0, 255) // Orange
raylib.PINK = raylib.Color(255, 109, 194, 255) // Pink
raylib.RED = raylib.Color(230, 41, 55, 255) // Red
raylib.MAROON = raylib.Color(190, 33, 55, 255) // Maroon
raylib.GREEN = raylib.Color(0, 228, 48, 255) // Green
raylib.LIME = raylib.Color(0, 158, 47, 255) // Lime
raylib.DARKGREEN = raylib.Color(0, 117, 44, 255) // Dark Green
raylib.SKYBLUE = raylib.Color(102, 191, 255, 255) // Sky Blue
raylib.BLUE = raylib.Color(0, 121, 241, 255) // Blue
raylib.DARKBLUE = raylib.Color(0, 82, 172, 255) // Dark Blue
raylib.PURPLE = raylib.Color(200, 122, 255, 255) // Purple
raylib.VIOLET = raylib.Color(135, 60, 190, 255) // Violet
raylib.DARKPURPLE = raylib.Color(112, 31, 126, 255) // Dark Purple
raylib.BEIGE = raylib.Color(211, 176, 131, 255) // Beige
raylib.BROWN = raylib.Color(127, 106, 79, 255) // Brown
raylib.DARKBROWN = raylib.Color(76, 63, 47, 255) // Dark Brown
raylib.WHITE = raylib.Color(255, 255, 255, 255) // White
raylib.BLACK = raylib.Color(0, 0, 0, 255) // Black
raylib.BLANK = raylib.Color(0, 0, 0, 0) // Blank (Transparent)
raylib.MAGENTA = raylib.Color(255, 0, 255, 255) // Magenta
raylib.RAYWHITE = raylib.Color(245, 245, 245, 255) // My own White (raylib logo)
/**
* Create a Vector2 object.
*
* @param {number} x The x parameter.
* @param {number} y The y parameter.
*/
raylib.Vector2 = function (x = 0, y = 0) {
return {
x,
y
}
}
raylib.Vector3 = function (x = 0, y = 0, z = 0) {
return {
x,
y,
z
}
}
raylib.Vector4 = function (x = 0, y = 0, z = 0, w = 0) {
return {
x,
y,
z,
w
}
}
raylib.Rectangle = function (x = 0, y = 0, width = 0, height = 0) {
return {
x,
y,
width,
height
}
}
raylib.Camera2D = function (offset, target, rotation, zoom) {
return {
offset,
target,
rotation,
zoom
}
}
raylib.Camera = function (position, target, up, fovy, type) {
return {
position,
target,
up,
fovy,
type
}
}
raylib.Camera3D = raylib.Camera
raylib.VrDeviceInfo = function () {
return {
hResolution: 2160,
vResolution: 1200,
hScreenSize: 0.133793,
vScreenSize: 0.0669,
vScreenCenter: 0.04678,
eyeToScreenDistance: 0.041,
lensSeparationDistance: 0.07,
interpupillaryDistance: 0.07,
lensDistortionValues: [1, 0.22, 0.24, 0],
chromaAbCorrection: [0.996, -0.004, 1.014, 0]
}
}
/**
* The following functions wrapped to allow object reference.
*
* @see /src/wrappedfunctions.h
*/
let wrapped_functions = [
'UpdateCamera',
'UpdateVrTracking',
'ImageFormat',
'ImageToPOT',
'ImageCrop',
'ImageAlphaCrop',
'ImageAlphaClear',
'ImageAlphaMask',
'ImageAlphaPremultiply',
'ImageResize',
'ImageResizeNN',
'ImageResizeCanvas',
'ImageMipmaps',
'ImageDither',
'ImageFlipVertical',
'ImageFlipHorizontal',
'ImageRotateCW',
'ImageRotateCCW',
'ImageColorTint',
'ImageColorInvert',
'ImageColorGrayscale',
'ImageColorContrast',
'ImageColorBrightness',
'ImageColorReplace',
'ImageClearBackground',
'ImageDrawPixel',
'ImageDrawPixelV',
'ImageDrawLine',
'ImageDrawLineV',
'ImageDrawCircle',
'ImageDrawCircleV',
'ImageDrawRectangle',
'ImageDrawRectangleV',
'ImageDrawRectangleRec',
'ImageDrawRectangleLines',
'ImageDraw',
'ImageDrawText',
'ImageDrawTextEx',
]
// Wrapped functions return the value modified after calling the function.
// When passed back to JS - the 'by reference' manipulation needs to occur
// manually like so:
for (let func of wrapped_functions) {
raylib[func] = function(...args) {
let obj = raylib[func + 'Wrap'](...args)
if (obj) {
for (let key in obj) {
// This makes the assumption the first argument of the function is
// the by-reference variable, which is true for the above functions so far
if (Object.hasOwnProperty.call(args[0], key)) {
args[0][key] = obj[key]
}
}
}
}
}
raylib.Ray = function (position, direction) {
return {
position,
direction
}
}
raylib.RayHitInfo = function (hit, distance, position, normal) {
return {
hit,
distance,
position,
normal
}
}
raylib.Shader = function (id, locs) {
return {
id,
locs
}
}
// #defines
raylib.FormatText = raylib.TextFormat
raylib.SubText = raylib.TextSubtext
raylib.ShowWindow = raylib.UnhideWindow
raylib.LoadText = raylib.LoadFileText
// Export the bindings for the module.
module.exports = raylib