1
0
mirror of synced 2025-01-18 00:56:45 +01:00

Add a template class 'CSavableT' for database classes

This commit is contained in:
0aubsq 2022-06-25 12:28:10 +02:00
parent 4e1628b4a1
commit 38be006289
15 changed files with 106 additions and 5 deletions

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TJAPlayer3
{
class CSavableT<T> where T : new()
{
public virtual string _fn
{
get;
protected set;
}
public void tDBInitSavable()
{
if (!File.Exists(_fn))
tSaveFile();
tLoadFile();
}
public T data = new T();
#region [private]
private void tSaveFile()
{
ConfigManager.SaveConfig(data, _fn);
}
private void tLoadFile()
{
data = ConfigManager.GetConfig<T>(_fn);
}
#endregion
}
}

View File

@ -4,9 +4,15 @@ using Newtonsoft.Json;
namespace TJAPlayer3
{
class DBCDN
class DBCDN : CSavableT<Dictionary<string, DBCDN.CDNData>>
{
public DBCDN()
{
_fn = @".\Databases\CDN.json";
base.tDBInitSavable();
}
/*
public void tDBCDN()
{
if (!File.Exists(@".\Databases\CDN.json"))
@ -14,6 +20,7 @@ namespace TJAPlayer3
tLoadFile();
}
*/
#region [Auxiliary classes]
@ -67,8 +74,10 @@ namespace TJAPlayer3
#endregion
/*
public Dictionary<string, CDNData> data = new Dictionary<string, CDNData>();
#region [private]
private void tSaveFile()
@ -82,5 +91,6 @@ namespace TJAPlayer3
}
#endregion
*/
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TJAPlayer3
{
class DBEncyclopediaMenus : CSavableT<Dictionary<int, string>>
{
public DBEncyclopediaMenus()
{
_fn = @".\Encyclopedia\Menus.json";
base.tDBInitSavable();
}
}
}

View File

@ -8,8 +8,6 @@ namespace TJAPlayer3
public void tDatabases()
{
DBCDN = new DBCDN();
DBCDN.tDBCDN();
}
public DBCDN DBCDN;

View File

@ -126,6 +126,7 @@
<Compile Include="Character\CMenuCharacter.cs" />
<Compile Include="Common\CCrypto.cs" />
<Compile Include="Common\CHitSounds.cs" />
<Compile Include="Common\CSavableT.cs" />
<Compile Include="Common\CVersionList.cs" />
<Compile Include="Common\RecentlyPlayedSongs.cs" />
<Compile Include="Common\ModalQueue.cs" />
@ -137,6 +138,7 @@
<Compile Include="Common\Easing.cs" />
<Compile Include="Common\NamePlateConfig.cs" />
<Compile Include="Databases\DBCDN.cs" />
<Compile Include="Databases\DBEncyclopediaMenus.cs" />
<Compile Include="Databases\DBPuchichara.cs" />
<Compile Include="Databases\DBUnlockables.cs" />
<Compile Include="Databases\Databases.cs" />
@ -407,7 +409,9 @@
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Stages\15.OpenEncyclopedia\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -1,7 +1,20 @@
{
"menus": [
1: {
"menus": [
10: {
"pages": [
100,
101,
102,
],
},
11: {
},
],
},
2: {

View File

@ -0,0 +1 @@
Test1

View File

@ -0,0 +1 @@
Test10

View File

@ -0,0 +1 @@
Test11

View File

@ -0,0 +1 @@
Test2

View File

@ -0,0 +1,3 @@
This is a test page
with the number
100

View File

@ -0,0 +1,3 @@
This is a test page
with the number
101

View File

@ -0,0 +1,3 @@
This is a test page
with the number
102