This repository was archived by the owner on Mar 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneptune.ts
More file actions
98 lines (89 loc) · 2.96 KB
/
neptune.ts
File metadata and controls
98 lines (89 loc) · 2.96 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
/**
* Neptune blocks
*/
//% groups='["Registration", "Implementation", "Util"]'
//% weight=40 color=#593ec7 icon="\uf135"
namespace neptune {
/**
* The currently loaded Cartridge.
*/
//% val
export let currentlyLoadedCart: Cartridge;
/**
* The currently bootstrapped Plugin.
*/
//% val
export let currentlyBootstrappedPlugin: Plugin;
/**
* Throws a Fatal Error using a given string. Will stop the game forcefully, proceed with caution.
* @param reason The reason for throwing a Fatal Error
*/
//% block
//% group="Util"
export function crash(reason: string) {
control.fail(reason);
}
/**
* Checks if the current program name equals a given string.
* @param program The name of the program you want to check for (i.e) "Neptune". Use the name of your project, in the bottom left.
*/
//% block
//% group="Util"
export function isUnder(program: string): boolean {
return control.programName() == program;
}
/**
* Loads a Cartridge.
* @param cartToLoad The Cartridge to load.
*/
//% block
//% group="Implementation"
export function loadCart(cartToLoad: Cartridge) {
const load: Function = cartToLoad.loadFunction();
if (cartToLoad != null) {
currentlyLoadedCart = cartToLoad;
load();
console.log("(" + control.programName() + ") Loaded Cartridge: " + cartToLoad.stringId);
} else {
crash("Null Cartridge!");
}
}
/**
* Bootstraps a Plugin.
* @param plugin The Plugin to load.
*/
//% block
//% group="Implementation"
export function bootstrapPlugin(plugin: Plugin) {
const pluginToRun: Function = plugin.plugin();
if (plugin != null) {
currentlyBootstrappedPlugin = plugin;
pluginToRun();
console.log("(" + control.programName() + ") Bootstrapped plugin: " + plugin.id);
} else {
crash("Null Plugin!");
}
}
/**
* Creates a Cartridge, similar to 'sprites.create'
* @param id The string Id. Should be in regular spelling, "Test Cart".
* @param loadFunction The function to load upon the Cartridge being loaded. This function must not use any parameters.
*/
//% block
//% group="Registration"
export function createCart(id: string, loadFunction: Function): Cartridge {
const createdCart = new Cartridge(id, loadFunction);
return createdCart;
}
/**
* Creates a Plugin, similar to 'sprites.create'
* @param id The string Id. Should be in regular spelling, "Test Plugin".
* @param plugin The Plugin function to load. This function will be run upon the Plugin being bootstrapped.
*/
//% block
//% group="Registration"
export function createPlugin(id: string, plugin: Function): Plugin {
const registeredPlugin = new Plugin(id, plugin);
return registeredPlugin;
}
}