@evitcastudio/kit 1.0.1 → 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/README.md +3 -1
- package/bin/cli.ts +1 -1
- package/bin/index.ts +1 -1
- package/bin/resource-builder.ts +25 -2
- package/bin/types/shared-types.ts +1 -1
- package/docs/assets/highlight.css +8 -8
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/index.Kit.html +10 -9
- package/docs/index.html +4 -3
- package/docs/modules/types_shared-types.html +1 -1
- package/docs/types/types_shared-types.EmitterEvent.html +1 -1
- package/docs/types/types_shared-types.Listener.html +1 -1
- package/docs/types/types_shared-types.ResourceData.html +1 -0
- package/docs/variables/types_shared-types.VYLO.html +1 -0
- package/lib/bundle/cli/cli.js +17 -3
- package/lib/event-system.d.ts +1 -1
- package/lib/event-system.d.ts.map +1 -1
- package/lib/event-system.js +1 -0
- package/lib/kit.d.ts +11 -1
- package/lib/kit.d.ts.map +1 -1
- package/lib/kit.js +62 -0
- package/lib/types/shared-types.d.ts +6 -1
- package/lib/types/shared-types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/event-system.ts +1 -1
- package/src/kit.ts +71 -1
- package/src/types/shared-types.ts +8 -1
- package/src/types/vylo.d.ts +3790 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>VYLO | @evitcastudio/kit</title><meta name="description" content="Documentation for @evitcastudio/kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@evitcastudio/kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@evitcastudio/kit</a></li><li><a href="../modules/types_shared-types.html">types/shared-types</a></li><li><a href="types_shared-types.VYLO.html">VYLO</a></li></ul><h1>Variable VYLO</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">VYLO</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">VyloType</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/EvitcaStudio/Kit/blob/6c0f7eee9dc164114a257080f04e3fdab304ea32/src/types/shared-types.ts#L23">types/shared-types.ts:23</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@evitcastudio/kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/lib/bundle/cli/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/*!
|
|
4
|
-
* @evitcastudio/kit@1.0
|
|
5
|
-
* Compiled
|
|
4
|
+
* @evitcastudio/kit@1.1.0 git+https://github.com/EvitcaStudio/Kit.git
|
|
5
|
+
* Compiled Fri, 27 Dec 2024 09:59:47 UTC
|
|
6
6
|
* Copyright (c) 2024 Jared Bates, Evitca Studio, "doubleactii"
|
|
7
7
|
*
|
|
8
8
|
* @evitcastudio/kit is licensed under the MIT License.
|
|
@@ -2491,6 +2491,7 @@ function isValidExtension(pExtension) {
|
|
|
2491
2491
|
}
|
|
2492
2492
|
async function processAllFiles() {
|
|
2493
2493
|
try {
|
|
2494
|
+
await clearResourceTypeDirectories(`${resourceOutDirectory}/resources`, RESOURCE_TYPES);
|
|
2494
2495
|
const copyOperations = resourcesToProcess.map(({ filePath, type }) => {
|
|
2495
2496
|
const fileName = basename(filePath);
|
|
2496
2497
|
const resource = resourceJSON[type].find((res) => res.fileName === fileName);
|
|
@@ -2507,6 +2508,19 @@ async function processAllFiles() {
|
|
|
2507
2508
|
logError(`[Error] Processing files in batch: ${pError.message}`);
|
|
2508
2509
|
}
|
|
2509
2510
|
}
|
|
2511
|
+
async function clearResourceTypeDirectories(pBaseDirectory, pDirectoriesToRemove) {
|
|
2512
|
+
try {
|
|
2513
|
+
for (const directory of pDirectoriesToRemove) {
|
|
2514
|
+
const directoryPath = join(pBaseDirectory, directory);
|
|
2515
|
+
const directoryExists = await fs.stat(directoryPath).then((stat) => stat.isDirectory()).catch(() => false);
|
|
2516
|
+
if (directoryExists) {
|
|
2517
|
+
await fs.rm(directoryPath, { recursive: true });
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
} catch (pError) {
|
|
2521
|
+
log(`${error(`[Error]`)} clearing directories: ${pError}`);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2510
2524
|
async function copyFile(pSource, pDestinationDir, pNewName) {
|
|
2511
2525
|
try {
|
|
2512
2526
|
await fs.mkdir(pDestinationDir, { recursive: true });
|
|
@@ -2561,7 +2575,7 @@ class KitCLI {
|
|
|
2561
2575
|
// package.json
|
|
2562
2576
|
var package_default = {
|
|
2563
2577
|
name: "@evitcastudio/kit",
|
|
2564
|
-
version: "1.0
|
|
2578
|
+
version: "1.1.0",
|
|
2565
2579
|
author: "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
|
|
2566
2580
|
main: "./lib/index.js",
|
|
2567
2581
|
types: "./lib/index.d.ts",
|
package/lib/event-system.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-system.d.ts","sourceRoot":"","sources":["../src/event-system.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"event-system.d.ts","sourceRoot":"","sources":["../src/event-system.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAmB;gBAErB,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAe,GAAG;IAK1D;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;CAcnC"}
|
package/lib/event-system.js
CHANGED
package/lib/kit.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './types/shared-types';
|
|
2
2
|
export declare class Kit {
|
|
3
3
|
/**
|
|
4
4
|
* A record of all plugins registered with the Kit class.
|
|
@@ -12,6 +12,7 @@ export declare class Kit {
|
|
|
12
12
|
* A record of all event listeners.
|
|
13
13
|
*/
|
|
14
14
|
private static events;
|
|
15
|
+
private constructor();
|
|
15
16
|
/**
|
|
16
17
|
* Initialize the Kit class with plugins.
|
|
17
18
|
* @param pPlugins - An array of plugins to initialize.
|
|
@@ -50,5 +51,14 @@ export declare class Kit {
|
|
|
50
51
|
* @param pListener - The listener to remove.
|
|
51
52
|
*/
|
|
52
53
|
static off(pPluginName: string, pEventName: string, pListener: (pData: EmitterEvent) => void): void;
|
|
54
|
+
/**
|
|
55
|
+
* 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.
|
|
56
|
+
* @param pData - An array of each file that was found in the resources folder
|
|
57
|
+
*/
|
|
58
|
+
private static setResource;
|
|
59
|
+
/**
|
|
60
|
+
* Sets the resources found in resources and preloads all interfaces found.
|
|
61
|
+
*/
|
|
62
|
+
static setResources(): Promise<void>;
|
|
53
63
|
}
|
|
54
64
|
//# 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,
|
|
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 {
|
|
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;
|
|
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
package/src/event-system.ts
CHANGED
package/src/kit.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { EventEmitter } from './event-system';
|
|
2
|
-
import
|
|
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 {
|
|
26
|
+
export type {};
|