From f720acc73845b44f2d6b772dbc2be23c94fb2a22 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Tue, 9 Jul 2024 23:42:43 -0400 Subject: [PATCH] add param to hide() to auto remove the agent --- msagent.js/src/agent.ts | 11 ++++++----- webapp/src/ts/testbed.ts | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/msagent.js/src/agent.ts b/msagent.js/src/agent.ts index a8e61da..db37fec 100644 --- a/msagent.js/src/agent.ts +++ b/msagent.js/src/agent.ts @@ -176,12 +176,13 @@ export class Agent { this.playAnimationByName("Show", () => {}); } - hide() { - // TODO: play the hide animation (then clear the canvas) - // (if not constructing. We can probably just duplicate this one line and put it in the constructor tbh) - + hide(remove: boolean = false) { this.playAnimationByName("Hide", () => { - this.cnv.style.display = 'none'; + if(remove) + this.remove(); + else + this.cnv.style.display = 'none'; + }); } } diff --git a/webapp/src/ts/testbed.ts b/webapp/src/ts/testbed.ts index 4ac0b63..54fc0ca 100644 --- a/webapp/src/ts/testbed.ts +++ b/webapp/src/ts/testbed.ts @@ -11,8 +11,9 @@ input.addEventListener("change", async () => { console.log("About to parse character"); let agent = msagent.agentParseCharacterTestbed(new Uint8Array(buffer)); + // destroy the previous agent if(w.agent != null) { - w.agent.hide(); + w.agent.hide(true); } w.agent = agent;