Skip to content

Commit 8bf3919

Browse files
committed
1.0
1 parent 0c206df commit 8bf3919

File tree

2 files changed

+301
-0
lines changed

2 files changed

+301
-0
lines changed

MoveViewport.js

+290
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
/**
2+
*
3+
*/
4+
const DEBUG = false;
5+
var window;
6+
7+
// Default setting
8+
var enablePlugin = false;
9+
var isRotate = true;
10+
var moveInterval = 20;
11+
var watchRandomRide = true;
12+
var watchRandomPoint = true;
13+
14+
var showWindow = function() {
15+
if(window) {
16+
window.bringToFront();
17+
return;
18+
}
19+
var windowDesc = {
20+
classification: 'move_viewport',
21+
width: 235,
22+
height: 170,
23+
title: 'Move Viewport',
24+
widgets: [
25+
{ // Checkbox
26+
type: 'checkbox',
27+
x: 5,
28+
y: 18,
29+
width: 225,
30+
height: 16,
31+
text: 'Enable this plugin.',
32+
isChecked: enablePlugin,
33+
onChange: function(checked) {
34+
enablePlugin = checked;
35+
context.sharedStorage.set('TELK.MoveViewport.enablePlugin', enablePlugin);
36+
}
37+
},
38+
39+
{
40+
type: 'groupbox',
41+
x: 5,
42+
y: 35,
43+
width: 225,
44+
height: 35,
45+
text: 'Watch',
46+
},
47+
{
48+
type: 'checkbox',
49+
x: 15,
50+
y: 50,
51+
width: 100,
52+
height: 16,
53+
text: 'Rides and Shops',
54+
isChecked: watchRandomRide,
55+
onChange: function(checked) {
56+
watchRandomRide = checked;
57+
context.sharedStorage.set('TELK.MoveViewport.watchRandomRide', watchRandomRide);
58+
}
59+
},
60+
{
61+
type: 'checkbox',
62+
x: 130,
63+
y: 50,
64+
width: 100,
65+
height: 16,
66+
text: 'Random point',
67+
isChecked: watchRandomPoint,
68+
onChange: function(checked) {
69+
watchRandomPoint = checked;
70+
context.sharedStorage.set('TELK.MoveViewport.watchRandomPoint', watchRandomPoint);
71+
}
72+
},
73+
74+
// Settings
75+
{
76+
type: 'groupbox',
77+
x: 5,
78+
y: 75,
79+
width: 225,
80+
height: 50,
81+
text: 'Settings',
82+
},
83+
{
84+
type: 'checkbox',
85+
x: 15,
86+
y: 88,
87+
width: 210,
88+
height: 16,
89+
text: 'Rotate randomly',
90+
isChecked: isRotate,
91+
onChange: function(checked) {
92+
isRotate = checked;
93+
context.sharedStorage.set('TELK.MoveViewport.isRotate', isRotate);
94+
}
95+
},
96+
{
97+
type: 'label',
98+
x: 15,
99+
y: 105,
100+
width: 225,
101+
height: 16,
102+
text: 'Move viewport every',
103+
},
104+
{
105+
type: 'spinner',
106+
x: 135,
107+
y: 103,
108+
width: 50,
109+
height: 16,
110+
name: 'move_interval',
111+
text: String(moveInterval),
112+
onDecrement: function(t) {
113+
if(moveInterval <= 1) return;
114+
moveInterval--;
115+
window.findWidget('move_interval').text = String(moveInterval);
116+
context.sharedStorage.set('TELK.MoveViewport.moveInterval', moveInterval);
117+
},
118+
onIncrement: function(t) {
119+
moveInterval++;
120+
window.findWidget('move_interval').text = String(moveInterval);
121+
context.sharedStorage.set('TELK.MoveViewport.moveInterval', moveInterval);
122+
}
123+
},
124+
{
125+
type: 'label',
126+
x: 185,
127+
y: 105,
128+
width: 225,
129+
height: 16,
130+
text: 'sec',
131+
},
132+
133+
// Now watching
134+
{
135+
type: 'groupbox',
136+
x: 5,
137+
y: 130,
138+
width: 225,
139+
height: 35,
140+
text: 'Now watching ...',
141+
},
142+
{
143+
type: 'label',
144+
x: 15,
145+
y: 145,
146+
width: 225,
147+
height: 16,
148+
name: 'now_watching',
149+
text: '(Unknown)',
150+
isDisabled: true,
151+
},
152+
],
153+
onClose: function () {
154+
window = undefined;
155+
}
156+
};
157+
window = ui.openWindow(windowDesc);
158+
}
159+
160+
var NowWatching = function(str, disabled) {
161+
if(disabled === undefined) disabled = false;
162+
if(!window) return;
163+
var now_watching = window.findWidget('now_watching');
164+
now_watching.isDisabled = disabled;
165+
now_watching.text = str;
166+
}
167+
168+
var moveScreen = function(viewportMode) {
169+
// Select viewport type
170+
if(viewportMode) {
171+
_viewportType = viewportMode;
172+
} else {
173+
var viewportTypes = [];
174+
if(watchRandomRide) viewportTypes.push('ride');
175+
if(watchRandomPoint) viewportTypes.push('map');
176+
_viewportType = viewportTypes[Math.floor(Math.random() * viewportTypes.length)];
177+
}
178+
if(!_viewportType) {
179+
trace('No _viewportType');
180+
NowWatching('Please set what you want to watch', true);
181+
return;
182+
}
183+
184+
// Rotate screen randomly
185+
if(isRotate) {
186+
ui.mainViewport.rotation = Math.floor(Math.random() * 4);
187+
}
188+
189+
move = {
190+
x: 0,
191+
y: 0
192+
};
193+
194+
switch(_viewportType) {
195+
case 'map':
196+
// Get map's size. Each tile is size of 32x32
197+
// eg) mapSize = {x: 201, y: 201};
198+
mapSize = map.size;
199+
200+
var goto_x = Math.floor(Math.random() * mapSize.x);
201+
var goto_y = Math.floor(Math.random() * mapSize.y);
202+
move.x = goto_x * 32;
203+
move.y = goto_y * 32;
204+
205+
trace('[MoveTo] (' + goto_x + ', ' + goto_y + ')');
206+
NowWatching('Random point (' + goto_x + ', ' + goto_y + ')');
207+
break;
208+
209+
case 'ride':
210+
// Get all rides
211+
rides = map.rides;
212+
213+
// Get a random ride
214+
t = 0;
215+
while(t < rides.length) {
216+
rnd_rides = Math.floor(Math.random() * rides.length);
217+
_ride = rides[rnd_rides];
218+
219+
// Get stations
220+
max_station_num = 0;
221+
for(s=0; s<_ride.stations.length; s++) {
222+
if(_ride.stations[s].start !== null) {
223+
max_station_num++;
224+
}
225+
}
226+
227+
if(max_station_num > 0) {
228+
break;
229+
}
230+
t++;
231+
}
232+
233+
selected_station = Math.floor((Math.random() * (max_station_num - 1)));
234+
_station = _ride.stations[selected_station];
235+
236+
var where_to_watch = ['start'];
237+
if(_station.entrance !== null) where_to_watch.push('entrance');
238+
if(_station.exit !== null) where_to_watch.push('exit');
239+
var where_to_watch_obj = where_to_watch[Math.floor(Math.random() * where_to_watch.length)];
240+
241+
move.x = _station[where_to_watch_obj].x;
242+
move.y = _station[where_to_watch_obj].y;
243+
244+
trace('[#' + rnd_rides + '] ' + _ride.name);
245+
NowWatching('“' + _ride.name + '” at (' + (move.x / 32) + ', ' + (move.y / 32) + ')');
246+
break;
247+
}
248+
249+
ui.mainViewport.scrollTo(move);
250+
}
251+
252+
var trace = function(msg) {
253+
if(DEBUG) console.log(msg);
254+
}
255+
256+
var initMain = function() {
257+
trace('initMain loaded');
258+
259+
// Load config
260+
enablePlugin = context.sharedStorage.get('TELK.MoveViewport.enablePlugin', false);
261+
isRotate = context.sharedStorage.get('TELK.MoveViewport.isRotate', true);
262+
moveInterval = context.sharedStorage.get('TELK.MoveViewport.moveInterval', 20);
263+
watchRandomRide = context.sharedStorage.get('TELK.MoveViewport.watchRandomRide', true);
264+
watchRandomPoint = context.sharedStorage.get('TELK.MoveViewport.watchRandomPoint', true);
265+
266+
context.subscribe('interval.tick', function() {
267+
// Every 20 seconds (assume 1sec = 40 tick)
268+
if((date.ticksElapsed % (40 * moveInterval)) === 0) {
269+
if(!enablePlugin) {
270+
return;
271+
}
272+
273+
// move and rotate screen
274+
moveScreen();
275+
}
276+
});
277+
278+
ui.registerMenuItem('Move Viewport', function() {
279+
showWindow();
280+
});
281+
}
282+
283+
registerPlugin({
284+
name: "MoveViewport",
285+
version: "1.0",
286+
licence: "MIT",
287+
authors: ["TELK"],
288+
type: "local",
289+
main: initMain
290+
});

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# MoveViewport
2+
**MoveViewport** is an OpenRCT2 plugin which moves game's main viewport every n-seconds, like CCTV.
3+
It requires latest develop version of OpenRCT2 to run this plugin.
4+
5+
# Features
6+
* Watching a ride's entrance, exit or start position of its random station
7+
* Watching a random position of map
8+
* Rotating the screen
9+
10+
# Todo
11+
* Zooming the screen

0 commit comments

Comments
 (0)