diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index e97cce55..ae0a5367 100755 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -12,7 +12,7 @@ jobs: clangFormatVersion: 14 exclude: './players' inplace: False - + dotnet-format-checking-logic: runs-on: windows-latest steps: @@ -21,7 +21,7 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 6.0.x - + - name: Check Logic run: | dotnet restore "./logic/logic.sln" @@ -53,4 +53,17 @@ jobs: - name: Check Launcher run: | dotnet restore "./launcher/launcher.sln" - dotnet format "./launcher/launcher.sln" --severity error --no-restore --verify-no-changes \ No newline at end of file + dotnet format "./launcher/launcher.sln" --severity error --no-restore --verify-no-changes + + dotnet-format-checking-interface: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Check Interface + run: | + dotnet format whitespace "./interface/Assets/Scripts/" --folder --verify-no-changes \ No newline at end of file diff --git a/interface/Assets/Scripts/Debugger.cs b/interface/Assets/Scripts/Debugger.cs index 0f5ee4d7..14e04a82 100644 --- a/interface/Assets/Scripts/Debugger.cs +++ b/interface/Assets/Scripts/Debugger.cs @@ -8,13 +8,11 @@ public class Debugger : MonoBehaviour // Start is called before the first frame update void Start() { - target.transform.Find("mask1").GetComponent().material.color = Color.blue; } // Update is called once per frame void Update() { - } } diff --git a/interface/Assets/Scripts/Live/MessageReceiverLive.cs b/interface/Assets/Scripts/Live/MessageReceiverLive.cs index e7522f28..e7f7e61a 100644 --- a/interface/Assets/Scripts/Live/MessageReceiverLive.cs +++ b/interface/Assets/Scripts/Live/MessageReceiverLive.cs @@ -15,12 +15,14 @@ public class MessageReceiverLive : SingletonDontDestory // Start is called before the first frame update async void Start() { - try { + try + { var channel = new Channel(IP + ":" + Port, ChannelCredentials.Insecure); var client = new AvailableService.AvailableServiceClient(channel); Debug.Log(channel); Debug.Log(client); - PlayerMsg msg = new PlayerMsg() { + PlayerMsg msg = new PlayerMsg() + { PlayerId = 2024, ShipType = ShipType.NullShipType, TeamId = -1, @@ -29,30 +31,38 @@ async void Start() }; var response = client.AddPlayer(msg); MapControl.GetInstance().DrawMap(client.GetMap(new NullRequest())); - if (await response.ResponseStream.MoveNext()) { + if (await response.ResponseStream.MoveNext()) + { var responseVal = response.ResponseStream.Current; Debug.Log("recieve further info"); ParaDefine.GetInstance().map = responseVal.ObjMessage[0].MapMessage; MapControl.GetInstance().DrawMap(ParaDefine.GetInstance().map); } - while (await response.ResponseStream.MoveNext()) { + while (await response.ResponseStream.MoveNext()) + { var responseVal = response.ResponseStream.Current; Receive(responseVal); } IP = null; Port = null; - }catch (RpcException) { + } + catch (RpcException) + { Debug.Log("net work error: "); IP = null; Port = null; } } - private void Receive(MessageToClient message) { - foreach (var messageOfObj in message.ObjMessage) { - switch (messageOfObj.MessageOfObjCase) { + private void Receive(MessageToClient message) + { + foreach (var messageOfObj in message.ObjMessage) + { + switch (messageOfObj.MessageOfObjCase) + { case MessageOfObj.MessageOfObjOneofCase.ShipMessage: - if(MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] == null){ - MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] = + if (MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] == null) + { + MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] = ObjectCreater.GetInstance().CreateObject(ParaDefine.GetInstance().PT(messageOfObj.ShipMessage.ShipType), new Vector3(messageOfObj.ShipMessage.X, messageOfObj.ShipMessage.Y), Quaternion.identity, @@ -62,8 +72,9 @@ private void Receive(MessageToClient message) { } break; case MessageOfObj.MessageOfObjOneofCase.BulletMessage: - if(MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] == null){ - MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] = + if (MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] == null) + { + MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] = ObjectCreater.GetInstance().CreateObject(ParaDefine.GetInstance().PT(messageOfObj.BulletMessage.Type), new Vector3(messageOfObj.BulletMessage.X, messageOfObj.BulletMessage.Y), Quaternion.identity, diff --git a/interface/Assets/Scripts/Manager/MapControl.cs b/interface/Assets/Scripts/Manager/MapControl.cs index b5e38ce8..09c58033 100644 --- a/interface/Assets/Scripts/Manager/MapControl.cs +++ b/interface/Assets/Scripts/Manager/MapControl.cs @@ -4,13 +4,18 @@ using UnityEngine; using Protobuf; -public class MapControl : SingletonMono { +public class MapControl : SingletonMono +{ public GameObject mapFa; - public void DrawMap(MessageOfMap map) { - for (int i = 0; i < 50; i++) { - for (int j = 0; j < 50; j++) { - if(ParaDefine.GetInstance().PT(map.Rows[i].Cols[j])){ - if(map.Rows[i].Cols[j] == PlaceType.Shadow) + public void DrawMap(MessageOfMap map) + { + for (int i = 0; i < 50; i++) + { + for (int j = 0; j < 50; j++) + { + if (ParaDefine.GetInstance().PT(map.Rows[i].Cols[j])) + { + if (map.Rows[i].Cols[j] == PlaceType.Shadow) ObjectCreater.GetInstance().CreateObject( ParaDefine.GetInstance().PT(PlaceType.Space), ParaDefine.GetInstance().CellToMap(i, j), diff --git a/interface/Assets/Scripts/Manager/MessageManager.cs b/interface/Assets/Scripts/Manager/MessageManager.cs index 56fddba8..2ce6edeb 100644 --- a/interface/Assets/Scripts/Manager/MessageManager.cs +++ b/interface/Assets/Scripts/Manager/MessageManager.cs @@ -6,8 +6,8 @@ public class MessageManager : Singleton { - public Dictionary Ship = new Dictionary(); - public Dictionary ShipG = new Dictionary(); - public Dictionary Bullet = new Dictionary(); - public Dictionary BulletG = new Dictionary(); + public Dictionary Ship = new Dictionary(); + public Dictionary ShipG = new Dictionary(); + public Dictionary Bullet = new Dictionary(); + public Dictionary BulletG = new Dictionary(); } \ No newline at end of file diff --git a/interface/Assets/Scripts/Manager/ObjectCreater.cs b/interface/Assets/Scripts/Manager/ObjectCreater.cs index 6fb5a901..7d17f2fb 100644 --- a/interface/Assets/Scripts/Manager/ObjectCreater.cs +++ b/interface/Assets/Scripts/Manager/ObjectCreater.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using UnityEngine; -public class ObjectCreater : SingletonMono{ - public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1){ +public class ObjectCreater : SingletonMono +{ + public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1) + { GameObject obj = Instantiate(targetG, position, quaternion, targetPa); - if(targetG.transform.childCount == 0) return obj; + if (targetG.transform.childCount == 0) return obj; Tuple col = RendererControl.GetInstance().GetColFromTeam(teamKey); obj.transform.Find("mask1").GetComponent().material.color = col.Item1; obj.transform.Find("mask2").GetComponent().material.color = col.Item2; diff --git a/interface/Assets/Scripts/Manager/RendererControl.cs b/interface/Assets/Scripts/Manager/RendererControl.cs index 8ef0e4e8..0e5f3817 100644 --- a/interface/Assets/Scripts/Manager/RendererControl.cs +++ b/interface/Assets/Scripts/Manager/RendererControl.cs @@ -3,9 +3,12 @@ using System.Collections.Generic; using UnityEngine; -public class RendererControl : Singleton{ - public Tuple GetColFromTeam(int teamKey){ - switch(teamKey) { +public class RendererControl : Singleton +{ + public Tuple GetColFromTeam(int teamKey) + { + switch (teamKey) + { case 0: return new Tuple(new Color(114f / 255, 107f / 255, 217f / 255, 1), new Color(107f / 255, 144f / 255, 217f / 255, 1)); case 1: return new Tuple(new Color(217f / 255, 107f / 255, 107f / 255, 1), new Color(217f / 255, 163f / 255, 107f / 255, 1)); default: return new Tuple(new Color(0, 0, 0, 1), new Color(0, 0, 0, 1)); diff --git a/interface/Assets/Scripts/MapControl.cs b/interface/Assets/Scripts/MapControl.cs index b5e38ce8..09c58033 100755 --- a/interface/Assets/Scripts/MapControl.cs +++ b/interface/Assets/Scripts/MapControl.cs @@ -4,13 +4,18 @@ using UnityEngine; using Protobuf; -public class MapControl : SingletonMono { +public class MapControl : SingletonMono +{ public GameObject mapFa; - public void DrawMap(MessageOfMap map) { - for (int i = 0; i < 50; i++) { - for (int j = 0; j < 50; j++) { - if(ParaDefine.GetInstance().PT(map.Rows[i].Cols[j])){ - if(map.Rows[i].Cols[j] == PlaceType.Shadow) + public void DrawMap(MessageOfMap map) + { + for (int i = 0; i < 50; i++) + { + for (int j = 0; j < 50; j++) + { + if (ParaDefine.GetInstance().PT(map.Rows[i].Cols[j])) + { + if (map.Rows[i].Cols[j] == PlaceType.Shadow) ObjectCreater.GetInstance().CreateObject( ParaDefine.GetInstance().PT(PlaceType.Space), ParaDefine.GetInstance().CellToMap(i, j), diff --git a/interface/Assets/Scripts/MessageManager.cs b/interface/Assets/Scripts/MessageManager.cs index 56fddba8..d87b6a64 100644 --- a/interface/Assets/Scripts/MessageManager.cs +++ b/interface/Assets/Scripts/MessageManager.cs @@ -5,9 +5,8 @@ public class MessageManager : Singleton { - - public Dictionary Ship = new Dictionary(); - public Dictionary ShipG = new Dictionary(); - public Dictionary Bullet = new Dictionary(); - public Dictionary BulletG = new Dictionary(); + public Dictionary Ship = new Dictionary(); + public Dictionary ShipG = new Dictionary(); + public Dictionary Bullet = new Dictionary(); + public Dictionary BulletG = new Dictionary(); } \ No newline at end of file diff --git a/interface/Assets/Scripts/ObjectCreater.cs b/interface/Assets/Scripts/ObjectCreater.cs index 6fb5a901..7d17f2fb 100644 --- a/interface/Assets/Scripts/ObjectCreater.cs +++ b/interface/Assets/Scripts/ObjectCreater.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using UnityEngine; -public class ObjectCreater : SingletonMono{ - public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1){ +public class ObjectCreater : SingletonMono +{ + public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1) + { GameObject obj = Instantiate(targetG, position, quaternion, targetPa); - if(targetG.transform.childCount == 0) return obj; + if (targetG.transform.childCount == 0) return obj; Tuple col = RendererControl.GetInstance().GetColFromTeam(teamKey); obj.transform.Find("mask1").GetComponent().material.color = col.Item1; obj.transform.Find("mask2").GetComponent().material.color = col.Item2; diff --git a/interface/Assets/Scripts/ParaDefine.cs b/interface/Assets/Scripts/ParaDefine.cs index bdadc703..7e0cb7d3 100755 --- a/interface/Assets/Scripts/ParaDefine.cs +++ b/interface/Assets/Scripts/ParaDefine.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using UnityEngine; using Protobuf; -public class ParaDefine : SingletonDontDestory{ +public class ParaDefine : SingletonDontDestory +{ public MessageOfMap map; public GameObject spaceG; public GameObject[] ruinG; @@ -22,27 +23,31 @@ public class ParaDefine : SingletonDontDestory{ public GameObject[] shellG; public GameObject[] missileG; public GameObject[] arcG; - public GameObject PT(PlaceType _placeType, int teamKey = 0) { - switch (_placeType) { + public GameObject PT(PlaceType _placeType, int teamKey = 0) + { + switch (_placeType) + { case PlaceType.Home: return homeG[teamKey]; case PlaceType.Space: return spaceG; case PlaceType.Ruin: - return ruinG[GetRand()%2]; + return ruinG[GetRand() % 2]; case PlaceType.Shadow: return shadowG; case PlaceType.Asteroid: - return asteroidG[GetRand()%3]; + return asteroidG[GetRand() % 3]; case PlaceType.Resource: - return resourceG[GetRand()%3]; + return resourceG[GetRand() % 3]; case PlaceType.Wormhole: return wormholeG; default: return null; } } - public GameObject PT(ConstructionType _constructionType, int teamKey = 0) { - switch (_constructionType) { + public GameObject PT(ConstructionType _constructionType, int teamKey = 0) + { + switch (_constructionType) + { case ConstructionType.Community: return communityG[teamKey]; case ConstructionType.Factory: @@ -52,8 +57,10 @@ public GameObject PT(ConstructionType _constructionType, int teamKey = 0) { default: return null; } } - public GameObject PT(ShipType _shipType, int teamKey = 0) { - switch (_shipType) { + public GameObject PT(ShipType _shipType, int teamKey = 0) + { + switch (_shipType) + { case ShipType.CivilianShip: return civilianshipG; case ShipType.MilitaryShip: @@ -63,8 +70,10 @@ public GameObject PT(ShipType _shipType, int teamKey = 0) { default: return null; } } - public GameObject PT(BulletType _bulletType, int teamKey = 0) { - switch (_bulletType) { + public GameObject PT(BulletType _bulletType, int teamKey = 0) + { + switch (_bulletType) + { case BulletType.Laser: return laserG[teamKey]; case BulletType.Plasma: @@ -78,11 +87,13 @@ public GameObject PT(BulletType _bulletType, int teamKey = 0) { default: return null; } } - public Vector3 CellToMap(int x, int y){ + public Vector3 CellToMap(int x, int y) + { return new Vector3(y, 50 - x, 0); } private System.Random random = new System.Random(); - public int GetRand(){ + public int GetRand() + { return random.Next(); } } diff --git a/interface/Assets/Scripts/Play/MessageReceiverPlay.cs b/interface/Assets/Scripts/Play/MessageReceiverPlay.cs index e0118c41..ce91e777 100644 --- a/interface/Assets/Scripts/Play/MessageReceiverPlay.cs +++ b/interface/Assets/Scripts/Play/MessageReceiverPlay.cs @@ -15,12 +15,14 @@ public class MessageReceiverPlay : SingletonDontDestory // Start is called before the first frame update async void Start() { - try { + try + { var channel = new Channel(IP + ":" + Port, ChannelCredentials.Insecure); var client = new AvailableService.AvailableServiceClient(channel); Debug.Log(channel); Debug.Log(client); - PlayerMsg msg = new PlayerMsg() { + PlayerMsg msg = new PlayerMsg() + { PlayerId = 0, TeamId = 0, ShipType = ShipType.CivilianShip, @@ -59,30 +61,38 @@ async void Start() // }; // var response4 = client.AddPlayer(msg4); MapControl.GetInstance().DrawMap(client.GetMap(new NullRequest())); - if (await response.ResponseStream.MoveNext()) { + if (await response.ResponseStream.MoveNext()) + { var responseVal = response.ResponseStream.Current; Debug.Log("recieve further info"); ParaDefine.GetInstance().map = responseVal.ObjMessage[0].MapMessage; MapControl.GetInstance().DrawMap(ParaDefine.GetInstance().map); } - while (await response.ResponseStream.MoveNext()) { + while (await response.ResponseStream.MoveNext()) + { var responseVal = response.ResponseStream.Current; Receive(responseVal); } IP = null; Port = null; - }catch (RpcException) { + } + catch (RpcException) + { Debug.Log("net work error: "); IP = null; Port = null; } } - private void Receive(MessageToClient message) { - foreach (var messageOfObj in message.ObjMessage) { - switch (messageOfObj.MessageOfObjCase) { + private void Receive(MessageToClient message) + { + foreach (var messageOfObj in message.ObjMessage) + { + switch (messageOfObj.MessageOfObjCase) + { case MessageOfObj.MessageOfObjOneofCase.ShipMessage: - if(MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] == null){ - MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] = + if (MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] == null) + { + MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] = Instantiate(ParaDefine.GetInstance().PT(messageOfObj.ShipMessage.ShipType), new Vector3(messageOfObj.ShipMessage.X, messageOfObj.ShipMessage.Y), Quaternion.identity, @@ -91,8 +101,9 @@ private void Receive(MessageToClient message) { } break; case MessageOfObj.MessageOfObjOneofCase.BulletMessage: - if(MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] == null){ - MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] = + if (MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] == null) + { + MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] = Instantiate(ParaDefine.GetInstance().PT(messageOfObj.BulletMessage.Type), new Vector3(messageOfObj.BulletMessage.X, messageOfObj.BulletMessage.Y), Quaternion.identity, diff --git a/interface/Assets/Scripts/PlayerControl.cs b/interface/Assets/Scripts/PlayerControl.cs index 69ed4d9a..fc8f3fbd 100755 --- a/interface/Assets/Scripts/PlayerControl.cs +++ b/interface/Assets/Scripts/PlayerControl.cs @@ -2,38 +2,46 @@ using System.Collections.Generic; using UnityEngine; using static UnityEngine.GraphicsBuffer; -public class PlayerControl : MonoBehaviour { +public class PlayerControl : MonoBehaviour +{ public Rigidbody2D rbPlayer; public float moveSpeed; private float targetQ; - void SetVQTo(Vector2 targetV) { + void SetVQTo(Vector2 targetV) + { rbPlayer.velocity = Vector2.Lerp(rbPlayer.velocity, targetV, 0.05f); rbPlayer.rotation = Mathf.Lerp(rbPlayer.rotation, targetQ, 0.03f); } - float DealQ(float qTar) { + float DealQ(float qTar) + { while (qTar - targetQ > 180) qTar -= 360; while (targetQ - qTar > 180) qTar += 360; return qTar; } - void Move() { - if (Input.GetKey(KeyCode.A)) { + void Move() + { + if (Input.GetKey(KeyCode.A)) + { targetQ = DealQ(90); SetVQTo(new Vector2(-moveSpeed, 0)); return; } - if (Input.GetKey(KeyCode.D)) { + if (Input.GetKey(KeyCode.D)) + { targetQ = DealQ(-90); SetVQTo(new Vector2(moveSpeed, 0)); return; } - if (Input.GetKey(KeyCode.W)) { + if (Input.GetKey(KeyCode.W)) + { targetQ = DealQ(0); SetVQTo(new Vector2(0, moveSpeed)); return; } - if (Input.GetKey(KeyCode.S)) { + if (Input.GetKey(KeyCode.S)) + { targetQ = DealQ(180); SetVQTo(new Vector2(0, -moveSpeed)); return; @@ -44,7 +52,8 @@ void Start() { rbPlayer = GetComponent(); } - void Update() { + void Update() + { Move(); } } diff --git a/interface/Assets/Scripts/RendererControl.cs b/interface/Assets/Scripts/RendererControl.cs index 8ef0e4e8..0e5f3817 100644 --- a/interface/Assets/Scripts/RendererControl.cs +++ b/interface/Assets/Scripts/RendererControl.cs @@ -3,9 +3,12 @@ using System.Collections.Generic; using UnityEngine; -public class RendererControl : Singleton{ - public Tuple GetColFromTeam(int teamKey){ - switch(teamKey) { +public class RendererControl : Singleton +{ + public Tuple GetColFromTeam(int teamKey) + { + switch (teamKey) + { case 0: return new Tuple(new Color(114f / 255, 107f / 255, 217f / 255, 1), new Color(107f / 255, 144f / 255, 217f / 255, 1)); case 1: return new Tuple(new Color(217f / 255, 107f / 255, 107f / 255, 1), new Color(217f / 255, 163f / 255, 107f / 255, 1)); default: return new Tuple(new Color(0, 0, 0, 1), new Color(0, 0, 0, 1)); diff --git a/interface/Assets/Scripts/base/Singleton.cs b/interface/Assets/Scripts/base/Singleton.cs index b4b4b5b6..39cfa068 100755 --- a/interface/Assets/Scripts/base/Singleton.cs +++ b/interface/Assets/Scripts/base/Singleton.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class Singleton where T : new() +public class Singleton where T : new() { private static T Instance; public static T GetInstance() diff --git a/interface/Assets/Scripts/base/SingletonDontDestory.cs b/interface/Assets/Scripts/base/SingletonDontDestory.cs index cbb01f6a..a326b366 100755 --- a/interface/Assets/Scripts/base/SingletonDontDestory.cs +++ b/interface/Assets/Scripts/base/SingletonDontDestory.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class SingletonDontDestory : MonoBehaviour where T: MonoBehaviour +public class SingletonDontDestory : MonoBehaviour where T : MonoBehaviour { private static T Instance; public static T GetInstance() diff --git a/interface/Assets/Scripts/base/SingletonMono.cs b/interface/Assets/Scripts/base/SingletonMono.cs index 003d9752..62fac0db 100755 --- a/interface/Assets/Scripts/base/SingletonMono.cs +++ b/interface/Assets/Scripts/base/SingletonMono.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class SingletonMono : MonoBehaviour where T: MonoBehaviour +public class SingletonMono : MonoBehaviour where T : MonoBehaviour { private static T Instance; public static T GetInstance() @@ -12,14 +12,14 @@ public static T GetInstance() protected void Awake() { - if (Instance==null) + if (Instance == null) { Instance = this as T; -// DontDestroyOnLoad(gameObject); + // DontDestroyOnLoad(gameObject); } else { -// Destroy(gameObject); + // Destroy(gameObject); } }