From c47b241e429436aa31b1b88165a973da5d98cab3 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Fri, 20 Sep 2024 17:10:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8D=E5=BE=AE=E9=87=8D=E6=9E=84,=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8A=A0=E8=BD=BD=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E6=8F=90=E4=BE=9B=E7=9A=84Rom=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AxibugEmuOnline.Client/Assets/Script/App.cs | 4 +-- .../Assets/Script/Manager/RomLib/RomFile.cs | 33 ++++++++++++++----- .../Assets/Script/Manager/RomLib/RomLib.cs | 9 +++++ .../Assets/Script/UI/RomItem.cs | 2 ++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index 858b6ec..96147f1 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -57,7 +57,7 @@ namespace AxibugEmuOnline.Client.ClientCore coRunner = go.AddComponent(); var importNode = GameObject.Find("IMPORTENT"); - GameObject.DontDestroyOnLoad(importNode); + if (importNode != null) GameObject.DontDestroyOnLoad(importNode); StartCoroutine(AppTickFlow()); RePullNetInfo(); @@ -79,7 +79,7 @@ namespace AxibugEmuOnline.Client.ClientCore static IEnumerator StartNetInit() { - if (App.network.isConnected) + if (App.network.isConnected) yield break; int platform = 0; diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs index 5dc30e9..a4eb71a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs @@ -11,12 +11,17 @@ namespace AxibugEmuOnline.Client { private HttpAPI.Resp_RomInfo webData; private bool hasLocalFile; - private string fileName; private EnumPlatform platform; private UnityWebRequest downloadRequest; + public bool IsUserRom { get; private set; } + /// 指示该Rom文件的存放路径 - public string LocalFilePath => $"{App.PersistentDataPath}/RemoteRoms/{platform}/{fileName}"; + public string LocalFilePath => + IsUserRom ? + $"{App.PersistentDataPath}/UserRoms/{platform}/{FileName}" : + $"{App.PersistentDataPath}/RemoteRoms/{platform}/{FileName}"; + /// 指示该Rom文件是否已下载完毕 public bool RomReady => hasLocalFile; /// 指示是否正在下载Rom文件 @@ -29,14 +34,14 @@ namespace AxibugEmuOnline.Client /// 唯一标识 public int ID => webData != null ? webData.id : -1; /// 别名 - public string Alias => webData.romName; + public string Alias => IsUserRom ? Path.GetFileNameWithoutExtension(FileName) : webData.romName; /// 描述 - public string Descript => webData.desc; + public string Descript => IsUserRom ? string.Empty : webData.desc; /// 小图URL - public string ImageURL => webData.imgUrl; + public string ImageURL => IsUserRom ? string.Empty : webData.imgUrl; /// 文件名 - public string FileName => fileName; + public string FileName { get; private set; } /// 在查询结果中的索引 public int Index { get; private set; } /// 在查询结果中的所在页 @@ -74,7 +79,7 @@ namespace AxibugEmuOnline.Client public byte[] GetRomFileData() { - if (webData == null) throw new Exception("Not Valid Rom"); + if (!IsUserRom && webData == null) throw new Exception("Not Valid Rom"); if (!RomReady) throw new Exception("Rom File Not Downloaded"); var bytes = File.ReadAllBytes(LocalFilePath); @@ -123,8 +128,8 @@ namespace AxibugEmuOnline.Client public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo) { webData = resp_RomInfo; - fileName = Path.GetFileName(webData.url); - fileName = System.Net.WebUtility.UrlDecode(fileName); + FileName = Path.GetFileName(webData.url); + FileName = System.Net.WebUtility.UrlDecode(FileName); if (File.Exists(LocalFilePath)) { @@ -142,5 +147,15 @@ namespace AxibugEmuOnline.Client OnInfoFilled?.Invoke(); } + + private RomFile() { } + public static RomFile CreateExistRom(EnumPlatform platform, string fileName) + { + var res = new RomFile(); + res.IsUserRom = true; + res.FileName = fileName; + res.hasLocalFile = File.Exists(res.LocalFilePath); + return res; + } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs index 3e2985f..1aafdac 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs @@ -30,6 +30,15 @@ namespace AxibugEmuOnline.Client } } + public RomFile GetExistRom(string fileName) + { + var res = RomFile.CreateExistRom(m_platform, fileName); + + nesRomFileNameMapper[res.FileName] = res; + + return res; + } + public RomFile GetRomFile(string romFileName) { RomFile romFile; diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs index 9892b9b..dd81d0b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs @@ -82,6 +82,8 @@ namespace AxibugEmuOnline.Client } else { + //һûԼṩRomʱ,ʹ + //App.emu.BeginGame(App.nesRomLib.GetExistRom("bad_apple_2_5.nes")); App.emu.BeginGame(m_romfile); return false;