@evitcastudio/kit 1.1.3 → 1.1.5
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/lib/bundle/cli/cli.js +12 -8
- package/package.json +10 -6
- package/CONTRIBUTING.md +0 -0
- package/bin/cli.ts +0 -71
- package/bin/index.ts +0 -11
- package/bin/resource-builder.ts +0 -219
- package/bin/types/shared-types.ts +0 -10
- package/bun-build.ts +0 -56
- package/bun.lockb +0 -0
- package/bunfig.toml +0 -4
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1610
- package/docs/classes/index.Kit.html +0 -24
- package/docs/index.html +0 -16
- package/docs/modules/index.html +0 -1
- package/docs/modules/types_shared-types.html +0 -1
- package/docs/modules.html +0 -1
- package/docs/types/types_shared-types.EmitterEvent.html +0 -4
- package/docs/types/types_shared-types.KitPluginConstructor.html +0 -1
- package/docs/types/types_shared-types.Listener.html +0 -1
- package/docs/types/types_shared-types.ResourceData.html +0 -1
- package/docs/variables/types_shared-types.VYLO.html +0 -1
- package/eslint.config.js +0 -13
- package/src/event-system.ts +0 -30
- package/src/index.ts +0 -1
- package/src/kit.ts +0 -175
- package/src/types/shared-types.ts +0 -30
- package/src/types/vylo.d.ts +0 -3790
- package/tests/kit-cli.test.ts +0 -75
- package/tests/kit.test.ts +0 -33
- package/tsconfig.json +0 -37
package/src/kit.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from './event-system';
|
|
2
|
-
import type { KitPlugin } from '@evitcastudio/kit-plugin';
|
|
3
|
-
import './types/shared-types';
|
|
4
|
-
|
|
5
|
-
const extensionToPath: Record<string, string> = {
|
|
6
|
-
'.vyint': 'interface',
|
|
7
|
-
'.vym': 'map',
|
|
8
|
-
'.vyi': 'icon',
|
|
9
|
-
'.vymac': 'macros',
|
|
10
|
-
'.aac': 'sound',
|
|
11
|
-
'.mp3': 'sound',
|
|
12
|
-
'.wav': 'sound',
|
|
13
|
-
'.m4a': 'sound',
|
|
14
|
-
'.ogg': 'sound',
|
|
15
|
-
'.flac': 'sound'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class Kit {
|
|
19
|
-
/**
|
|
20
|
-
* A record of all plugins registered with the Kit class.
|
|
21
|
-
*/
|
|
22
|
-
private static plugins: Record<string, KitPlugin> = {};
|
|
23
|
-
/**
|
|
24
|
-
* A set of all plugin emitters.
|
|
25
|
-
*/
|
|
26
|
-
private static emitters = new Map<string, EventEmitter>();
|
|
27
|
-
/**
|
|
28
|
-
* A record of all event listeners.
|
|
29
|
-
*/
|
|
30
|
-
private static events: Record<string, Array<Listener>> = {};
|
|
31
|
-
|
|
32
|
-
private constructor() {
|
|
33
|
-
throw new Error('[Kit] is not to be instantiated.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Initialize the Kit class with plugins.
|
|
38
|
-
* @param pPlugins - An array of plugins to initialize.
|
|
39
|
-
*/
|
|
40
|
-
static init<T extends KitPlugin>(pPlugins: KitPluginConstructor<T>[]): void {
|
|
41
|
-
pPlugins.forEach(pPlugin => {
|
|
42
|
-
this.registerPlugin(pPlugin);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Register a plugin with the Kit class.
|
|
48
|
-
* @param pPlugin - The plugin to register.
|
|
49
|
-
*/
|
|
50
|
-
static registerPlugin<T extends KitPlugin>(pPlugin: KitPluginConstructor<T>): void {
|
|
51
|
-
const plugin = new pPlugin();
|
|
52
|
-
|
|
53
|
-
if (Kit.plugins[plugin.name]) {
|
|
54
|
-
throw new Error(`[Kit] plugin with name '${plugin.name}' is already registered.`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const listener: Listener = (pEvent: EmitterEvent) => {
|
|
58
|
-
Kit.emit(pEvent);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const emitter = new EventEmitter(listener, plugin);
|
|
62
|
-
Kit.emitters.set(plugin.name, emitter);
|
|
63
|
-
|
|
64
|
-
Kit.plugins[plugin.name] = plugin;
|
|
65
|
-
plugin._register(emitter);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets a plugin by name.
|
|
70
|
-
* @param pName - String name of the plugin to retrieve.
|
|
71
|
-
*/
|
|
72
|
-
static getPlugin<T extends KitPlugin>(pName: string): T | undefined {
|
|
73
|
-
return Kit.plugins[pName] as T;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Lists all registered plugins.
|
|
78
|
-
*/
|
|
79
|
-
static getPlugins(): string[] {
|
|
80
|
-
return Object.keys(Kit.plugins);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Emit an event to all listeners.
|
|
85
|
-
* @param pEvent - The event to emit.
|
|
86
|
-
*/
|
|
87
|
-
private static emit(pEvent: EmitterEvent): void {
|
|
88
|
-
const { plugin, event } = pEvent;
|
|
89
|
-
const eventScope = `${plugin}-${event}`;
|
|
90
|
-
|
|
91
|
-
if (!Kit.events[eventScope]) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
Kit.events[eventScope].forEach(pListener => pListener(pEvent));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Listen for an event.
|
|
100
|
-
* @param pPluginName - The plugin namespace.
|
|
101
|
-
* @param pEventName - The event name.
|
|
102
|
-
* @param pListener - The listener to call when the event is emitted.
|
|
103
|
-
*/
|
|
104
|
-
static on(pPluginName: string, pEventName: string, pListener: Listener): void {
|
|
105
|
-
const eventScope = `${pPluginName}-${pEventName}`;
|
|
106
|
-
if (!Kit.events[eventScope]) {
|
|
107
|
-
Kit.events[eventScope] = [];
|
|
108
|
-
}
|
|
109
|
-
Kit.events[eventScope].push(pListener);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Removes an event listener.
|
|
114
|
-
* @param pPluginName - The plugin namespace.
|
|
115
|
-
* @param pEventName - The event name.
|
|
116
|
-
* @param pListener - The listener to remove.
|
|
117
|
-
*/
|
|
118
|
-
static off(pPluginName: string, pEventName: string, pListener: (pData: EmitterEvent) => void): void {
|
|
119
|
-
const eventScope = `${pPluginName}-${pEventName}`;
|
|
120
|
-
if (Kit.events[eventScope].includes(pListener)) {
|
|
121
|
-
Kit.events[eventScope].splice(Kit.events[eventScope].indexOf(pListener), 1);
|
|
122
|
-
}
|
|
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
|
-
private static setResource(pData: ResourceData[]): void {
|
|
130
|
-
pData.forEach((pResource: ResourceData): void => {
|
|
131
|
-
const extensionMatch = pResource.fileName.match(/\.[^.]+$/);
|
|
132
|
-
const fileNameWithoutExtensionMatch = pResource.fileName.match(/(.+?)(?=\.[^.]+$|$)/);
|
|
133
|
-
|
|
134
|
-
if (extensionMatch && fileNameWithoutExtensionMatch) {
|
|
135
|
-
const extension = extensionMatch[0];
|
|
136
|
-
const fileNameWithoutExtension = fileNameWithoutExtensionMatch[0];
|
|
137
|
-
const resourceType = extensionToPath[extension];
|
|
138
|
-
|
|
139
|
-
if (resourceType) {
|
|
140
|
-
globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `resources/${resourceType}/${pResource.resourceIdentifier}`, true);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Sets the resources found in resources and preloads all interfaces found.
|
|
148
|
-
*/
|
|
149
|
-
static async setResources(): Promise<void> {
|
|
150
|
-
if (!globalThis.VYLO) {
|
|
151
|
-
throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
|
|
152
|
-
}
|
|
153
|
-
const resourcePath = './resource.json';
|
|
154
|
-
// Load the resource json and set the resources found
|
|
155
|
-
try {
|
|
156
|
-
const response = await fetch(resourcePath);
|
|
157
|
-
|
|
158
|
-
if (!response.ok) {
|
|
159
|
-
throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const resourceJSON = await response.json();
|
|
163
|
-
|
|
164
|
-
if (resourceJSON) {
|
|
165
|
-
const resources: ResourceData[] = Object.values(resourceJSON);
|
|
166
|
-
// Group all data from separate arrays in object to one unified array of all resource data
|
|
167
|
-
const consolidatedData = resources.flat();
|
|
168
|
-
// Set all the resources
|
|
169
|
-
this.setResource(consolidatedData);
|
|
170
|
-
}
|
|
171
|
-
} catch (pError) {
|
|
172
|
-
console.error(`[Kit] error reading ${resourcePath}`, pError);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { KitPlugin } from '@evitcastudio/kit-plugin';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
/**
|
|
5
|
-
* The EmitterEvent type is used to define the shape of the data that is passed to the event listeners.
|
|
6
|
-
*/
|
|
7
|
-
type EmitterEvent = {
|
|
8
|
-
/**
|
|
9
|
-
* The event name, e.g., "draw-frame".
|
|
10
|
-
*/
|
|
11
|
-
event: string;
|
|
12
|
-
/**
|
|
13
|
-
* The data associated with the event.
|
|
14
|
-
*/
|
|
15
|
-
data?: Record<string, unknown>;
|
|
16
|
-
} & Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
type ResourceData = {
|
|
19
|
-
resourceIdentifier: string,
|
|
20
|
-
fileName: string
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type Listener = (pData: EmitterEvent) => void;
|
|
24
|
-
|
|
25
|
-
type KitPluginConstructor<T extends KitPlugin> = new () => T;
|
|
26
|
-
/* eslint-disable-next-line no-var */
|
|
27
|
-
var VYLO: VyloType;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type {};
|