-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraffitiClient.js
More file actions
59 lines (44 loc) · 2.14 KB
/
Copy pathgraffitiClient.js
File metadata and controls
59 lines (44 loc) · 2.14 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
// Include the json parse/stringify library. We host it here if you want to use it:
// !ref: http://meshmoon.data.s3.amazonaws.com/app/lib/json2.js, Script
// Include our utils script that has asset storage and bytearray utils etc.
// !ref: http://meshmoon.data.s3.amazonaws.com/app/lib/admino-utils-common-deploy.js, Script
// !ref: http://meshmoon.data.s3.amazonaws.com/app/lib/class.js, Script
/*engine.IncludeFile("http://meshmoon.data.s3.amazonaws.com/app/lib/class.js");
engine.IncludeFile("http://meshmoon.data.s3.amazonaws.com/app/lib/admino-utils-common-deploy.js");
SetLogChannelName("graffitiClient"); //this can be anything, but best is your aplication name
Log("Script starting...");
var myHandler = function (myAsset) {
Log("successfully connected");
var data = JSON.parse(myAsset.RawData());
for(var i=0; i<data.length; ++i) {
addAvatar(data[i]);
}
// Forget the disk asset so it wont be returned from cache next time you do the same request
asset.ForgetAsset(myAsset.Name(), true);
}
var addAvatar = function(user){
var avatarEntityName = user.username;
Log(avatarEntityName);
var avatarEntity = scene.CreateEntity(scene.NextFreeId(), ["Script", "Placeable", "AnimationController", "DynamicComponent"]);
avatarEntity.SetTemporary(true); // We never want to save the avatar entities to disk.
avatarEntity.SetName(avatarEntityName);
avatarEntity.SetDescription(avatarEntityName);
var script = avatarEntity.script;
script.className = "GraffitiApp.Gangster";
// Set random starting position for avatar
var placeable = avatarEntity.placeable;
var transform = placeable.transform;
transform.pos.x = (Math.random() - 0.5);
transform.pos.y = 11; //TODO put height DEFAULT variables
transform.pos.z = (Math.random() - 0.5);
placeable.transform = transform;
Log("Created avatar for " + avatarEntityName);
}
if (server.IsRunning()) {
Log("This is the server...");
//GET active users
var transfer = asset.RequestAsset("http://vm0063.virtues.fi/gangsters/?active", "Binary", true);
transfer.Succeeded.connect(myHandler);
} else {
Log("This is the client...");
}*/