Bugs gefixt, InitializeTickleiste und Reload Tickleiste hinzugefügt
This commit is contained in:
parent
3c7eddea98
commit
af32a253dc
2 changed files with 77 additions and 35 deletions
|
@ -13,9 +13,13 @@
|
|||
|
||||
<img src="tickleiste.png" width= "100%" height= "auto">
|
||||
<form>
|
||||
<input type="text" placeholder="TickleistenID" id="D"></input>
|
||||
<input type="button" class="sub" value="Neue Tickleiste" id="d"></input>
|
||||
<input type="text" pattern="[0-9a-f]" placeholder="TickleistenID" id="D"></input>
|
||||
<input type="button" class="sub" value="Tickleiste ändern" id="d"></input>
|
||||
</form>
|
||||
<form>
|
||||
<input type="button" class="sub" value="Neu laden" id="e"></input>
|
||||
</form>
|
||||
<p id="p4">-<p>
|
||||
</div>
|
||||
|
||||
<div id="right">
|
||||
|
@ -29,7 +33,8 @@
|
|||
</div>
|
||||
<div id="hinzufügen">
|
||||
<form>
|
||||
<input type="text" placeholder="Name" id="A"></input>
|
||||
<input type="text" placeholder="Name" id="A1"></input>
|
||||
<input type="text" placeholder="Tick" pattern="Abwarten|Bereithalten|[0,9]" id="A2"></input>
|
||||
<input type="button" class="sub" value="Spieler hinzufügen" id="a"></input>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -44,7 +49,7 @@
|
|||
<div id="ändern">
|
||||
<form>
|
||||
<input type="text" placeholder="Name" id="C1"></input>
|
||||
<input type="text" placeholder="Tick" pattern="[0-9]" id="C2"></input>
|
||||
<input type="text" placeholder="Tick" pattern="Abwarten|Bereithalten|[0,9]" id="C2"></input>
|
||||
<input type="button" class="sub" value="Tick ändern" id="c"></input>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
var ws = new WebSocket("ws:10.9.1.129:8080/tickLeistenId");
|
||||
let addButton = document.getElementById("a");
|
||||
let deleteButton = document.getElementById("b");
|
||||
let changeTickButton = document.getElementById("c");
|
||||
let changeIdButton = document.getElementById("d");
|
||||
let reloadButton = document.getElementById("e");
|
||||
var players = [];
|
||||
let Id = Math.floor(Math.random()*10000000000000000).toString(16)
|
||||
var ws = new WebSocket("ws:10.9.1.129:8080/" + Id);
|
||||
document.getElementById("p4").innerHTML = "" + Id;
|
||||
|
||||
|
||||
|
||||
/* Handles Events from Server */
|
||||
ws.onmessage = function(evt){
|
||||
var msg = evt.data;
|
||||
var obj = JSON.parse(msg);
|
||||
var valid = false;
|
||||
|
||||
/*Changes Tick of one Player in players. Updates the Playerlist and current Player.*/
|
||||
if (obj.eventType == "SetPlayerTickE") {
|
||||
valid = true;
|
||||
for (i = 0; i < players.length; i++){
|
||||
if (players[i].UUID == obj.playerUUID){
|
||||
players[i].Tick = obj.tick;
|
||||
|
@ -18,12 +26,14 @@ ws.onmessage = function(evt){
|
|||
PlayerList();
|
||||
CurrentPlayer();
|
||||
}
|
||||
/*Adds Player and their Tick to players. Updates the Playerlist and current Player.*/
|
||||
if (obj.eventType == "AddPlayerTickE") {
|
||||
valid = true;
|
||||
var newPlayer = new Object ();
|
||||
newPlayer.Name = obj.playerName;
|
||||
newPlayer.UUID = obj.playerUUID;
|
||||
if (obj.tick.tickType == "Tick"){
|
||||
newPlayer.Tick = tick.tickValue;
|
||||
newPlayer.Tick = obj.tick.tickValue;
|
||||
}
|
||||
else {
|
||||
newPlayer.Tick = tickType;
|
||||
|
@ -32,17 +42,32 @@ ws.onmessage = function(evt){
|
|||
PlayerList();
|
||||
CurrentPlayer();
|
||||
}
|
||||
/*Adds players an their Ticks to players. Updates the Playerlist and current Player.*/
|
||||
if (obj.eventType == "InitializeTickLeisteE") {
|
||||
|
||||
valid = true;
|
||||
var newPlayer = new Object();
|
||||
for (i = 0; i<obj.tickLeiste.length;i++){
|
||||
newPlayer.Tick = obj.tickLeiste[i][0];
|
||||
newPlayer.UUID = obj.tickLeiste[i][0][0];
|
||||
newPlayer.Name = obj.tickLeiste[i][0][1];
|
||||
}
|
||||
players.push(newPlayer);
|
||||
PlayerList();
|
||||
CurrentPlayer();
|
||||
|
||||
}
|
||||
/*Changes the Name of a Player in players. Updates the Playerlist and current Player*/
|
||||
if (obj.eventType == "ChangeNameE") {
|
||||
valid = true;
|
||||
for (i = 0; i < players.length; i++){
|
||||
if (players[i].UUID == obj.playerUUID){
|
||||
players[i].Name = obj.playerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Removes one Player from players. Updates the Playerlist and current Player*/
|
||||
if (obj.eventType == "RemovePlayerE") {
|
||||
valid = true;
|
||||
for (i = 0; i < players.length; i++){
|
||||
if (players[i].UUID == obj.playerUUID){
|
||||
players.splice(i,1);
|
||||
|
@ -51,47 +76,76 @@ ws.onmessage = function(evt){
|
|||
PlayerList();
|
||||
CurrentPlayer();
|
||||
}
|
||||
else {
|
||||
/*If no eventType was recognized, an error is thrown.*/
|
||||
if (valid == false) {
|
||||
console.error('Invalid Event received');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*When the Button is clicked, a AddPlayerTickR request is send to the server.*/
|
||||
addButton.onclick = function() {
|
||||
ws.send('{"requestType" : "AddPlayerTickR" "' + document.getElementById("A") + '", "player" : <UnknownPlayer>, "tick" :}');
|
||||
var type = "";
|
||||
if (document.getElementById("A2").value == "Abwarten") {
|
||||
type = "Abwarten";
|
||||
}
|
||||
if (document.getElementById("A2").value == "Bereithalten") {
|
||||
type = "Bereithalten";
|
||||
}
|
||||
else {
|
||||
type = "Tick";
|
||||
}
|
||||
ws.send('{"requestType" : "AddPlayerTickR", "playerName" : "' + document.getElementById("A").value + '" , "tick" : {"tickType" : "' + type + '", "tickValue" : ' + document.getElementById("A2").value + '}}');
|
||||
}
|
||||
|
||||
/*When the Button is clicked, a RemovePlayerR request is send to the server.*/
|
||||
deleteButton.onclick = function() {
|
||||
var UUID = "";
|
||||
for (i = 0; i < players.length; i++){
|
||||
if (players[i].Name == document.getElementById("B")){
|
||||
if (players[i].Name == document.getElementById("B").value){
|
||||
UUID = players[i].UUID;
|
||||
}
|
||||
}
|
||||
ws.send('{"requestType" : "RemovePlayerR", "playerUUID" : "' + UUID + '"}');
|
||||
}
|
||||
|
||||
/*When the Button is clicked, a SetPlayerTickR request is send to the server*/
|
||||
changeTickButton.onclick = function() {
|
||||
var UUID = "";
|
||||
var Tick = document.getElementById("C2");
|
||||
var Tick = document.getElementById("C2").value;
|
||||
for (i = 0; i < players.length; i++){
|
||||
if (players[i].Name == document.getElementById("C1")){
|
||||
UUID = players[i].UUID;
|
||||
}
|
||||
}
|
||||
ws.send('{"requestType" : "SetPlayerTickR", "playerUUID" : "' + UUID + '", "tick" : "' + Tick + '"}');
|
||||
}
|
||||
|
||||
/*When the Button is clicked, a new WebSocket connection is opened with the new ID*/
|
||||
changeIdButton.onclick = function() {
|
||||
Id = document.getElementById("D").value;
|
||||
ws.close();
|
||||
ws = new WebSocket("ws:10.9.1.129:8080/" + Id);
|
||||
document.getElementById("p4").innerHTML = "" + Id;
|
||||
}
|
||||
|
||||
/*When the Button is clicked, a TickLeisteR request is send to the server.*/
|
||||
reloadButton.onclick = function() {
|
||||
ws.send('{"requestType" : "TickLeisteR"}');
|
||||
}
|
||||
|
||||
|
||||
/*Updates the Playerlist according to the content of players.*/
|
||||
function PlayerList(){
|
||||
var content = "";
|
||||
for (i = 0; i < players.length; i++){
|
||||
content = content + players[i].Name + " " + players[i].Tick + "\n";
|
||||
content = content + players[i].Name + " " + players[i].Tick + "<br>";
|
||||
}
|
||||
document.getElementById("p3").innerHTML = content;
|
||||
}
|
||||
|
||||
|
||||
/*Updates the current Player according to the Player with the smallest Tick in players.*/
|
||||
function CurrentPlayer(){
|
||||
var curr = "-";
|
||||
var smallest = Infinity;
|
||||
|
@ -102,27 +156,10 @@ function CurrentPlayer(){
|
|||
}
|
||||
}
|
||||
if (smallest != Infinity){
|
||||
document.getElementById("p1").innerHTML = curr;
|
||||
document.getElementById("p2").innerHTML = "" + smallest;
|
||||
document.getElementById("p2").innerHTML = curr;
|
||||
document.getElementById("p1").innerHTML = "" + smallest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*function WebSocketTest() {
|
||||
|
||||
if ("WebSocket" in window) {
|
||||
|
||||
|
||||
ws.onopen = function() {
|
||||
|
||||
};
|
||||
|
||||
ws.onmessage = function (evt) {
|
||||
var received_msg = evt.data;
|
||||
alert("Message is received...");
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue