diff --git a/client.js b/client.js index b2ccf47..ef571d3 100644 --- a/client.js +++ b/client.js @@ -8,7 +8,7 @@ const $ = jquery; function run(flag) { client.setRenderer(flag ? godRenderer : playerRenderer); - client.connectGame("//" + location.host, $("#name").val(), (success, msg) => { + client.connectGame(io, "//" + location.host, $("#name").val(), (success, msg) => { if (success) { $("#main-ui").fadeIn(1000); $("#begin, #wasted").fadeOut(1000); diff --git a/paper-io-bot.js b/paper-io-bot.js index 98d79f3..20777a4 100644 --- a/paper-io-bot.js +++ b/paper-io-bot.js @@ -3,6 +3,7 @@ if (process.argv.length < 3) { process.exit(1); } +import io from "socket.io-client"; import * as client from "./src/game-client.js"; import { consts } from "./config.js"; @@ -26,7 +27,7 @@ function connect() { const prefixes = consts.PREFIXES.split(" "); const names = consts.NAMES.split(" "); const name = process.argv[3] || [prefixes[Math.floor(Math.random() * prefixes.length)], names[Math.floor(Math.random() * names.length)]].join(" "); - client.connectGame(process.argv[2], "[BOT] " + name, function(success, msg) { + client.connectGame(io, process.argv[2], "[BOT] " + name, function(success, msg) { if (!success) { console.error(msg); setTimeout(connect, 1000); diff --git a/src/game-client.js b/src/game-client.js index 2bd7217..2cc59ae 100644 --- a/src/game-client.js +++ b/src/game-client.js @@ -1,4 +1,3 @@ -import io from "socket.io-client"; import { Grid, Player, initPlayer, updateFrame } from "./core/index.js"; import { consts } from "../config.js"; let running = false; @@ -24,7 +23,7 @@ try { } //Public API -function connectGame(url, name, callback, flag) { +function connectGame(io, url, name, callback, flag) { if (running) return; //Prevent multiple runs running = true; user = null;