-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
111 lines (96 loc) · 6 KB
/
demo.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
108
109
110
111
const net = require('net');
const connection = {
connect: (onConnected) => {
this._client = net.createConnection({ port: 8000 }, () => {
console.log('Connected to OpenSpace backend');
onConnected();
});
this._client.on('data', (data) => {
const messageObject = JSON.parse(data.toString());
if (messageObject.topic !== undefined) {
this._callbacks[messageObject.topic](messageObject.payload);
}
});
this._client.on('end', () => {
console.log('Disconnected from OpenSpace');
});
this._callbacks = {};
this._nextTopicId = 0;
},
disconnect: () => {
this._client.end();
},
startTopic: (type, payload, callback) => {
const topic = this._nextTopicId++;
const messageObject = {
topic: topic,
type: type,
payload: payload
};
this._callbacks[topic] = callback || function() {};
this._client.write(JSON.stringify(messageObject) + "\n");
return topic;
},
talk: (topic, payload) => {
const messageObject = {
topic: topic,
payload: payload
};
this._client.write(JSON.stringify(messageObject) + "\n");
}
}
connection.connect(() => {
var delay = 500
// pause and setup scene
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('1') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.MilkyWay.renderable.Opacity', 1.000000);"}); }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValue('Scene.*Trail.renderable.Enabled', false);"}); }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.Earth.RenderableGlobe.Layers.NightLayers.Earth_at_Night_Temporal.Enabled', true);"}); console.log('2') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.Earth.RenderableGlobe.Layers.NightLayers.Earth_at_Night_2012.Enabled', false);"}); console.log('3') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.Earth.RenderableGlobe.Layers.NightLayers.Earth_at_Night_Temporal.BlendMode', 4);"}); console.log('4') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.Earth.RenderableGlobe.Layers.ColorLayers.ESRI_VIIRS_Combo.Enabled', false);"})});
setTimeout(() => {connection.startTopic('luascript', {script: "openspace.setPropertyValueSingle('Scene.Earth.RenderableGlobe.Layers.ColorLayers.ESRI_World_Imagery.Enabled', true);"})});
var isodate = process.argv[2] // 2018-11-27
var lat = process.argv[3] // 64.125614
var lon = process.argv[4] // -21.914953
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setTime("' + isodate + '");'}); console.log('0') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.globebrowsing.goToGeo(' + lat + ', ' + lon + ', 8000000);'}); console.log('0') }, delay);
var delay += 3000
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('8') }, delay); // resume
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(360);'}); console.log('9') }, delay);
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(7200);'}); console.log('7') }, delay);
// await sleep();
delay += 1000*12*2
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(360);'}); console.log('9') }, delay);
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('10') }, delay);
delay += 1000*1;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-360);'}); console.log('11') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('12') }, delay); // resume
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-7200);'}); console.log('13') }, delay);
delay += 1000*12*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-360);'}); console.log('14') }, delay);
delay += 1000*1;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('8') }, delay);
delay += 1000*1;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('8') }, delay); // resume
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(360);'}); console.log('9') }, delay);
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(7200);'}); console.log('7') }, delay);
// await sleep();
delay += 1000*12*2
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(360);'}); console.log('9') }, delay);
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('10') }, delay);
delay += 1000*1;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-360);'}); console.log('11') }, delay);
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.togglePause();'}); console.log('12') }, delay); // resume
delay += 1000*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-7200);'}); console.log('13') }, delay);
delay += 1000*12*2;
setTimeout(() => {connection.startTopic('luascript', {script: 'openspace.time.setDeltaTime(-360);'}); console.log('14') }, delay);
delay += 1000*3;
setTimeout(() => {connection.disconnect(); console.log('15')}, delay);
});