增加长时间保存,解决取影子以后后续请求失效问题(使用unity的请求库)
This commit is contained in:
parent
d498dd9148
commit
6effadc1e9
@ -365,7 +365,8 @@
|
|||||||
"Please enter an integer between 0-59.": "请输入一个0-59的整数!",
|
"Please enter an integer between 0-59.": "请输入一个0-59的整数!",
|
||||||
"Please check the network status!": "请检查网络连接是否正常!",
|
"Please check the network status!": "请检查网络连接是否正常!",
|
||||||
"FINISH": "终点",
|
"FINISH": "终点",
|
||||||
"Continue the game?": "有中断的划船记录,是否继续?"
|
"Continue the game?": "有中断的划船记录,是否继续?",
|
||||||
|
"Save the game?": "有中断的划船记录,是否保存?"
|
||||||
},
|
},
|
||||||
"en": {
|
"en": {
|
||||||
"HOT ROUTES": "HOT ROUTES",
|
"HOT ROUTES": "HOT ROUTES",
|
||||||
@ -725,6 +726,7 @@
|
|||||||
"Please enter an integer between 0-59.": "Please enter an integer between 0-59.",
|
"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!",
|
"Please check the network status!": "Please check if the network connection is normal!",
|
||||||
"FINISH": "FINISH",
|
"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
@ -126,7 +126,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
|||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
var output = "";
|
var output = "";
|
||||||
output += "收到消息:" + string.Join("\t", data);
|
output += "收到消息:" + string.Join(",", data);
|
||||||
Debug.Log(output);
|
Debug.Log(output);
|
||||||
this.Flags = (RowerDataFlag)BitConverter.ToUInt16(data, 0);
|
this.Flags = (RowerDataFlag)BitConverter.ToUInt16(data, 0);
|
||||||
int b = 2;
|
int b = 2;
|
||||||
|
|||||||
@ -183,6 +183,7 @@ public class NewMainNav : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (App.IsRowerMode == true)
|
if (App.IsRowerMode == true)
|
||||||
{
|
{
|
||||||
|
if (UIManager.Instance.RowerHomeScript.checkRowing()) return;
|
||||||
UIManager.ShowEditUserPanel();
|
UIManager.ShowEditUserPanel();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -287,6 +287,7 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
rowerType = new RowerType { type = 1, value = 500 };
|
rowerType = new RowerType { type = 1, value = 500 };
|
||||||
HandleSelectType();
|
HandleSelectType();
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RowerResultModel reRowData = null;
|
RowerResultModel reRowData = null;
|
||||||
@ -523,11 +524,11 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TempRecordData tempRecordData;
|
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();
|
RowerRecordModel model = new RowerRecordModel();
|
||||||
model.Ticks = records.Count;
|
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)
|
if (bleDevice != null)
|
||||||
{
|
{
|
||||||
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
|
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
|
||||||
@ -535,8 +536,8 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
}
|
}
|
||||||
model.Id = Id;//Guid.NewGuid().ToString();
|
model.Id = Id;//Guid.NewGuid().ToString();
|
||||||
model.Weight = App.CurrentUser.Weight;
|
model.Weight = App.CurrentUser.Weight;
|
||||||
model.Kj = RowerData.TotalEnergy;
|
|
||||||
model.StartTime = startTime;
|
model.StartTime = createTime.Value.AddSeconds(-values.Count);
|
||||||
model.CreateTime = createTime.Value;
|
model.CreateTime = createTime.Value;
|
||||||
Debug.Log(values.Count);
|
Debug.Log(values.Count);
|
||||||
if (values.Count > 0)
|
if (values.Count > 0)
|
||||||
@ -554,11 +555,13 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
model.AvgHeartRate = (int)values.Average(x => x.heartRate);
|
model.AvgHeartRate = (int)values.Average(x => x.heartRate);
|
||||||
model.StrokeCount = (ushort)values.Max(x=>x.strokeCount);
|
model.StrokeCount = (ushort)values.Max(x=>x.strokeCount);
|
||||||
model.TotalDistance = (ushort)values.Max(x => x.distance);
|
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.Type = rowerType.type == 0 ? (int?)null : rowerType.type;
|
||||||
model.TypeValue = rowerType.value == 0 ? (float?)null : rowerType.value;
|
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;
|
var path = PFConstants.RowerRecordFolder + "/" + model.Id;
|
||||||
Helper.CreateDirectoryIfNotExsit(path);
|
Helper.CreateDirectoryIfNotExsit(path);
|
||||||
var files = new List<string>();
|
var files = new List<string>();
|
||||||
@ -940,6 +943,54 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
var files = Directory.GetFiles(dir);
|
var files = Directory.GetFiles(dir);
|
||||||
if (files.Length == 0)
|
if (files.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
var historyRowerTime = PlayerPrefs.GetString("historyRowerTime");
|
||||||
|
if (!string.IsNullOrEmpty(historyRowerTime))
|
||||||
|
{
|
||||||
|
if ((UIManager.Now.GetDateTime() - Convert.ToDateTime(historyRowerTime)).TotalMinutes >= 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Save 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}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]) };
|
||||||
|
}
|
||||||
|
createTime = UIManager.Now.GetDateTime();
|
||||||
|
Save(PlayerPrefs.GetString("historyRowerShadowIds"));
|
||||||
|
Helper.DelectDir(dir);
|
||||||
|
UIManager.CloseConfirm();
|
||||||
|
}, 2,
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
Helper.DelectDir(dir);
|
||||||
|
UIManager.CloseConfirm();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Continue the game?"), () =>
|
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Continue the game?"), () =>
|
||||||
{
|
{
|
||||||
var str = File.ReadAllText(files[0]);
|
var str = File.ReadAllText(files[0]);
|
||||||
@ -949,9 +1000,22 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(item))
|
if (!string.IsNullOrEmpty(item))
|
||||||
{
|
{
|
||||||
|
var datas = item.Split(',');
|
||||||
records.Add(item);
|
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}");
|
//records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||||
|
|
||||||
|
}
|
||||||
var _re = records.LastOrDefault();
|
var _re = records.LastOrDefault();
|
||||||
if (!string.IsNullOrEmpty(_re))
|
if (!string.IsNullOrEmpty(_re))
|
||||||
{
|
{
|
||||||
@ -970,7 +1034,6 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
seconds = historyTime;
|
seconds = historyTime;
|
||||||
historyEnergy = int.Parse(datas[8]);
|
historyEnergy = int.Parse(datas[8]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Helper.DelectDir(dir);
|
Helper.DelectDir(dir);
|
||||||
UIManager.CloseConfirm();
|
UIManager.CloseConfirm();
|
||||||
}, 2,
|
}, 2,
|
||||||
@ -981,6 +1044,8 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError(e);
|
Debug.LogError(e);
|
||||||
@ -1000,6 +1065,9 @@ public class RowerHomeScript : PFUIPanel
|
|||||||
File.WriteAllText(path, string.Join("\r\n", records));
|
File.WriteAllText(path, string.Join("\r\n", records));
|
||||||
File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
||||||
PlayerPrefs.SetString("historyRowerType", $"{rowerType.type},{rowerType.value}");
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,6 +10,8 @@ using UnityEngine.UI;
|
|||||||
using Assets.Scripts.UI.Prefab.Login;
|
using Assets.Scripts.UI.Prefab.Login;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Assets.Scripts.UI.UIEffect;
|
using Assets.Scripts.UI.UIEffect;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using Assets.Scripts.Apis;
|
||||||
|
|
||||||
public class RowerMultiModeScript : MonoBehaviour
|
public class RowerMultiModeScript : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -197,20 +199,53 @@ public class RowerMultiModeScript : MonoBehaviour
|
|||||||
public int diff { get; set; }
|
public int diff { get; set; }
|
||||||
public int sumdiff { get; set; }
|
public int sumdiff { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<int, RankDiff> rankDiffDict;
|
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)
|
public async void GetShadowList(RowerTaskPanel.RowerType rowerType, RowerResultModel reRowData)
|
||||||
{
|
{
|
||||||
this.rowerType = rowerType;
|
this.rowerType = rowerType;
|
||||||
currentSecond = GetComponent<RowerHomeScript>().historyTime - 1;
|
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)
|
var url = $"{App.Host}Rower/GetShadowList?type={rowerType.type}&typeValue={rowerType.value}";
|
||||||
//{
|
if (reRowData != null)
|
||||||
// t.userId = 0;
|
{
|
||||||
// t.trace.gameObject.SetActive(false);
|
url = $"{App.Host}Rower/GetReRowShadowList?Id={reRowData.Id}";
|
||||||
//}
|
}
|
||||||
|
StartCoroutine(Get(url, (res) =>
|
||||||
|
{
|
||||||
|
shadowList = res.data;
|
||||||
var _tmpList = shadowList.Select(x => new TraceData
|
var _tmpList = shadowList.Select(x => new TraceData
|
||||||
{
|
{
|
||||||
list = x.list,
|
list = x.list,
|
||||||
@ -240,6 +275,10 @@ public class RowerMultiModeScript : MonoBehaviour
|
|||||||
}
|
}
|
||||||
DisplayUserRanks(true);
|
DisplayUserRanks(true);
|
||||||
DisplayTraces(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)
|
float GetStrokeSpeed(uint rate)
|
||||||
{
|
{
|
||||||
@ -951,6 +990,7 @@ public class RowerMultiModeScript : MonoBehaviour
|
|||||||
}
|
}
|
||||||
private void DisplayUserRanks(bool isRefresh = false)
|
private void DisplayUserRanks(bool isRefresh = false)
|
||||||
{
|
{
|
||||||
|
if (!scrollRank) return;
|
||||||
if (isRefresh)
|
if (isRefresh)
|
||||||
{
|
{
|
||||||
scrollRank.content.DestroyChildren();
|
scrollRank.content.DestroyChildren();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user