Commit 5ec93fca authored by hex's avatar hex

Add in-app game data reload and manager reset support

parent 2a4c8eae
...@@ -55,6 +55,9 @@ public class Menu : WindowServantSP ...@@ -55,6 +55,9 @@ public class Menu : WindowServantSP
{ {
base.show(); base.show();
Program.charge(); Program.charge();
// 如有资源更新完成,回到主菜单后自动重载数据(无需重启 App)
Program.I().ApplyPendingReloadGameDatabases();
// 自动检查超先行卡更新 // 自动检查超先行卡更新
if (!_isCheckingUpdate && !isPreDownloading) if (!_isCheckingUpdate && !isPreDownloading)
...@@ -679,7 +682,17 @@ public class Menu : WindowServantSP ...@@ -679,7 +682,17 @@ public class Menu : WindowServantSP
{ {
byte[] ypkData = File.ReadAllBytes(ypkFilePathInDownloads); byte[] ypkData = File.ReadAllBytes(ypkFilePathInDownloads);
Program.I().ExtractZipFile(ypkData, expansionsDir); Program.I().ExtractZipFile(ypkData, expansionsDir);
Program.PrintToChat("更新成功!请【重启游戏】以使改动完全生效。");
Program.PrintToChat("超先行卡包安装完成,正在重载数据...");
Program.I().RequestReloadGameDatabases();
if (isShowed)
{
Program.I().ApplyPendingReloadGameDatabases();
}
else
{
Program.PrintToChat("更新成功!请返回主菜单以自动生效(无需重启)。");
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -785,7 +798,16 @@ public class Menu : WindowServantSP ...@@ -785,7 +798,16 @@ public class Menu : WindowServantSP
// 同步操作,如果失败会抛出异常 // 同步操作,如果失败会抛出异常
Program.I().ExtractZipFile(ypkData, expansionsDir); Program.I().ExtractZipFile(ypkData, expansionsDir);
Program.PrintToChat("更新成功!请【重启游戏】以使改动完全生效。"); Program.PrintToChat("超先行卡包安装完成,正在重载数据...");
Program.I().RequestReloadGameDatabases();
if (isShowed)
{
Program.I().ApplyPendingReloadGameDatabases();
}
else
{
Program.PrintToChat("更新成功!请返回主菜单以自动生效(无需重启)。");
}
} }
else else
{ {
......
...@@ -584,6 +584,101 @@ public class Program : MonoBehaviour ...@@ -584,6 +584,101 @@ public class Program : MonoBehaviour
return false; return false;
} }
private bool _pendingReloadGameDatabases = false;
public void RequestReloadGameDatabases()
{
_pendingReloadGameDatabases = true;
}
public bool ApplyPendingReloadGameDatabases()
{
if (!_pendingReloadGameDatabases)
{
return false;
}
_pendingReloadGameDatabases = false;
return ReloadGameDatabases();
}
public bool ReloadGameDatabases()
{
PrintToChat(InterString.Get("正在重新加载本地数据..."));
try
{
GameStringManager.Reset();
YGOSharp.CardsManager.Reset();
YGOSharp.PacksManager.Reset();
YGOSharp.BanlistManager.Reset();
bool cardsLoaded = LoadDatabaseFile(
"cards.cdb",
(path) => YGOSharp.CardsManager.initialize(path)
);
bool stringsLoaded = LoadDatabaseFile(
"strings.conf",
(path) => GameStringManager.initialize(path)
);
if (File.Exists("expansions/lflist.conf"))
{
YGOSharp.BanlistManager.initialize("expansions/lflist.conf");
}
else
{
LoadDatabaseFile(
"lflist.conf",
(path) => YGOSharp.BanlistManager.initialize(path)
);
}
YGOSharp.BanlistManager.initializeComplete();
if (File.Exists("expansions/strings.conf"))
{
GameStringManager.initialize("expansions/strings.conf");
}
if (Directory.Exists("expansions"))
{
FileInfo[] fileInfos = (new DirectoryInfo("expansions"))
.GetFiles("*.cdb")
.OrderByDescending(x => x.Name)
.ToArray();
foreach (var fileInfo in fileInfos)
{
YGOSharp.CardsManager.initialize(fileInfo.FullName, false, true);
}
}
YGOSharp.CardsManager.updateSetNames();
if (Directory.Exists("pack"))
{
FileInfo[] fileInfos = (new DirectoryInfo("pack")).GetFiles("*.db");
foreach (var fileInfo in fileInfos)
{
YGOSharp.PacksManager.initialize(fileInfo.FullName);
}
YGOSharp.PacksManager.initializeSec();
}
if (!cardsLoaded || !stringsLoaded)
{
PrintToChat(InterString.Get("本地数据部分重载失败,建议【重启游戏】以确保完整生效。"));
return false;
}
PrintToChat(InterString.Get("本地数据已重新加载,无需重启。"));
return true;
}
catch (Exception e)
{
DEBUGLOG(e);
PrintToChat(InterString.Get("本地数据重载失败,请【重启游戏】后重试。"));
return false;
}
}
// [修改] 使用 UnityFileDownloader 完全重写后台更新协程 // [修改] 使用 UnityFileDownloader 完全重写后台更新协程
private IEnumerator UpdateClientCoroutine() private IEnumerator UpdateClientCoroutine()
{ {
......
...@@ -15,6 +15,12 @@ public static class GameStringManager ...@@ -15,6 +15,12 @@ public static class GameStringManager
public static List<hashedString> xilies = new List<hashedString>(); public static List<hashedString> xilies = new List<hashedString>();
public static void Reset()
{
hashedStrings.Clear();
xilies.Clear();
}
public static int helper_stringToInt(string str) public static int helper_stringToInt(string str)
{ {
int return_value = 0; int return_value = 0;
......
...@@ -95,7 +95,7 @@ public class SelectServer : WindowServantSP ...@@ -95,7 +95,7 @@ public class SelectServer : WindowServantSP
} }
case "[OCG]EXP": case "[OCG]EXP":
{ {
UIHelper.getByName<UIInput>(gameObject, "ip_").value = "exp.baldlee.top"; UIHelper.getByName<UIInput>(gameObject, "ip_").value = "e.ygo.pro";
UIHelper.getByName<UIInput>(gameObject, "port_").value = "23333"; UIHelper.getByName<UIInput>(gameObject, "port_").value = "23333";
Config.Set("serversPicker", "[OCG]EXP"); Config.Set("serversPicker", "[OCG]EXP");
......
...@@ -8,6 +8,11 @@ namespace YGOSharp ...@@ -8,6 +8,11 @@ namespace YGOSharp
{ {
public static List<Banlist> Banlists { get; private set; } public static List<Banlist> Banlists { get; private set; }
public static void Reset()
{
Banlists = new List<Banlist>();
}
public static bool initialize(string fileName, bool test = false) public static bool initialize(string fileName, bool test = false)
{ {
List<Banlist> new_list = new List<Banlist>(); List<Banlist> new_list = new List<Banlist>();
......
...@@ -10,12 +10,22 @@ namespace YGOSharp ...@@ -10,12 +10,22 @@ namespace YGOSharp
{ {
internal static class CardsManager internal static class CardsManager
{ {
private static readonly object _lock = new object();
private static IDictionary<int, Card> _cards = new Dictionary<int, Card>(); private static IDictionary<int, Card> _cards = new Dictionary<int, Card>();
public static string nullName = ""; public static string nullName = "";
public static string nullString = ""; public static string nullString = "";
internal static void Reset()
{
lock (_lock)
{
_cards = new Dictionary<int, Card>();
}
}
internal static bool initialize( internal static bool initialize(
string databaseFullPath, string databaseFullPath,
bool test = false, bool test = false,
...@@ -35,53 +45,62 @@ namespace YGOSharp ...@@ -35,53 +45,62 @@ namespace YGOSharp
nullString += "\r\n\r\n"; nullString += "\r\n\r\n";
nullString += "喜欢游戏王DIY的朋友欢迎来222服QQ群642043095"; nullString += "喜欢游戏王DIY的朋友欢迎来222服QQ群642043095";
} }
bool success = true; lock (_lock)
try
{ {
using ( bool success = true;
SqliteConnection connection = new SqliteConnection( try
"Data Source=" + databaseFullPath
)
)
{ {
connection.Open();
using ( using (
IDbCommand command = new SqliteCommand( SqliteConnection connection = new SqliteConnection(
"SELECT datas.*, texts.* FROM datas,texts WHERE datas.id=texts.id;", "Data Source=" + databaseFullPath
connection
) )
) )
{ {
using (IDataReader reader = command.ExecuteReader()) connection.Open();
using (
IDbCommand command = new SqliteCommand(
"SELECT datas.*, texts.* FROM datas,texts WHERE datas.id=texts.id;",
connection
)
)
{ {
while (reader.Read()) using (IDataReader reader = command.ExecuteReader())
{ {
LoadCard(reader, test, replace); while (reader.Read())
{
LoadCard(reader, test, replace);
}
} }
} }
} }
} }
catch (System.Exception)
{
success = false;
}
return success;
} }
catch (System.Exception e)
{
success = false;
}
return success;
} }
internal static Card GetCard(int id) internal static Card GetCard(int id)
{ {
if (_cards.ContainsKey(id)) lock (_lock)
return _cards[id].clone(); {
return null; if (_cards.ContainsKey(id))
return _cards[id].clone();
return null;
}
} }
internal static Card GetCardRaw(int id) internal static Card GetCardRaw(int id)
{ {
if (_cards.ContainsKey(id)) lock (_lock)
return _cards[id]; {
return null; if (_cards.ContainsKey(id))
return _cards[id];
return null;
}
} }
internal static Card Get(int id) internal static Card Get(int id)
...@@ -125,10 +144,13 @@ namespace YGOSharp ...@@ -125,10 +144,13 @@ namespace YGOSharp
internal static void updateSetNames() internal static void updateSetNames()
{ {
foreach (var item in _cards) lock (_lock)
{ {
Card card = item.Value; foreach (var item in _cards)
card.strSetName = GameStringHelper.getSetName(card.Setcode); {
Card card = item.Value;
card.strSetName = GameStringHelper.getSetName(card.Setcode);
}
} }
} }
...@@ -156,81 +178,86 @@ namespace YGOSharp ...@@ -156,81 +178,86 @@ namespace YGOSharp
) )
{ {
List<Card> returnValue = new List<Card>(); List<Card> returnValue = new List<Card>();
foreach (var item in _cards) lock (_lock)
{ {
Card card = item.Value; foreach (var item in _cards)
if ((card.Type & (uint)CardType.Token) == 0)
{ {
if ( Card card = item.Value;
getName == "" if ((card.Type & (uint)CardType.Token) == 0)
|| Regex.Replace(card.Name, getName, "miaowu", RegexOptions.IgnoreCase)
!= card.Name
|| Regex.Replace(card.Desc, getName, "miaowu", RegexOptions.IgnoreCase)
!= card.Desc
|| Regex.Replace(
card.strSetName,
getName,
"miaowu",
RegexOptions.IgnoreCase
) != card.strSetName
|| card.Id.ToString() == getName
)
{ {
if ( if (
((card.Type & getTypeFilter) == getTypeFilter || getTypeFilter == 0) getName == ""
&& ( || Regex.Replace(card.Name, getName, "miaowu", RegexOptions.IgnoreCase)
( != card.Name
card.Type == getTypeFilter2 || Regex.Replace(card.Desc, getName, "miaowu", RegexOptions.IgnoreCase)
|| getTypeFilter == (UInt32)CardType.Monster != card.Desc
) || Regex.Replace(
&& (card.Type & getTypeFilter2) == getTypeFilter2 card.strSetName,
|| getTypeFilter2 == 0 getName,
) "miaowu",
RegexOptions.IgnoreCase
) != card.strSetName
|| card.Id.ToString() == getName
) )
{ {
if ((card.Race & getRaceFilter) > 0 || getRaceFilter == 0) if (
{ ((card.Type & getTypeFilter) == getTypeFilter || getTypeFilter == 0)
if ( && (
(card.Attribute & getAttributeFilter) > 0 (
|| getAttributeFilter == 0 card.Type == getTypeFilter2
|| getTypeFilter == (UInt32)CardType.Monster
)
&& (card.Type & getTypeFilter2) == getTypeFilter2
|| getTypeFilter2 == 0
) )
)
{
if ((card.Race & getRaceFilter) > 0 || getRaceFilter == 0)
{ {
if ( if (
((card.Category & getCatagoryFilter)) == getCatagoryFilter (card.Attribute & getAttributeFilter) > 0
|| getCatagoryFilter == 0 || getAttributeFilter == 0
) )
{ {
if (judgeint(getAttack, getAttack_UP, card.Attack)) if (
((card.Category & getCatagoryFilter)) == getCatagoryFilter
|| getCatagoryFilter == 0
)
{ {
if (judgeint(getDefence, getDefence_UP, card.Defense)) if (judgeint(getAttack, getAttack_UP, card.Attack))
{ {
if (judgeint(getLevel, getLevel_UP, card.Level)) if (
judgeint(getDefence, getDefence_UP, card.Defense)
)
{ {
if (judgeint(getP, getP_UP, card.LScale)) if (judgeint(getLevel, getLevel_UP, card.Level))
{ {
if ( if (judgeint(getP, getP_UP, card.LScale))
judgeint(getYear, getYear_UP, card.year)
)
{ {
if ( if (
getBAN == -233 judgeint(getYear, getYear_UP, card.year)
|| banlist == null
|| banlist.GetQuantity(card.Id)
== getBAN
) )
{ {
if ( if (
getOT == -233 getBAN == -233
|| (getOT & card.Ot) == getOT || banlist == null
|| banlist.GetQuantity(card.Id)
== getBAN
) )
{ {
if ( if (
getPack == "" getOT == -233
|| card.packFullName || (getOT & card.Ot) == getOT
== getPack
) )
{ {
returnValue.Add(card); if (
getPack == ""
|| card.packFullName
== getPack
)
{
returnValue.Add(card);
}
} }
} }
} }
...@@ -279,22 +306,29 @@ namespace YGOSharp ...@@ -279,22 +306,29 @@ namespace YGOSharp
internal static List<Card> search(string getName, List<int> getsearchCode) internal static List<Card> search(string getName, List<int> getsearchCode)
{ {
List<Card> returnValue = new List<Card>(); List<Card> returnValue = new List<Card>();
foreach (var item in _cards) lock (_lock)
{ {
Card card = item.Value; foreach (var item in _cards)
if (
getName == ""
|| Regex.Replace(card.Name, getName, "miaowu", RegexOptions.IgnoreCase)
!= card.Name
//|| Regex.Replace(card.Desc, getName, "miaowu", RegexOptions.IgnoreCase) != card.Desc
|| Regex.Replace(card.strSetName, getName, "miaowu", RegexOptions.IgnoreCase)
!= card.strSetName
|| card.Id.ToString() == getName
)
{ {
if (getsearchCode.Count == 0 || is_declarable(card, getsearchCode)) Card card = item.Value;
if (
getName == ""
|| Regex.Replace(card.Name, getName, "miaowu", RegexOptions.IgnoreCase)
!= card.Name
//|| Regex.Replace(card.Desc, getName, "miaowu", RegexOptions.IgnoreCase) != card.Desc
|| Regex.Replace(
card.strSetName,
getName,
"miaowu",
RegexOptions.IgnoreCase
) != card.strSetName
|| card.Id.ToString() == getName
)
{ {
returnValue.Add(card); if (getsearchCode.Count == 0 || is_declarable(card, getsearchCode))
{
returnValue.Add(card);
}
} }
} }
} }
...@@ -619,6 +653,12 @@ namespace YGOSharp ...@@ -619,6 +653,12 @@ namespace YGOSharp
static Dictionary<string, string> pacDic = new Dictionary<string, string>(); static Dictionary<string, string> pacDic = new Dictionary<string, string>();
internal static void Reset()
{
packs.Clear();
pacDic.Clear();
}
internal static void initialize(string databaseFullPath) internal static void initialize(string databaseFullPath)
{ {
using ( using (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment