milimoe b4ce65a35b
更新 DataRequest, RunTime, GameMode; 添加 FunGameConfig (#33)
* 更新DataRequest GetResult<T>

* 更新了DataRequest的构造方法,以及RunTime类

* 更新RunTime控制器

* 从Desktop复制Config到Core;更新常量

* 添加GameMode
2023-06-19 09:07:20 +08:00

55 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.Json.Serialization;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Library.Common.Network
{
[Serializable]
public readonly struct SocketObject
{
public SocketMessageType SocketType { get; } = SocketMessageType.Unknown;
public Guid Token { get; } = Guid.Empty;
public object[] Parameters { get; } = Array.Empty<object>();
public int Length => Parameters.Length;
/// <summary>
/// 从参数列表中获取指定索引的参数的Json字符串
/// -- 此索引器仅返回Json字符串对象类型请使用反序列化方法GetParam<T>() --
/// -- 当然也可以自己反序列化 --
/// -- 基本类型可能有效,但仍建议使用反序列化方法 --
/// </summary>
/// <param name="index">索引</param>
/// <returns></returns>
/// <exception cref="IndexOutOfArrayLengthException">索引超过数组上限</exception>
public object? this[int index]
{
get
{
if (index >= Parameters.Length) throw new IndexOutOfArrayLengthException();
object? obj = Parameters[index];
return JsonManager.GetObject(obj.ToString() ?? "");
}
}
[JsonConstructor]
public SocketObject(SocketMessageType SocketType, Guid Token, params object[] Parameters)
{
this.SocketType = SocketType;
this.Token = Token;
if (Parameters != null && Parameters.Length > 0) this.Parameters = Parameters;
}
/// <summary>
/// 从参数列表中获取指定类型和索引的参数
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="index">索引</param>
/// <returns>类型的参数</returns>
/// <exception cref="IndexOutOfArrayLengthException">索引超过数组上限</exception>
public T? GetParam<T>(int index)
{
return JsonManager.GetObject<T>(this, index);
}
}
}