From d0e91fdc7819ba3cc9a4c9568c81a35d414100d2 Mon Sep 17 00:00:00 2001 From: AlessandroCH Date: Sun, 9 Mar 2025 22:14:29 +0100 Subject: [PATCH] some summary comments --- Campofinale/Resource/ResourceLoader.cs | 22 +++++----------------- Campofinale/Resource/ResourceManager.cs | 5 +++++ Campofinale/Resource/TableCfgResource.cs | 10 +++++++++- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Campofinale/Resource/ResourceLoader.cs b/Campofinale/Resource/ResourceLoader.cs index f2fa7a8..e0607a3 100644 --- a/Campofinale/Resource/ResourceLoader.cs +++ b/Campofinale/Resource/ResourceLoader.cs @@ -11,7 +11,9 @@ namespace Campofinale.Resource { public class ResourceLoader { - + /// + /// Load table cfg automatically inside ResourceManager fields + /// public static void LoadTableCfg() { var tableCfgTypes = GetAllTableCfgTypes(); @@ -19,7 +21,7 @@ namespace Campofinale.Resource foreach (var type in tableCfgTypes) { var attr = type.GetCustomAttribute(); - string json = ReadJsonFile(attr.Name); + string json = ResourceManager.ReadJsonFile(attr.Name); FieldInfo field = GetResourceField(type); if (field != null && json.Length > 0) { @@ -49,21 +51,7 @@ namespace Campofinale.Resource return JsonConvert.DeserializeObject(json, valueType); } - public static string ReadJsonFile(string path) - { - try - { - return File.ReadAllText(path); - } - catch (Exception e) - { - Logger.PrintError($"Error occured while loading {path} Err: {e.Message}"); - ResourceManager.missingResources = true; - return ""; - } - - } - + public static List GetAllTableCfgTypes() { return Assembly.GetExecutingAssembly() diff --git a/Campofinale/Resource/ResourceManager.cs b/Campofinale/Resource/ResourceManager.cs index f40fc32..b1f1d2e 100644 --- a/Campofinale/Resource/ResourceManager.cs +++ b/Campofinale/Resource/ResourceManager.cs @@ -78,6 +78,11 @@ namespace Campofinale.Resource return levelDatas.Find(a => a.id == name).idNum; } public static bool missingResources = false; + /// + /// Utility method for read a json file + /// + /// The file path + /// Return the file content if the file exist, else it return an empty string public static string ReadJsonFile(string path) { try diff --git a/Campofinale/Resource/TableCfgResource.cs b/Campofinale/Resource/TableCfgResource.cs index 9f75734..15d7c48 100644 --- a/Campofinale/Resource/TableCfgResource.cs +++ b/Campofinale/Resource/TableCfgResource.cs @@ -8,7 +8,9 @@ namespace Campofinale.Resource { public abstract class TableCfgResource { - + /// + /// Not implemented yet + /// public void OnLoad() { @@ -17,7 +19,13 @@ namespace Campofinale.Resource [AttributeUsage(AttributeTargets.Class, Inherited = false)] public class TableCfgTypeAttribute : Attribute { + /// + /// Path of the Resource + /// public string Name { get; } + /// + /// Priority of load (still not implemented) + /// public LoadPriority Priority { get; } public TableCfgTypeAttribute(string name, LoadPriority priority)