Browse Source

fixed schedule to Godot Node,add Godot Path Extension in Node Extension.remove godot method in some files,prepare for used in dotnet blazor

master
jkpete 4 months ago
parent
commit
f07142ea8c
  1. 9
      addons/EGFramework/EGPlatform.cs
  2. 2
      addons/EGFramework/Module/EGMessage.cs
  3. 38
      addons/EGFramework/Module/NodeExtension/EGGodotPath.cs
  4. 37
      addons/EGFramework/Module/NodeExtension/EGProtocolScheduleGodot.cs
  5. 26
      addons/EGFramework/Module/ProtocolTools/EGProtocolSchedule.cs
  6. 4
      addons/EGFramework/Module/ProtocolTools/EGSsh.cs
  7. 2
      addons/EGFramework/Module/ProtocolTools/EGUDP.cs
  8. 23
      addons/EGFramework/Module/SaveTools/EGSave.cs

9
addons/EGFramework/EGPlatform.cs

@ -16,6 +16,15 @@ namespace EGFramework{ @@ -16,6 +16,15 @@ namespace EGFramework{
// Console.WriteLine(what);
}
}
// if not use please explain this
public class EGPlatformDotnet : IPlatform{
public void Log(string message){
Console.WriteLine(message);
}
public void Log(params object[] what){
Console.WriteLine(what);
}
}
public static class EG
{
public static EGPlatformGodot Platform = new EGPlatformGodot();

2
addons/EGFramework/Module/EGMessage.cs

@ -15,7 +15,7 @@ namespace EGFramework @@ -15,7 +15,7 @@ namespace EGFramework
public EasyEvent<RequestMsgEvent> OnRequest { set; get; } = new EasyEvent<RequestMsgEvent>();
/// <summary>
/// Send delay in millisecond,if you don't need a Timer to delay send message,you can set it to 0.
/// Send delay in millisecond,if you don't need a Timer to delay send message,you can set it to 0. ( this delay options is prevent for sticky package )
/// </summary>
/// <value></value>
public int SendDelay { set; get; } = 100;

38
addons/EGFramework/Module/NodeExtension/EGGodotPath.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
using Godot;
namespace EGFramework{
public partial class EGGodotPath : IModule, IEGFramework
{
public void Init()
{
}
public void OpenResPath(){
OS.ShellOpen("".GetGodotResPath());
}
public void OpenUserPath(){
OS.ShellOpen("".GetGodotUserPath());
}
public IArchitecture GetArchitecture()
{
throw new System.NotImplementedException();
}
}
public static class GodotPathExtension{
public static string GetGodotResPath(this string path){
return ProjectSettings.GlobalizePath("res://"+path);
}
public static string GetGodotUserPath(this string path){
return ProjectSettings.GlobalizePath("user://"+path);
}
}
}

37
addons/EGFramework/Module/NodeExtension/EGProtocolScheduleGodot.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
using Godot;
namespace EGFramework{
/// <summary>
/// In Godot engine, the async method return cannot operate the godot main thread such as Screen Trees Node.
/// The protocol schedule provide a main thread to check the message in protocol tools 's response message.
/// If you have more idea ,please issue to me, thanks.
/// </summary>
public partial class EGProtocolScheduleGodot : Node, IModule, IEGFramework
{
public EGProtocolSchedule ProtocolSchedule { set; get; } = new EGProtocolSchedule();
public override void _Process(double delta)
{
ProtocolSchedule.CheckedProcess();
}
public void Init()
{
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class CanGetEGProtocolInGodotExtension{
public static EGProtocolSchedule EGProtocolSchedule(this Node self){
return self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule;
}
public static void EGEnabledProtocolTools(this Node self){
self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule.EnabledAllTools();
}
public static void EGEnabledProtocolTool<TProtocolReceived>(this Node self) where TProtocolReceived : class, IModule,IProtocolReceived,new(){
self.NodeModule<EGProtocolScheduleGodot>().ProtocolSchedule.EnabledTool<TProtocolReceived>();
}
}
}

26
addons/EGFramework/Module/ProtocolTools/EGProtocolSchedule.cs

@ -3,21 +3,11 @@ using System; @@ -3,21 +3,11 @@ using System;
using System.Collections.Generic;
namespace EGFramework{
/// <summary>
/// In Godot engine, the async method return cannot operate the godot main thread such as Screen Trees Node.
/// The protocol schedule provide a main thread to check the message in protocol tools 's response message.
/// If you have more idea ,please issue to me, thanks.
/// </summary>
public partial class EGProtocolSchedule : Node, IModule,IEGFramework
public class EGProtocolSchedule : IEGFramework
{
public Dictionary<Type,IProtocolReceived> ProtocolTools = new Dictionary<Type, IProtocolReceived>();
public void Init()
{
}
public override void _Process(double delta)
{
public void CheckedProcess(){
foreach(IProtocolReceived tool in ProtocolTools.Values){
if(tool.GetReceivedMsg().Count>0){
this.GetModule<EGMessage>().OnDataReceived.Invoke(tool.GetReceivedMsg().Dequeue());
@ -55,17 +45,5 @@ namespace EGFramework{ @@ -55,17 +45,5 @@ namespace EGFramework{
}
}
public static class CanGetEGProtocolExtension{
public static EGProtocolSchedule EGProtocolSchedule(this Node self){
return self.NodeModule<EGProtocolSchedule>();
}
public static void EGEnabledProtocolTools(this Node self){
self.NodeModule<EGProtocolSchedule>().EnabledAllTools();
}
public static void EGEnabledProtocolTool<TProtocolReceived>(this Node self) where TProtocolReceived : class, IModule,IProtocolReceived,new(){
self.NodeModule<EGProtocolSchedule>().EnabledTool<TProtocolReceived>();
}
}
}

4
addons/EGFramework/Module/ProtocolTools/EGSsh.cs

@ -83,7 +83,7 @@ namespace EGFramework{ @@ -83,7 +83,7 @@ namespace EGFramework{
}else{
CancellationTokenSource sourceReconnect = new CancellationTokenSource();
CancellationToken tokenReconnect = sourceReconnect.Token;
tokenReconnect.Register(() => Godot.GD.Print("Ssh connect timeout!"));
tokenReconnect.Register(() => EG.Print("Ssh connect timeout!"));
await SshClientDevices[host].ConnectAsync(tokenReconnect);
if(!SshClientDevices[host].IsConnected){
return false;
@ -96,7 +96,7 @@ namespace EGFramework{ @@ -96,7 +96,7 @@ namespace EGFramework{
SshClient client = new SshClient(host, username, keyFile);
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
token.Register(() => Godot.GD.Print("Ssh connect timeout!"));
token.Register(() => EG.Print("Ssh connect timeout!"));
source.CancelAfter(TimeOutDelay);
await client.ConnectAsync(token);
if(!client.IsConnected){

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

@ -3,7 +3,7 @@ using System.Collections.Generic; @@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using Godot;
namespace EGFramework{
public class EGUDP : IEGFramework, IModule, IProtocolSend, IProtocolReceived
{

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

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Collections.Generic;
using Godot;
namespace EGFramework
{
@ -33,7 +32,7 @@ namespace EGFramework @@ -33,7 +32,7 @@ namespace EGFramework
public EGSave() {}
public override void Init()
{
LoadObjectFile<EGJsonSave>("SaveData/DefaultJsonSave.json".GetGodotResPath());
LoadObjectFile<EGJsonSave>("SaveData/DefaultJsonSave.json");
}
public void LoadDataFile<TSaveData>(string path) where TSaveData:IEGSaveData,IEGSave,new(){
@ -196,32 +195,12 @@ namespace EGFramework @@ -196,32 +195,12 @@ namespace EGFramework
}
#endregion
//------------------------------------------------------------------------------//
public void OpenResPath(){
OS.ShellOpen("".GetGodotResPath());
}
public void OpenUserPath(){
OS.ShellOpen("".GetGodotUserPath());
}
}
public static class CanGetEGSaveExtension{
public static EGSave EGSave(this IEGFramework self){
return self.GetModule<EGSave>();
}
public static string GetGodotResPath(this string path){
return ProjectSettings.GlobalizePath("res://"+path);
}
public static string GetGodotUserPath(this string path){
return ProjectSettings.GlobalizePath("user://"+path);
}
public static string GetDirectoryName(this string path){
return Path.GetDirectoryName(path);

Loading…
Cancel
Save