-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandAPI.user.js
100 lines (91 loc) · 2.29 KB
/
CommandAPI.user.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
// ==UserScript==
// @name Name TBA
// @description Command API
// @author Tumble
// @version 0.0.1.1
// @run-at document-start
// @grant none
// @require https://github.com/SArpnt/joinFunction/raw/master/script.js
// @require https://github.com/SArpnt/EventHandler/raw/master/script.js
// @require https://github.com/SArpnt/cardboard/raw/master/script.user.js
// @require file:///E:/dev/boxcritters/mods/commandapi/message.js
// @match https://boxcritters.com/play/
// @match https://boxcritters.com/play/?*
// @match https://boxcritters.com/play/#*
// @match https://boxcritters.com/play/index.html
// @match https://boxcritters.com/play/index.html?*
// @match https://boxcritters.com/play/index.html#*
// ==/UserScript==
/**
* @typedef CardboardMod
* @property {string} modName
*/
/**
* Commands for the game /modname:command
* @typedef Mod
* @type {CardboardMod|String}
*/
/**
* @typedef Command
*/
/**
* @typedef CommandGroup
* @property {CardboardMod|String} mod Represents the mods that the commands are for
* @property {Array.<Command>} commands All of the commands for the mod
*/
/**
* @module CommandAPI
*/
var commandapi = {
/**
* @member
* @type {Array.<CommandGroup>}
*/
commandGroups:new Array
};
function getModName(mod) {
for (const modName in cardboard.mods) {
// Object == Object is true if they are the same instance
if(cardboard.mods[modName] = mod) {
return modName;
}
}
return undefined;
}
/**
* @class Command
*/
class Command {
constructor(mod) {
/**
* @property {Mod} mod mod that the command relates to
*/
this.mod = mod;
}
/**
* Executes the command
* @param {Number} argc Argument Count
* @param {Array.<String>} argv Argument Values
*/
exec(argc,argv){}
/**
* Displays Help info in console or dialogue (haven't decided)
* @param {Number} argc Argument Count
* @param {Array.<String>} argv Argument Values
*/
help(argc,argv){}
}
/**
*
* @param {Mod} mod
*/
var registerCommandGroup = (mod)=>{
var group = {
mod,
commands: new Object
}
var modName = mod.name||getModName(mod)||mod;
commandapi.commandGroups[modName] = group;
return commandapi.commandGroups[modName];
}
commandapi.registerCommandGroup = registerCommandGroup;