-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtimescenetools.js
148 lines (115 loc) · 4.78 KB
/
runtimescenetools.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* GDevelop JS Platform
* Copyright 2013-2015 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
/**
* Tools related to runtime scene, for events generated code.
* @namespace gdjs.evtTools
* @class runtimeScene
* @static
* @private
*/
gdjs.evtTools.runtimeScene = gdjs.evtTools.runtimeScene || {};
gdjs.evtTools.runtimeScene.sceneJustBegins = function(runtimeScene) {
return runtimeScene.isFirstFrame();
};
gdjs.evtTools.runtimeScene.getSceneName = function(runtimeScene) {
return runtimeScene.getName();
};
gdjs.evtTools.runtimeScene.setBackgroundColor = function(runtimeScene, rgbColor) {
var colors = rgbColor.split(";");
if ( colors.length < 3 ) return;
runtimeScene.setBackgroundColor(parseInt(colors[0]),
parseInt(colors[1]),
parseInt(colors[2]));
};
gdjs.evtTools.runtimeScene.getElapsedTimeInSeconds = function(runtimeScene) {
return runtimeScene.getElapsedTime() / 1000;
};
gdjs.evtTools.runtimeScene.setTimeScale = function(runtimeScene, timeScale) {
return runtimeScene.setTimeScale(timeScale);
};
gdjs.evtTools.runtimeScene.getTimeScale = function(runtimeScene) {
return runtimeScene.getTimeScale();
};
gdjs.evtTools.runtimeScene.timerElapsedTime = function(runtimeScene, timeInSeconds, timerName) {
if ( !runtimeScene.hasTimer(timerName) ) {
runtimeScene.addTimer(timerName);
return false;
}
return runtimeScene.getTimer(timerName).getTime() / 1000 >= timeInSeconds;
};
gdjs.evtTools.runtimeScene.timerPaused = function(runtimeScene, timerName) {
if ( !runtimeScene.hasTimer(timerName) ) return false;
return runtimeScene.getTimer(timerName).isPaused();
};
gdjs.evtTools.runtimeScene.resetTimer = function(runtimeScene, timerName) {
if ( !runtimeScene.hasTimer(timerName) )
runtimeScene.addTimer(timerName);
else
runtimeScene.getTimer(timerName).reset();
};
gdjs.evtTools.runtimeScene.pauseTimer = function(runtimeScene, timerName) {
if ( !runtimeScene.hasTimer(timerName) ) runtimeScene.addTimer(timerName);
runtimeScene.getTimer(timerName).setPaused(true);
};
gdjs.evtTools.runtimeScene.unpauseTimer = function(runtimeScene, timerName) {
if ( !runtimeScene.hasTimer(timerName) ) runtimeScene.addTimer(timerName);
return runtimeScene.getTimer(timerName).setPaused(false);
};
gdjs.evtTools.runtimeScene.removeTimer = function(runtimeScene, timerName) {
if ( runtimeScene.hasTimer(timerName) ) runtimeScene.removeTimer(timerName);
};
gdjs.evtTools.runtimeScene.getTimerElapsedTimeInSeconds = function(runtimeScene, timerName) {
if ( !runtimeScene.hasTimer(timerName) ) return 0;
return runtimeScene.getTimer(timerName).getTime() / 1000;
};
gdjs.evtTools.runtimeScene.getTimeFromStartInSeconds = function(runtimeScene) {
return runtimeScene.getTimeFromStart() / 1000;
};
gdjs.evtTools.runtimeScene.getTime = function(runtimeScene, what) {
var now = new Date();
if ( what === "hour" )
return now.getHours();
else if ( what === "min" )
return now.getMinutes();
else if ( what === "sec" )
return now.getSeconds();
else if ( what === "mday" )
return now.getdate();
else if ( what === "mon" )
return now.getMonth();
else if ( what === "year" )
return now.getFullYear() - 1900; //Conform to the C way of returning years.
else if ( what === "wday" )
return now.getday();
else if ( what === "yday" ) {
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
return 0;
};
gdjs.evtTools.runtimeScene.replaceScene = function(runtimeScene, newSceneName, clearOthers) {
if (!runtimeScene.getGame().getSceneData(newSceneName)) return;
runtimeScene.requestChange(clearOthers ?
gdjs.RuntimeScene.CLEAR_SCENES :
gdjs.RuntimeScene.REPLACE_SCENE, newSceneName);
};
gdjs.evtTools.runtimeScene.pushScene = function(runtimeScene, newSceneName) {
if (!runtimeScene.getGame().getSceneData(newSceneName)) return;
runtimeScene.requestChange(gdjs.RuntimeScene.PUSH_SCENE, newSceneName);
};
gdjs.evtTools.runtimeScene.popScene = function(runtimeScene) {
runtimeScene.requestChange(gdjs.RuntimeScene.POP_SCENE);
};
gdjs.evtTools.runtimeScene.stopGame = function(runtimeScene) {
runtimeScene.requestChange(gdjs.RuntimeScene.STOP_GAME);
};
gdjs.evtTools.runtimeScene.createObjectsFromExternalLayout = function(scene, externalLayout, xPos, yPos) {
var externalLayoutData = scene.getGame().getExternalLayoutData(externalLayout);
if ( externalLayoutData === null ) return;
scene.createObjectsFrom(externalLayoutData.instances, xPos, yPos);
};