@evitcastudio/kit 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -13
- package/lib/bundle/cli/cli.js +14 -3
- package/lib/bundle/cli/kit-game-templates/multi/README.md +3 -13
- package/lib/bundle/cli/kit-game-templates/multi/package.json +4 -3
- package/lib/bundle/cli/kit-game-templates/multi/src/server/settings.json +1 -1
- package/lib/bundle/cli/kit-game-templates/single/README.md +3 -13
- package/lib/bundle/cli/kit-game-templates/single/bun-serve.ts +2 -1
- package/lib/bundle/cli/kit-game-templates/single/package.json +3 -3
- package/lib/cli/init.d.ts.map +1 -0
- package/lib/{src/cli → cli}/init.js +14 -0
- package/lib/cli/main.d.ts +5 -0
- package/lib/cli/main.d.ts.map +1 -1
- package/lib/cli/main.js +7 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/plugins/network/index.d.ts +7 -0
- package/lib/plugins/network/index.d.ts.map +1 -1
- package/lib/plugins/network/index.js +18 -5
- package/package.json +1 -1
- package/lib/package.json +0 -72
- package/lib/src/cli/init.d.ts.map +0 -1
- package/lib/src/cli/main.d.ts +0 -13
- package/lib/src/cli/main.d.ts.map +0 -1
- package/lib/src/cli/main.js +0 -16
- package/lib/src/cli/resource-builder.d.ts +0 -6
- package/lib/src/cli/resource-builder.d.ts.map +0 -1
- package/lib/src/cli/resource-builder.js +0 -191
- package/lib/src/cli/types.d.ts +0 -11
- package/lib/src/cli/types.d.ts.map +0 -1
- package/lib/src/cli/types.js +0 -1
- package/lib/src/events/event-system.d.ts +0 -13
- package/lib/src/events/event-system.d.ts.map +0 -1
- package/lib/src/events/event-system.js +0 -25
- package/lib/src/index.d.ts +0 -8
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/index.js +0 -5
- package/lib/src/kit.d.ts +0 -67
- package/lib/src/kit.d.ts.map +0 -1
- package/lib/src/kit.js +0 -158
- package/lib/src/plugins/kit-plugin.d.ts +0 -27
- package/lib/src/plugins/kit-plugin.d.ts.map +0 -1
- package/lib/src/plugins/kit-plugin.js +0 -24
- package/lib/src/plugins/network/index.d.ts +0 -55
- package/lib/src/plugins/network/index.d.ts.map +0 -1
- package/lib/src/plugins/network/index.js +0 -101
- package/lib/src/types/shared-types.d.ts +0 -30
- package/lib/src/types/shared-types.d.ts.map +0 -1
- package/lib/src/types/shared-types.js +0 -1
- /package/lib/{src/cli → cli}/init.d.ts +0 -0
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { join, extname, basename } from 'path';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
// Logging helpers
|
|
6
|
-
const log = console.log;
|
|
7
|
-
const info = chalk.hex('#ffa552');
|
|
8
|
-
const error = chalk.hex('#c42847');
|
|
9
|
-
const alert = chalk.hex('#EFF2C0');
|
|
10
|
-
// Resource types and valid file extensions
|
|
11
|
-
const RESOURCE_TYPES = ['interface', 'icon', 'map', 'sound', 'macros'];
|
|
12
|
-
const VALID_EXTENSIONS = ['vyint', 'vyi', 'vym', 'vymac', 'mp3', 'aac', 'wav', 'm4a', 'ogg', 'flac'];
|
|
13
|
-
// State variables
|
|
14
|
-
let resourceJSON = initializeResourceJSON();
|
|
15
|
-
let isVerbose = false;
|
|
16
|
-
let ignoringSound = false;
|
|
17
|
-
let resourceInDirectory = '';
|
|
18
|
-
let resourceOutDirectory = '';
|
|
19
|
-
const resourcesToProcess = [];
|
|
20
|
-
/**
|
|
21
|
-
* Initializes the resource JSON structure.
|
|
22
|
-
*/
|
|
23
|
-
function initializeResourceJSON() {
|
|
24
|
-
return RESOURCE_TYPES.reduce((acc, type) => {
|
|
25
|
-
acc[type] = [];
|
|
26
|
-
return acc;
|
|
27
|
-
}, {});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Processes a single file and updates the resource JSON.
|
|
31
|
-
*/
|
|
32
|
-
function prepareFileForProcessing(pFilePath) {
|
|
33
|
-
const extension = extname(pFilePath).slice(1);
|
|
34
|
-
const fileName = basename(pFilePath);
|
|
35
|
-
const resourceIdentifier = `${uuidv4()}.vyr`;
|
|
36
|
-
const type = getResourceType(extension);
|
|
37
|
-
if (!type)
|
|
38
|
-
return;
|
|
39
|
-
if (type === 'sound' && ignoringSound) {
|
|
40
|
-
logVerbose(`[Ignored File] ${pFilePath} (ignoreSound flag enabled)`);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
resourcesToProcess.push({ filePath: pFilePath, type });
|
|
44
|
-
resourceJSON[type].push({ resourceIdentifier, fileName });
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Determines the resource type based on the file extension.
|
|
48
|
-
*/
|
|
49
|
-
function getResourceType(pExtension) {
|
|
50
|
-
switch (pExtension) {
|
|
51
|
-
case 'vyint': return 'interface';
|
|
52
|
-
case 'vyi': return 'icon';
|
|
53
|
-
case 'vym': return 'map';
|
|
54
|
-
case 'vymac': return 'macros';
|
|
55
|
-
case 'mp3':
|
|
56
|
-
case 'aac':
|
|
57
|
-
case 'wav':
|
|
58
|
-
case 'm4a':
|
|
59
|
-
case 'ogg':
|
|
60
|
-
case 'flac': return 'sound';
|
|
61
|
-
default: return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Processes a directory and its contents recursively.
|
|
66
|
-
*/
|
|
67
|
-
async function processDirectory(pDirectoryPath) {
|
|
68
|
-
try {
|
|
69
|
-
const contents = await fs.readdir(pDirectoryPath);
|
|
70
|
-
for (const item of contents) {
|
|
71
|
-
const itemPath = join(pDirectoryPath, item);
|
|
72
|
-
const stats = await fs.stat(itemPath);
|
|
73
|
-
if (stats.isDirectory()) {
|
|
74
|
-
await processDirectory(itemPath);
|
|
75
|
-
}
|
|
76
|
-
else if (isValidExtension(extname(itemPath).slice(1))) {
|
|
77
|
-
prepareFileForProcessing(itemPath);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (pError) {
|
|
82
|
-
logError(`[Error] Processing directory: ${pError}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Checks if a file extension is valid.
|
|
87
|
-
*/
|
|
88
|
-
function isValidExtension(pExtension) {
|
|
89
|
-
return VALID_EXTENSIONS.includes(pExtension);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Executes all file copy operations in parallel after preparation.
|
|
93
|
-
*/
|
|
94
|
-
async function processAllFiles() {
|
|
95
|
-
try {
|
|
96
|
-
await clearResourceTypeDirectories(`${resourceOutDirectory}/resources`);
|
|
97
|
-
// Create copy operations for all files
|
|
98
|
-
const copyOperations = resourcesToProcess.map(({ filePath, type }) => {
|
|
99
|
-
const fileName = basename(filePath);
|
|
100
|
-
const resource = resourceJSON[type].find(res => res.fileName === fileName);
|
|
101
|
-
if (!resource) {
|
|
102
|
-
throw new Error(`Resource not found for file: ${fileName}`);
|
|
103
|
-
}
|
|
104
|
-
const destination = join(resourceOutDirectory, 'resources');
|
|
105
|
-
const resourceName = resource.resourceIdentifier;
|
|
106
|
-
return copyFile(filePath, destination, resourceName);
|
|
107
|
-
});
|
|
108
|
-
// Execute all copy operations concurrently
|
|
109
|
-
await Promise.all(copyOperations);
|
|
110
|
-
logVerbose(`[Kit CLI] All resources have been processed.`);
|
|
111
|
-
await saveResourceJSON();
|
|
112
|
-
}
|
|
113
|
-
catch (pError) {
|
|
114
|
-
const errorMessage = pError instanceof Error ? pError.message : String(pError);
|
|
115
|
-
logError(`[Error] Processing files in batch: ${errorMessage}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Clears specified directories within a base directory.
|
|
120
|
-
* @param pBaseDirectory - The path to the base directory.
|
|
121
|
-
*/
|
|
122
|
-
async function clearResourceTypeDirectories(pBaseDirectory) {
|
|
123
|
-
try {
|
|
124
|
-
const directoryExists = await fs.stat(pBaseDirectory).then(stat => stat.isDirectory()).catch(() => false);
|
|
125
|
-
if (directoryExists) {
|
|
126
|
-
await fs.rm(pBaseDirectory, { recursive: true });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (pError) {
|
|
130
|
-
log(`${error(`[Error]`)} clearing resource directory: ${pError}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Copies a file to the specified directory.
|
|
135
|
-
*/
|
|
136
|
-
async function copyFile(pSource, pDestinationDir, pNewName) {
|
|
137
|
-
try {
|
|
138
|
-
await fs.mkdir(pDestinationDir, { recursive: true });
|
|
139
|
-
await fs.copyFile(pSource, join(pDestinationDir, pNewName));
|
|
140
|
-
}
|
|
141
|
-
catch (pError) {
|
|
142
|
-
logError(`[Error] Copying file ${pSource}: ${pError}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Saves the resource JSON to a file.
|
|
147
|
-
*/
|
|
148
|
-
async function saveResourceJSON() {
|
|
149
|
-
const filePath = 'resource.json';
|
|
150
|
-
try {
|
|
151
|
-
await fs.writeFile(filePath, JSON.stringify(resourceJSON, null, 4));
|
|
152
|
-
}
|
|
153
|
-
catch (pError) {
|
|
154
|
-
logError(`[Error] Saving resource JSON: ${pError}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Main entry point for building resources.
|
|
159
|
-
*/
|
|
160
|
-
export async function processResources({ inDirectory, outDirectory, verbose, ignoreSound }) {
|
|
161
|
-
// Initialize state
|
|
162
|
-
resourceInDirectory = inDirectory;
|
|
163
|
-
resourceOutDirectory = outDirectory;
|
|
164
|
-
isVerbose = verbose;
|
|
165
|
-
ignoringSound = ignoreSound;
|
|
166
|
-
resourceJSON = initializeResourceJSON();
|
|
167
|
-
// Validate inputs
|
|
168
|
-
if (!resourceInDirectory || !resourceOutDirectory) {
|
|
169
|
-
logError('[Error] Input and output directories must be specified');
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
// Process resources
|
|
173
|
-
await processDirectory(resourceInDirectory);
|
|
174
|
-
if (resourcesToProcess.length > 0) {
|
|
175
|
-
await processAllFiles();
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
logAlert('No resources found!');
|
|
179
|
-
await saveResourceJSON();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function logVerbose(pMessage) {
|
|
183
|
-
if (isVerbose)
|
|
184
|
-
log(info(pMessage));
|
|
185
|
-
}
|
|
186
|
-
function logError(pMessage) {
|
|
187
|
-
log(error(pMessage));
|
|
188
|
-
}
|
|
189
|
-
function logAlert(pMessage) {
|
|
190
|
-
log(alert(pMessage));
|
|
191
|
-
}
|
package/lib/src/cli/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cli/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,cAAc,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/lib/src/cli/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { EmitterEvent, Listener } from '../types/shared-types';
|
|
2
|
-
import type { KitPlugin } from '../plugins/kit-plugin';
|
|
3
|
-
export declare class EventEmitter {
|
|
4
|
-
private listener;
|
|
5
|
-
private plugin;
|
|
6
|
-
constructor(pListener: Listener, pPlugin: KitPlugin);
|
|
7
|
-
/**
|
|
8
|
-
* Emit an event to all listeners.
|
|
9
|
-
* @param pEvent - The event to emit.
|
|
10
|
-
*/
|
|
11
|
-
emit(pEvent: EmitterEvent): void;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=event-system.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-system.d.ts","sourceRoot":"","sources":["../../../src/events/event-system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAY;gBAEd,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS;IAKnD;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;CAcnC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export class EventEmitter {
|
|
2
|
-
listener;
|
|
3
|
-
plugin;
|
|
4
|
-
constructor(pListener, pPlugin) {
|
|
5
|
-
this.listener = pListener;
|
|
6
|
-
this.plugin = pPlugin;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Emit an event to all listeners.
|
|
10
|
-
* @param pEvent - The event to emit.
|
|
11
|
-
*/
|
|
12
|
-
emit(pEvent) {
|
|
13
|
-
if (pEvent.plugin && pEvent.plugin !== this.plugin.name) {
|
|
14
|
-
throw new Error(`Event mismatch: ${this.plugin.name} tried to emit an event from the ${pEvent.plugin} namespace.`);
|
|
15
|
-
}
|
|
16
|
-
const event = {
|
|
17
|
-
plugin: this.plugin.name,
|
|
18
|
-
event: pEvent.event,
|
|
19
|
-
data: pEvent?.data,
|
|
20
|
-
timestamp: Date.now()
|
|
21
|
-
};
|
|
22
|
-
Object.freeze(event);
|
|
23
|
-
this.listener(event);
|
|
24
|
-
}
|
|
25
|
-
}
|
package/lib/src/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { Kit } from './kit';
|
|
2
|
-
export { EventEmitter } from './events/event-system';
|
|
3
|
-
export type { EmitterEvent, ResourceData, Listener, KitPluginConstructor } from './types/shared-types';
|
|
4
|
-
export type { Client, Diob } from './types/vylo';
|
|
5
|
-
export { KitPlugin } from './plugins/kit-plugin';
|
|
6
|
-
export { Network } from './plugins/network';
|
|
7
|
-
export type { NetworkListener } from './plugins/network';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACvG,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/lib/src/index.js
DELETED
package/lib/src/kit.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { KitPlugin } from './plugins/kit-plugin';
|
|
2
|
-
import type { ResourceData, Listener, KitPluginConstructor } from './types/shared-types';
|
|
3
|
-
export declare class Kit {
|
|
4
|
-
/**
|
|
5
|
-
* A record of all plugins registered with the Kit class.
|
|
6
|
-
*/
|
|
7
|
-
private static plugins;
|
|
8
|
-
/**
|
|
9
|
-
* A set of all plugin emitters.
|
|
10
|
-
*/
|
|
11
|
-
private static emitters;
|
|
12
|
-
/**
|
|
13
|
-
* A record of all event listeners.
|
|
14
|
-
*/
|
|
15
|
-
private static events;
|
|
16
|
-
private constructor();
|
|
17
|
-
/**
|
|
18
|
-
* Initialize the Kit class with plugins.
|
|
19
|
-
* @deprecated Use `registerPlugin` instead.
|
|
20
|
-
* @param pPlugins - An array of plugins to initialize.
|
|
21
|
-
*/
|
|
22
|
-
static init<T extends KitPlugin>(pPlugins: KitPluginConstructor<T>[]): void;
|
|
23
|
-
/**
|
|
24
|
-
* Register a plugin with the Kit class.
|
|
25
|
-
* @param pPlugin - The plugin to register.
|
|
26
|
-
*/
|
|
27
|
-
static registerPlugin<T extends KitPlugin>(pPlugin: KitPluginConstructor<T>): T;
|
|
28
|
-
static registerPlugin<T extends KitPlugin>(pPlugin: KitPluginConstructor<T>[]): T[];
|
|
29
|
-
/**
|
|
30
|
-
* Gets a plugin by name.
|
|
31
|
-
* @param pName - String name of the plugin to retrieve.
|
|
32
|
-
*/
|
|
33
|
-
static getPlugin<T extends KitPlugin>(pName: string): T | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Lists all registered plugins.
|
|
36
|
-
*/
|
|
37
|
-
static getPlugins(): string[];
|
|
38
|
-
/**
|
|
39
|
-
* Emit an event to all listeners.
|
|
40
|
-
* @param pEvent - The event to emit.
|
|
41
|
-
*/
|
|
42
|
-
private static emit;
|
|
43
|
-
/**
|
|
44
|
-
* Listen for an event.
|
|
45
|
-
* @param pPluginName - The plugin namespace.
|
|
46
|
-
* @param pEventName - The event name.
|
|
47
|
-
* @param pListener - The listener to call when the event is emitted.
|
|
48
|
-
*/
|
|
49
|
-
static on(pPluginName: string, pEventName: string, pListener: Listener): void;
|
|
50
|
-
/**
|
|
51
|
-
* Removes an event listener.
|
|
52
|
-
* @param pPluginName - The plugin namespace.
|
|
53
|
-
* @param pEventName - The event name.
|
|
54
|
-
* @param pListener - The listener to remove.
|
|
55
|
-
*/
|
|
56
|
-
static off(pPluginName: string, pEventName: string, pListener: Listener): void;
|
|
57
|
-
/**
|
|
58
|
-
* Sets the resource locator for the engine to reference the files we have in the resources folder. interface | map | icon | macro | sound are checked for.
|
|
59
|
-
* @param pData - An array of each file that was found in the resources folder.
|
|
60
|
-
*/
|
|
61
|
-
private static setResource;
|
|
62
|
-
/**
|
|
63
|
-
* Sets the resources found in resources and preloads all interfaces found.
|
|
64
|
-
*/
|
|
65
|
-
static setResources(pResourceJson: Record<string, ResourceData[]>): Promise<void>;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=kit.d.ts.map
|
package/lib/src/kit.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../../src/kit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAgB,YAAY,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAgBvG,qBAAa,GAAG;IACZ;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmC;IAC1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM,CAAuC;IAE5D,OAAO;IAIP;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAM3E;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC;IAC/E,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;IAsCnF;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAQnE;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,MAAM,EAAE;IAI7B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAWlB;;;;;MAKE;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,GAAG,IAAI;IAQ7E;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,GAAG,IAAI;IAO9E;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAiB1B;;OAEG;WACU,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAa1F"}
|
package/lib/src/kit.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from './events/event-system';
|
|
2
|
-
const extensionToPath = {
|
|
3
|
-
'.vyint': 'interface',
|
|
4
|
-
'.vym': 'map',
|
|
5
|
-
'.vyi': 'icon',
|
|
6
|
-
'.vymac': 'macros',
|
|
7
|
-
'.aac': 'sound',
|
|
8
|
-
'.mp3': 'sound',
|
|
9
|
-
'.wav': 'sound',
|
|
10
|
-
'.m4a': 'sound',
|
|
11
|
-
'.ogg': 'sound',
|
|
12
|
-
'.flac': 'sound'
|
|
13
|
-
};
|
|
14
|
-
export class Kit {
|
|
15
|
-
/**
|
|
16
|
-
* A record of all plugins registered with the Kit class.
|
|
17
|
-
*/
|
|
18
|
-
static plugins = {};
|
|
19
|
-
/**
|
|
20
|
-
* A set of all plugin emitters.
|
|
21
|
-
*/
|
|
22
|
-
static emitters = new Map();
|
|
23
|
-
/**
|
|
24
|
-
* A record of all event listeners.
|
|
25
|
-
*/
|
|
26
|
-
static events = {};
|
|
27
|
-
constructor() {
|
|
28
|
-
throw new Error('[Kit] is not to be instantiated.');
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Initialize the Kit class with plugins.
|
|
32
|
-
* @deprecated Use `registerPlugin` instead.
|
|
33
|
-
* @param pPlugins - An array of plugins to initialize.
|
|
34
|
-
*/
|
|
35
|
-
static init(pPlugins) {
|
|
36
|
-
pPlugins.forEach(pPlugin => {
|
|
37
|
-
this.registerPlugin(pPlugin);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
static registerPlugin(pPlugin) {
|
|
41
|
-
if (Array.isArray(pPlugin)) {
|
|
42
|
-
const plugins = [];
|
|
43
|
-
pPlugin.forEach(pPlugin => {
|
|
44
|
-
const plugin = this.registerPlugin(pPlugin);
|
|
45
|
-
if (plugin && !Array.isArray(plugin)) {
|
|
46
|
-
plugins.push(plugin);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return plugins;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const plugin = new pPlugin();
|
|
53
|
-
const pluginName = plugin.name;
|
|
54
|
-
if (!pluginName || typeof pluginName !== 'string' || !/^[a-zA-Z0-9-_]+$/.test(pluginName)) {
|
|
55
|
-
throw new Error(`[Kit] Invalid plugin name: '${pluginName}'. The name must be a non-empty string containing only alphanumeric characters, dashes, or underscores.`);
|
|
56
|
-
}
|
|
57
|
-
if (Kit.plugins[pluginName]) {
|
|
58
|
-
throw new Error(`[Kit] plugin with name '${pluginName}' is already registered.`);
|
|
59
|
-
}
|
|
60
|
-
const listener = function (pEvent) {
|
|
61
|
-
Kit.emit(pEvent);
|
|
62
|
-
};
|
|
63
|
-
const emitter = new EventEmitter(listener, plugin);
|
|
64
|
-
Kit.emitters.set(pluginName, emitter);
|
|
65
|
-
Kit.plugins[pluginName] = plugin;
|
|
66
|
-
plugin._register(emitter);
|
|
67
|
-
plugin.onRegistered();
|
|
68
|
-
return plugin;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets a plugin by name.
|
|
73
|
-
* @param pName - String name of the plugin to retrieve.
|
|
74
|
-
*/
|
|
75
|
-
static getPlugin(pName) {
|
|
76
|
-
const plugin = Kit.plugins[pName];
|
|
77
|
-
if (!plugin) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
return plugin;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Lists all registered plugins.
|
|
84
|
-
*/
|
|
85
|
-
static getPlugins() {
|
|
86
|
-
return Object.keys(Kit.plugins);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Emit an event to all listeners.
|
|
90
|
-
* @param pEvent - The event to emit.
|
|
91
|
-
*/
|
|
92
|
-
static emit(pEvent) {
|
|
93
|
-
const { plugin, event } = pEvent;
|
|
94
|
-
const eventScope = `${plugin}-${event}`;
|
|
95
|
-
if (!Kit.events[eventScope]) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
Kit.events[eventScope].forEach(pListener => pListener(pEvent));
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Listen for an event.
|
|
102
|
-
* @param pPluginName - The plugin namespace.
|
|
103
|
-
* @param pEventName - The event name.
|
|
104
|
-
* @param pListener - The listener to call when the event is emitted.
|
|
105
|
-
*/
|
|
106
|
-
static on(pPluginName, pEventName, pListener) {
|
|
107
|
-
const eventScope = `${pPluginName}-${pEventName}`;
|
|
108
|
-
if (!Kit.events[eventScope]) {
|
|
109
|
-
Kit.events[eventScope] = [];
|
|
110
|
-
}
|
|
111
|
-
Kit.events[eventScope].push(pListener);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Removes an event listener.
|
|
115
|
-
* @param pPluginName - The plugin namespace.
|
|
116
|
-
* @param pEventName - The event name.
|
|
117
|
-
* @param pListener - The listener to remove.
|
|
118
|
-
*/
|
|
119
|
-
static off(pPluginName, pEventName, pListener) {
|
|
120
|
-
const eventScope = `${pPluginName}-${pEventName}`;
|
|
121
|
-
if (Kit.events[eventScope].includes(pListener)) {
|
|
122
|
-
Kit.events[eventScope].splice(Kit.events[eventScope].indexOf(pListener), 1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Sets the resource locator for the engine to reference the files we have in the resources folder. interface | map | icon | macro | sound are checked for.
|
|
127
|
-
* @param pData - An array of each file that was found in the resources folder.
|
|
128
|
-
*/
|
|
129
|
-
static setResource(pData) {
|
|
130
|
-
pData.forEach((pResource) => {
|
|
131
|
-
const extensionMatch = pResource.fileName.match(/\.[^.]+$/);
|
|
132
|
-
const fileNameWithoutExtensionMatch = pResource.fileName.match(/(.+?)(?=\.[^.]+$|$)/);
|
|
133
|
-
if (extensionMatch && fileNameWithoutExtensionMatch) {
|
|
134
|
-
const extension = extensionMatch[0];
|
|
135
|
-
const fileNameWithoutExtension = fileNameWithoutExtensionMatch[0];
|
|
136
|
-
const resourceType = extensionToPath[extension];
|
|
137
|
-
if (resourceType) {
|
|
138
|
-
globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `${pResource.resourceIdentifier}`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Sets the resources found in resources and preloads all interfaces found.
|
|
145
|
-
*/
|
|
146
|
-
static async setResources(pResourceJson) {
|
|
147
|
-
if (!globalThis.VYLO) {
|
|
148
|
-
throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
|
|
149
|
-
}
|
|
150
|
-
if (pResourceJson) {
|
|
151
|
-
const resources = Object.values(pResourceJson);
|
|
152
|
-
// Group all data from separate arrays in object to one unified array of all resource data
|
|
153
|
-
const consolidatedData = resources.flat();
|
|
154
|
-
// Set all the resources
|
|
155
|
-
this.setResource(consolidatedData);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { EventEmitter } from '../events/event-system';
|
|
2
|
-
import type { EmitterEvent } from '../types/shared-types';
|
|
3
|
-
export declare abstract class KitPlugin {
|
|
4
|
-
/**
|
|
5
|
-
* The name of this plugin.
|
|
6
|
-
*/
|
|
7
|
-
abstract name: string;
|
|
8
|
-
/**
|
|
9
|
-
* The emitter that belongs to this plugin.
|
|
10
|
-
*/
|
|
11
|
-
private _emitter;
|
|
12
|
-
/**
|
|
13
|
-
* Register this plugin with the event system.
|
|
14
|
-
* @param pEmitter - The emitter that belongs to this plugin.
|
|
15
|
-
*/
|
|
16
|
-
_register(pEmitter: EventEmitter): void;
|
|
17
|
-
/**
|
|
18
|
-
* The entry point for custom behavior after registration for custom plugins.
|
|
19
|
-
*/
|
|
20
|
-
abstract onRegistered(): void;
|
|
21
|
-
/**
|
|
22
|
-
* Emit an event.
|
|
23
|
-
* @param pEvent - The event to emit.
|
|
24
|
-
*/
|
|
25
|
-
emit(pEvent: EmitterEvent): void;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=kit-plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kit-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/kit-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,8BAAsB,SAAS;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAA6B;IAE7C;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY;IAIhC;;OAEG;IACH,QAAQ,CAAC,YAAY,IAAI,IAAI;IAE7B;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,YAAY;CAO5B"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export class KitPlugin {
|
|
2
|
-
/**
|
|
3
|
-
* The emitter that belongs to this plugin.
|
|
4
|
-
*/
|
|
5
|
-
_emitter = null;
|
|
6
|
-
/**
|
|
7
|
-
* Register this plugin with the event system.
|
|
8
|
-
* @param pEmitter - The emitter that belongs to this plugin.
|
|
9
|
-
*/
|
|
10
|
-
_register(pEmitter) {
|
|
11
|
-
this._emitter = pEmitter;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Emit an event.
|
|
15
|
-
* @param pEvent - The event to emit.
|
|
16
|
-
*/
|
|
17
|
-
emit(pEvent) {
|
|
18
|
-
if (!this._emitter) {
|
|
19
|
-
console.error('[Kit Plugin] emitter not set. This is an indication that the plugin is not registered.');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
this._emitter.emit(pEvent);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { KitPlugin } from '../kit-plugin';
|
|
2
|
-
import type { Client } from '../../types/vylo.d.ts';
|
|
3
|
-
export type NetworkListener<T extends unknown[] = unknown[]> = (pClient: Client, ...pData: T) => void;
|
|
4
|
-
export declare class Network extends KitPlugin {
|
|
5
|
-
name: string;
|
|
6
|
-
/**
|
|
7
|
-
* If this plugin is initiated.
|
|
8
|
-
*/
|
|
9
|
-
private initiated;
|
|
10
|
-
/**
|
|
11
|
-
* The packets that this plugin has registered. It is in the format of name: index
|
|
12
|
-
*/
|
|
13
|
-
private packets;
|
|
14
|
-
/**
|
|
15
|
-
* The packets that this plugin has registered. It is in the format of index: name
|
|
16
|
-
*/
|
|
17
|
-
private reversedPacketMap;
|
|
18
|
-
onRegistered(): void;
|
|
19
|
-
/**
|
|
20
|
-
* The listeners that are registered.
|
|
21
|
-
*/
|
|
22
|
-
private listeners;
|
|
23
|
-
/**
|
|
24
|
-
* Register a listener for a packet.
|
|
25
|
-
* @param pPacketName - The name of the packet that will be listened to.
|
|
26
|
-
* @param pListener - The listener that will be called when the packet is received.
|
|
27
|
-
*/
|
|
28
|
-
onPacket<T extends unknown[]>(pPacketName: string, pListener: NetworkListener<T>): void;
|
|
29
|
-
/**
|
|
30
|
-
* Register a listener for a packet.
|
|
31
|
-
* @deprecated Use `onPacket` instead.
|
|
32
|
-
* @param pPacketName - The name of the packet that will be listened to.
|
|
33
|
-
* @param pListener - The listener that will be called when the packet is received.
|
|
34
|
-
*/
|
|
35
|
-
on<T extends unknown[]>(pPacketName: string, pListener: NetworkListener<T>): void;
|
|
36
|
-
/**
|
|
37
|
-
* API for receiving data from the server.
|
|
38
|
-
* @param pClient - The client involved with this packet.
|
|
39
|
-
* @param pPacketName - The name of the packet that was sent.
|
|
40
|
-
* @param pData - The data that was sent.
|
|
41
|
-
* @param [pVerbose] - If the plugin should log packets.
|
|
42
|
-
*/
|
|
43
|
-
onNetwork(pClient: Client, pPacketName: number | string, pData?: unknown[], pVerbose?: boolean): void;
|
|
44
|
-
/**
|
|
45
|
-
* Register the packets registry.
|
|
46
|
-
* @param pPackets - An array of strings that represent the packet names.
|
|
47
|
-
*/
|
|
48
|
-
registerPackets(pPackets: readonly string[]): void;
|
|
49
|
-
/**
|
|
50
|
-
* Gets the index of a packet.
|
|
51
|
-
* @param pPacketName - The name of the packet.
|
|
52
|
-
*/
|
|
53
|
-
getPacket(pPacketName: string): number | undefined;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/network/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEtG,qBAAa,OAAQ,SAAQ,SAAS;IAClC,IAAI,SAAa;IACjB;;OAEG;IACH,OAAO,CAAC,SAAS,CAAkB;IACnC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAkC;IACjD;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAAkC;IAC3D,YAAY,IAAI,IAAI;IAGpB;;OAEG;IACH,OAAO,CAAC,SAAS,CAAiD;IAClE;;;;OAIG;IACH,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAOvF;;;;;OAKG;IACH,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAGjF;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,GAAE,OAAO,EAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI;IA+BzG;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IASlD;;;OAGG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAOrD"}
|