Browse Source

add eglitedbSave

master
jkpete 2 months ago
parent
commit
b71b121852
  1. 6
      addons/EGFramework/Module/SaveTools/EGByteSave.cs
  2. 15
      addons/EGFramework/Module/SaveTools/EGCsv.cs
  3. 39
      addons/EGFramework/Module/SaveTools/EGCsvSave.cs
  4. 2
      addons/EGFramework/Module/SaveTools/EGJsonSave.cs
  5. 16
      addons/EGFramework/Module/SaveTools/EGLiteDB.cs
  6. 71
      addons/EGFramework/Module/SaveTools/EGLiteDBSave.cs
  7. 13
      addons/EGFramework/Module/SaveTools/EGSave.cs
  8. 9
      addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

6
addons/EGFramework/Module/SaveTools/EGByteSave.cs

@ -7,7 +7,7 @@ using Godot; @@ -7,7 +7,7 @@ using Godot;
namespace EGFramework
{
public class EGByteSave : EGModule, IEGSave,IEGSaveObject
public class EGByteSave : IEGSave,IEGSaveObject
{
public void SaveToFile(string content)
@ -26,10 +26,6 @@ namespace EGFramework @@ -26,10 +26,6 @@ namespace EGFramework
Variant pos = file.GetVar();
return pos;
}
public override void Init()
{
}
public void InitSaveFile(string path)
{

15
addons/EGFramework/Module/SaveTools/EGCsv.cs

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EGFramework
{
public class EGCsv : EGModule
{
public override void Init()
{
}
}
}

39
addons/EGFramework/Module/SaveTools/EGCsvSave.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace EGFramework
{
public class EGCsvSave : IEGSaveData, IEGSave
{
public void InitSaveFile(string path)
{
throw new NotImplementedException();
}
public void SetData<TData>(string dataKey, TData data, object id)
{
throw new NotImplementedException();
}
public TData GetData<TData>(string dataKey, object id) where TData : new()
{
throw new NotImplementedException();
}
public IEnumerable<TData> QueryData<TData>(string dataKey, string sql) where TData : new()
{
throw new NotImplementedException();
}
public IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new()
{
throw new NotImplementedException();
}
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new()
{
throw new NotImplementedException();
}
}
}

2
addons/EGFramework/Module/SaveTools/EGJsonSave.cs

@ -28,7 +28,7 @@ namespace EGFramework @@ -28,7 +28,7 @@ namespace EGFramework
{
DefaultPath = path;
if(!File.Exists(path)){
if (!Directory.Exists(DefaultPath))
if (!Directory.Exists(Path.GetDirectoryName(DefaultPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(DefaultPath));
File.WriteAllText(DefaultPath,"{}");

16
addons/EGFramework/Module/SaveTools/EGLiteDB.cs

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LiteDB;
namespace EGFramework
{
public class EGLiteDB : EGModule
{
public override void Init()
{
// throw new NotImplementedException();
}
}
}

71
addons/EGFramework/Module/SaveTools/EGLiteDBSave.cs

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using LiteDB;
namespace EGFramework
{
public class EGLiteDBSave : IEGSave,IEGSaveData
{
private string DefaultPath { set; get; }
private LiteDatabase _Database { set; get; }
private LiteDatabase Database{
get {
if(_Database == null){
InitSaveFile(DefaultPath);
}
return _Database;
}
}
public void InitSaveFile(string path)
{
DefaultPath = path;
if (!Directory.Exists(Path.GetDirectoryName(DefaultPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(DefaultPath));
}
// Default is "SaveData/DefaultLiteDBData.db"
_Database = new LiteDatabase(path);
}
public TData GetData<TData>(string dataKey, object id) where TData : new()
{
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
TData result = collection.FindById((BsonValue)id);
return result;
}
public void SetData<TData>(string dataKey, TData data, object id)
{
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
if(collection.FindById((BsonValue)id)==null){
collection.Insert((BsonValue)id, data);
}
collection.Update(data);
}
public IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new()
{
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
return collection.FindAll();
}
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new()
{
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
return collection.Find(expression);
}
public IEnumerable<TData> QueryData<TData>(string dataKey, string sql="") where TData : new()
{
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
return collection.FindAll();
}
}
}

13
addons/EGFramework/Module/SaveTools/EGSave.cs

@ -30,7 +30,7 @@ namespace EGFramework @@ -30,7 +30,7 @@ namespace EGFramework
public EGSave() {}
public override void Init()
{
LoadObjectFile("Default/SaveData.json".GetGodotUserPath(),TypeEGSave.Json);
LoadObjectFile("SaveData/DefaultJsonSave.json".GetGodotResPath(),TypeEGSave.Json);
}
public void LoadDataFile(string path,TypeDBSave type){
@ -61,14 +61,21 @@ namespace EGFramework @@ -61,14 +61,21 @@ namespace EGFramework
return ObjectFiles[path].GetObject<TObject>(key);
}
public void SetData<TData>(string path,string dataKey,TData data,int id){
DataBaseFiles[path].SetData(dataKey,data,id);
}
public void GetData<TData>(string path,string key,int id) where TData : new(){
DataBaseFiles[path].GetData<TData>(key,id);
}
//------------------------------------------------------------------------------//
#region Default Json Operation
public void SetObjectToJson<TObject>(TObject obj){
ObjectFiles["Default/SaveData.json"].SetObject(typeof(TObject).ToString(),obj);
ObjectFiles["SaveData/DefaultJsonSave.json"].SetObject(typeof(TObject).ToString(),obj);
}
public TObject GetObjectFromJson<TObject>() where TObject : new(){
return ObjectFiles["Default/SaveData.json"].GetObject<TObject>(typeof(TObject).ToString());
return ObjectFiles["SaveData/DefaultJsonSave.json"].GetObject<TObject>(typeof(TObject).ToString());
}
#endregion

9
addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace EGFramework
@ -16,8 +17,10 @@ namespace EGFramework @@ -16,8 +17,10 @@ namespace EGFramework
//
public interface IEGSaveData{
void SetData<TData>(TData data,string dataKey,int id);
TData GetData<TData>(string dataKey,int id) where TData : new();
IList<TData> QueryData<TData>(string dataKey,string sql) where TData : new();
void SetData<TData>(string dataKey,TData data,object id);
TData GetData<TData>(string dataKey,object id) where TData : new();
IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new();
IEnumerable<TData> FindData<TData>(string dataKey,Expression<Func<TData, bool>> expression) where TData : new();
IEnumerable<TData> QueryData<TData>(string dataKey,string sql) where TData : new();
}
}
Loading…
Cancel
Save