From 89d0092f65a8590487bccebc381830488fcf6f06 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Wed, 10 Jul 2024 00:08:01 -0400 Subject: [PATCH] add agentCreateCharacterFromUrl --- msagent.js/src/character.ts | 6 ++++++ webapp/src/html/testbed.html | 7 +++++++ webapp/src/ts/testbed.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/msagent.js/src/character.ts b/msagent.js/src/character.ts index 5a897cf..2d98b5d 100644 --- a/msagent.js/src/character.ts +++ b/msagent.js/src/character.ts @@ -50,3 +50,9 @@ function agentCharacterParseACS(buffer: BufferStream): AcsData { export function agentCreateCharacter(data: Uint8Array): Agent { return new Agent(agentCharacterParseACS(new BufferStream(data))); } + +export async function agentCreateCharacterFromUrl(url: string) { + let res = await fetch(url); + let data = await res.arrayBuffer(); + return agentCreateCharacter(new Uint8Array(data)); +} \ No newline at end of file diff --git a/webapp/src/html/testbed.html b/webapp/src/html/testbed.html index 3f6c126..3736c2c 100644 --- a/webapp/src/html/testbed.html +++ b/webapp/src/html/testbed.html @@ -17,5 +17,12 @@ +
+
+
+
+ +
+
diff --git a/webapp/src/ts/testbed.ts b/webapp/src/ts/testbed.ts index 68fe71a..0629116 100644 --- a/webapp/src/ts/testbed.ts +++ b/webapp/src/ts/testbed.ts @@ -24,3 +24,15 @@ document.addEventListener("DOMContentLoaded", async () => { await msagent.agentInit(); console.log("msagent initalized!"); }) + +let form = document.getElementById("acsUrlForm") as HTMLFormElement; +form.addEventListener('submit', e => { + e.preventDefault(); + let url = (document.getElementById("acsUrl") as HTMLInputElement).value; + msagent.agentCreateCharacterFromUrl(url).then(agent => { + w.agents.push(agent); + agent.addToDom(document.body); + agent.show(); + console.log(`Loaded agent from ${url}`); + }); +}); \ No newline at end of file