Add support for other servers
This commit is contained in:
17
index.html
17
index.html
@ -11,25 +11,34 @@
|
|||||||
RUNIC
|
RUNIC
|
||||||
</h1>
|
</h1>
|
||||||
<input id="runic_username" class="username" placeholder="Username" maxlength="16"><br>
|
<input id="runic_username" class="username" placeholder="Username" maxlength="16"><br>
|
||||||
|
<input id="runic_server_url" class="username" placeholder="example.com:8080"><br>
|
||||||
<input type="button" class="play" onclick="play()" value="PLAY">
|
<input type="button" class="play" onclick="play()" value="PLAY">
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var usernameinput = document.getElementById("runic_username");
|
var usernameinput = document.getElementById("runic_username");
|
||||||
|
var urlinput = document.getElementById("runic_server_url");
|
||||||
function play() {
|
function play() {
|
||||||
var username = usernameinput.value;
|
/*if (username != "") {
|
||||||
if (username != "") {
|
|
||||||
window.location = "game.html" + "?name=" + username;
|
window.location = "game.html" + "?name=" + username;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location = "game.html";
|
window.location = "game.html";
|
||||||
|
}*/
|
||||||
|
let parameters = new String();
|
||||||
|
if (usernameinput.value != "") {
|
||||||
|
parameters += "?name=" + usernameinput.value;
|
||||||
}
|
}
|
||||||
|
if (urlinput.value != "") {
|
||||||
|
parameters += "&?server_url=" + urlinput.value;
|
||||||
|
}
|
||||||
|
window.location = "game.html" + parameters;
|
||||||
}
|
}
|
||||||
usernameinput.addEventListener("keypress", function(event) {
|
usernameinput.addEventListener("keypress", function(event) {
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -18,15 +18,29 @@ var username;
|
|||||||
//set name from URL
|
//set name from URL
|
||||||
try {
|
try {
|
||||||
let URL = window.location.search;
|
let URL = window.location.search;
|
||||||
params = new URLSearchParams(URL);
|
let params = new URLSearchParams(URL);
|
||||||
username = params.get("name"); //this will get foo from <url>?name=foo
|
username = params.get("name"); //this will get foo from <url>?name=foo
|
||||||
if (username === null) {
|
if (username === null) {
|
||||||
username = "Anonymous";
|
username = "Anonymous";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
console.error("Failed to get name from url", err);
|
console.error("Failed to get username from URL parameters", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var server_url;
|
||||||
|
try {
|
||||||
|
let URL = window.location.search;
|
||||||
|
params = new URLSearchParams(URL);
|
||||||
|
server_url = "ws://" + params.get("server_url");
|
||||||
|
if (server_url === "ws://null"/*Javascript why*/) {
|
||||||
|
server_url = "ws://" + "localhost:8080";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.error("Failed to get server from URL parameters", err);
|
||||||
|
}
|
||||||
|
|
||||||
var game_data = {
|
var game_data = {
|
||||||
"character": {
|
"character": {
|
||||||
"variants": [
|
"variants": [
|
||||||
@ -219,7 +233,7 @@ function game_tick(delta) {
|
|||||||
function render_characters() {
|
function render_characters() {
|
||||||
let ctx = canvas.getContext("2d");
|
let ctx = canvas.getContext("2d");
|
||||||
characters.forEach(function(itr, idx) {
|
characters.forEach(function(itr, idx) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
let character_position = global_to_canvas(itr.position);
|
let character_position = global_to_canvas(itr.position);
|
||||||
ctx.translate(character_position.x, character_position.y);
|
ctx.translate(character_position.x, character_position.y);
|
||||||
ctx.rotate(itr.rotation);
|
ctx.rotate(itr.rotation);
|
||||||
|
Reference in New Issue
Block a user