7
7
#include " ACraft.h"
8
8
#include " PieSlice.h"
9
9
10
+ #include " ConsoleMan.h"
11
+ #include " SettingsMan.h"
12
+
10
13
namespace RTE {
11
14
12
15
ConcreteClassInfo (GlobalScript, Entity, 10 );
@@ -16,7 +19,8 @@ namespace RTE {
16
19
void GlobalScript::Clear () {
17
20
m_ScriptPath.clear ();
18
21
m_LuaClassName.clear ();
19
- m_IsActive = false ;
22
+ m_IsActive = true ;
23
+ m_HasStarted = false ;
20
24
m_LateUpdate = false ;
21
25
m_PieSlicesToAdd.clear ();
22
26
}
@@ -29,6 +33,7 @@ namespace RTE {
29
33
m_ScriptPath = reference.m_ScriptPath ;
30
34
m_LuaClassName = reference.m_LuaClassName ;
31
35
m_IsActive = reference.m_IsActive ;
36
+ m_HasStarted = reference.m_HasStarted ;
32
37
m_LateUpdate = reference.m_LateUpdate ;
33
38
34
39
for (const std::unique_ptr<PieSlice> &referencePieSliceToAdd : reference.m_PieSlicesToAdd ) {
@@ -67,6 +72,17 @@ namespace RTE {
67
72
return 0 ;
68
73
}
69
74
75
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
+
77
+ const std::vector<std::unique_ptr<PieSlice>>& GlobalScript::GetPieSlicesToAdd () const {
78
+ const std::vector<std::unique_ptr<PieSlice>> emptyVector;
79
+ if (!m_HasStarted || !m_IsActive || !g_SettingsMan.IsGlobalScriptEnabled (GetModuleAndPresetName ())) {
80
+ return emptyVector;
81
+ }
82
+
83
+ return m_PieSlicesToAdd;
84
+ }
85
+
70
86
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
71
87
72
88
int GlobalScript::ReloadScripts () {
@@ -86,37 +102,82 @@ namespace RTE {
86
102
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87
103
88
104
int GlobalScript::Start () {
105
+ if (!g_SettingsMan.IsGlobalScriptEnabled (GetModuleAndPresetName ())) {
106
+ return 0 ;
107
+ }
108
+
109
+ if (g_SettingsMan.PrintDebugInfo ()) {
110
+ g_ConsoleMan.PrintString (" DEBUG: Start Global Script: " + GetPresetName ());
111
+ }
112
+
89
113
int error = ReloadScripts ();
90
- if (error == 0 ) { error = g_LuaMan.GetMasterScriptState ().RunScriptString (" if " + m_LuaClassName + " .StartScript then " + m_LuaClassName + " :StartScript(); end" ); }
91
- m_IsActive = error == 0 ;
114
+ if (error == 0 ) {
115
+ error = g_LuaMan.GetMasterScriptState ().RunScriptString (" if " + m_LuaClassName + " .StartScript then " + m_LuaClassName + " :StartScript(); end" );
116
+ m_HasStarted = true ;
117
+ }
92
118
119
+ m_IsActive = error == 0 ;
93
120
return error;
94
121
}
95
122
96
123
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97
124
98
125
int GlobalScript::Pause (bool pause) const {
126
+ if (!m_IsActive || !m_HasStarted || !g_SettingsMan.IsGlobalScriptEnabled (GetModuleAndPresetName ())) {
127
+ return 0 ;
128
+ }
129
+
99
130
return g_LuaMan.GetMasterScriptState ().RunScriptString (" if " + m_LuaClassName + " .PauseScript then " + m_LuaClassName + " :PauseScript(" + (pause ? " true" : " false" ) + " ); end" );
100
131
}
101
132
102
133
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
134
104
135
int GlobalScript::End () const {
136
+ if (!m_HasStarted) {
137
+ return 0 ;
138
+ }
139
+
140
+ if (g_SettingsMan.PrintDebugInfo ()) {
141
+ g_ConsoleMan.PrintString (" DEBUG: End Global Script: " + GetPresetName ());
142
+ }
143
+
105
144
return g_LuaMan.GetMasterScriptState ().RunScriptString (" if " + m_LuaClassName + " .EndScript then " + m_LuaClassName + " :EndScript(); end" );
106
145
}
107
146
108
147
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109
148
110
- void GlobalScript::HandleCraftEnteringOrbit (const ACraft *orbitedCraft) const {
111
- if (orbitedCraft && g_MovableMan.IsActor (orbitedCraft)) {
112
- g_LuaMan.GetMasterScriptState ().RunScriptFunctionString (m_LuaClassName + " .CraftEnteredOrbit" , m_LuaClassName, { m_LuaClassName, m_LuaClassName + " .CraftEnteredOrbit" }, { orbitedCraft });
149
+ void GlobalScript::HandleCraftEnteringOrbit (const ACraft *orbitedCraft) {
150
+ if (!m_IsActive || !!m_HasStarted || orbitedCraft == nullptr || !g_MovableMan.IsActor (orbitedCraft) || !g_SettingsMan.IsGlobalScriptEnabled (GetModuleAndPresetName ())) {
151
+ return ;
152
+ }
153
+
154
+ int error = g_LuaMan.GetMasterScriptState ().RunScriptFunctionString (m_LuaClassName + " .CraftEnteredOrbit" , m_LuaClassName, { m_LuaClassName, m_LuaClassName + " .CraftEnteredOrbit" }, { orbitedCraft });
155
+ if (error) {
156
+ m_IsActive = false ;
113
157
}
114
158
}
115
159
116
160
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117
161
118
162
void GlobalScript::Update () {
163
+ if (!m_IsActive) {
164
+ return ;
165
+ }
166
+
167
+ if (!g_SettingsMan.IsGlobalScriptEnabled (GetModuleAndPresetName ())) {
168
+ if (m_HasStarted) {
169
+ End ();
170
+ }
171
+ return ;
172
+ }
173
+
174
+ if (!m_HasStarted) {
175
+ Start ();
176
+ }
177
+
119
178
int error = g_LuaMan.GetMasterScriptState ().RunScriptString (" if " + m_LuaClassName + " .UpdateScript then " + m_LuaClassName + " :UpdateScript(); end" );
120
- if (error) { SetActive (false ); }
179
+ if (error) {
180
+ m_IsActive = false ;
181
+ }
121
182
}
122
183
}
0 commit comments