Add sound and midi to number extension

This commit is contained in:
2023-11-14 16:43:37 +02:00
parent 463aef7736
commit ef596948c6

View File

@ -1,5 +1,7 @@
import { type UserAPI } from "../API"; import { type UserAPI } from "../API";
import { MidiEvent } from "../classes/MidiEvent";
import { Player } from "../classes/ZPlayer"; import { Player } from "../classes/ZPlayer";
import { SoundEvent } from "../classes/SoundEvent";
declare global { declare global {
interface Number { interface Number {
@ -21,78 +23,91 @@ declare global {
z14(): Player; z14(): Player;
z15(): Player; z15(): Player;
z16(): Player; z16(): Player;
note(): number; midi(): MidiEvent;
sound(name: string): SoundEvent;
} }
} }
export const makeNumberExtensions = (api: UserAPI) => { export const makeNumberExtensions = (api: UserAPI) => {
Number.prototype.z0 = function (options: {[key: string]: any} = {}) { Number.prototype.z0 = function (options: {[key: string]: any} = {}) {
return api.z0(this.valueOf().toString().split("").join(), options); return api.z0(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z1 = function (options: {[key: string]: any} = {}) { Number.prototype.z1 = function (options: {[key: string]: any} = {}) {
return api.z1(this.valueOf().toString().split("").join(), options); return api.z1(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z2 = function (options: {[key: string]: any} = {}) { Number.prototype.z2 = function (options: {[key: string]: any} = {}) {
return api.z2(this.valueOf().toString().split("").join(), options); return api.z2(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z3 = function (options: {[key: string]: any} = {}) { Number.prototype.z3 = function (options: {[key: string]: any} = {}) {
return api.z3(this.valueOf().toString().split("").join(), options); return api.z3(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z4 = function (options: {[key: string]: any} = {}) { Number.prototype.z4 = function (options: {[key: string]: any} = {}) {
return api.z4(this.valueOf().toString().split("").join(), options); return api.z4(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z5 = function (options: {[key: string]: any} = {}) { Number.prototype.z5 = function (options: {[key: string]: any} = {}) {
return api.z5(this.valueOf().toString().split("").join(), options); return api.z5(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z6 = function (options: {[key: string]: any} = {}) { Number.prototype.z6 = function (options: {[key: string]: any} = {}) {
return api.z6(this.valueOf().toString().split("").join(), options); return api.z6(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z7 = function (options: {[key: string]: any} = {}) { Number.prototype.z7 = function (options: {[key: string]: any} = {}) {
return api.z7(this.valueOf().toString().split("").join(), options); return api.z7(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z8 = function (options: {[key: string]: any} = {}) { Number.prototype.z8 = function (options: {[key: string]: any} = {}) {
return api.z8(this.valueOf().toString().split("").join(), options); return api.z8(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z9 = function (options: {[key: string]: any} = {}) { Number.prototype.z9 = function (options: {[key: string]: any} = {}) {
return api.z9(this.valueOf().toString().split("").join(), options); return api.z9(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z10 = function (options: {[key: string]: any} = {}) { Number.prototype.z10 = function (options: {[key: string]: any} = {}) {
return api.z10(this.valueOf().toString().split("").join(), options); return api.z10(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z11 = function (options: {[key: string]: any} = {}) { Number.prototype.z11 = function (options: {[key: string]: any} = {}) {
return api.z11(this.valueOf().toString().split("").join(), options); return api.z11(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z12 = function (options: {[key: string]: any} = {}) { Number.prototype.z12 = function (options: {[key: string]: any} = {}) {
return api.z12(this.valueOf().toString().split("").join(), options); return api.z12(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z13 = function (options: {[key: string]: any} = {}) { Number.prototype.z13 = function (options: {[key: string]: any} = {}) {
return api.z13(this.valueOf().toString().split("").join(), options); return api.z13(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z14 = function (options: {[key: string]: any} = {}) { Number.prototype.z14 = function (options: {[key: string]: any} = {}) {
return api.z14(this.valueOf().toString().split("").join(), options); return api.z14(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z15 = function (options: {[key: string]: any} = {}) { Number.prototype.z15 = function (options: {[key: string]: any} = {}) {
return api.z15(this.valueOf().toString().split("").join(), options); return api.z15(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.z16 = function (options: {[key: string]: any} = {}) { Number.prototype.z16 = function (options: {[key: string]: any} = {}) {
return api.z16(this.valueOf().toString().split("").join(), options); return api.z16(this.valueOf().toString().split("").join(" "), options);
}; };
Number.prototype.midi = function (...kwargs: any[]) {
return api.midi(this.valueOf(), ...kwargs);
}
Number.prototype.sound = function (name: string) {
if(Number.isInteger(this.valueOf())) {
return (api.sound(name) as SoundEvent).note(this.valueOf());
} else {
return (api.sound(name) as SoundEvent).freq(this.valueOf());
}
}
} }