Skip to content

Commit

Permalink
Add instance name and instance name displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Nov 25, 2024
1 parent b1d6358 commit 19f73fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instance> {
public static displayInstanceId: boolean = true

static async copy(s: Instance, name?: string, display?: boolean): Promise<Instance> {
const ig: any = {}
const igToInit: string[] = []
for (const key in s.ig) {
Expand Down Expand Up @@ -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}`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 19f73fe

Please sign in to comment.