Beispiel #1
0
        public static bool SaveToFile(SpriteData data, string file)
        {
            Extensions.ValidateDirectory(Path.GetDirectoryName(file));

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(data.resX.ToString());
            sb.AppendLine(data.resY.ToString());

            sb.AppendLine(data.pivotOffsetX.ToString());
            sb.AppendLine(data.pivotOffsetY.ToString());

            sb.AppendLine(data.order.ToString());

            int i = 0;

            for (int y = 0; y < data.resY; y++)
            {
                for (int x = 0; x < data.resX; x++)
                {
                    sb.Append(x == data.resX - 1 ? $"{data.pixels[i]}\n" : $"{data.pixels[i]}");
                    i++;
                }
            }

            if (data.isMasker)
            {
                sb.AppendLine("1");
                for (int y = 0; y < data.resY; y++)
                {
                    for (int x = 0; x < data.resX; x++)
                    {
                        sb.Append(x == data.resX - 1 ? $"{data.mask[i]}\n" : $"{data.mask[i]}");
                        i++;
                    }
                }
            }

            File.WriteAllText(file, sb.ToString());
            return(true);
        }
Beispiel #2
0
        public static SpriteData FromSaveString(string data)
        {
            int    end;
            string dataPart  = data.Substring(0, end = data.IndexOf('['));
            string pixelPart = data.Remove(0, end + 1);

            pixelPart = pixelPart.Substring(0, pixelPart.Length - 1);

            string[] datas = dataPart.Split(',');

            SpriteData finalData = new SpriteData()
            {
                pixels = pixelPart.ToCharArray(),

                pivotOffsetX = datas[2].ToFloat(0.0f),
                pivotOffsetY = datas[3].ToFloat(0.0f),
            };

            int.TryParse(datas[0], out finalData.resX);
            int.TryParse(datas[1], out finalData.resY);
            int.TryParse(datas[4], out finalData.order);

            return(finalData);
        }
Beispiel #3
0
        public static bool SaveToFile(Bitmap bm, string file, out string path, string additionPath = "")
        {
            SpriteData data = ToData(bm, file);

            return(SaveToFile(data, path = GetFileName(Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Console Bullethell/Sprites/{additionPath}"), data)));
        }
Beispiel #4
0
 public static string GetFileName(string path, SpriteData data)
 {
     return(Path.Combine(path, $"{data.name}{EXTENSION}"));
 }