- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r306 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO; 3 4 using System.Net; 4 using System.Threading; 5 using UnityEngine; 6 using Object = UnityEngine.Object; 5 7 6 using UnityEngine; 7 using System.IO; 8 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 9 public class ItemIconHandler : PathHandler { 10 private readonly Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 11 private readonly bool logMissingFiles; 8 12 9 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 10 { 11 public class ItemIconHandler : PathHandler { 12 private static ItemIconHandler instance = null; 13 public static ItemIconHandler Instance { 14 get { return instance; } 13 private readonly string staticPart; 14 private bool loaded; 15 16 static ItemIconHandler () { 17 Instance = null; 15 18 } 16 19 17 private string staticPart; 18 private bool logMissingFiles; 19 private Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 20 private bool loaded = false; 21 22 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base(moduleName) { 20 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base (moduleName) { 23 21 this.staticPart = staticPart; 24 22 this.logMissingFiles = logMissingFiles; 25 I temIconHandler.instance = this;23 Instance = this; 26 24 } 27 25 28 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 26 public static ItemIconHandler Instance { get; private set; } 27 28 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 29 int permissionLevel) { 29 30 if (!loaded) { 30 resp.StatusCode = (int) HttpStatusCode.InternalServerError;31 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 31 32 Log.Out ("Web:IconHandler: Icons not loaded"); 32 33 return; … … 44 45 resp.OutputStream.Write (itemIconData, 0, itemIconData.Length); 45 46 } else { 46 resp.StatusCode = (int) HttpStatusCode.NotFound;47 resp.StatusCode = (int) HttpStatusCode.NotFound; 47 48 if (logMissingFiles) { 48 49 Log.Out ("Web:IconHandler:FileNotFound: \"" + req.Url.AbsolutePath + "\" "); 49 50 } 50 return;51 51 } 52 52 } … … 66 66 return false; 67 67 } 68 68 69 DynamicUIAtlas atlas = atlasObj.GetComponent<DynamicUIAtlas> (); 69 70 if (atlas == null) { … … 78 79 Texture2D atlasTex; 79 80 80 if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor (textureResourceName, out sprites, out elementWidth, out elementHeight)) { 81 if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor (textureResourceName, out sprites, 82 out elementWidth, out elementHeight)) { 81 83 SdtdConsole.Instance.Output ("Web:IconHandler: Could not read dynamic atlas descriptor"); 82 84 return false; … … 98 100 tintedIcons.Add (name, new List<Color> ()); 99 101 } 102 100 103 List<Color> list = tintedIcons [name]; 101 104 list.Add (tintColor); … … 108 111 string name = data.name; 109 112 Texture2D tex = new Texture2D (data.width, data.height, TextureFormat.ARGB32, false); 110 tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, data.height)); 113 tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, 114 data.height)); 111 115 112 116 AddIcon (name, tex, tintedIcons); 113 117 114 UnityEngine.Object.Destroy (tex);118 Object.Destroy (tex); 115 119 } 116 Resources.UnloadAsset(atlasTex); 120 121 Resources.UnloadAsset (atlasTex); 117 122 118 123 // Load icons from mods … … 131 136 } 132 137 133 UnityEngine.Object.Destroy (tex);138 Object.Destroy (tex); 134 139 } 135 140 } … … 168 173 icons [tintedName] = tintedTex.EncodeToPNG (); 169 174 170 UnityEngine.Object.Destroy (tintedTex);175 Object.Destroy (tintedTex); 171 176 } 172 177 } 173 178 } 174 179 } 175 176 180 } 177 181 } 178
Note:
See TracChangeset
for help on using the changeset viewer.