AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs

132 lines
4.2 KiB
C#
Raw Normal View History

2024-08-13 18:35:20 +08:00
using AxibugEmuOnline.Client.ClientCore;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace AxibugEmuOnline.Client
{
public class HttpAPI
{
2024-09-13 10:07:24 +08:00
public string WebHost = "http://emu.axibug.com";
public string WebSiteApi => WebHost + "/api";
2024-08-13 18:35:20 +08:00
2024-08-22 15:16:58 +08:00
public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10);
2024-11-13 13:55:36 +08:00
public delegate void SearchRomListAPI(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10);
2024-08-22 15:16:58 +08:00
2024-08-13 18:35:20 +08:00
public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10)
{
2024-09-11 18:31:25 +08:00
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
2024-08-13 18:35:20 +08:00
}
2024-11-13 13:55:36 +08:00
public void SearchNesRomList(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10)
{
App.StartCoroutine(SearchNesRomListFlow(searchKey, page, pageSize, callback));
}
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> callback)
{
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
callback.Invoke(null);
yield break;
}
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
callback.Invoke(resp);
}
2024-08-13 18:35:20 +08:00
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<Resp_GameList> callback)
{
2024-09-13 10:07:24 +08:00
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
2024-08-13 18:35:20 +08:00
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
callback.Invoke(null);
yield break;
}
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
callback.Invoke(resp);
}
2024-09-18 15:53:58 +08:00
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
2024-09-18 12:54:13 +08:00
{
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
callback.Invoke(null);
yield break;
}
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
callback.Invoke(resp);
}
enum PlatformType : byte
{
All = 0,
Nes = 1,
}
2024-08-14 13:09:22 +08:00
enum GameType : byte
{
NONE = 0,
ACT,
ARPG,
AVG,
ETC,
FTG,
PUZ,
RAC,
RPG,
SLG,
SPG,
SRPG,
STG,
TAB,
/// <summary>
/// 合卡
/// </summary>
ALLINONE,
}
[Serializable]
2024-08-13 18:35:20 +08:00
public class Resp_GameList
{
2024-08-14 13:09:22 +08:00
public int page;
public int maxPage;
public int resultAllCount;
public List<Resp_RomInfo> gameList;
2024-08-13 18:35:20 +08:00
}
2024-08-14 13:09:22 +08:00
[Serializable]
2024-08-13 18:35:20 +08:00
public class Resp_RomInfo
{
2024-08-22 15:16:58 +08:00
public int orderid;
2024-08-14 13:09:22 +08:00
public int id;
public string romName;
public string gType;
public string desc;
public string url;
public string imgUrl;
public string hash;
public int stars;
2024-08-13 18:35:20 +08:00
}
2024-09-13 10:07:24 +08:00
[Serializable]
public class Resp_CheckStandInfo
{
public int needUpdateClient;
public string serverIp;
public ushort serverPort;
public string clientVersion;
public string downLoadUrl;
}
2024-08-13 18:35:20 +08:00
}
}