Browse Source

Implement the rest of the functions into the client

new_protocol
KeyKoder 5 years ago
parent
commit
1e75295c52
  1. 6
      unity/.vsconfig
  2. 53
      unity/Assets/Scenes/SampleScene.unity
  3. 1
      unity/Assets/Scripts/Card.cs
  4. 256
      unity/Assets/Scripts/Client.cs
  5. 123
      unity/Assets/Scripts/GameLoader.cs
  6. 97
      unity/Assets/Scripts/MainMenuController.cs
  7. 10
      unity/UserSettings/EditorUserSettings.asset

6
unity/.vsconfig

@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}

53
unity/Assets/Scenes/SampleScene.unity

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.43667546, g: 0.48427135, b: 0.5645225, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -288,6 +288,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &139238897
@ -604,6 +605,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &705507995
@ -633,6 +635,7 @@ GameObject:
- component: {fileID: 717906691}
- component: {fileID: 717906690}
- component: {fileID: 717906689}
- component: {fileID: 717906694}
m_Layer: 5
m_Name: NewDeck
m_TagString: Untagged
@ -733,11 +736,25 @@ RectTransform:
m_Father: {fileID: 1259467752}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -77}
m_SizeDelta: {x: 466.45, y: 150}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 60.692688}
m_SizeDelta: {x: 0, y: 121.38538}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &717906694
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 717906688}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 0
--- !u!1 &963194225
GameObject:
m_ObjectHideFlags: 0
@ -879,6 +896,7 @@ MonoBehaviour:
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!223 &1259467751
Canvas:
m_ObjectHideFlags: 0
@ -935,6 +953,7 @@ GameObject:
- component: {fileID: 1854025640}
- component: {fileID: 1854025638}
- component: {fileID: 1854025639}
- component: {fileID: 1854025642}
m_Layer: 5
m_Name: Content
m_TagString: Untagged
@ -949,7 +968,7 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1854025636}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
@ -960,7 +979,7 @@ RectTransform:
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &1854025638
MonoBehaviour:
m_ObjectHideFlags: 0
@ -968,7 +987,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1854025636}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc417d59709b83f40a9f4f9541441269, type: 3}
m_Name:
@ -1014,10 +1033,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_Color: {r: 0, g: 0.6, b: 0.8000001, a: 0.392}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_Maskable: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
@ -1039,6 +1058,20 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1854025636}
m_CullTransparentMesh: 0
--- !u!114 &1854025642
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1854025636}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 2
m_VerticalFit: 2
--- !u!1 &2017521284
GameObject:
m_ObjectHideFlags: 0

1
unity/Assets/Scripts/Card.cs

@ -63,6 +63,7 @@ public class Card : MonoBehaviour {//, IPointerEnterHandler, IPointerExitHandler
} else {
var conn = Client.GetConnection();
if (conn != null) {
conn.OnClickCard(inPileName, isInCommonPile, idx, mmc.currentUsername);
// conn.OnClickCard(inPileName, isInCommonPile, idx, mmc.currentUsername);
}
}

256
unity/Assets/Scripts/Client.cs

@ -1,3 +1,4 @@
using System.Linq;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading.Tasks;
@ -13,6 +14,13 @@ public class Client : MonoBehaviour {
public static void Connect(string name, string address = "127.0.0.1:50052") {
reference = new ConnectionImpl(name, address);
reference.eventManager.AddHandler("general_lobby_status_handler", (Lobby.LobbyStatus status) => {
reference.lobby_status.Set(status);
});
reference.eventManager.AddHandler("general_game_status_handler", (Game.GameStatus status) => {
reference.game_status.Set(status);
GameLoader.ReloadPiles();
});
}
public static ref ConnectionImpl GetConnection() {
@ -42,6 +50,10 @@ public class Client : MonoBehaviour {
private Dictionary<string, Action<Connection.LobbyCode>> returnCreateLobbyHandlers = new Dictionary<string, Action<Connection.LobbyCode>>();
private Dictionary<string, Action<Protocol.Games>> returnGamesHandlers = new Dictionary<string, Action<Protocol.Games>>();
private Dictionary<string, Action<Protocol.LobbyCodes>> returnPublicLobbiesHandlers = new Dictionary<string, Action<Protocol.LobbyCodes>>();
private Dictionary<string, Action<Protocol.Names>> returnUsersHandlers = new Dictionary<string, Action<Protocol.Names>>();
private Dictionary<string, Action<Lobby.LobbyStatus>> lobbyStatusHandlers = new Dictionary<string, Action<Lobby.LobbyStatus>>();
private Dictionary<string, Action<Game.Image>> returnCardImageHandlers = new Dictionary<string, Action<Game.Image>>();
private Dictionary<string, Action<Game.GameStatus>> gameStatusHandlers = new Dictionary<string, Action<Game.GameStatus>>();
public ConcurrentQueue<Protocol.ServerClientPacket> queue;
public void Update() {
@ -56,7 +68,6 @@ public class Client : MonoBehaviour {
n(p.ReturnName);
}
}
break;
case Protocol.ServerClientPacket.DataOneofCase.ReturnConnect: {
var v = new Action<Connection.UserID>[this.returnConnectHandlers.Count];
@ -90,6 +101,38 @@ public class Client : MonoBehaviour {
}
}
break;
case Protocol.ServerClientPacket.DataOneofCase.ReturnUsers: {
var v = new Action<Protocol.Names>[this.returnUsersHandlers.Count];
this.returnUsersHandlers.Values.CopyTo(v, 0);
foreach (var n in v) {
n(p.ReturnUsers);
}
}
break;
case Protocol.ServerClientPacket.DataOneofCase.LobbyStatus: {
var v = new Action<Lobby.LobbyStatus>[this.lobbyStatusHandlers.Count];
this.lobbyStatusHandlers.Values.CopyTo(v, 0);
foreach (var n in v) {
n(p.LobbyStatus);
}
}
break;
case Protocol.ServerClientPacket.DataOneofCase.ReturnCardImage: {
var v = new Action<Game.Image>[this.returnCardImageHandlers.Count];
this.returnCardImageHandlers.Values.CopyTo(v, 0);
foreach (var n in v) {
n(p.ReturnCardImage);
}
}
break;
case Protocol.ServerClientPacket.DataOneofCase.GameStatus: {
var v = new Action<Game.GameStatus>[this.gameStatusHandlers.Count];
this.gameStatusHandlers.Values.CopyTo(v, 0);
foreach (var n in v) {
n(p.GameStatus);
}
}
break;
default:
break;
}
@ -116,6 +159,22 @@ public class Client : MonoBehaviour {
returnPublicLobbiesHandlers.Add(name, handler);
}
public void AddHandler(string name, Action<Protocol.Names> handler) {
returnUsersHandlers.Add(name, handler);
}
public void AddHandler(string name, Action<Lobby.LobbyStatus> handler) {
lobbyStatusHandlers.Add(name, handler);
}
public void AddHandler(string name, Action<Game.Image> handler) {
returnCardImageHandlers.Add(name, handler);
}
public void AddHandler(string name, Action<Game.GameStatus> handler) {
gameStatusHandlers.Add(name, handler);
}
public void RemoveHandler(Protocol.ServerClientPacket.DataOneofCase kind, string name) {
switch (kind) {
case Protocol.ServerClientPacket.DataOneofCase.ReturnName:
@ -133,6 +192,18 @@ public class Client : MonoBehaviour {
case Protocol.ServerClientPacket.DataOneofCase.ReturnPublicLobbies:
returnPublicLobbiesHandlers.Remove(name);
break;
case Protocol.ServerClientPacket.DataOneofCase.ReturnUsers:
returnUsersHandlers.Remove(name);
break;
case Protocol.ServerClientPacket.DataOneofCase.LobbyStatus:
lobbyStatusHandlers.Remove(name);
break;
case Protocol.ServerClientPacket.DataOneofCase.ReturnCardImage:
returnCardImageHandlers.Remove(name);
break;
case Protocol.ServerClientPacket.DataOneofCase.GameStatus:
gameStatusHandlers.Remove(name);
break;
default:
break;
}
@ -149,7 +220,8 @@ public class Client : MonoBehaviour {
public NetEventManager eventManager;
private Modifiable<Lobby.LobbyStatus> lobby_status = null;
public Modifiable<Lobby.LobbyStatus> lobby_status = new Modifiable<Lobby.LobbyStatus>(null);
public Modifiable<Game.GameStatus> game_status = new Modifiable<Game.GameStatus>(null);
public ConnectionImpl(string user, string address) {
Debug.Log("Connecting with the tcp channel");
conn = new TcpConnection(address);
@ -176,12 +248,16 @@ public class Client : MonoBehaviour {
}
public void JoinLobby(string code) {
lobby = Base32.FromString(code);
conn.SendMessage(new Protocol.ClientServerPacket() { JoinLobby = new Connection.LobbyCode { Code = Base32.FromString(code) } });
// connection.joinLobbyWithCode(new ConnectionService.LobbyCode { Code = (uint)lobby }, new Metadata { new Metadata.Entry("client_id", connId) });
}
public void CreateLobby(bool isPublic) {
conn.SendMessage(new Protocol.ClientServerPacket() {CreateLobby = new Connection.LobbyConfig {Public = isPublic}});
eventManager.AddHandler("client_create_lobby_auto_join", (Connection.LobbyCode lobby1) => {
lobby = lobby1.Code;
eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnCreateLobby, "client_create_lobby_auto_join");
});
conn.SendMessage(new Protocol.ClientServerPacket() { CreateLobby = new Connection.LobbyConfig { Public = isPublic } });
// lobby = connection.createLobby(new ConnectionService.LobbyConfig {Public = isPublic}, new Metadata { new Metadata.Entry("client_id", connId) }).Code;
}
@ -193,141 +269,92 @@ public class Client : MonoBehaviour {
}
}
public List<string> GetUsersInSameLobby() {
// AsyncServerStreamingCall<Common.Name> stream = lobby_client.users(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
List<string> l = new List<string>();
// while (runSync(stream.ResponseStream.MoveNext()))
// {
// Common.Name g = stream.ResponseStream.Current;
// l.Add(g.Name_);
// // Debug.Log("Received " + feature.ToString());
// }
// Debug.Log(stream.ResponseStream.Current);
return l;
}
public Lobby.LobbyStatus GetLobbyStatus(out bool hasChanged) {
hasChanged = false;
// if (lobby != null) {
// if (lobby_status != null) {
// var hasNew = lobby_client.pollStatus(
// new Common.LastStatusTimestamp {
// Time = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(lobby_status.GetLastModfication()),
// Lobby = (uint)lobby,
// },
// new Metadata { new Metadata.Entry("client_id", connId) }
// ).Value;
// Debug.Log("HasNewStatus: " + hasNew);
// if (hasNew) {
// lobby_status.Set(lobby_client.getStatus(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) }));
// hasChanged = true;
// }
// } else {
// Debug.Log("Getting status");
// lobby_status = new Modifiable<Lobby.LobbyStatus>(lobby_client.getStatus(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) }));
// hasChanged = true;
// }
// return lobby_status.Get();
// } else {
// return null;
// }
return null;
public void GetUsersInSameLobby() {
conn.SendMessage(new Protocol.ClientServerPacket() { QueryUsers = new Empty() });
}
public List<Lobby.Vote> GetLobbyVotes(uint game) {
bool _b = false;
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = GetLobbyStatus(out _b).Votes;
var gameVotes = new List<Lobby.Vote>();
foreach (Lobby.Vote vote in votes) {
if (vote.Game == game) {
gameVotes.Add(vote);
if (lobby_status.Get() != null){
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = lobby_status.Get()?.Votes;
foreach (Lobby.Vote vote in votes) {
if (vote.Game == game) {
gameVotes.Add(vote);
}
}
}
return gameVotes;
}
public int GetLobbyVoteCount(uint game) {
bool _b = false;
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = GetLobbyStatus(out _b).Votes;
var gameVotes = new List<Lobby.Vote>();
foreach (Lobby.Vote vote in votes) {
if (vote.Game == game) {
gameVotes.Add(vote);
if (lobby_status.Get() != null) {
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = lobby_status.Get()?.Votes;
foreach (Lobby.Vote vote in votes) {
if (vote.Game == game) {
gameVotes.Add(vote);
}
}
}
return gameVotes.Count;
}
public Lobby.Vote GetSelfVote(string player) {
bool _b = false;
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = GetLobbyStatus(out _b).Votes;
foreach (Lobby.Vote vote in votes) {
Debug.Log(vote);
if (vote.Player == player) {
return vote;
if (lobby_status.Get() != null) {
Google.Protobuf.Collections.RepeatedField<Lobby.Vote> votes = lobby_status.Get().Votes;
foreach (Lobby.Vote vote in votes) {
Debug.Log(vote);
if (vote.Player == player) {
return vote;
}
}
}
return null;
}
public bool IsStarting() {
return lobby_status.Get() != null && lobby_status.Get().IsStarting;
}
public void Vote(uint game) {
conn.SendMessage(new Protocol.ClientServerPacket() { Vote = new Lobby.SingleVote { Game = game } });
// lobby_client.vote(new Lobby.SingleVote() { Game = game }, new Metadata { new Metadata.Entry("client_id", connId) });
}
public void SetReady() {
conn.SendMessage(new Protocol.ClientServerPacket() { Ready = new Empty() });
// lobby_client.ready(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
}
public void LeaveLobby() {
// lobby_client.leave(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
conn.SendMessage(new Protocol.ClientServerPacket() { Leave = new Empty() });
lobby = null;
}
public List<string> GetPublicLobbies() {
// AsyncServerStreamingCall<ConnectionService.LobbyCode> stream = connection.getPublicLobbies(new Google.Protobuf.WellKnownTypes.Empty());
List<string> l = new List<string>();
// while (runSync(stream.ResponseStream.MoveNext()))
// {
// ConnectionService.LobbyCode g = stream.ResponseStream.Current;
// l.Add(Base32.ToString(g.Code));
// // Debug.Log("Received " + feature.ToString());
// }
// Debug.Log(stream.ResponseStream.Current);
return l;
public void GetPublicLobbies() {
conn.SendMessage(new Protocol.ClientServerPacket() { QueryPublicLobbies = new Empty() });
}
// public Game.Image GetCardImage(string cardKind) {
// return game_client.getCardImage(new Game.CardKind() { Kind = cardKind }, new Metadata { new Metadata.Entry("client_id", connId) });
// }
// public ICollection<Game.MessageStatus.Types.Pile> GetCards(string user) {
// var status = game_client.status(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
// return status.PlayerPiles[status.Names.IndexOf(new Common.Name() { Name_ = user })].Piles_.Values;
// }
// public Dictionary<string, Dictionary<string, Game.GameStatus.Types.Pile>> GetPiles(string user) {
// var status = game_client.status(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
// var piles = new Dictionary<string, Dictionary<string, Game.GameStatus.Types.Pile>>();
// var playerPilesMap = status.PlayerPiles[status.Names.IndexOf(new Common.Name() { Name_ = user })].Piles_;
// var playerPiles = new Dictionary<string, Game.MessageStatus.Types.Pile>();
// foreach(string key in playerPilesMap.Keys) {
// playerPiles.Add(key, playerPilesMap[key]);
// }
// var commonPilesMap = status.CommonPiles.Piles_;
// var commonPiles = new Dictionary<string, Game.MessageStatus.Types.Pile>();
// foreach (string key in commonPilesMap.Keys) {
// commonPiles.Add(key, commonPilesMap[key]);
// }
// piles.Add("Owned", playerPiles);
// piles.Add("Common", commonPiles);
// return piles;
// }
// public int GetUserIndex(string user) {
// var status = game_client.status(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) });
// return status.Names.IndexOf(new Common.Name { Name_ = user });
// }
public void GetCardImage(string cardKind) {
conn.SendMessage(new Protocol.ClientServerPacket() { QueryCardImage = new Game.CardKind { Kind = cardKind } });
}
public int GetUserIndex(string user) {
if (game_status.Get() != null) return game_status.Get().Names.IndexOf(new Common.Name { Name_ = user });
else return -1;
}
public Google.Protobuf.Collections.MapField<string, Game.GameStatus.Types.Pile> GetPlayerPiles(string user) {
int idx = this.GetUserIndex(user);
if (idx != -1) {
return game_status.Get().PlayerPiles[idx].Piles_;
}
return null;
}
public Google.Protobuf.Collections.MapField<string, Game.GameStatus.Types.Pile> GetCommonPiles() {
if (game_status.Get() != null) return game_status.Get().CommonPiles.Piles_;
else return null;
}
public void OnClickCard(string pileName, bool isCommonPile, int cardIdx, string user) {
Game.PileKind pileKind = new Game.PileKind() { Owned = (uint)GetUserIndex(user) };
if (isCommonPile) pileKind = new Game.PileKind { Common = new Empty() };
conn.SendMessage(new Protocol.ClientServerPacket() { CallOnClick = new Game.CardId { PileKind = pileKind, CardIndex = new Game.CardIndex { Index = (uint)cardIdx }, PileName = pileName } });
}
// public Dictionary<string, Dictionary<string, Game.MessageStatus.Types.Pile>> OnClickCard(string pileName, bool isCommonPile, int cardIdx, string user) {
// Game.PileKind pileKind = new Game.PileKind() { Owned = (uint)GetUserIndex(user) };
@ -335,22 +362,11 @@ public class Client : MonoBehaviour {
// return GetPiles(user);
// }
// public List<ConnectionService.Game> GetGames()
// {
// AsyncServerStreamingCall<ConnectionService.Game> stream = connection.getGames(new Google.Protobuf.WellKnownTypes.Empty());
// List<ConnectionService.Game> l = new List<ConnectionService.Game>();
// while (runSync(stream.ResponseStream.MoveNext()))
// {
// ConnectionService.Game g = stream.ResponseStream.Current;
// l.Add(g);
// // Debug.Log("Received " + feature.ToString());
// }
// // Debug.Log(stream.ResponseStream.Current);
// return l;
// }
public void GetGames() {
conn.SendMessage(new Protocol.ClientServerPacket() { QueryGames = new Empty() });
}
static T runSync<T>(Task<T> task) {
static T runSync<T>(Task<T> task) {
task.Wait();
return task.Result;
}

123
unity/Assets/Scripts/GameLoader.cs

@ -15,6 +15,8 @@ public class GameLoader : MonoBehaviour {
public GameObject thrownCards;
public static MainMenuController mmc;
public static System.Action onReloadPiles;
private int tmpCounter = 0;
void Start() {
mmc = FindObjectOfType<MainMenuController>();
mmc.gameObject.SetActive(false);
@ -36,75 +38,66 @@ public class GameLoader : MonoBehaviour {
onReloadPiles += SpawnClientCards;
}
// GameObject SpawnCard(Client.Connection conn, string cardKind) {
// var cardImages = conn.GetCardImage(cardKind);
// var card = Instantiate(cardPrefab, Vector3.zero, Quaternion.identity, handUI.transform);
// var front = new Texture2D(1, 1);
// front.LoadImage(cardImages.Face.Span.ToArray());
// var back = new Texture2D(1, 1);
// back.LoadImage(cardImages.Back.Span.ToArray());
// card.transform.Find("Images").GetComponentsInChildren<RawImage>()[0].texture = front;
// card.transform.Find("Images").GetComponentsInChildren<RawImage>()[1].texture = back;
// card.transform.localScale = new Vector3(0.15f, 0.15f, 1f);
// return card;
// }
// GameObject SpawnCardInTable(Client.Connection conn, string cardKind, GameObject parent) {
// var cardImages = conn.GetCardImage(cardKind);
// var card = Instantiate(cardPrefab, Vector3.zero, Quaternion.identity, parent.transform);
// var front = new Texture2D(1, 1);
// front.LoadImage(cardImages.Face.Span.ToArray());
// var back = new Texture2D(1, 1);
// back.LoadImage(cardImages.Back.Span.ToArray());
// card.transform.Find("Images").GetComponentsInChildren<RawImage>()[0].texture = front;
// card.transform.Find("Images").GetComponentsInChildren<RawImage>()[1].texture = back;
// card.transform.localScale = new Vector3(0.15f, 0.15f, 1f);
// card.GetComponent<Card>().ThrowCard(parent);
// return card;
// }
void SpawnCard(Client.ConnectionImpl conn, string cardKind, GameObject parent, System.Action<GameObject> callback) {
var card = Instantiate(cardPrefab, Vector3.zero, Quaternion.identity, parent.transform);
conn.eventManager.AddHandler("game_card_image", (Game.Image image) => {
var front = new Texture2D(1, 1);
front.LoadImage(image.Face.Span.ToArray());
var back = new Texture2D(1, 1);
back.LoadImage(image.Back.Span.ToArray());
card.transform.Find("Images").GetComponentsInChildren<RawImage>()[0].texture = front;
card.transform.Find("Images").GetComponentsInChildren<RawImage>()[1].texture = back;
card.transform.localScale = new Vector3(0.15f, 0.15f, 1f);
callback.Invoke(card);
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnCardImage, "game_card_image");
});
conn.GetCardImage(cardKind);
}
void SpawnClientCards() {
// var conn = Client.GetConnection();
// if (conn != null) {
// var clientPiles = conn.GetPiles(mmc.currentUsername);
// foreach (string key in clientPiles["Owned"].Keys) {
// var pile = clientPiles["Owned"][key];
// int idx = 0;
// foreach(Game.MessageStatus.Types.Card card in pile.Cards) {
// var cardGO = SpawnCard(conn, card.Kind.Kind);
// if(cardGO != null) {
// cardGO.GetComponent<Card>().InitData(key, false, idx);
// }
// idx++;
// }
// }
// }
var conn = Client.GetConnection();
if (conn != null) {
Debug.Log("Spawning player cards.");
var clientPiles = conn.GetPlayerPiles(mmc.currentUsername);
Debug.Log("[player] clientPiles = "+clientPiles);
if (clientPiles == null) return;
foreach (string key in clientPiles.Keys) {
var pile = clientPiles[key];
int idx = 0;
foreach (Game.GameStatus.Types.Card card in pile.Cards) {
SpawnCard(conn, card.Kind.Kind, handUI, (GameObject card) => {
card.GetComponent<Card>().InitData(key, false, idx);
});
idx++;
}
}
}
}
void SpawnCommonCards() {
// var conn = Client.GetConnection();
// if (conn != null) {
// var clientPiles = conn.GetPiles(mmc.currentUsername);
// foreach (string key in clientPiles["Common"].Keys) {
// var pile = clientPiles["Common"][key];
// int idx = 0;
// foreach (Game.MessageStatus.Types.Card card in pile.Cards) {
// var cardGO = SpawnCardInTable(conn, card.Kind.Kind, key == "placed" ? thrownCards : deck);
// if (cardGO != null) {
// cardGO.GetComponent<Card>().InitData(key, true, idx);
// }
// idx++;
// }
// }
// }
var conn = Client.GetConnection();
if (conn != null) {
Debug.Log("Spawning common cards.");
var clientPiles = conn.GetCommonPiles();
Debug.Log("[common] clientPiles = " + clientPiles);
if (clientPiles == null) return;
foreach (string key in clientPiles.Keys) {
var pile = clientPiles[key];
int idx = 0;
foreach (Game.GameStatus.Types.Card card in pile.Cards) {
SpawnCard(conn, card.Kind.Kind, key == "placed" ? thrownCards : deck, (GameObject card) => {
card.GetComponent<Card>().InitData(key, true, idx);
});
idx++;
}
}
}
}
// public static void ReloadPiles(Dictionary<string, Dictionary<string, Game.MessageStatus.Types.Pile>> piles, bool reloadHand = true) {
// var cards = GameObject.FindGameObjectsWithTag("Card");
// foreach (GameObject card in cards) {
// Destroy(card);
// }
// onReloadPiles();
// }
void Update() {}
public static void ReloadPiles() {
var cards = GameObject.FindGameObjectsWithTag("Card");
foreach (GameObject card in cards) {
Destroy(card);
}
onReloadPiles();
}
}

97
unity/Assets/Scripts/MainMenuController.cs

@ -1,4 +1,5 @@
using System.Collections;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@ -72,20 +73,9 @@ public class MainMenuController : MonoBehaviour {
void Update() {
var conn = Client.GetConnection();
if (conn != null) {
if (SceneManager.GetActiveScene().buildIndex == 0) {
if (lobbyMenu.activeSelf) {
bool newStatus;
lobbyStatus = conn.GetLobbyStatus(out newStatus);
if (newStatus)
ReloadMenu(false);
}
}
if (lobbyStatus != null && lobbyStatus.IsStarting) {
SceneManager.LoadScene(1);
}
}
if(conn != null) {
if (conn.IsStarting()) SceneManager.LoadScene(1);
}
}
public void OnApplicationQuit() {
@ -136,17 +126,13 @@ public class MainMenuController : MonoBehaviour {
public void ConnectLobby(string code) {
var conn = Client.GetConnection();
if (conn != null) {
var lobby = conn.GetLobby();
if (lobby == null) {
conn.JoinLobby(code);
mainMenu.SetActive(false);
serverMenu.SetActive(false);
lobbyMenu.SetActive(true);
lobbyCode.text = "Code: " + code;
bool _b;
lobbyStatus = conn.GetLobbyStatus(out _b);
ReloadMenu();
}
conn.JoinLobby(code);
Debug.Log("Lobby joined");
mainMenu.SetActive(false);
serverMenu.SetActive(false);
lobbyMenu.SetActive(true);
lobbyCode.text = "Code: " + code;
ReloadMenu();
}
}
@ -229,21 +215,21 @@ public class MainMenuController : MonoBehaviour {
discordLobbyId = -1;
}
if (serverMenu.activeSelf) {
for (int i = serverScroll.transform.childCount - 1; i >= 1; i--) {
DestroyImmediate(serverScroll.transform.GetChild(i).gameObject);
}
var conn = Client.GetConnection();
if (conn != null) {
foreach (string lobby in conn.GetPublicLobbies()) {
Client.GetConnection().eventManager.AddHandler("ui_list_public_lobbies", (Protocol.LobbyCodes codes) => {
for (int i = serverScroll.transform.childCount - 1; i >= 1; i--) {
DestroyImmediate(serverScroll.transform.GetChild(i).gameObject);
}
foreach (string lobby in codes.LobbyCodes_.ToList().Select(code => Base32.ToString(code.Code))) {
var lobbyGO = Instantiate(serverScroll.transform.GetChild(0), serverScroll.transform);
lobbyGO.GetComponentInChildren<Text>().text = lobby;
lobbyGO.gameObject.SetActive(true);
}
// conn.Close();
}
Client.GetConnection().eventManager.AddHandler("name handler", (Common.Name name) => {
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnPublicLobbies, "ui_list_public_lobbies");
});
Client.GetConnection().GetPublicLobbies();
Client.GetConnection().eventManager.AddHandler("name_handler", (Common.Name name) => {
serverName.text = name.Name_;
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnName, "name handler");
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnName, "name_handler");
});
Client.GetConnection().QueryName();
// Protocol.ServerClientPacket p = null;
@ -272,34 +258,35 @@ public class MainMenuController : MonoBehaviour {
}
var conn = Client.GetConnection();
if (conn != null) {
// var games = conn.GetGames();
// foreach(ConnectionService.Game game in games) {
// var gameGO = Instantiate(lobbyScroll.transform.GetChild(0), lobbyScroll.transform);
// gameGO.GetComponentsInChildren<Text>()[0].text = game.Name;
// gameGO.GetComponentsInChildren<Text>()[1].text = game.Version;
// gameGO.GetComponentsInChildren<Text>()[2].text = string.Join(", ", game.Authors);
// gameGO.GetComponentsInChildren<Text>()[3].text = conn.GetLobbyVoteCount(game.Id) + " votes";
// gameGO.GetComponentsInChildren<Text>()[4].text = ""+game.Id;
// gameGO.gameObject.SetActive(true);
// }
var selfVote = conn.GetSelfVote(username.text);
Client.GetConnection().eventManager.AddHandler("ui_game_lister", (Protocol.Games games) => {
foreach (Connection.Game game in games.Games_) {
var gameGO = Instantiate(lobbyScroll.transform.GetChild(0), lobbyScroll.transform);
gameGO.GetComponentsInChildren<Text>()[0].text = game.Name;
gameGO.GetComponentsInChildren<Text>()[1].text = game.Version;
gameGO.GetComponentsInChildren<Text>()[2].text = string.Join(", ", game.Authors);
gameGO.GetComponentsInChildren<Text>()[3].text = conn.GetLobbyVoteCount(game.Id) + " votes";
gameGO.GetComponentsInChildren<Text>()[4].text = "" + game.Id;
gameGO.gameObject.SetActive(true);
}
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnGames, "ui_game_lister");
});
conn.GetGames();
var selfVote = conn.GetSelfVote(username.text);
if (selfVote != null)
ready = selfVote.Ready;
//Debug.Log(selfVote);
lobbyMenu.transform.Find("ReadyButton").GetComponent<Image>().color = ready ? new Color(0, 255, 0) : new Color(255, 255, 255);
if (lobbyStatus != null) {
var usernames = lobbyStatus.Names;
Client.GetConnection().eventManager.AddHandler("ui_same_users_lobby", (Protocol.Names usernames) => {
List<string> users = new List<string>();
foreach (Common.Name username in usernames) {
foreach (Common.Name username in usernames.Names_) {
users.Add(username.Name_);
}
lobbyMenu.FindRecursive("Usercount").GetComponent<Text>().text = "x " + users.Count;
usersInLobby = users;
}
Client.GetConnection().eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnUsers, "ui_same_users_lobby");
});
conn.GetUsersInSameLobby();
// conn.Close();
if (reloadDiscord) {
Debug.Log(discordLobbyId);

10
unity/UserSettings/EditorUserSettings.asset

@ -5,6 +5,12 @@ EditorUserSettings:
m_ObjectHideFlags: 0
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c72111f19352f223d68252320092a
flags: 0
lightmappingDeviceAndPlatform:
value: 53
flags: 0
@ -18,5 +24,7 @@ EditorUserSettings:
m_SemanticMergeMode: 2
m_VCShowFailedCheckout: 1
m_VCOverwriteFailedCheckoutAssets: 1
m_VCOverlayIcons: 1
m_VCProjectOverlayIcons: 1
m_VCHierarchyOverlayIcons: 1
m_VCOtherOverlayIcons: 1
m_VCAllowAsyncUpdate: 0

Loading…
Cancel
Save