add agentCreateCharacterFromUrl
This commit is contained in:
parent
b50091c5fc
commit
89d0092f65
3 changed files with 25 additions and 0 deletions
|
@ -50,3 +50,9 @@ function agentCharacterParseACS(buffer: BufferStream): AcsData {
|
||||||
export function agentCreateCharacter(data: Uint8Array): Agent {
|
export function agentCreateCharacter(data: Uint8Array): Agent {
|
||||||
return new Agent(agentCharacterParseACS(new BufferStream(data)));
|
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));
|
||||||
|
}
|
|
@ -17,5 +17,12 @@
|
||||||
<label for="testbed-input">ACS to test</label>
|
<label for="testbed-input">ACS to test</label>
|
||||||
<input id="testbed-input" type="file" accept=".acs" />
|
<input id="testbed-input" type="file" accept=".acs" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field-row-stacked" style="width: 400px">
|
||||||
|
<form id="acsUrlForm">
|
||||||
|
<label for="acsUrl">Load ACS from URL</label><br>
|
||||||
|
<input type="url" id="acsUrl" required/><br>
|
||||||
|
<input type="submit" value="Load"/>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -24,3 +24,15 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||||
await msagent.agentInit();
|
await msagent.agentInit();
|
||||||
console.log("msagent initalized!");
|
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}`);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue