Compare commits

...

4 Commits

  1. 2
      EGFramework.csproj
  2. 2
      Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs
  3. 2
      Example/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs
  4. 21
      Example/UsingTest/Script/EGSaveTest.cs
  5. 1
      Font/SourceHanSansCN-Regular.otf.import
  6. 9
      addons/EGFramework/EGFramework.cs
  7. 21
      addons/EGFramework/License_Third_Part/QFramework/LICENSE
  8. 60
      addons/EGFramework/Module/EGEvent.cs
  9. 19
      addons/EGFramework/Module/Extension/EGDateTimeExtension.cs
  10. 20
      addons/EGFramework/Module/NodeExtension/EGNode.cs
  11. 60
      addons/EGFramework/Module/NodeExtension/EGThread.cs
  12. 2
      addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs
  13. 23
      addons/EGFramework/Module/ProtocolTools/EGUDP.cs
  14. 39
      addons/EGFramework/Module/SaveTools/EGDapper.cs
  15. 5
      addons/EGFramework/Module/SaveTools/EGSqlite.cs
  16. 1
      project.godot

2
EGFramework.csproj

@ -16,5 +16,7 @@ @@ -16,5 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
<PackageReference Include="LiteDB" Version="5.0.21" />
<PackageReference Include="BACnet" Version="2.0.4" />
<PackageReference Include="MySql.Data" Version="9.1.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
</ItemGroup>
</Project>

2
Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs

@ -28,7 +28,7 @@ namespace EGFramework.Example.SystemExamples.PlayerStorage @@ -28,7 +28,7 @@ namespace EGFramework.Example.SystemExamples.PlayerStorage
throw new NotImplementedException();
}
public string GetName()
public string GetItemName()
{
throw new NotImplementedException();
}

2
Example/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs

@ -9,7 +9,7 @@ namespace EGFramework.Example.SystemExamples.PlayerStorage @@ -9,7 +9,7 @@ namespace EGFramework.Example.SystemExamples.PlayerStorage
public interface IItem
{
public int GetItemId();
public string GetName();
public string GetItemName();
public Texture GetIcon();
public string GetInfo();
}

21
Example/UsingTest/Script/EGSaveTest.cs

@ -1,15 +1,32 @@ @@ -1,15 +1,32 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
using LiteDB;
namespace EGFramework.Examples.Test{
public partial class EGSaveTest : Node,IEGFramework
{
public Label Label { set; get; }
public override void _Ready()
{
base._Ready();
TestCode();
this.Label = this.GetNode<Label>("Label");
this.EGEnabledThread();
this.ExecuteAfterSecond(TestMainThreadFunc,2.0f);
//base._Ready();
//TestCode();
}
public async void TestThread(){
await Task.Run(()=>{
//this.ExecuteInMainThread(TestMainThreadFunc);
this.ExecuteAfterSecond(TestMainThreadFunc,2.0f);
});
}
public void TestMainThreadFunc(){
this.Label.Text = "Thread Test";
GD.Print("Invoked!");
}
public void TestSqlite(){

1
Font/SourceHanSansCN-Regular.otf.import

@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/SourceHanSansCN-Regular.otf-a74baadd242fcbfb4 @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/SourceHanSansCN-Regular.otf-a74baadd242fcbfb4
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48

9
addons/EGFramework/EGFramework.cs

@ -165,19 +165,16 @@ namespace EGFramework @@ -165,19 +165,16 @@ namespace EGFramework
public struct CustomUnRegister : IUnRegister
{
/// <summary>
/// 委托对象
/// delegate object
/// </summary>
private Action OnUnRegister { get; set; }
/// <summary>
/// 带参构造函数
/// </summary>
/// <param name="onDispose"></param>
public CustomUnRegister(Action onUnRegister)
{
OnUnRegister = onUnRegister;
}
/// <summary>
/// 资源释放
/// release by parent;
/// </summary>
public void UnRegister()
{

21
addons/EGFramework/License_Third_Part/QFramework/LICENSE

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 凉鞋
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

60
addons/EGFramework/Module/EGEvent.cs

@ -80,6 +80,66 @@ namespace EGFramework @@ -80,6 +80,66 @@ namespace EGFramework
}
}
/// <summary>
/// This EasyEvent will release all registered function while invoked.
/// </summary>
/// <typeparam name="T"></typeparam>
public class EasyEventOnce<T> : IEasyEvent
{
private Action<T> OnEvent = e => { };
private List<CustomUnRegister> AutoUnRegister = new List<CustomUnRegister>();
public IUnRegister Register(Action<T> onEvent)
{
OnEvent += onEvent;
CustomUnRegister unRegister = new CustomUnRegister(() => { UnRegister(onEvent); });
AutoUnRegister.Add(unRegister);
return unRegister;
}
public void UnRegister(Action<T> onEvent)
{
OnEvent -= onEvent;
}
public void Invoke(T t)
{
if(AutoUnRegister.Count>0){
OnEvent?.Invoke(t);
foreach(CustomUnRegister unRegister in AutoUnRegister){
unRegister.UnRegister();
}
AutoUnRegister.Clear();
}
}
}
/// <summary>
/// This EasyEvent will release all registered function while invoked.
/// </summary>
public class EasyEventOnce : IEasyEvent{
private Action OnEvent = () => { };
private List<CustomUnRegister> AutoUnRegister = new List<CustomUnRegister>();
public IUnRegister Register(Action onEvent)
{
OnEvent += onEvent;
CustomUnRegister unRegister = new CustomUnRegister(() => { UnRegister(onEvent); });
AutoUnRegister.Add(unRegister);
return unRegister;
}
public void UnRegister(Action onEvent)
{
OnEvent -= onEvent;
}
public void Invoke()
{
if(AutoUnRegister.Count>0){
OnEvent?.Invoke();
foreach(CustomUnRegister unRegister in AutoUnRegister){
unRegister.UnRegister();
}
AutoUnRegister.Clear();
}
}
}
public static class CanRegisterEventExtension
{

19
addons/EGFramework/Module/Extension/EGDateTimeExtension.cs

@ -10,11 +10,22 @@ namespace EGFramework{ @@ -10,11 +10,22 @@ namespace EGFramework{
{
return DateTime.Now.ToString("HH:mm:ss");
}
public static long GetTimeStamp(this IEGFramework self)
public static long GetDateTime(this object self)
{
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 8, 0, 0, 0);
return System.Convert.ToInt64(ts.TotalSeconds);
DateTime dt = DateTime.Now;
return dt.Ticks;
}
public static string GetFullDateMsg(this long ticks){
DateTime dateTime = new DateTime(ticks);
return dateTime.ToString("yyyy-MM-dd") + " " + dateTime.ToString("HH:mm:ss");
}
public static string GetDayDateMsg(this long ticks){
DateTime dateTime = new DateTime(ticks);
return dateTime.ToString("HH:mm:ss");
}
public static string GetDateMsg(this long ticks){
DateTime dateTime = new DateTime(ticks);
return dateTime.ToString("yyyy-MM-dd");
}
}
}

20
addons/EGFramework/Module/NodeExtension/EGNode.cs

@ -25,5 +25,25 @@ namespace EGFramework{ @@ -25,5 +25,25 @@ namespace EGFramework{
}
}
public static void ClearChildren<T>(this Node itemContainer) where T : Node
{
foreach (Node child in itemContainer.GetChildren())
{
if(child.GetType()==typeof(T)){
child.QueueFree();
}
}
}
public static void ClearChildrenLabel(this Node itemContainer)
{
foreach (Node child in itemContainer.GetChildren())
{
if(child.GetType()==typeof(Label)){
child.QueueFree();
}
}
}
}
}

60
addons/EGFramework/Module/NodeExtension/EGThread.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
using Godot;
using static Godot.GD;
using System;
using System.Collections.Generic;
namespace EGFramework{
public partial class EGThread : Node,IModule,IEGFramework{
public EasyEventOnce EventPool = new EasyEventOnce();
public Dictionary<Action,SceneTreeTimer> EventDelayPool = new Dictionary<Action, SceneTreeTimer>();
public void Init()
{
}
public override void _Ready()
{
}
public override void _Process(double delta)
{
//base._Process(delta);
EventPool.Invoke();
}
public void ExecuteInMainThread(Action action){
//ActionQueue.Enqueue(action);
EventPool.Register(action);
}
public void ExecuteAfterSecond(Action action,double delay){
SceneTreeTimer timer = this.GetTree().CreateTimer(delay);
timer.Timeout += action;
timer.Timeout += () => EventDelayPool.Remove(action);
EventDelayPool.Add(action,timer);
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGThreadExtension
{
public static void ExecuteInMainThread(this Node self, Action action){
//action.Invoke();
self.NodeModule<EGThread>().ExecuteInMainThread(action);
}
public static void ExecuteAfterSecond(this Node self, Action action,double delay){
self.NodeModule<EGThread>().ExecuteAfterSecond(action,delay);
}
public static void EGEnabledThread(this Node self){
self.NodeModule<EGThread>();
}
}
}

2
addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs

@ -64,7 +64,7 @@ namespace EGFramework{ @@ -64,7 +64,7 @@ namespace EGFramework{
Dictionary<string,string> getDic = data.AllKeys.ToDictionary(k=>k,k=>data[k]);
string getData = JsonConvert.SerializeObject(getDic);
byte[] getBuffer = StringEncoding.GetBytes(getData);
responseKey = "GET:"+this.GetTimeStamp().ToString();
responseKey = "GET:"+this.GetDateTime().ToString();
receivedMsgs = new ResponseMsg(getData,getBuffer,responseKey, ProtocolType.HttpServer);
//GD.Print("Received from "+receivedMsgs.sender+": "+receivedMsgs.stringData);
}

23
addons/EGFramework/Module/ProtocolTools/EGUDP.cs

@ -1,10 +1,9 @@ @@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Godot;
namespace EGFramework{
public class EGUDP : IEGFramework, IModule, IProtocolSend, IProtocolReceived
{
@ -34,6 +33,7 @@ namespace EGFramework{ @@ -34,6 +33,7 @@ namespace EGFramework{
{
UdpClient udpDevice = new UdpClient(localPort);
UDPDevices.Add(localPort,udpDevice);
//udpDevice.EnableBroadcast = true;
HandleUDPListenAsync(udpDevice);
//StartListening(localPort);
}
@ -54,6 +54,7 @@ namespace EGFramework{ @@ -54,6 +54,7 @@ namespace EGFramework{
{
try
{
//GD.Print("UDP listened in "+((IPEndPoint)client.Client.LocalEndPoint).Port);
while (true)
{
UdpReceiveResult data = await client.ReceiveAsync();
@ -63,22 +64,31 @@ namespace EGFramework{ @@ -63,22 +64,31 @@ namespace EGFramework{
ResponseMsgs.Enqueue(receivedMsgs);
}
}
catch (Exception)
catch (Exception e)
{
GD.Print("Listen false by:"+e);
}
}
public void SendByteData(string host,int port,byte[] data){
UdpClient udpClient = new UdpClient();
UdpClient udpClient;
if(UDPDevices.Count>0){
udpClient = UDPDevices.First().Value;
}else{
udpClient = new UdpClient();
}
try{
GD.Print(udpClient.EnableBroadcast);
udpClient.Send(data, data.Length, host, port);
}
catch ( Exception e ){
Godot.GD.Print(e.ToString());
}
if(UDPDevices.Count<=0){
udpClient.Close();
udpClient.Dispose();
}
}
public void SendByteData(string destination,byte[] data){
SendByteData(destination.GetHostByIp(),destination.GetPortByIp(),data);
}
@ -118,6 +128,9 @@ namespace EGFramework{ @@ -118,6 +128,9 @@ namespace EGFramework{
public static void EGUDPListen(this IEGFramework self ,int port){
self.GetModule<EGUDP>().ListenUDP(port);
}
public static void EGUDPEndListen(this IEGFramework self ,int port){
self.GetModule<EGUDP>().EndListenUDP(port);
}
}
}

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

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
//ORM Save tools. First support SQLite and MySQL,In future we will support other Database who implement DBConnection.
namespace EGFramework{
public class EGDapper : IEGSave, IEGSaveData
{
/// <summary>
///
/// </summary>
/// <param name="conn">files conn Str or address ip port,username and passwd</param>
public void InitSaveFile(string conn)
{
throw new System.NotImplementedException();
}
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new()
{
throw new NotImplementedException();
}
public IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new()
{
throw new NotImplementedException();
}
public TData GetData<TData>(string dataKey, object id) where TData : new()
{
throw new NotImplementedException();
}
public void SetData<TData>(string dataKey, TData data, object id)
{
throw new NotImplementedException();
}
}
}

5
addons/EGFramework/Module/SaveTools/EGSqlite.cs

@ -6,11 +6,6 @@ using Microsoft.Data.Sqlite; @@ -6,11 +6,6 @@ using Microsoft.Data.Sqlite;
using Newtonsoft.Json;
namespace EGFramework{
public interface IEGSqlite{
void SaveData<TData>(TData data) where TData : new();
List<TData> GetDataSet<TData>() where TData : new();
void InitDatabase(string dataBaseName);
}
public class EGSqlite : EGModule
{
public string DBName = "Default";

1
project.godot

@ -88,4 +88,5 @@ jump={ @@ -88,4 +88,5 @@ jump={
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

Loading…
Cancel
Save