forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayers.js
More file actions
80 lines (69 loc) · 2.1 KB
/
Players.js
File metadata and controls
80 lines (69 loc) · 2.1 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
// Generated by CoffeeScript 2.5.1
var Player, Players;
import {
SkeletonUtils
} from './jsm/utils/SkeletonUtils.js';
import * as THREE from './build/three.module.js';
Player = class Player {
constructor(options) {
this.playerObject = options.playerObject;
this.scene = options.scene;
}
setup() {
this.object = SkeletonUtils.clone(this.playerObject);
return this.scene.add(this.object);
}
setPos(x, y, z, xyaw, zyaw) {
this.object.children[1].position.set(x, y - 0.5, z);
this.object.children[1].children[0].children[0].children[0].children[2].rotation.x = xyaw;
return this.object.children[1].children[0].rotation.z = zyaw;
}
remove() {
return this.scene.remove(this.object);
}
};
Players = class Players {
constructor(options) {
var texturex;
this.al = options.al;
this.scene = options.scene;
this.playersx = {};
this.socket = options.socket;
this.playerObject = this.al.get("player");
texturex = this.al.get("steve");
texturex.magFilter = THREE.NearestFilter;
this.playerObject.children[1].scale.set(1, 1, 1);
this.playerObject.children[1].position.set(25, 25, 25);
this.playerObject.children[0].material.map = texturex;
this.playerObject.children[0].material.color = new THREE.Color(0xffffff);
this.playerObject.children[1].scale.set(0.5, 0.5, 0.5);
}
update(players) {
var _this, sockets;
_this = this;
sockets = {};
Object.keys(players).forEach(function(p) {
sockets[p] = true;
if (_this.playersx[p] === void 0 && p !== _this.socket.id) {
_this.playersx[p] = new Player({
scene: _this.scene,
playerObject: _this.playerObject,
scene: _this.scene
});
_this.playersx[p].setup();
}
try {
_this.playersx[p].setPos(players[p].x, players[p].y, players[p].z, players[p].xyaw, players[p].zyaw);
} catch (error) {}
});
Object.keys(this.playersx).forEach(function(p) {
if (sockets[p] === void 0) {
_this.playersx[p].remove();
delete _this.playersx[p];
}
});
}
};
export {
Players
};