From 9a3a435d35544303ecdb3b2878f000e7b51471d6 Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Mon, 21 Oct 2024 23:22:07 +0800 Subject: [PATCH] fixed manual --- addons/EGFramework/Manual/EGSave.md | 100 ++++++++++++++++++ .../EGFramework/Module/SaveTools/EGCsvSave.cs | 4 + .../Module/SaveTools/EGJsonSave.cs | 5 + addons/EGFramework/Module/SaveTools/EGSave.cs | 8 +- 4 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 addons/EGFramework/Manual/EGSave.md diff --git a/addons/EGFramework/Manual/EGSave.md b/addons/EGFramework/Manual/EGSave.md new file mode 100644 index 0000000..98a55f9 --- /dev/null +++ b/addons/EGFramework/Manual/EGSave.md @@ -0,0 +1,100 @@ +# SaveTools(EGSave)模块使用说明 + +--- + +SaveTools使用了两种数据格式,一种是表式存储,一种是对象存储,统一使用key-value方式存储数据,通过唯一key值锁定对应的数据。 + +在使用该库时,一定要保证该数据被加载。 + +只读&非只读数据: + +- [x] CSV + +- [x] Json + +- [ ] XML + +- [ ] etc... + +非只读数据: + +- [x] LiteDB + +- [x] Byte + +- [ ] Sqlite + +- [ ] Other DataBase + +- [ ] etc... + +# API参考 + +--- + +## 属性 + +暂无 + +## 方法 + +| 方法名 | 简介 | +| ----------------------------------------------------------------- | ------------------ | +| void LoadDataFile(string path) | 加载数据文件(需要路径) | +| void ReadData(string key,string data) | 读取数据(需获取string原始值) | +| void LoadObjectFile(string path) | 加载对象文件(需要路径) | +| void ReadObject(string key,string data) | 读取对象(需获取string原始值) | +| void SetObject(string path,string objectKey,TObject obj) | 设置对象(写入文件) | +| TObject GetObject(string path,string key) | 获取对象(读取文件) | +| void SetData(string path,string dataKey,TData data,int id) | 设置数据(写入文件) | +| TData GetData(string path,string key,int id) | 获取单个数据(读取文件) | +| IEnumerable GetAllData(string path,string key) | 获取全部数据(读取文件) | +| OpenResPath() | 打开Res文件目录 | +| OpenUserPath() | 打开User文件目录 | + +## 扩展方法 + +| 方法名 | 简介 | +| ------------------------------------------- | -------------- | +| this.EGSave() | 使用存储模块 | +| [string].GetGodotResPath(this string path) | 转为res文件下的相对路径 | +| [string].GetGodotUserPath(this string path) | 转为User文件下的相对路径 | + +## 属性说明 + +暂无 + +## 方法说明 + +# 接口说明 + +--- + +只读&非只读数据说明: + +只读数据不实现写数据功能,非只读需要实现写数据功能。 + +正常数据通过Path加载,只读数据则是通过string加载,无法对其中Path进行写入操作。 + +| 接口名称 | 接口简介 | +| --------------------- | ------ | +| IEGSave | 读写数据加载 | +| IEGSaveReadOnly | 只读数据加载 | +| IEGSaveObjectReadOnly | 只读对象 | +| IEGSaveDataReadOnly | 只读数据 | +| IEGSaveObject | 读写对象 | +| IEGSaveData | 读写数据 | + +## IEGSave + +### 描述 + +通用的存储数据加载接口,通过Path加载文件的数据。 + +### 方法说明 + +void InitSaveFile(string path) + +> 通过文件路径加载存储文件 + +## IEGSaveReadOnly diff --git a/addons/EGFramework/Module/SaveTools/EGCsvSave.cs b/addons/EGFramework/Module/SaveTools/EGCsvSave.cs index d681579..1079a16 100644 --- a/addons/EGFramework/Module/SaveTools/EGCsvSave.cs +++ b/addons/EGFramework/Module/SaveTools/EGCsvSave.cs @@ -11,6 +11,7 @@ namespace EGFramework { public class EGCsvSave : IEGSaveData, IEGSave, IEGSaveReadOnly { + public bool IsReadOnly { get; set; } public Encoding StringEncoding { set; get; } = Encoding.UTF8; private string DefaultPath { set; get; } private List CsvDataBlock { get; set; } @@ -118,6 +119,9 @@ namespace EGFramework public void SetData(string dataKey, TData data, object id) { + if(IsReadOnly){ + throw new Exception("This file is readonly! can't set any data to file."); + } bool IsAdd = false; int dataID = 0; if(id.GetType()==typeof(int)){ diff --git a/addons/EGFramework/Module/SaveTools/EGJsonSave.cs b/addons/EGFramework/Module/SaveTools/EGJsonSave.cs index 9c8f2c4..1294173 100644 --- a/addons/EGFramework/Module/SaveTools/EGJsonSave.cs +++ b/addons/EGFramework/Module/SaveTools/EGJsonSave.cs @@ -10,6 +10,7 @@ namespace EGFramework { public class EGJsonSave : IEGSave,IEGSaveReadOnly,IEGSaveObject { + public bool IsReadOnly { get; set; } private string DefaultPath { set; get; } private JObject _SaveObject; private JObject SaveObject{ @@ -45,10 +46,14 @@ namespace EGFramework public void InitReadOnly(string data) { _SaveObject = JObject.Parse(data); + IsReadOnly = true; } public void SetObject(string objectKey,TObject obj) { + if(IsReadOnly){ + throw new Exception("This file is readonly! can't set any object to file."); + } if(SaveObject.ContainsKey(objectKey)){ SaveObject[objectKey] = JToken.FromObject(obj); }else{ diff --git a/addons/EGFramework/Module/SaveTools/EGSave.cs b/addons/EGFramework/Module/SaveTools/EGSave.cs index 1f499f1..f17a878 100644 --- a/addons/EGFramework/Module/SaveTools/EGSave.cs +++ b/addons/EGFramework/Module/SaveTools/EGSave.cs @@ -136,12 +136,12 @@ namespace EGFramework return self.GetModule(); } - public static string GetGodotResPath(this string absPath){ - return ProjectSettings.GlobalizePath("res://"+absPath); + public static string GetGodotResPath(this string path){ + return ProjectSettings.GlobalizePath("res://"+path); } - public static string GetGodotUserPath(this string absPath){ - return ProjectSettings.GlobalizePath("user://"+absPath); + public static string GetGodotUserPath(this string path){ + return ProjectSettings.GlobalizePath("user://"+path); } }