- Timestamp:
- Apr 10, 2025, 3:30:00 PM (4 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/src/UrlHandlers/ItemIconHandler.cs
r467 r505 1 1 using System; 2 using System.Collections; 2 3 using System.Collections.Generic; 3 4 using System.IO; … … 68 69 } 69 70 70 public bool LoadIcons () { 71 private const int LoadingMaxMsPerFrame = 100; 72 private bool loading; 73 public IEnumerator LoadIcons () { 71 74 72 75 lock (icons) { 73 if (loaded) { 74 return true; 75 } 76 if (loading || loaded) { 77 yield break; 78 } 79 80 loading = true; 81 82 MicroStopwatch mswPerFrame = new MicroStopwatch (true); 76 83 77 84 LoadingStats stats = new LoadingStats (); … … 99 106 } 100 107 101 try { 102 loadIconsFromFolder (GameIO.GetGameDir ("Data/ItemIcons"), tintedIcons, stats); 103 } catch (Exception e) { 104 Log.Error ("[Web] Failed loading icons from base game"); 105 Log.Exception (e); 106 } 108 yield return loadIconsFromFolder (GameIO.GetGameDir ("Data/ItemIcons"), tintedIcons, stats, mswPerFrame); 107 109 108 110 // Load icons from mods 109 111 foreach (Mod mod in ModManager.GetLoadedMods ()) { 110 try { 111 string modIconsPath = $"{mod.Path}/ItemIcons"; 112 loadIconsFromFolder (modIconsPath, tintedIcons, stats); 113 } catch (Exception e) { 114 Log.Error ($"[Web] Failed loading icons from mod {mod.Name}"); 115 Log.Exception (e); 116 } 112 string modIconsPath = $"{mod.Path}/ItemIcons"; 113 yield return loadIconsFromFolder (modIconsPath, tintedIcons, stats, mswPerFrame); 117 114 } 118 115 … … 133 130 Log.Out ($"[Web] IconHandler: Cached {totalSize / 1024} KiB"); 134 131 } 135 136 return true; 137 } 138 } 139 140 private void loadIconsFromFolder (string _path, Dictionary<string, List<Color>> _tintedIcons, LoadingStats _stats) { 132 } 133 } 134 135 private IEnumerator loadIconsFromFolder (string _path, Dictionary<string, List<Color>> _tintedIcons, LoadingStats _stats, 136 MicroStopwatch _mswPerFrame) { 141 137 if (!Directory.Exists (_path)) { 142 return; 143 } 138 yield break; 139 } 140 141 _mswPerFrame.ResetAndRestart (); 144 142 145 143 foreach (string file in Directory.GetFiles (_path)) { … … 164 162 Object.Destroy (tex); 165 163 } catch (Exception e) { 164 Log.Error ($"[Web] Failed loading icon from {_path}"); 166 165 Log.Exception (e); 166 } 167 168 if (_mswPerFrame.ElapsedMilliseconds >= LoadingMaxMsPerFrame) { 169 yield return null; 170 _mswPerFrame.ResetAndRestart (); 167 171 } 168 172 }
Note:
See TracChangeset
for help on using the changeset viewer.