From 19f73fe2f0d39e372d0b230470d8e438e26f0f48 Mon Sep 17 00:00:00 2001 From: krypek Date: Mon, 25 Nov 2024 16:54:48 +0100 Subject: [PATCH] Add instance name and instance name displaying --- src/instance.ts | 21 +++++++++++++++++---- src/plugin.ts | 6 +++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/instance.ts b/src/instance.ts index cac8711..1c715ec 100644 --- a/src/instance.ts +++ b/src/instance.ts @@ -2,11 +2,13 @@ type SetFunc = (name: string, to?: any) => void export class Instance { private static instanceIdCounter = 0 - static currentReference(display?: boolean): Instance { - return new Instance(ig, sc, display) + static currentReference(name?: string, display?: boolean): Instance { + return new Instance(ig, sc, name, display) } - static async copy(s: Instance, display?: boolean): Promise { + public static displayInstanceId: boolean = true + + static async copy(s: Instance, name?: string, display?: boolean): Promise { const ig: any = {} const igToInit: string[] = [] for (const key in s.ig) { @@ -82,7 +84,7 @@ export class Instance { scset('skilltree') scset('version') - const ns = new Instance(ig, sc, display) + const ns = new Instance(ig, sc, name, display) ns.apply() const canvasId = `canvas${ns.id}` @@ -209,6 +211,7 @@ export class Instance { private constructor( public ig: typeof window.ig, public sc: typeof window.sc, + public name: string = 'default', public display: boolean = true ) { this.id = Instance.instanceIdCounter @@ -259,6 +262,16 @@ export function injectInstance() { this.parent() }, + draw() { + this.parent() + if (!Instance.displayInstanceId) return + const text = new ig.TextBlock( + sc.fontsystem.font, + `#${inst.instanceId} ${inst.instances[inst.instanceId]?.name ?? 'initializing...'}`, + {} + ) + text.draw(2, 0) + }, }) ig.Loader.inject({ diff --git a/src/plugin.ts b/src/plugin.ts index ec1d47d..e9ea65c 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -65,10 +65,10 @@ export default class CCInstanceinator implements PluginClass { } async poststart() { - this.instances[0] = Instance.currentReference() + this.instances[0] = Instance.currentReference('master') - for (let i = 1; i < 2; i++) { - const instance = await Instance.copy(this.instances[0], false) + for (let i = 1; i < 6; i++) { + const instance = await Instance.copy(this.instances[0], 'child') this.append(instance) instance.apply() }