forked from TheCyaniteProject/exit_code_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.java
More file actions
308 lines (267 loc) · 10.9 KB
/
Copy pathAPI.java
File metadata and controls
308 lines (267 loc) · 10.9 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package exitcode;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.lang.Runnable;
import java.util.*;
// Internal dependancies: Logger, Desktop, LoadingScreen
public class API {
/*/
NOTE:
This is our WIP API. Everything here (and in this entire game) is subject to
change without warning.
Please check that your addon works with each new game release.
!!ATTENTION!!
We are not responsible for misuse of this API, or any Modder-implimented code.
Modders take full responsibility for their own code, as well as ANY and ALL
issues and damage that they may potentially cause.
We kindly ask Modders to be respectful, and not create and/or distribute potentially
or perpously harmful code. Doing so not only hurts YOUR reputation, but also this
community as a whole.
Thank you~
Allison Smith - Head Developer of ExitCode
/*/
/**
* These are Runnable's to be executed after the login page loads.
*/
private static Map<String, Runnable> login_tasks = new TreeMap<>();
/**
* These are Runnable's to be executed after the Desktop loads.
* (Desktop mods go here)
*/
private static Map<String, Runnable> desktop_tasks = new TreeMap<>();
/**
* These are secondary Runnable's to be executed after the Desktop loads.
* (Apps and other Addons go here, to make sure they load correctly after desktop mods)
*/
private static Map<String, Runnable> desktop_tasks2 = new TreeMap<>();
/**
* These are Runnable's to be executed when the game shutsdown.
* (Use these to propperly kill threads and close files to avoid potential data loss)
*/
private static Map<String, Runnable> shutdown_tasks = new TreeMap<>();
/**
* This is a public modders resource. It's intended for communication between mods.
*
* Other mods use this too. So don't clear it or anything like that.
*/
public static Map<String, ?> resource_map = new TreeMap<>();
/**
* This is a public modders resource. It's intended for communication between mods.
*
* Other mods use this too. So don't clear it or anything like that.
*/
public static Hashtable<String, ?> resource_hashtable = new Hashtable<>();
/**
* Adds a new function to login_tasks.
* These are Runnable's to be executed after the Login Page loads.
*
* @param uniqueObjectIdentifier This is a String ID that should be unique to a single
* function, or other resource. This is used to help troubleshoot problems, and enable you
* to reference your addon's implimented functions, or other resources.
*
* @param function This is the Runnable to be executed.
*/
public static void addLoginTask(String uniqueObjectIdentifier, Runnable function) {
API.login_tasks.put(uniqueObjectIdentifier, function);
}
/**
* Adds a new function to desktop_tasks.
* These are Runnable's to be executed after the Desktop loads.
* (Desktop mods go here)
*
* @param uniqueObjectIdentifier This is a String ID that should be unique to a single
* function, or other resource. This is used to help troubleshoot problems, and enable you
* to reference your addon's implimented functions, or other resources.
*
* @param function This is the Runnable to be executed.
*/
public static void addDesktopTask(String uniqueObjectIdentifier, Runnable function) {
API.desktop_tasks.put(uniqueObjectIdentifier, function);
}
/**
* Adds a new function to desktop_tasks2.
* These are secondary Runnable's to be executed after the Desktop loads.
* (Apps and other Addons go here, to make sure they load correctly after desktop mods)
*
* @param uniqueObjectIdentifier This is a String ID that should be unique to a single
* function, or other resource. This is used to help troubleshoot problems, and enable you
* to reference your addon's implimented functions, or other resources.
*
* @param function This is the Runnable to be executed.
*/
public static void addSecondaryDesktopTask(String uniqueObjectIdentifier, Runnable function) {
API.desktop_tasks2.put(uniqueObjectIdentifier, function);
}
/**
* Adds a new function to desktop_tasks2.
* These are secondary Runnable's to be executed after the Desktop loads.
* (Apps and other Addons go here, to make sure they load correctly after desktop mods)
*
* @param uniqueObjectIdentifier This is a String ID that should be unique to a single
* function, or other resource. This is used to help troubleshoot problems, and enable you
* to reference your addon's implimented functions, or other resources.
*
* @param function This is the Runnable to be executed.
*/
public static void addShutdownTask(String uniqueObjectIdentifier, Runnable function) {
API.shutdown_tasks.put(uniqueObjectIdentifier, function);
}
/**
* Spawns an in-game Notification.
*
* @param title The is the Title/Header of the Notification.
*
* @param body The is the Body/Text/Sum of the Notification.
*
* <br><br>
*
* Example:<br>
*
* {@code API.spawnNotification("System", "Hello, from the matrix!");}
*
* <h4>System</h4>
* <hr>
* <em>Hello, from the matrix!</em>
*/
public static void spawnNotification(String title, String body) {
}
/**
* This sets the OS Start Menu. Each time this is run, it overwrites the last input.
*
* @param function This is the Runnable that is executed to call the startmenu. In reality,
* you could put anything here. Not just an actual Menu.
*/
public static void setStartMenu(Runnable function) {
Desktop.startMenu = function;
}
/**
* This sets the OS Start Menu. Each time this is run, it overwrites the last input.
*
* @param function This is the Runnable that is executed to close the startmenu.
*/
public static void setStartMenuClose(Runnable function) {
Desktop.startMenuClose = function;
}
public static void addNewApp(String appName, Runnable function) {
Apps.appButtons.putIfAbsent(appName, function);
}
/**
* Please use this instead of the regular "System.out.println()"
* This will allow us to make use of your output.
*
* This forwards output to Logger.message().
*
* @param string This is the string to print.
*/
public static void println(String string) {
Logger.messageCustom("API", string);
}
//
// Mods should never reference these.. (doing so would duplicate things... Basically, NEVER run more than once!)
//
/**
* This executes all of the Runnable's stored within API.login_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Login() {
if (API.login_tasks.entrySet().size() >= 1) {
API.println("Executing LoginPage Tasks..");
for (Map.Entry<String, Runnable> entry : API.login_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.desktop_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Desktop() {
if (API.desktop_tasks.entrySet().size() >= 1) {
API.println("Executing Desktop Tasks..");
for (Map.Entry<String, Runnable> entry : API.desktop_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.desktop_tasks2
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Desktop2() {
if (API.desktop_tasks2.entrySet().size() >= 1) {
API.println("Executing Secondary Desktop Tasks..");
for (Map.Entry<String, Runnable> entry : API.desktop_tasks2.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.shutdown_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeShutdownTasks() {
if (API.shutdown_tasks.entrySet().size() >= 1) {
API.println("Executing Shutdown Tasks..");
for (Map.Entry<String, Runnable> entry : API.shutdown_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This adds the .class files from an addon.eca (ExitCode Addon) to the game classpath.
*
* NOT TO BE REFERENCED BY MODS
*
* LoadingScreen.setLoadingBar(1.0);
LoadingScreen.setTaskText("All Done.");
*/
static void modLoader() {
LoadingScreen.setLoadingBar(-1.0);
LoadingScreen.setTaskText("Checking for addons");
File folder = new File(System.getProperty("user.dir"), "addons");
if (folder.isDirectory()) {
API.println("Checking for addons...");
if(folder.list().length > 0) {
if (folder.list().length < 2) {
API.println("1 addon found!");
} else {
API.println(String.format("%s addons found!", folder.list().length));
}
File[] listOfFiles = folder.listFiles();
Integer num = 0;
for (File file : listOfFiles) {
num++;
Double percent = (double)(((num * 100.0f) / folder.list().length) / 100);
if (file.isFile()) {
try {
LoadingScreen.setTaskText(String.format("Loading %s", file.getName()));
API.println(String.format("Loading %s...", file.getName()));
URLClassLoader child = new URLClassLoader(new URL[] {new URL("file:///" + file.getPath())});
Class.forName("addon.Plugin", true, child);
API.println(String.format("Finished loading %s!", file.getName()));
} catch(Exception e) {
API.println(e.toString());
Logger.error(String.format("Failed to load %s!", file.getName()));
}
LoadingScreen.setLoadingBar(percent);
}
}
} else {
API.println("No mods found");
}
} else {
folder.mkdir();
}
LoadingScreen.setLoadingBar(1.0);
}
}