@evitcastudio/kit 1.0.2 → 1.1.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/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,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEnE,qBAAa,GAAG;IACZ;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAwC;IAC9D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmC;IAC1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM,CAAmD;IAExE;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAkB,GAAG,EAAE,GAAG,IAAI;IAMlD;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAkB,GAAG,GAAG,IAAI;IAkBzD;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAA0B,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIzE;;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,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;CAMtG"}
1
+ {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AACA,OAAO,sBAAsB,CAAC;AAiB9B,qBAAa,GAAG;IACZ;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAwC;IAC9D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmC;IAC1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM,CAAmD;IAExE,OAAO;IAIP;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAkB,GAAG,EAAE,GAAG,IAAI;IAMlD;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAkB,GAAG,GAAG,IAAI;IAkBzD;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAA0B,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIzE;;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,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAOnG;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAiB1B;;OAEG;WACU,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CA0B7C"}
package/lib/kit.js CHANGED
@@ -1,4 +1,18 @@
1
1
  import { EventEmitter } from './event-system';
2
+ import './types/shared-types';
3
+ const VYLO = globalThis.VYLO;
4
+ const extensionToPath = {
5
+ '.vyint': 'interface',
6
+ '.vym': 'map',
7
+ '.vyi': 'icon',
8
+ '.vymac': 'macros',
9
+ '.aac': 'sound',
10
+ '.mp3': 'sound',
11
+ '.wav': 'sound',
12
+ '.m4a': 'sound',
13
+ '.ogg': 'sound',
14
+ '.flac': 'sound'
15
+ };
2
16
  export class Kit {
3
17
  /**
4
18
  * A record of all plugins registered with the Kit class.
@@ -12,6 +26,9 @@ export class Kit {
12
26
  * A record of all event listeners.
13
27
  */
14
28
  static events = {};
29
+ constructor() {
30
+ throw new Error('[Kit] is not to be instantiated.');
31
+ }
15
32
  /**
16
33
  * Initialize the Kit class with plugins.
17
34
  * @param pPlugins - An array of plugins to initialize.
@@ -88,4 +105,49 @@ export class Kit {
88
105
  Kit.events[eventScope].splice(Kit.events[eventScope].indexOf(pListener), 1);
89
106
  }
90
107
  }
108
+ /**
109
+ * 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.
110
+ * @param pData - An array of each file that was found in the resources folder
111
+ */
112
+ static setResource(pData) {
113
+ pData.forEach((pResource) => {
114
+ const extensionMatch = pResource.fileName.match(/\.[^.]+$/);
115
+ const fileNameWithoutExtensionMatch = pResource.fileName.match(/(.+?)(?=\.[^.]+$|$)/);
116
+ if (extensionMatch && fileNameWithoutExtensionMatch) {
117
+ const extension = extensionMatch[0];
118
+ const fileNameWithoutExtension = fileNameWithoutExtensionMatch[0];
119
+ const resourceType = extensionToPath[extension];
120
+ if (resourceType) {
121
+ globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `resources/${resourceType}/${pResource.resourceIdentifier}`, true);
122
+ }
123
+ }
124
+ });
125
+ }
126
+ /**
127
+ * Sets the resources found in resources and preloads all interfaces found.
128
+ */
129
+ static async setResources() {
130
+ if (!globalThis.VYLO) {
131
+ throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
132
+ }
133
+ const resourcePath = './resource.json';
134
+ // Load the resource json and set the resources found
135
+ try {
136
+ const response = await fetch(resourcePath);
137
+ if (!response.ok) {
138
+ throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
139
+ }
140
+ const resourceJSON = await response.json();
141
+ if (resourceJSON) {
142
+ const resources = Object.values(resourceJSON);
143
+ // Group all data from separate arrays in object to one unified array of all resource data
144
+ const consolidatedData = resources.flat();
145
+ // Set all the resources
146
+ this.setResource(consolidatedData);
147
+ }
148
+ }
149
+ catch (pError) {
150
+ console.error(`[Kit] error reading ${resourcePath}`, pError);
151
+ }
152
+ }
91
153
  }
@@ -12,7 +12,12 @@ declare global {
12
12
  */
13
13
  data?: Record<string, any>;
14
14
  } & Record<string, any>;
15
+ type ResourceData = {
16
+ resourceIdentifier: string;
17
+ fileName: string;
18
+ };
15
19
  type Listener = (pData: EmitterEvent) => void;
20
+ var VYLO: VyloType;
16
21
  }
17
- export type { EmitterEvent, Listener };
22
+ export type {};
18
23
  //# sourceMappingURL=shared-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/types/shared-types.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,YAAY,GAAG;QAChB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAExB,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CACjD;AAED,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/types/shared-types.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,YAAY,GAAG;QAChB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAExB,KAAK,YAAY,GAAG;QAChB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,QAAQ,EAAE,MAAM,CAAA;KACnB,CAAC;IAEF,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAE9C,IAAI,IAAI,EAAE,QAAQ,CAAC;CACtB;AAED,YAAY,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evitcastudio/kit",
3
- "version": "1.0.2",
3
+ "version": "1.1.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",
@@ -1,4 +1,4 @@
1
- import type { EmitterEvent, Listener } from './types/shared-types';
1
+ import './types/shared-types';
2
2
  export class EventEmitter {
3
3
  private listener: Listener;
4
4
  private plugin: /*KitPlugin*/any;
package/src/kit.ts CHANGED
@@ -1,5 +1,20 @@
1
1
  import { EventEmitter } from './event-system';
2
- import type { EmitterEvent, Listener } from './types/shared-types';
2
+ import './types/shared-types';
3
+
4
+ const VYLO: VyloType = globalThis.VYLO;
5
+
6
+ const extensionToPath: Record<string, string> = {
7
+ '.vyint': 'interface',
8
+ '.vym': 'map',
9
+ '.vyi': 'icon',
10
+ '.vymac': 'macros',
11
+ '.aac': 'sound',
12
+ '.mp3': 'sound',
13
+ '.wav': 'sound',
14
+ '.m4a': 'sound',
15
+ '.ogg': 'sound',
16
+ '.flac': 'sound'
17
+ }
3
18
 
4
19
  export class Kit {
5
20
  /**
@@ -15,6 +30,10 @@ export class Kit {
15
30
  */
16
31
  private static events: Record<string, Array<(pData: any) => void>> = {};
17
32
 
33
+ private constructor() {
34
+ throw new Error('[Kit] is not to be instantiated.');
35
+ }
36
+
18
37
  /**
19
38
  * Initialize the Kit class with plugins.
20
39
  * @param pPlugins - An array of plugins to initialize.
@@ -103,4 +122,55 @@ export class Kit {
103
122
  Kit.events[eventScope].splice(Kit.events[eventScope].indexOf(pListener), 1);
104
123
  }
105
124
  }
125
+
126
+ /**
127
+ * 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.
128
+ * @param pData - An array of each file that was found in the resources folder
129
+ */
130
+ private static setResource(pData: ResourceData[]): void {
131
+ pData.forEach((pResource: ResourceData): void => {
132
+ const extensionMatch = pResource.fileName.match(/\.[^.]+$/);
133
+ const fileNameWithoutExtensionMatch = pResource.fileName.match(/(.+?)(?=\.[^.]+$|$)/);
134
+
135
+ if (extensionMatch && fileNameWithoutExtensionMatch) {
136
+ const extension = extensionMatch[0];
137
+ const fileNameWithoutExtension = fileNameWithoutExtensionMatch[0];
138
+ const resourceType = extensionToPath[extension];
139
+
140
+ if (resourceType) {
141
+ globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `resources/${resourceType}/${pResource.resourceIdentifier}`, true);
142
+ }
143
+ }
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Sets the resources found in resources and preloads all interfaces found.
149
+ */
150
+ static async setResources(): Promise<void> {
151
+ if (!globalThis.VYLO) {
152
+ throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
153
+ }
154
+ const resourcePath = './resource.json';
155
+ // Load the resource json and set the resources found
156
+ try {
157
+ const response = await fetch(resourcePath);
158
+
159
+ if (!response.ok) {
160
+ throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
161
+ }
162
+
163
+ const resourceJSON = await response.json();
164
+
165
+ if (resourceJSON) {
166
+ const resources: ResourceData[] = Object.values(resourceJSON);
167
+ // Group all data from separate arrays in object to one unified array of all resource data
168
+ const consolidatedData = resources.flat();
169
+ // Set all the resources
170
+ this.setResource(consolidatedData);
171
+ }
172
+ } catch (pError) {
173
+ console.error(`[Kit] error reading ${resourcePath}`, pError);
174
+ }
175
+ }
106
176
  }
@@ -13,7 +13,14 @@ declare global {
13
13
  data?: Record<string, any>;
14
14
  } & Record<string, any>;
15
15
 
16
+ type ResourceData = {
17
+ resourceIdentifier: string,
18
+ fileName: string
19
+ };
20
+
16
21
  type Listener = (pData: EmitterEvent) => void;
22
+
23
+ var VYLO: VyloType;
17
24
  }
18
25
 
19
- export type { EmitterEvent, Listener };
26
+ export type {};