Commit 95e620d7 authored by Maxime's avatar Maxime
Browse files

Merge branch 'web-api' of https://gitlab.isima.fr/mapoulain1/zzzzzz into web-api

parents 72f95417 46d24ae2
......@@ -30,9 +30,8 @@ namespace WebAPI.Controller
}
[HttpPut("SendPlayer")]
public IActionResult SendPlayer(string code, int id, float x, float y, bool flipX, bool flipY)
public IActionResult SendPlayer(string code, int id, float x, float y, bool flipX, bool flipY, int rotation)
{
Trace.WriteLine($"Sendplayer{id} <{code}>");
var game = GameManager.Instance.Games.Find(x => x.Code == code);
if (game == null)
return BadRequest("Game not found");
......@@ -45,6 +44,7 @@ namespace WebAPI.Controller
player.Y = y;
player.FlipX = flipX;
player.FlipY = flipY;
player.Rotation = rotation;
}
return Ok();
......
......@@ -8,6 +8,7 @@
public bool FlipX { get; set; }
public bool FlipY { get; set; }
public bool Online { get; set; }
public int Rotation { get; set; }
public Player(int id)
......
......@@ -49,7 +49,7 @@ namespace ZZZZZZ
{
Task.Run(() =>
{
API = new WebAPI();
API = new WebAPI("https://localhost:5000/");
if (string.IsNullOrEmpty(gamecode))
{
API.CreateGame();
......@@ -80,23 +80,25 @@ namespace ZZZZZZ
RemotePlayerManager = new RemotePlayerManager(new RemoteCharacter((joinedID + 1) % 2), LevelManager);
});
Task.Delay(50).Wait();
Task.Run(() =>
InvokeOnMain(() =>
{
while (true)
Task.Run(() =>
{
API.UpdateLocal(LocalPlayerManager.Character as LocalCharacter);
Task.Delay(16).Wait();
}
});
while (true)
{
API.UpdateLocal(LocalPlayerManager.Character as LocalCharacter);
Task.Delay(16).Wait();
}
});
Task.Run(() =>
{
while (true)
Task.Run(() =>
{
API.UpdateRemote(RemotePlayerManager.Character as RemoteCharacter);
Task.Delay(16).Wait();
}
while (true)
{
API.UpdateRemote(RemotePlayerManager.Character as RemoteCharacter);
Task.Delay(16).Wait();
}
});
});
}
......
......@@ -18,7 +18,7 @@ namespace ZZZZZZ.WebAPIs
public string Hook { get; }
public HttpClient Client { get; }
public WebAPI(string hook = "http://91.170.211.147:5000/")
public WebAPI(string hook = "http://91.170.211.147:50000/")
{
Hook = hook;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
......@@ -69,8 +69,7 @@ namespace ZZZZZZ.WebAPIs
{
try
{
Trace.WriteLine($"{Hook}Game/SendPlayer?code={Code}&id={player.CharacterID}&x={FormatFloat(player.Node.Position2D.X)}&y={FormatFloat(player.Node.Position2D.Y)}&flipX={player.Flip.X}&flipY={player.Flip.Y}");
var post = Client.PutAsync($"{Hook}Game/SendPlayer?code={Code}&id={player.CharacterID}&x={FormatFloat(player.Node.Position2D.X)}&y={FormatFloat(player.Node.Position2D.Y)}&flipX={player.Flip.X}&flipY={player.Flip.Y}", null);
var post = Client.PutAsync($"{Hook}Game/SendPlayer?code={Code}&id={player.CharacterID}&x={FormatFloat(player.Node.Position2D.X)}&y={FormatFloat(player.Node.Position2D.Y)}&flipX={player.Flip.X}&flipY={player.Flip.Y}&rotation={(int)player.Node.Rotation2D}", null);
post.Wait();
var content = post.Result.Content.ReadAsStringAsync();
content.Wait();
......@@ -87,8 +86,8 @@ namespace ZZZZZZ.WebAPIs
{
try
{
var get = Client.GetAsync($"{Hook}Game/GetPlayer?code={Code}&ownId={(remote.CharacterID+1)%2}");
var get = Client.GetAsync($"{Hook}Game/GetPlayer?code={Code}&ownId={(remote.CharacterID + 1) % 2}");
get.Wait();
var content = get.Result.Content.ReadAsStringAsync();
content.Wait();
......@@ -102,9 +101,11 @@ namespace ZZZZZZ.WebAPIs
var flipX = bool.Parse(values["flipX"]);
var flipY = bool.Parse(values["flipY"]);
var online = bool.Parse(values["online"]);
var rotation = int.Parse(values["rotation"]);
remote.Move(new Vector2(x, y));
remote.Flip = (flipX, flipY);
remote.Node.Rotation2D = rotation;
remote.Online = online;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment