LubanServerLoaderInvoker.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #if DOTNET
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace ET
  6. {
  7. [Invoke]
  8. public class LubanServerLoaderInvokerGetAll : AInvokeHandler<ConfigLoader.LubanGetAllConfigBytes, ETTask<Dictionary<Type, byte[]>>>
  9. {
  10. public override async ETTask<Dictionary<Type, byte[]>> Handle(ConfigLoader.LubanGetAllConfigBytes args)
  11. {
  12. var output = new Dictionary<Type, byte[]>();
  13. var allTypes = CodeTypes.Instance.GetTypes(typeof(ConfigAttribute));
  14. var codeMode = "Server";
  15. foreach (Type configType in allTypes)
  16. {
  17. var configAttribute = configType.GetCustomAttributes(typeof(ConfigAttribute), false)[0] as ConfigAttribute;
  18. var configBytes = await EventSystem.Instance.Invoke<ConfigLoader.LubanGetConfigBytes, ETTask<byte[]>>(configAttribute.ConfigType, new ConfigLoader.LubanGetConfigBytes
  19. {
  20. Type = configType,
  21. CodeMode = codeMode
  22. });
  23. if (configBytes != null)
  24. {
  25. output[configType] = configBytes;
  26. }
  27. else
  28. {
  29. Log.Error($"没有读取到配置,{codeMode},{configType}");
  30. }
  31. }
  32. return output;
  33. }
  34. }
  35. [Invoke(ConfigType.Luban)]
  36. public class LubanGetConfigBytes_Luban : AInvokeHandler<ConfigLoader.LubanGetConfigBytes, ETTask<byte[]>>
  37. {
  38. public override async ETTask<byte[]> Handle(ConfigLoader.LubanGetConfigBytes args)
  39. {
  40. var configType = args.Type;
  41. var codeMode = args.CodeMode;
  42. string configFilePath;
  43. if (LubanHelper.StartConfigs.Contains(configType.Name))
  44. {
  45. Log.Error($"Options.Instance.StartConfig {Options.Instance.StartConfig}");
  46. configFilePath = Path.Combine($"{LubanHelper.ConfigResPath}/{Options.Instance.StartConfig}/Binary/{codeMode}/{configType.Name}.bytes");
  47. }
  48. else
  49. {
  50. configFilePath = Path.Combine($"{LubanHelper.ConfigResPath}/Config/Binary/{codeMode}/{configType.Name}.bytes");
  51. }
  52. return await File.ReadAllBytesAsync(configFilePath);
  53. }
  54. }
  55. [Invoke(ConfigType.Luban)]
  56. public class LubanServerLoaderInvokerGetOne : AInvokeHandler<ConfigLoader.LubanGetOneConfigBytes, ETTask<byte[]>>
  57. {
  58. public override async ETTask<byte[]> Handle(ConfigLoader.LubanGetOneConfigBytes args)
  59. {
  60. return await File.ReadAllBytesAsync($"{LubanHelper.ConfigResPath}/Config/Binary/Server/{args.ConfigName}.bytes");
  61. }
  62. }
  63. }
  64. #endif