Skip to content

Commit

Permalink
Interface patch (#2)
Browse files Browse the repository at this point in the history
ci: ✨ add format-check for interface
  • Loading branch information
asdawej authored Jan 12, 2024
1 parent eb5bc7f commit 4fae605
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 91 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
clangFormatVersion: 14
exclude: './players'
inplace: False

dotnet-format-checking-logic:
runs-on: windows-latest
steps:
Expand All @@ -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"
Expand Down Expand Up @@ -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
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
2 changes: 0 additions & 2 deletions interface/Assets/Scripts/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ public class Debugger : MonoBehaviour
// Start is called before the first frame update
void Start()
{

target.transform.Find("mask1").GetComponent<SpriteRenderer>().material.color = Color.blue;
}

// Update is called once per frame
void Update()
{

}
}
35 changes: 23 additions & 12 deletions interface/Assets/Scripts/Live/MessageReceiverLive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class MessageReceiverLive : SingletonDontDestory<MessageReceiverLive>
// 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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions interface/Assets/Scripts/Manager/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
using UnityEngine;
using Protobuf;

public class MapControl : SingletonMono<MapControl> {
public class MapControl : SingletonMono<MapControl>
{
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),
Expand Down
8 changes: 4 additions & 4 deletions interface/Assets/Scripts/Manager/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public class MessageManager : Singleton<MessageManager>
{

public Dictionary <long, MessageOfShip> Ship = new Dictionary<long, MessageOfShip>();
public Dictionary <long, GameObject> ShipG = new Dictionary<long, GameObject>();
public Dictionary <long, MessageOfBullet> Bullet = new Dictionary<long, MessageOfBullet>();
public Dictionary <long, GameObject> BulletG = new Dictionary<long, GameObject>();
public Dictionary<long, MessageOfShip> Ship = new Dictionary<long, MessageOfShip>();
public Dictionary<long, GameObject> ShipG = new Dictionary<long, GameObject>();
public Dictionary<long, MessageOfBullet> Bullet = new Dictionary<long, MessageOfBullet>();
public Dictionary<long, GameObject> BulletG = new Dictionary<long, GameObject>();
}
8 changes: 5 additions & 3 deletions interface/Assets/Scripts/Manager/ObjectCreater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.Collections.Generic;
using UnityEngine;

public class ObjectCreater : SingletonMono<ObjectCreater>{
public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1){
public class ObjectCreater : SingletonMono<ObjectCreater>
{
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<Color, Color> col = RendererControl.GetInstance().GetColFromTeam(teamKey);
obj.transform.Find("mask1").GetComponent<SpriteRenderer>().material.color = col.Item1;
obj.transform.Find("mask2").GetComponent<SpriteRenderer>().material.color = col.Item2;
Expand Down
9 changes: 6 additions & 3 deletions interface/Assets/Scripts/Manager/RendererControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
using System.Collections.Generic;
using UnityEngine;

public class RendererControl : Singleton<RendererControl>{
public Tuple<Color, Color> GetColFromTeam(int teamKey){
switch(teamKey) {
public class RendererControl : Singleton<RendererControl>
{
public Tuple<Color, Color> GetColFromTeam(int teamKey)
{
switch (teamKey)
{
case 0: return new Tuple<Color, Color>(new Color(114f / 255, 107f / 255, 217f / 255, 1), new Color(107f / 255, 144f / 255, 217f / 255, 1));
case 1: return new Tuple<Color, Color>(new Color(217f / 255, 107f / 255, 107f / 255, 1), new Color(217f / 255, 163f / 255, 107f / 255, 1));
default: return new Tuple<Color, Color>(new Color(0, 0, 0, 1), new Color(0, 0, 0, 1));
Expand Down
17 changes: 11 additions & 6 deletions interface/Assets/Scripts/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
using UnityEngine;
using Protobuf;

public class MapControl : SingletonMono<MapControl> {
public class MapControl : SingletonMono<MapControl>
{
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),
Expand Down
9 changes: 4 additions & 5 deletions interface/Assets/Scripts/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

public class MessageManager : Singleton<MessageManager>
{

public Dictionary <long, MessageOfShip> Ship = new Dictionary<long, MessageOfShip>();
public Dictionary <long, GameObject> ShipG = new Dictionary<long, GameObject>();
public Dictionary <long, MessageOfBullet> Bullet = new Dictionary<long, MessageOfBullet>();
public Dictionary <long, GameObject> BulletG = new Dictionary<long, GameObject>();
public Dictionary<long, MessageOfShip> Ship = new Dictionary<long, MessageOfShip>();
public Dictionary<long, GameObject> ShipG = new Dictionary<long, GameObject>();
public Dictionary<long, MessageOfBullet> Bullet = new Dictionary<long, MessageOfBullet>();
public Dictionary<long, GameObject> BulletG = new Dictionary<long, GameObject>();
}
8 changes: 5 additions & 3 deletions interface/Assets/Scripts/ObjectCreater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.Collections.Generic;
using UnityEngine;

public class ObjectCreater : SingletonMono<ObjectCreater>{
public GameObject CreateObject(GameObject targetG, Vector2 position, Quaternion quaternion, Transform targetPa, int teamKey = -1){
public class ObjectCreater : SingletonMono<ObjectCreater>
{
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<Color, Color> col = RendererControl.GetInstance().GetColFromTeam(teamKey);
obj.transform.Find("mask1").GetComponent<SpriteRenderer>().material.color = col.Item1;
obj.transform.Find("mask2").GetComponent<SpriteRenderer>().material.color = col.Item2;
Expand Down
39 changes: 25 additions & 14 deletions interface/Assets/Scripts/ParaDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.Collections.Generic;
using UnityEngine;
using Protobuf;
public class ParaDefine : SingletonDontDestory<ParaDefine>{
public class ParaDefine : SingletonDontDestory<ParaDefine>
{
public MessageOfMap map;
public GameObject spaceG;
public GameObject[] ruinG;
Expand All @@ -22,27 +23,31 @@ public class ParaDefine : SingletonDontDestory<ParaDefine>{
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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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();
}
}
Loading

0 comments on commit 4fae605

Please sign in to comment.