增加长时间保存,解决取影子以后后续请求失效问题(使用unity的请求库)

This commit is contained in:
CaiYanPeng 2022-06-02 19:33:02 +08:00
parent d498dd9148
commit 6effadc1e9
6 changed files with 1648 additions and 1537 deletions

View File

@ -365,7 +365,8 @@
"Please enter an integer between 0-59.": "请输入一个0-59的整数",
"Please check the network status!": "请检查网络连接是否正常!",
"FINISH": "终点",
"Continue the game?": "有中断的划船记录,是否继续?"
"Continue the game?": "有中断的划船记录,是否继续?",
"Save the game?": "有中断的划船记录,是否保存?"
},
"en": {
"HOT ROUTES": "HOT ROUTES",
@ -725,6 +726,7 @@
"Please enter an integer between 0-59.": "Please enter an integer between 0-59.",
"Please check the network status!": "Please check if the network connection is normal!",
"FINISH": "FINISH",
"Continue the game?": "Continue the game?"
"Continue the game?": "Continue the game?",
"Save the game?": "Save the game?"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -126,7 +126,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
// return;
//}
var output = "";
output += "收到消息:" + string.Join("\t", data);
output += "收到消息:" + string.Join(",", data);
Debug.Log(output);
this.Flags = (RowerDataFlag)BitConverter.ToUInt16(data, 0);
int b = 2;

View File

@ -183,6 +183,7 @@ public class NewMainNav : MonoBehaviour
{
if (App.IsRowerMode == true)
{
if (UIManager.Instance.RowerHomeScript.checkRowing()) return;
UIManager.ShowEditUserPanel();
}
else

View File

@ -287,6 +287,7 @@ public class RowerHomeScript : PFUIPanel
rowerType = new RowerType { type = 1, value = 500 };
HandleSelectType();
Init();
}
RowerResultModel reRowData = null;
@ -523,11 +524,11 @@ public class RowerHomeScript : PFUIPanel
}
}
TempRecordData tempRecordData;
private bool Save()
private bool Save(string shadowids = null)
{
var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice;
RowerRecordModel model = new RowerRecordModel();
model.Ticks = records.Count;
var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice;
if (bleDevice != null)
{
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
@ -535,8 +536,8 @@ public class RowerHomeScript : PFUIPanel
}
model.Id = Id;//Guid.NewGuid().ToString();
model.Weight = App.CurrentUser.Weight;
model.Kj = RowerData.TotalEnergy;
model.StartTime = startTime;
model.StartTime = createTime.Value.AddSeconds(-values.Count);
model.CreateTime = createTime.Value;
Debug.Log(values.Count);
if (values.Count > 0)
@ -554,11 +555,13 @@ public class RowerHomeScript : PFUIPanel
model.AvgHeartRate = (int)values.Average(x => x.heartRate);
model.StrokeCount = (ushort)values.Max(x=>x.strokeCount);
model.TotalDistance = (ushort)values.Max(x => x.distance);
model.Kj = values.Max(x => x.energy);
}
model.TotalTime = RowerData.ElapsedTime;
model.TotalTime = records.Count;
model.Type = rowerType.type == 0 ? (int?)null : rowerType.type;
model.TypeValue = rowerType.value == 0 ? (float?)null : rowerType.value;
model.ShadowIds = string.Join(",",GetComponent<RowerMultiModeScript>().shadowList.Select(x=>x.Nid));
model.ShadowIds = string.IsNullOrEmpty(shadowids)?string.Join(",",GetComponent<RowerMultiModeScript>().shadowList.Select(x=>x.Nid)):shadowids;
var path = PFConstants.RowerRecordFolder + "/" + model.Id;
Helper.CreateDirectoryIfNotExsit(path);
var files = new List<string>();
@ -940,45 +943,107 @@ public class RowerHomeScript : PFUIPanel
var files = Directory.GetFiles(dir);
if (files.Length == 0)
return;
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Continue the game?"), () =>
var historyRowerTime = PlayerPrefs.GetString("historyRowerTime");
if (!string.IsNullOrEmpty(historyRowerTime))
{
var str = File.ReadAllText(files[0]);
var list = str.Replace("\r\n", " ").Split(' ');
records.Clear();
foreach (var item in list)
if ((UIManager.Now.GetDateTime() - Convert.ToDateTime(historyRowerTime)).TotalMinutes >= 2)
{
if (!string.IsNullOrEmpty(item))
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Save the game?"), () =>
{
records.Add(item);
}
//records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
var _re = records.LastOrDefault();
if (!string.IsNullOrEmpty(_re))
{
var datas = _re.Split(',');
historyTime = int.Parse(datas[10]);
var str = File.ReadAllText(files[0]);
var list = str.Replace("\r\n", " ").Split(' ');
records.Clear();
foreach (var item in list)
{
if (!string.IsNullOrEmpty(item))
{
var datas = item.Split(',');
records.Add(item);
values.Add(new TempRowerCalc() {
strokeCount = int.Parse(datas[0]),
pace = ushort.Parse(datas[4]),
power = int.Parse(datas[3]),
rate = uint.Parse(datas[5]),
heartRate = int.Parse(datas[7]),
distance = int.Parse(datas[2]),
energy = int.Parse(datas[8]) });
}
//records.Add($"{strokeCount}0,{RowerData.ElapsedTime},{distance}2,{power}3,{pace}4,{rate}5,{RowerData.ResistanceLevel},{heartRate}7,{energy}8,{RowerData.AveragePower},{truelyTime}");
}
var historyRowerType = PlayerPrefs.GetString("historyRowerType");
if (!string.IsNullOrEmpty(historyRowerType))
{
var typeObject = historyRowerType.Split(',');
rowerType = new RowerType() { type = int.Parse(typeObject[0]), value = float.Parse(typeObject[1]) };
HandleSelectType();
}
historyTime = int.Parse(datas[10]);
historyStrokeCount = int.Parse(datas[0]);
historyDistance = int.Parse(datas[2]);
seconds = historyTime;
historyEnergy = int.Parse(datas[8]);
}
createTime = UIManager.Now.GetDateTime();
Save(PlayerPrefs.GetString("historyRowerShadowIds"));
Helper.DelectDir(dir);
UIManager.CloseConfirm();
}, 2,
() =>
{
Helper.DelectDir(dir);
UIManager.CloseConfirm();
});
}
Helper.DelectDir(dir);
UIManager.CloseConfirm();
}, 2,
() =>
{
Helper.DelectDir(dir);
UIManager.CloseConfirm();
});
else
{
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Continue the game?"), () =>
{
var str = File.ReadAllText(files[0]);
var list = str.Replace("\r\n", " ").Split(' ');
records.Clear();
foreach (var item in list)
{
if (!string.IsNullOrEmpty(item))
{
var datas = item.Split(',');
records.Add(item);
values.Add(new TempRowerCalc()
{
strokeCount = int.Parse(datas[0]),
pace = ushort.Parse(datas[4]),
power = int.Parse(datas[3]),
rate = uint.Parse(datas[5]),
heartRate = int.Parse(datas[7]),
distance = int.Parse(datas[2]),
energy = int.Parse(datas[8])
});
}
//records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
}
var _re = records.LastOrDefault();
if (!string.IsNullOrEmpty(_re))
{
var datas = _re.Split(',');
historyTime = int.Parse(datas[10]);
var historyRowerType = PlayerPrefs.GetString("historyRowerType");
if (!string.IsNullOrEmpty(historyRowerType))
{
var typeObject = historyRowerType.Split(',');
rowerType = new RowerType() { type = int.Parse(typeObject[0]), value = float.Parse(typeObject[1]) };
HandleSelectType();
}
historyTime = int.Parse(datas[10]);
historyStrokeCount = int.Parse(datas[0]);
historyDistance = int.Parse(datas[2]);
seconds = historyTime;
historyEnergy = int.Parse(datas[8]);
}
Helper.DelectDir(dir);
UIManager.CloseConfirm();
}, 2,
() =>
{
Helper.DelectDir(dir);
UIManager.CloseConfirm();
});
}
}
}
}
catch (Exception e)
@ -1000,6 +1065,9 @@ public class RowerHomeScript : PFUIPanel
File.WriteAllText(path, string.Join("\r\n", records));
File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
PlayerPrefs.SetString("historyRowerType", $"{rowerType.type},{rowerType.value}");
PlayerPrefs.SetString("historyRowerTime", UIManager.Now.GetDateTime().ToString());
PlayerPrefs.SetString("historyRowerShadowIds", string.Join(",", GetComponent<RowerMultiModeScript>().shadowList.Select(x => x.Nid)));
//Debug.Log(Convert.ToDateTime());
}
catch (Exception e)
{

View File

@ -10,6 +10,8 @@ using UnityEngine.UI;
using Assets.Scripts.UI.Prefab.Login;
using Newtonsoft.Json;
using Assets.Scripts.UI.UIEffect;
using UnityEngine.Networking;
using Assets.Scripts.Apis;
public class RowerMultiModeScript : MonoBehaviour
{
@ -197,49 +199,86 @@ public class RowerMultiModeScript : MonoBehaviour
public int diff { get; set; }
public int sumdiff { get; set; }
}
public Dictionary<int, RankDiff> rankDiffDict;
private IEnumerator Get(string url,Action<JsonResult<List<RowerRank>>> callback)
{
var request = new UnityWebRequest(url, "GET");
request.SetRequestHeader("Accept", "application/json");
request.SetRequestHeader("User-Agent", "PowerFun UnityApp/2.1.3 Android");
request.SetRequestHeader("Pf-User-Agent", "PowerFun UnityApp/2.1.3 Android");
request.SetRequestHeader("Cookie", $"PowerFun.AUTH={App.CurrentUser.cookie}");
request.SetRequestHeader("Language", App.GetLocalLanguage());
request.SetRequestHeader("deviceUniqueIdentifier", App.DeviceUniqueIdentifier);
request.SetRequestHeader("host", "pf.juze.pro");
//request.SetRequestHeader("Accept-Encoding", "gzip, deflate");
//defaultRequestHeaders.Add("deviceUniqueIdentifier", App.DeviceUniqueIdentifier);
//defaultRequestHeaders.Remove("Language");
//defaultRequestHeaders.Add("Language", App.GetLocalLanguage());
request.downloadHandler = new DownloadHandlerBuffer();
yield return request.SendWebRequest();
if (request.isHttpError || request.isNetworkError)
{
Debug.LogError(request.error);
}
else
{
var res = JsonConvert.DeserializeObject<JsonResult<List<RowerRank>>>(request.downloadHandler.text, new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Local
});
callback.Invoke(res);
//Debug.Log(request.downloadHandler.text);
}
}
public async void GetShadowList(RowerTaskPanel.RowerType rowerType, RowerResultModel reRowData)
{
this.rowerType = rowerType;
currentSecond = GetComponent<RowerHomeScript>().historyTime - 1;
//if(Application.internetReachability == NetworkReachability.NotReachable)
var res = reRowData ==null? await ConfigHelper.rowerApi.GetShadowList(rowerType): await ConfigHelper.rowerApi.GetReRowShadowList(reRowData.Id);
shadowList = res.data;
//foreach (var t in traceList)
//{
// t.userId = 0;
// t.trace.gameObject.SetActive(false);
//}
var _tmpList = shadowList.Select(x => new TraceData
var url = $"{App.Host}Rower/GetShadowList?type={rowerType.type}&typeValue={rowerType.value}";
if (reRowData != null)
{
list = x.list,
NickName = x.NickName,
Avatar = x.WxHeadImg,
UserId = x.UserId,
isMine = false,
currentDistance = 0,
Country = x.Country
}).ToList();
myData = new TraceData();
myData.list = new List<RowerChartModel>();
myData.UserId = App.CurrentUser.Id;
myData.NickName = App.CurrentUser.Nickname;
myData.Avatar = App.CurrentUser.WxHeadImg;
myData.isMine = true;
myData.Country = App.CurrentUser.Country;
_tmpList.Insert(_tmpList.Count / 2, myData);
//_tmpList.Add(myData);
userList = _tmpList.OrderByDescending(x => x.currentDistance).ToList();
rankDiffDict = new Dictionary<int, RankDiff>();
for (int i = 0; i < userList.Count; i++)
{
userList[i].currentRank = i + 1;
rankDiffDict.Add(userList[i].UserId, new RankDiff { rank = userList[i].currentRank, diff = 0 });
url = $"{App.Host}Rower/GetReRowShadowList?Id={reRowData.Id}";
}
DisplayUserRanks(true);
DisplayTraces(true);
StartCoroutine(Get(url, (res) =>
{
shadowList = res.data;
var _tmpList = shadowList.Select(x => new TraceData
{
list = x.list,
NickName = x.NickName,
Avatar = x.WxHeadImg,
UserId = x.UserId,
isMine = false,
currentDistance = 0,
Country = x.Country
}).ToList();
myData = new TraceData();
myData.list = new List<RowerChartModel>();
myData.UserId = App.CurrentUser.Id;
myData.NickName = App.CurrentUser.Nickname;
myData.Avatar = App.CurrentUser.WxHeadImg;
myData.isMine = true;
myData.Country = App.CurrentUser.Country;
_tmpList.Insert(_tmpList.Count / 2, myData);
//_tmpList.Add(myData);
userList = _tmpList.OrderByDescending(x => x.currentDistance).ToList();
rankDiffDict = new Dictionary<int, RankDiff>();
for (int i = 0; i < userList.Count; i++)
{
userList[i].currentRank = i + 1;
rankDiffDict.Add(userList[i].UserId, new RankDiff { rank = userList[i].currentRank, diff = 0 });
}
DisplayUserRanks(true);
DisplayTraces(true);
}));
//App.Host + $"/Rower/GetShadowList?type={rowerType.type}&typeValue={rowerType.value}"
//var res = reRowData == null ? await ConfigHelper.rowerApi.GetShadowList(rowerType) : await ConfigHelper.rowerApi.GetReRowShadowList(reRowData.Id);
//return;
}
float GetStrokeSpeed(uint rate)
{
@ -951,6 +990,7 @@ public class RowerMultiModeScript : MonoBehaviour
}
private void DisplayUserRanks(bool isRefresh = false)
{
if (!scrollRank) return;
if (isRefresh)
{
scrollRank.content.DestroyChildren();