@evitcastudio/kit 1.3.2 → 2.0.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 CHANGED
@@ -14,6 +14,31 @@ npm i @evitcastudio/kit -g
14
14
 
15
15
  *global flag is so the path is set properly for the CLI tool*
16
16
 
17
+ # Resources
18
+
19
+ This script will locate all Vylocity engine-related files within the specified directory and anonymize them before placing them in the designated resources folder.
20
+
21
+ ```bash
22
+ # From the CLI you will build all your resources to the out dir
23
+ kit build -i ./<in-dir> -o ./<out-dir>
24
+ ```
25
+
26
+ During the execution of this command, a `resource.json` file will be automatically generated within your source directory.
27
+ It is recommended to exclude this file from your version control system, as it is considered a build artifact.
28
+
29
+
30
+ > [!IMPORTANT]
31
+ > This API should be ran BEFORE VYLO.load() is called.
32
+
33
+ > [!WARNING]
34
+ > Depending on your environment the following [import syntax](https://github.com/EvitcaStudio/Kit/wiki/FAQ#importing-json-resources) for json may not work.
35
+
36
+
37
+ ```js
38
+ import resourceJSON from 'resource.json';
39
+ await Kit.setResources(resourceJSON);
40
+ ```
41
+
17
42
  # Using Kit with plugins
18
43
 
19
44
  ```ts
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /*!
4
- * @evitcastudio/kit@1.3.2 git+https://github.com/EvitcaStudio/Kit.git
5
- * Compiled Sat, 04 Jan 2025 16:05:39 UTC
4
+ * @evitcastudio/kit@2.0.0 git+https://github.com/EvitcaStudio/Kit.git
5
+ * Compiled Wed, 08 Jan 2025 21:06:50 UTC
6
6
  * Copyright (c) 2025 Jared Bates, Evitca Studio, "doubleactii"
7
7
  *
8
8
  * @evitcastudio/kit is licensed under the MIT License.
@@ -2528,7 +2528,7 @@ async function copyFile(pSource, pDestinationDir, pNewName) {
2528
2528
  }
2529
2529
  }
2530
2530
  async function saveResourceJSON() {
2531
- const filePath = join(resourceOutDirectory, "resources", "resource.json");
2531
+ const filePath = "resource.json";
2532
2532
  try {
2533
2533
  await fs.writeFile(filePath, JSON.stringify(resourceJSON, null, 4));
2534
2534
  } catch (pError) {
@@ -2573,7 +2573,7 @@ class KitCLI {
2573
2573
  // package.json
2574
2574
  var package_default = {
2575
2575
  name: "@evitcastudio/kit",
2576
- version: "1.3.2",
2576
+ version: "2.0.0",
2577
2577
  author: "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
2578
2578
  main: "./lib/index.js",
2579
2579
  types: "./lib/index.d.ts",
@@ -2613,7 +2613,6 @@ var package_default = {
2613
2613
  devDependencies: {
2614
2614
  "@eslint/create-config": "1.4.0",
2615
2615
  "@eslint/js": "^9.17.0",
2616
- "@evitcastudio/kit-plugin": "^1.0.7",
2617
2616
  "@types/bun": "latest",
2618
2617
  "@types/node": "^22.10.2",
2619
2618
  bun: "^1.1.42",
@@ -0,0 +1,13 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,25 @@
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/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export { Kit } from './kit';
2
- export { EventEmitter } from './event-system';
2
+ export { EventEmitter } from './events/event-system';
3
3
  export type { EmitterEvent, ResourceData, Listener } from './types/shared-types';
4
+ export { KitPlugin } from './plugins/kit-plugin';
5
+ export { Network } from './plugins/network';
6
+ export type { NetworkListener } from './plugins/network';
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,gBAAgB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
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,MAAM,sBAAsB,CAAC;AAGjF,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/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export { Kit } from './kit';
2
- export { EventEmitter } from './event-system';
2
+ export { EventEmitter } from './events/event-system';
3
+ // Plugins
4
+ export { KitPlugin } from './plugins/kit-plugin';
5
+ export { Network } from './plugins/network';
package/lib/kit.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { KitPlugin } from '@evitcastudio/kit-plugin';
2
- import type { EmitterEvent, Listener, KitPluginConstructor } from './types/shared-types';
1
+ import type { KitPlugin } from './plugins/kit-plugin';
2
+ import type { ResourceData, Listener, KitPluginConstructor } from './types/shared-types';
3
3
  export declare class Kit {
4
4
  /**
5
5
  * A record of all plugins registered with the Kit class.
@@ -51,7 +51,7 @@ export declare class Kit {
51
51
  * @param pEventName - The event name.
52
52
  * @param pListener - The listener to remove.
53
53
  */
54
- static off(pPluginName: string, pEventName: string, pListener: (pData: EmitterEvent) => void): void;
54
+ static off(pPluginName: string, pEventName: string, pListener: Listener): void;
55
55
  /**
56
56
  * 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.
57
57
  * @param pData - An array of each file that was found in the resources folder.
@@ -60,6 +60,6 @@ export declare class Kit {
60
60
  /**
61
61
  * Sets the resources found in resources and preloads all interfaces found.
62
62
  */
63
- static setResources(): Promise<void>;
63
+ static setResources(pResourceJson: Record<string, ResourceData[]>): Promise<void>;
64
64
  }
65
65
  //# sourceMappingURL=kit.d.ts.map
package/lib/kit.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAg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Emitter } from './event-system';
1
+ import { EventEmitter } from './events/event-system';
2
2
  const extensionToPath = {
3
3
  '.vyint': 'interface',
4
4
  '.vym': 'map',
@@ -42,23 +42,32 @@ export class Kit {
42
42
  */
43
43
  static registerPlugin(pPlugin) {
44
44
  const plugin = new pPlugin();
45
- if (Kit.plugins[plugin.name]) {
46
- throw new Error(`[Kit] plugin with name '${plugin.name}' is already registered.`);
45
+ const pluginName = plugin.name;
46
+ if (!pluginName || typeof pluginName !== 'string' || !/^[a-zA-Z0-9-_]+$/.test(pluginName)) {
47
+ throw new Error(`[Kit] Invalid plugin name: '${pluginName}'. The name must be a non-empty string containing only alphanumeric characters, dashes, or underscores.`);
47
48
  }
48
- const listener = (pEvent) => {
49
+ if (Kit.plugins[pluginName]) {
50
+ throw new Error(`[Kit] plugin with name '${pluginName}' is already registered.`);
51
+ }
52
+ const listener = function (pEvent) {
49
53
  Kit.emit(pEvent);
50
54
  };
51
55
  const emitter = new EventEmitter(listener, plugin);
52
- Kit.emitters.set(plugin.name, emitter);
53
- Kit.plugins[plugin.name] = plugin;
56
+ Kit.emitters.set(pluginName, emitter);
57
+ Kit.plugins[pluginName] = plugin;
54
58
  plugin._register(emitter);
59
+ plugin.onRegistered();
55
60
  }
56
61
  /**
57
62
  * Gets a plugin by name.
58
63
  * @param pName - String name of the plugin to retrieve.
59
64
  */
60
65
  static getPlugin(pName) {
61
- return Kit.plugins[pName];
66
+ const plugin = Kit.plugins[pName];
67
+ if (!plugin) {
68
+ return undefined;
69
+ }
70
+ return plugin;
62
71
  }
63
72
  /**
64
73
  * Lists all registered plugins.
@@ -124,39 +133,12 @@ export class Kit {
124
133
  /**
125
134
  * Sets the resources found in resources and preloads all interfaces found.
126
135
  */
127
- static async setResources() {
136
+ static async setResources(pResourceJson) {
128
137
  if (!globalThis.VYLO) {
129
138
  throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
130
139
  }
131
- let resourcePath = './resources/resource.json';
132
- let resourceJson;
133
- // Server environment (we do not use fetch as the file:// protocol is not supported atm)
134
- if (!globalThis.window) {
135
- const [fsPromises, path] = await Promise.all([
136
- import('fs/promises'),
137
- import('path')
138
- ]);
139
- const { readFile } = fsPromises;
140
- resourcePath = path.resolve('resources', 'resource.json');
141
- const data = await readFile(resourcePath, 'utf-8');
142
- resourceJson = JSON.parse(data);
143
- // Client environment
144
- }
145
- else {
146
- // Load the resource json and set the resources found
147
- try {
148
- const response = await fetch(resourcePath);
149
- if (!response.ok) {
150
- throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
151
- }
152
- resourceJson = await response.json();
153
- }
154
- catch (pError) {
155
- console.error(`[Kit] error reading ${resourcePath}`, pError);
156
- }
157
- }
158
- if (resourceJson) {
159
- const resources = Object.values(resourceJson);
140
+ if (pResourceJson) {
141
+ const resources = Object.values(pResourceJson);
160
142
  // Group all data from separate arrays in object to one unified array of all resource data
161
143
  const consolidatedData = resources.flat();
162
144
  // Set all the resources
@@ -0,0 +1,27 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,48 @@
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
+ on<T extends unknown[]>(pPacketName: string, pListener: NetworkListener<T>): void;
29
+ /**
30
+ * API for receiving data from the server.
31
+ * @param pClient - The client involved with this packet.
32
+ * @param pPacketName - The name of the packet that was sent.
33
+ * @param pData - The data that was sent.
34
+ * @param [pVerbose] - If the plugin should log packets.
35
+ */
36
+ onNetwork(pClient: Client, pPacketName: number | string, pData?: unknown[], pVerbose?: boolean): void;
37
+ /**
38
+ * Register the packets registry.
39
+ * @param pPackets - An array of strings that represent the packet names.
40
+ */
41
+ registerPackets(pPackets: readonly string[]): void;
42
+ /**
43
+ * Gets the index of a packet.
44
+ * @param pPacketName - The name of the packet.
45
+ */
46
+ getPacket(pPacketName: string): number | undefined;
47
+ }
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI;IAMjF;;;;;;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;IA4BzG;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IASlD;;;OAGG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAOrD"}
@@ -0,0 +1,88 @@
1
+ import { KitPlugin } from '../kit-plugin';
2
+ export class Network extends KitPlugin {
3
+ name = 'Network';
4
+ /**
5
+ * If this plugin is initiated.
6
+ */
7
+ initiated = false;
8
+ /**
9
+ * The packets that this plugin has registered. It is in the format of name: index
10
+ */
11
+ packets = new Map();
12
+ /**
13
+ * The packets that this plugin has registered. It is in the format of index: name
14
+ */
15
+ reversedPacketMap = new Map();
16
+ onRegistered() {
17
+ this.initiated = true;
18
+ }
19
+ /**
20
+ * The listeners that are registered.
21
+ */
22
+ listeners = new Map();
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
+ on(pPacketName, pListener) {
29
+ if (!this.packets.has(pPacketName)) {
30
+ throw new Error(`Packet name '${pPacketName}' is not registered.`);
31
+ }
32
+ this.listeners.set(pPacketName, pListener);
33
+ }
34
+ /**
35
+ * API for receiving data from the server.
36
+ * @param pClient - The client involved with this packet.
37
+ * @param pPacketName - The name of the packet that was sent.
38
+ * @param pData - The data that was sent.
39
+ * @param [pVerbose] - If the plugin should log packets.
40
+ */
41
+ onNetwork(pClient, pPacketName, pData = [], pVerbose) {
42
+ if (!this.initiated)
43
+ return;
44
+ if (typeof pPacketName === 'number') {
45
+ const packetName = this.reversedPacketMap.get(pPacketName);
46
+ if (!packetName) {
47
+ console.warn(`Unknown packet index: ${pPacketName}`);
48
+ return;
49
+ }
50
+ const listener = this.listeners.get(packetName);
51
+ if (pVerbose) {
52
+ console.group(`Kit.${this.name}Plugin.onNetwork`);
53
+ console.log(`Packet name: ${pPacketName}`);
54
+ console.log(`Resolved packet name: ${packetName}`);
55
+ console.log(`Data:`, pData);
56
+ console.groupEnd();
57
+ if (!listener) {
58
+ console.warn(`No listener registered for packet: ${packetName}`);
59
+ }
60
+ }
61
+ listener?.(pClient, ...pData);
62
+ }
63
+ }
64
+ /**
65
+ * Register the packets registry.
66
+ * @param pPackets - An array of strings that represent the packet names.
67
+ */
68
+ registerPackets(pPackets) {
69
+ this.packets.clear();
70
+ this.reversedPacketMap.clear();
71
+ pPackets.forEach((name, index) => {
72
+ this.packets.set(name, index);
73
+ this.reversedPacketMap.set(index, name);
74
+ });
75
+ }
76
+ /**
77
+ * Gets the index of a packet.
78
+ * @param pPacketName - The name of the packet.
79
+ */
80
+ getPacket(pPacketName) {
81
+ const packet = this.packets.get(pPacketName);
82
+ if (packet === undefined) {
83
+ console.warn(`Packet '${pPacketName}' is not registered.`);
84
+ }
85
+ ;
86
+ return packet;
87
+ }
88
+ }
@@ -1,4 +1,5 @@
1
- import type { KitPlugin } from '@evitcastudio/kit-plugin';
1
+ import type { KitPlugin } from '../plugins/kit-plugin';
2
+ import type { VyloType } from './vylo.d.ts';
2
3
  /**
3
4
  * The EmitterEvent type is used to define the shape of the data that is passed to the event listeners.
4
5
  */
@@ -11,7 +12,8 @@ type EmitterEvent = {
11
12
  * The data associated with the event.
12
13
  */
13
14
  data?: Record<string, unknown>;
14
- } & Record<string, unknown>;
15
+ [key: string]: unknown;
16
+ };
15
17
  type ResourceData = {
16
18
  resourceIdentifier: string;
17
19
  fileName: string;
@@ -19,6 +21,9 @@ type ResourceData = {
19
21
  type Listener = (pData: EmitterEvent) => void;
20
22
  type KitPluginConstructor<T extends KitPlugin> = new () => T;
21
23
  declare global {
24
+ /**
25
+ * The Vylocity engine.
26
+ */
22
27
  var VYLO: VyloType;
23
28
  }
24
29
  export type { EmitterEvent, ResourceData, Listener, KitPluginConstructor };
@@ -1 +1 @@
1
- {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/types/shared-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,KAAK,YAAY,GAAG;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B,KAAK,YAAY,GAAG;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAC;AAEF,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAE9C,KAAK,oBAAoB,CAAC,CAAC,SAAS,SAAS,IAAI,UAAU,CAAC,CAAC;AAC7D,OAAO,CAAC,MAAM,CAAC;IAEX,IAAI,IAAI,EAAE,QAAQ,CAAC;CACtB;AAED,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/types/shared-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C;;GAEG;AACH,KAAK,YAAY,GAAG;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAA;AAED,KAAK,YAAY,GAAG;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAC;AAEF,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAE9C,KAAK,oBAAoB,CAAC,CAAC,SAAS,SAAS,IAAI,UAAU,CAAC,CAAC;AAC7D,OAAO,CAAC,MAAM,CAAC;IACX;;OAEG;IAEH,IAAI,IAAI,EAAE,QAAQ,CAAC;CACtB;AAED,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evitcastudio/kit",
3
- "version": "1.3.2",
3
+ "version": "2.0.0",
4
4
  "author": "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -40,7 +40,6 @@
40
40
  "devDependencies": {
41
41
  "@eslint/create-config": "1.4.0",
42
42
  "@eslint/js": "^9.17.0",
43
- "@evitcastudio/kit-plugin": "^1.0.7",
44
43
  "@types/bun": "latest",
45
44
  "@types/node": "^22.10.2",
46
45
  "bun": "^1.1.42",