forked from sin365/AxibugEmuOnline
修复一些拉取rom列表的bug
This commit is contained in:
parent
194150b911
commit
3bbb347e84
@ -1,4 +1,4 @@
|
||||
using AxibugEmuOnline.Client.ClientCore;
|
||||
using AxibugEmuOnline.Client.ClientCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -12,21 +12,20 @@ namespace AxibugEmuOnline.Client
|
||||
public string WebHost = "http://emu.axibug.com";
|
||||
public string WebSiteApi => WebHost + "/api";
|
||||
|
||||
public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10);
|
||||
public delegate void SearchRomListAPI(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10);
|
||||
public delegate void GetRomListAPI(Action<int, Resp_GameList> callback, int page, int pageSize = 10);
|
||||
public delegate void SearchRomListAPI(Action<int, Resp_GameList> callback, string searchKey, int page, int pageSize = 10);
|
||||
|
||||
public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10)
|
||||
public void GetNesRomList(Action<int, Resp_GameList> callback, int page, int pageSize = 10)
|
||||
{
|
||||
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
|
||||
}
|
||||
|
||||
public void SearchNesRomList(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10)
|
||||
public void SearchNesRomList(Action<int, 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)
|
||||
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<int, Resp_GameList> callback)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrEmpty(searchKey))
|
||||
{
|
||||
string oldsearch = searchKey;
|
||||
@ -48,19 +47,19 @@ namespace AxibugEmuOnline.Client
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
callback.Invoke(null);
|
||||
callback.Invoke(page, null);
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
{
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
callback.Invoke(page, resp);
|
||||
yield break;
|
||||
}
|
||||
|
||||
App.log.Error(request.downloadHandler.ErrInfo);
|
||||
callback.Invoke(null);
|
||||
callback.Invoke(page, null);
|
||||
|
||||
/*
|
||||
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
||||
@ -73,7 +72,7 @@ namespace AxibugEmuOnline.Client
|
||||
}*/
|
||||
|
||||
}
|
||||
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<Resp_GameList> callback)
|
||||
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<int, Resp_GameList> callback)
|
||||
{
|
||||
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}";
|
||||
App.log.Info($"GetRomList=>{url}");
|
||||
@ -81,7 +80,7 @@ namespace AxibugEmuOnline.Client
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
callback.Invoke(null);
|
||||
callback.Invoke(page, null);
|
||||
yield break;
|
||||
}
|
||||
|
||||
@ -89,12 +88,12 @@ namespace AxibugEmuOnline.Client
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
{
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
callback.Invoke(page, resp);
|
||||
yield break;
|
||||
}
|
||||
|
||||
App.log.Error(request.downloadHandler.ErrInfo);
|
||||
callback.Invoke(null);
|
||||
callback.Invoke(page, null);
|
||||
/*
|
||||
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||
yield return request.SendWebRequest();
|
||||
|
@ -75,14 +75,17 @@ namespace AxibugEmuOnline.Client
|
||||
lastSearchKey = searchKey;
|
||||
if (string.IsNullOrWhiteSpace(searchKey))
|
||||
{
|
||||
m_romGetFunc((romList) =>
|
||||
m_romGetFunc((page, romList) =>
|
||||
{
|
||||
//TODO 请求失败对于romList为空时的处理
|
||||
|
||||
FetchPageCmd.Clear();
|
||||
nesRomFileIdMapper.Clear();
|
||||
nesRomFileNameMapper.Clear();
|
||||
|
||||
if (romList != null)
|
||||
nesRomFetchList = new RomFile[romList.resultAllCount];
|
||||
else
|
||||
nesRomFetchList = new RomFile[0];
|
||||
|
||||
for (int i = 0; i < nesRomFetchList.Length; i++)
|
||||
{
|
||||
//以后考虑用对象池实例化RomFile
|
||||
@ -95,14 +98,17 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
m_romSearchFunc((romList) =>
|
||||
m_romSearchFunc((page, romList) =>
|
||||
{
|
||||
//TODO 请求失败对于romList为空时的处理
|
||||
|
||||
FetchPageCmd.Clear();
|
||||
nesRomFileIdMapper.Clear();
|
||||
nesRomFileNameMapper.Clear();
|
||||
|
||||
if (romList != null)
|
||||
nesRomFetchList = new RomFile[romList.resultAllCount];
|
||||
else
|
||||
nesRomFetchList = new RomFile[0];
|
||||
|
||||
for (int i = 0; i < nesRomFetchList.Length; i++)
|
||||
{
|
||||
//以后考虑用对象池实例化RomFile
|
||||
@ -115,33 +121,47 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
}
|
||||
|
||||
bool m_needFetch = false;
|
||||
public void BeginFetchRomInfo(RomFile romFile)
|
||||
{
|
||||
if (romFile.InfoReady) return;
|
||||
|
||||
FetchPageCmd.Add(romFile.Page);
|
||||
if (FetchPageCmd.Add(romFile.Page))
|
||||
m_needFetch = true;
|
||||
}
|
||||
|
||||
public void ExecuteFetchRomInfo()
|
||||
{
|
||||
if (FetchPageCmd.Count == 0) return;
|
||||
if (!m_needFetch) return;
|
||||
|
||||
foreach (var pageNo in FetchPageCmd)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(lastSearchKey))
|
||||
{
|
||||
m_romSearchFunc(SaveRomInfoFromWeb, lastSearchKey, pageNo, PAGE_SIZE);
|
||||
m_romSearchFunc((page, resp) =>
|
||||
{
|
||||
FetchPageCmd.Remove(page);
|
||||
SaveRomInfoFromWeb(resp);
|
||||
}, lastSearchKey, pageNo, PAGE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_romGetFunc(SaveRomInfoFromWeb, pageNo, PAGE_SIZE);
|
||||
m_romGetFunc((page, resp) =>
|
||||
{
|
||||
FetchPageCmd.Remove(page);
|
||||
SaveRomInfoFromWeb(resp);
|
||||
}, pageNo, PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
FetchPageCmd.Clear();
|
||||
|
||||
m_needFetch = false;
|
||||
}
|
||||
|
||||
private void SaveRomInfoFromWeb(Resp_GameList resp)
|
||||
{
|
||||
if (resp == null) return;
|
||||
|
||||
for (int i = 0; i < resp.gameList.Count; i++)
|
||||
{
|
||||
var webData = resp.gameList[i];
|
||||
|
Loading…
Reference in New Issue
Block a user