@@ -27,6 +27,8 @@ export class Mod {
2727
2828 /** @type {string[] } */
2929 this . assets = [ ] ;
30+ /** @type {Record<string, string|string[]> } */
31+ this . runtimeAssets = { } ;
3032 /** @type {Record<string, string> } */
3133 this . dependencies = { } ;
3234 }
@@ -60,18 +62,19 @@ export class Mod {
6062 /**
6163 *
6264 * @param {string } path
65+ * @returns {string|string[]|undefined }
6366 */
6467 getAsset ( path ) {
6568 path = path . replace ( / \\ / g, '/' ) . trim ( ) ;
6669
67- if ( this . runtimeAssets && this . runtimeAssets [ path ] ) {
70+ if ( this . runtimeAssets [ path ] ) {
6871 return this . runtimeAssets [ path ] ;
6972 }
7073
71- const base = this . baseDirectory . substr ( 7 ) + 'assets/' ;
74+ const base = this . baseDirectory . substring ( 7 ) + 'assets/' ;
7275 for ( const asset of this . assets ) {
7376 if ( asset . startsWith ( base ) ) {
74- if ( asset . substr ( base . length ) === path ) {
77+ if ( asset . substring ( base . length ) === path ) {
7578 return asset ;
7679 }
7780 } else {
@@ -85,12 +88,28 @@ export class Mod {
8588 /**
8689 *
8790 * @param {string } original
88- * @param {string } newPath
91+ * @param {string|string[] } newPath
8992 */
9093 setAsset ( original , newPath ) {
9194 this . runtimeAssets [ original ] = newPath ;
9295 }
9396
97+ /**
98+ * Adds a patch to the mod.
99+ * @param {string } original The original file path without .patch
100+ * @param {string[] } patchPath The patch file path with .patch
101+ */
102+ addPatch ( original , ...patchPath ) {
103+ const originalPatchPath = original + '.patch' ;
104+ let list = this . runtimeAssets [ originalPatchPath ] || [ ] ;
105+ if ( typeof patchPath === 'string' ) {
106+ list = [ list , ...patchPath ] ;
107+ } else {
108+ list . push ( ...patchPath ) ;
109+ }
110+ this . runtimeAssets [ originalPatchPath ] = list ;
111+ }
112+
94113
95114 async _loadPlugin ( ) {
96115 window . _tmp = this . plugin ;
0 commit comments