private Sprite CreateFromStrip(CookingContext context, string path) { var name = Path.GetFileNameWithoutExtension(path); var directory = Path.GetDirectoryName(path); var bitmapPath1 = Path.Combine(directory, string.Format("{0}.png", name)); var bitmapPath2 = Path.Combine(directory, string.Format("{0}.bmp", name)); var bitmapPath3 = Path.Combine(directory, string.Format("{0}.jpg", name)); Bitmap bitmap = BitmapExtension.CreateOne(bitmapPath1, bitmapPath2, bitmapPath3); if (bitmap == null) { return(null); } context.AddDependency(bitmapPath1); context.AddDependency(bitmapPath2); context.AddDependency(bitmapPath3); var data = JsonSerializer.DeserializeDataFromFile(path) as Dictionary <string, object>; var frames = data.Get("frames", 0); var size = data.Get("size", Size.Empty); var sprite = CreateSprite(EnumerateStrip(bitmap, frames, size), data); bitmap.Dispose(); return(sprite); }
public sealed override ShaderEffect Cook(CookingContext context) { string assetPath = Path.Combine(context.Directory, context.ExpandVariables(Input)); string input = Path.Combine(context.BaseDirectory, assetPath); if (File.Exists(input) == false) { throw new FileNotFoundException(string.Empty, input); } context.AddDependency(input); List <string> codeLines = new List <string>(); using (var inputStream = new FileStream(input, FileMode.Open, FileAccess.Read)) { var reader = new StreamReader(inputStream); while (reader.EndOfStream == false) { codeLines.Add(reader.ReadLine()); } } string code = Preprocess(defines, codeLines); var result = Compile(code); var byteCode = result.Item1; var extra = result.Item2; return(new ShaderEffect(null) { Tag = new ShaderEffectCookingTag(byteCode, extra) }); }
public override SpriteSet Cook(CookingContext context) { string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(Input)); var items = new Dictionary <string, Sprite>(); foreach (var item in Directory.GetFiles(actualPath)) { string name = Path.GetFileNameWithoutExtension(item); string extension = Path.GetExtension(item); Sprite sprite = null; switch (extension.ToLower()) { case ".strip": sprite = CreateFromStrip(context, item); break; case ".celanim": sprite = CreateFromCelAnimation(context, item); break; default: sprite = null; break; } if (sprite != null) { context.AddDependency(item); items.Add(name, sprite); } } return(new SpriteSet(items)); }
public override Stream Cook(CookingContext context) { string[] paths = { Input1, Input2, Input3, Input4 }; foreach (string item in paths) { string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(item)); if (File.Exists(actualPath)) { context.AddDependency(actualPath); return(new FileStream(actualPath, FileMode.Open, FileAccess.Read)); } } return(null); }
public sealed override StreamingGameAsset Cook(CookingContext context) { string assetPath = Path.Combine(context.Directory, context.ExpandVariables(Input)); string input = Path.Combine(context.BaseDirectory, assetPath); if (File.Exists(input) == false) { throw new FileNotFoundException(string.Empty, input); } context.AddDependency(input); byte[] buffer = null; using (var fs = new FileStream(input, FileMode.Open, FileAccess.Read)) { BinaryReader reader = new BinaryReader(fs); buffer = reader.ReadBytes((int)fs.Length); } return(new StreamingGameAsset(buffer)); }
public sealed override StreamingGameAsset Cook(CookingContext context) { string assetPath = Path.Combine(context.Directory, context.ExpandVariables(Input)); string input = Path.Combine(context.BaseDirectory, assetPath); if (File.Exists(input) == false) { throw new FileNotFoundException(string.Empty, input); } context.AddDependency(input); string output = Path.GetTempFileName(); var byteCode = Utility.ConvertUsingExternalTool( path: @"Plugin\luac52.exe", args: string.Format("-o \"{1}\" \"{0}\"", input, output), output: output); var textCode = Encoding.UTF8.GetBytes(File.ReadAllText(input) + "\n"); for (int i = 0; i < textCode.Length; i++) { textCode[i] ^= 0xA8; } using (var stream = new MemoryStream(byteCode.Length + textCode.Length + 16)) using (var writer = new BinaryWriter(stream)) { writer.Write(byteCode.Length); writer.Write(textCode.Length); writer.Write(byteCode); writer.Write(textCode); var buffer = new byte[stream.Length]; Buffer.BlockCopy(stream.GetBuffer(), 0, buffer, 0, buffer.Length); return(new StreamingGameAsset(buffer)); } }