public BlockJsonInfo[] Import(string name) { // Thanks to Nullpersona for the idea // Load image file and convert to Gamecraft blocks Texture2D img = new Texture2D(64, 64); // load file into texture try { byte[] imgData = File.ReadAllBytes(name); img.LoadImage(imgData); } catch (Exception e) { Logging.CommandLogError($"Failed to load picture data. Reason: {e.Message}"); Logging.MetaLog(e.Message + "\n" + e.StackTrace); return(new BlockJsonInfo[0]); } string text = PixelUtility.TextureToString(img); // conversion // save console's command commandBlockContents[name] = text; return(new BlockJsonInfo[] { new BlockJsonInfo { color = new float[] { -1f, -1f, -1f }, name = "ConsoleBlock" } }); }
public BlockJsonInfo[] Import(string name) { Texture2D img = new Texture2D(64, 64); // load file into texture try { byte[] imgData = File.ReadAllBytes(name); img.LoadImage(imgData); } catch (Exception e) { Logging.CommandLogError($"Failed to load picture data. Reason: {e.Message}"); Logging.MetaLog(e.Message + "\n" + e.StackTrace); return(new BlockJsonInfo[0]); } string text = PixelUtility.TextureToString(img); // generate text block name byte[] textHash; using (HashAlgorithm hasher = SHA256.Create()) textHash = hasher.ComputeHash(Encoding.UTF8.GetBytes(text)); string textId = "Pixi_"; for (int i = 0; i < 2 && i < textHash.Length; i++) { textId += textHash[i].ToString("X2"); } // save text block info for post-processing textBlockContents[name] = new string[2] { textId, text }; return(new BlockJsonInfo[1] { new BlockJsonInfo { color = new float[] { -1f, -1f, -1f }, name = "TextBlock", position = new float[] { 0f, 0f, 0f }, rotation = new float[] { 0f, 0f, 0f }, scale = new float[] { Mathf.Ceil(img.width / 16f), 1f, Mathf.Ceil(img.height / 16f) } } }); }