Skip to content

Commit 5aba109

Browse files
authored
Merge pull request #107 from CCDirectLink/multiple-patches
Allow a mod to add multiple runtime patches
2 parents 67a5b55 + bf7dbff commit 5aba109

8 files changed

Lines changed: 60 additions & 17 deletions

File tree

assets/mods/simplify/ccmod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "Simplify",
3-
"version": "2.13.0",
3+
"version": "2.14.0",
44
"title": "Simplify",
55
"description": "Library mod for CCLoader2.",
66
"repository": "https://github.com/CCDirectLink/CCLoader",

assets/mods/simplify/mod.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
*
141141
* @param {string|Mod} mod
142142
* @param {string} name
143-
* @returns {string}
143+
* @returns {string|string[]}
144144
*/
145145
getAsset(mod, name) {
146146
if(!mod) {
@@ -164,7 +164,11 @@
164164
for (const mod of window.activeMods) {
165165
const asset = mod.getAsset(name);
166166
if(asset) {
167-
result.push(asset);
167+
if (typeof asset === 'string') {
168+
result.push(asset);
169+
} else {
170+
result.push(...asset);
171+
}
168172
}
169173
}
170174

assets/mods/simplify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"prestart": "prestart.js",
77
"plugin": "plugin.js",
88
"hidden": true,
9-
"version": "2.13.0",
9+
"version": "2.14.0",
1010
"ccmodDependencies": {
1111
"ccloader": "^2.22.0",
1212
"crosscode": "^1.0.0"

assets/mods/simplify/postloadModule.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ import CustomDebugState from './lib/custom-debug-state.js';
402402
for (const mod of window.activeMods) {
403403
const asset = mod.getAsset(name);
404404
if(asset) {
405-
result.push(asset);
405+
if (typeof asset === 'string') {
406+
result.push(asset);
407+
} else {
408+
result.push(...asset);
409+
}
406410
}
407411
}
408412

@@ -425,10 +429,19 @@ import CustomDebugState from './lib/custom-debug-state.js';
425429
for (const mod of window.activeMods) {
426430
const asset = mod.getAsset(name);
427431
if(asset) {
428-
result.push({
429-
mod: mod,
430-
path: asset
431-
});
432+
if (typeof asset === 'string') {
433+
result.push({
434+
mod: mod,
435+
path: asset
436+
});
437+
} else {
438+
for (const subasset of asset) {
439+
result.push({
440+
mod: mod,
441+
path: subasset
442+
});
443+
}
444+
}
432445
}
433446
}
434447

ccloader/ccmod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "ccloader",
3-
"version": "2.23.3",
3+
"version": "2.24.0",
44
"title": "CCLoader",
55
"description": "Modloader for CrossCode. This or a similar modloader is needed for most mods.",
66
"repository": "https://github.com/CCDirectLink/CCLoader",

ccloader/js/ccloader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Plugin } from './plugin.js';
55
import { Greenworks } from './greenworks.js';
66
import { Package } from './package.js';
77

8-
const CCLOADER_VERSION = '2.23.3';
8+
const CCLOADER_VERSION = '2.24.0';
99
const KNOWN_EXTENSIONS = ["post-game", "manlea", "ninja-skin", "fish-gear", "flying-hedgehag", "scorpion-robo", "snowman-tank"]
1010

1111
export class ModLoader {

ccloader/js/mod.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

ccloader/js/types/mod.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ declare namespace ccloader {
3131
get baseDirectory(): string;
3232
get isEnabled(): boolean;
3333

34-
getAsset(path: string): string | undefined;
35-
setAsset(original: string, newPath: string): void;
34+
getAsset(path: string): string | string[] | undefined;
35+
setAsset(original: string, newPath: string | string[]): void;
36+
37+
/**
38+
* Adds a patch to the mod.
39+
* @param original The original file path without .patch
40+
* @param patchPath The patch file path with .patch
41+
*/
42+
addPatch(original: string, ...patchPath: string[]): void;
3643
}
3744
}

0 commit comments

Comments
 (0)