forked from StrafesNET/roblox-bot-player
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import init, {
|
|
setup,
|
|
CompleteBot,
|
|
Graphics,
|
|
CompleteMap,
|
|
PlaybackHead,
|
|
} from "./pkg/strafesnet_roblox_bot_player_wasm_module.js";
|
|
|
|
await init(); // load the wasm module
|
|
|
|
const b = await fetch("bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot");
|
|
const m = await fetch("bhop_marble_5692093612.snfm");
|
|
|
|
const canvas = document.querySelector("canvas");
|
|
|
|
const context = await setup(canvas);
|
|
const graphics = new Graphics(context);
|
|
const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
|
|
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
|
const playback = new PlaybackHead(0);
|
|
|
|
graphics.change_map(map);
|
|
|
|
const startTime = performance.now();
|
|
|
|
function animate(now) {
|
|
const elapsedMs = now - startTime;
|
|
const elapsedSec = elapsedMs / 1000; // wasm expects seconds
|
|
|
|
// Advance the playback head to the current time
|
|
playback.advance_time(bot, elapsedSec);
|
|
|
|
// Render the frame that the bot is at that time
|
|
graphics.render(bot, playback, elapsedSec);
|
|
|
|
// Keep the loop going
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
requestAnimationFrame(animate);
|
|
|
|
function resize() {
|
|
canvas.width = canvas.clientWidth;
|
|
canvas.height = canvas.clientHeight;
|
|
graphics.resize(canvas.width, canvas.height);
|
|
}
|
|
window.addEventListener("resize", resize);
|
|
resize();
|