1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 02:01:51 +00:00

Allow overwrite by default

Also changed syntax to be more like the other methods
This commit is contained in:
Bagel03 2022-01-25 21:27:52 -05:00 committed by GitHub
parent 18c112ec47
commit 66f6aeced1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,11 @@ import { BaseHUDPart } from "../game/hud/base_hud_part";
* @typedef {{new(...args: any[]): any, prototype: any}} constructable
*/
/**
* @template O, T
* @typedef {{[P in keyof O as O[P] extends T ? P : never]: O[P] }} withOnlyType
*/
/**
* @template {(...args: any) => any} F The function
* @template {object} T The value of this
@ -484,19 +489,24 @@ export class ModInterface {
}
/**
* Creates a new class that extends another class (DOES NOT OVERWRITE)
* @template {any} S Scope
* @template {withOnlyType<S, constructable>} T
* @template {keyof T} C Original constructor name
* @template {Extract<T[C], constructable>} M the method
*
* @template {constructable} C
* @param {C} classHandle
* @param {bindThis<(...args: ConstructorParameters<C>) => any, InstanceType<C>>} constructor
* @returns {C}
* @param {bindThis<extendsPrams<(...args: ConstructorParameters<M>) => any>, InstanceType<M>>} constructor
* @param {S} scope
*/
extendConstructor(classHandle, constructor) {
//@ts-ignore
return function (...args) {
const obj = new classHandle();
//@ts-ignore
constructor.apply(obj, args);
extendConstructor(scope, classHandle, constructor) {
//@ts-ignore Holy crap guys so get this TSC IS A DUMBASS LMAO
const old = scope[classHandle];
//@ts-ignore lmao (2)
scope[classHandle] = function () {
const obj = new old(...arguments);
//@ts-ignore lmao (3)
constructor.apply(obj, arguments);
return obj;
};
}