-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlibrary.js
92 lines (70 loc) · 2.28 KB
/
library.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
mergeInto(LibraryManager.library, {
pick_color: function(name, x) {
name = Pointer_stringify(name).toLowerCase();
var match = name.match(/maps\/[^/]*\/(.*)_.*_.*_.*/);
if (match != null) {
//console.log(name+" -> "+match[1]);
name = match[1];
}
if (name == "tools/toolstrigger")
return -1;
var color = color_table[name];
if (color != null) {
if (Array.isArray(color)) {
var r0 = color[0] >> 16;
var g0 = (color[0] >> 8) & 0xFF;
var b0 = color[0] & 0xFF;
var r1 = color[1] >> 16;
var g1 = (color[1] >> 8) & 0xFF;
var b1 = color[1] & 0xFF;
r0 = Math.floor(r0 + (r1 - r0)*x);
g0 = Math.floor(g0 + (g1 - g0)*x);
b0 = Math.floor(b0 + (b1 - b0)*x);
color = (r0<<16) | (g0<<8) | b0;
}
return color;
}
return guess_color(name);
},
parse_ents: function(data) {
data = Pointer_stringify(data);
var cam_placed = false;
kvparse(data,function(ent) {
if (!cam_placed && ent.classname.substr(0,17) == "info_player_start") {
var pos = ent.origin.split(" ").map(parseFloat);
var yaw = parseFloat(ent.angles.split(" ")[1]);
Module.setCam(pos[0],pos[1],pos[2]+64,0,yaw);
cam_placed = true;
} else if (ent.classname == "sky_camera") {
var pos = ent.origin.split(" ").map(parseFloat);
var scale = parseFloat(ent.scale);
_setSkybox(pos[0],pos[1],pos[2],scale);
} else if (ent.classname == "light_environment") {
var color = ent._ambient.split(" ");
_setAmbient(color[0]/255,color[1]/255,color[2]/255);
var color = ent._light.split(" ");
_setLight(color[0]/255,color[1]/255,color[2]/255);
var yaw = ent.angles.split(" ")[1];
_setLightAngle(ent.pitch,yaw);
} else if (ent.classname == "worldspawn") {
var color = sky_colors[ent.skyname];
if (color==null) {
color = 0x3aa0ff;
}
//console.log(ent.skyname,color);
var r = color >> 16;
var g = (color >> 8) & 0xFF;
var b = color & 0xFF;
_setSkyColor(r/255,g/255,b/255);
} else if (ent.model != null && ent.model[0]=="*") {
var model_id = parseInt(ent.model.substr(1));
var pos;
if (ent.origin != null)
pos = ent.origin.split(" ").map(parseFloat);
else
pos = [0,0,0];
_setModel(model_id,pos[0],pos[1],pos[2]);
}
});
}
});