Skip to content

Commit cf7ab36

Browse files
authored
Merge pull request #22 from youngmonkeys/update-code-style
Update code style
2 parents b4c2fc2 + e8b1578 commit cf7ab36

10 files changed

+191
-56
lines changed

unity/EzyClientConfigJsonConverter.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
using com.tvd12.ezyfoxserver.client.config;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
5+
56
namespace Extensions.ezyfox_server_csharp_client.unity
67
{
78
public class EzyClientConfigJsonConverter : JsonConverter<EzyClientConfig>
89
{
9-
public override void WriteJson(JsonWriter writer, EzyClientConfig clientConfig, JsonSerializer serializer)
10+
public override void WriteJson(
11+
JsonWriter writer,
12+
EzyClientConfig clientConfig,
13+
JsonSerializer serializer
14+
)
1015
{
1116
JObject reconnectConfigJson = new JObject();
1217
EzyReconnectConfig reconnectConfig = clientConfig?.getReconnect();
1318
reconnectConfigJson.Add("enable", reconnectConfig?.isEnable());
14-
reconnectConfigJson.Add("maxReconnectCount", reconnectConfig?.getMaxReconnectCount());
15-
reconnectConfigJson.Add("reconnectPeriod", reconnectConfig?.getReconnectPeriod());
19+
reconnectConfigJson.Add(
20+
"maxReconnectCount",
21+
reconnectConfig?.getMaxReconnectCount()
22+
);
23+
reconnectConfigJson.Add(
24+
"reconnectPeriod",
25+
reconnectConfig?.getReconnectPeriod()
26+
);
1627

1728
JObject pingJson = new JObject();
1829
EzyPingConfig pingConfig = clientConfig?.getPing();
@@ -28,10 +39,18 @@ public override void WriteJson(JsonWriter writer, EzyClientConfig clientConfig,
2839
clientConfigJson.WriteTo(writer);
2940
}
3041

31-
public override EzyClientConfig? ReadJson(JsonReader reader, Type objectType, EzyClientConfig? existingValue, bool hasExistingValue,
32-
JsonSerializer serializer)
42+
public override EzyClientConfig? ReadJson(
43+
JsonReader reader,
44+
Type objectType,
45+
EzyClientConfig? existingValue,
46+
bool hasExistingValue,
47+
JsonSerializer serializer
48+
)
3349
{
34-
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
50+
throw new NotImplementedException(
51+
"Unnecessary because CanRead is false. " +
52+
"The type will skip the converter."
53+
);
3554
}
3655

3756
public override bool CanRead => false;

unity/EzyClientFactory.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public static EzyClientFactory getInstance()
1515
return INSTANCE;
1616
}
1717

18-
public EzyClient getOrCreateClient(EzyClientConfig config, bool udpUsage)
18+
public EzyClient getOrCreateClient(
19+
EzyClientConfig config,
20+
bool udpUsage
21+
)
1922
{
2023
var ezyClients = EzyClients.getInstance();
2124
var ezyClient = ezyClients.getClient(config.getZoneName());

unity/EzyDefaultController.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class EzyDefaultController : MonoBehaviour
1717

1818
private readonly List<Tuple<String, Object>> handlers = new();
1919

20-
protected static readonly EzyLogger LOGGER = EzyUnityLoggerFactory.getLogger<EzyDefaultController>();
20+
protected static readonly EzyLogger LOGGER = EzyUnityLoggerFactory
21+
.getLogger<EzyDefaultController>();
2122

2223
protected void Start()
2324
{
@@ -27,18 +28,27 @@ protected void Start()
2728
{
2829
socketProxyManager.init();
2930
}
30-
socketProxy = socketProxyManager.getSocketProxy(socketConfigVariable.Value.ZoneName);
31+
socketProxy = socketProxyManager.getSocketProxy(
32+
socketConfigVariable.Value.ZoneName
33+
);
3134
if (socketProxy.getClient() == null)
3235
{
3336
LOGGER.debug("Creating ezyClient");
3437
var config = EzyClientConfig.builder()
3538
.clientName(socketConfigVariable.Value.ZoneName)
3639
.zoneName(socketConfigVariable.Value.ZoneName)
3740
.build();
38-
EzyClientFactory.getInstance()
39-
.getOrCreateClient(config, socketConfigVariable.Value.UdpUsage);
41+
EzyClientFactory
42+
.getInstance()
43+
.getOrCreateClient(
44+
config,
45+
socketConfigVariable.Value.UdpUsage
46+
);
4047
}
41-
appProxy = socketProxy.getAppProxy(socketConfigVariable.Value.AppName, true);
48+
appProxy = socketProxy.getAppProxy(
49+
socketConfigVariable.Value.AppName,
50+
true
51+
);
4252
}
4353

4454
protected void on<T>(String cmd, EzyAppProxyDataHandler<T> handler)

unity/EzyDelegates.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ namespace com.tvd12.ezyfoxserver.client.unity
33
{
44
public class EzyDelegates
55
{
6-
public delegate void Delegate1(String clientName);
7-
public delegate void Delegate2(String clientName, String jsonData);
8-
public delegate void EventHandlerDelegate(String clientName, String eventType, String jsonData);
9-
public delegate void DataHandlerDelegate(String clientName, int commandId, String jsonData);
6+
public delegate void Delegate1(
7+
String clientName
8+
);
9+
public delegate void Delegate2(
10+
String clientName,
11+
String jsonData
12+
);
13+
public delegate void EventHandlerDelegate(
14+
String clientName,
15+
String eventType,
16+
String jsonData
17+
);
18+
public delegate void DataHandlerDelegate(
19+
String clientName,
20+
int commandId,
21+
String jsonData
22+
);
1023
}
1124
}

unity/EzyEventWSDataDeserializer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace com.tvd12.ezyfoxserver.client.unity
88
{
99
public sealed class EzyEventWSDataDeserializer
1010
{
11-
private static readonly Dictionary<String, EzyEventType> EVENT_TYPE_BY_STRING_VALUE = new()
11+
private static readonly Dictionary<String, EzyEventType>
12+
EVENT_TYPE_BY_STRING_VALUE = new()
1213
{
1314
{ "CONNECTION_SUCCESS", EzyEventType.CONNECTION_SUCCESS },
1415
{ "CONNECTION_FAILURE", EzyEventType.CONNECTION_FAILURE },
@@ -17,7 +18,8 @@ public sealed class EzyEventWSDataDeserializer
1718
{ "TRY_CONNECT", EzyEventType.TRY_CONNECT },
1819
};
1920

20-
private static readonly Dictionary<String, EzyConnectionFailedReason> CONNECTION_FAILED_REASON_BY_STRING_VALUE = new()
21+
private static readonly Dictionary<String, EzyConnectionFailedReason>
22+
CONNECTION_FAILED_REASON_BY_STRING_VALUE = new()
2123
{
2224
{ "TIME_OUT", EzyConnectionFailedReason.TIME_OUT },
2325
{ "NETWORK_UNREACHABLE", EzyConnectionFailedReason.NETWORK_UNREACHABLE },
@@ -26,7 +28,8 @@ public sealed class EzyEventWSDataDeserializer
2628
{ "UNKNOWN", EzyConnectionFailedReason.UNKNOWN },
2729
};
2830

29-
private static readonly Dictionary<EzyEventType, EventDeserializer> DESERIALIZER_BY_EVENT_TYPE = new()
31+
private static readonly Dictionary<EzyEventType, EventDeserializer>
32+
DESERIALIZER_BY_EVENT_TYPE = new()
3033
{
3134
{ EzyEventType.CONNECTION_SUCCESS, _ => new EzyConnectionSuccessEvent() },
3235
{
@@ -56,15 +59,20 @@ public sealed class EzyEventWSDataDeserializer
5659
)
5760
}
5861
};
62+
5963
private delegate EzyEvent EventDeserializer(String jsonData);
64+
6065
private static readonly EzyEventWSDataDeserializer INSTANCE = new();
6166

6267
public static EzyEventWSDataDeserializer getInstance()
6368
{
6469
return INSTANCE;
6570
}
6671

67-
public EzyEvent deserializeEvent(String eventTypeStringValue, String jsonData)
72+
public EzyEvent deserializeEvent(
73+
String eventTypeStringValue,
74+
String jsonData
75+
)
6876
{
6977
var eventType = EVENT_TYPE_BY_STRING_VALUE[eventTypeStringValue];
7078
return DESERIALIZER_BY_EVENT_TYPE[eventType].Invoke(jsonData);

unity/EzyJsons.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ public static String serialize(Object obj)
1717
switch (obj)
1818
{
1919
case EzyObject ezyObject:
20-
return JsonConvert.SerializeObject(ezyObject.toDict<string, object>());
20+
return JsonConvert.SerializeObject(
21+
ezyObject.toDict<string, object>()
22+
);
2123
case EzyArray ezyArray:
22-
return JsonConvert.SerializeObject(ezyArray.toList<object>());
24+
return JsonConvert.SerializeObject(
25+
ezyArray.toList<object>()
26+
);
2327
default:
2428
return JsonConvert.SerializeObject(obj);
2529
}
@@ -39,25 +43,31 @@ public static EzyData deserialize(string json)
3943
.appendRawDict(dict)
4044
.build();
4145
default:
42-
throw new Exception($"Failed to deserialize json to EzyData");
46+
throw new Exception(
47+
$"Failed to deserialize json to EzyData"
48+
);
4349
}
4450
}
4551

4652
private static object parseJElement(object jElement)
4753
{
4854
switch (jElement)
4955
{
50-
case JObject jObject: // jObject becomes Dictionary<string, object>
51-
return ((IEnumerable<KeyValuePair<string, JToken>>)jObject).ToDictionary(
52-
j => j.Key,
53-
j => parseJElement(j.Value)
54-
);
56+
// jObject becomes Dictionary<string, object>
57+
case JObject jObject:
58+
return ((IEnumerable<KeyValuePair<string, JToken>>)jObject)
59+
.ToDictionary(
60+
j => j.Key,
61+
j => parseJElement(j.Value)
62+
);
5563
case JArray jArray: // jArray becomes List<object>
5664
return jArray.Select(parseJElement).ToList();
5765
case JValue jValue: // jValue just becomes the value
5866
return jValue.Value;
5967
default:
60-
throw new Exception($"Unsupported type: {jElement.GetType()}");
68+
throw new Exception(
69+
$"Unsupported type: {jElement.GetType()}"
70+
);
6171
}
6272
}
6373
}

unity/EzyUnityLoggerFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public static EzyLogger getLogger(Type type)
2424
{
2525
if (!INITIALIZED)
2626
{
27-
EzyLoggerFactory.setLoggerSupply(type => new EzyUnityLogger(type));
27+
EzyLoggerFactory.setLoggerSupply(
28+
type => new EzyUnityLogger(type)
29+
);
2830
INITIALIZED = true;
2931
}
3032
return EzyLoggerFactory.getLogger(type);

0 commit comments

Comments
 (0)