Ejemplo n.º 1
0
        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)
            });
        }
Ejemplo n.º 2
0
        private void ExportAllMasks(CookingContext context, ICollection <UIImage> images)
        {
            int    maskNumber       = 0;
            string maskOutputFormat = context.ExpandVariables(MaskOutput);

            var readMask   = new ReadGameAsset();
            var maskRecipe = new GameAssetRecipe()
            {
                Cook    = readMask,
                Author  = GetType().FullName,
                Comment = "Automatically generated.",
            };

            var masks = new List <BitMask>(images.Count);

            foreach (var item in images)
            {
                if (item.Mask == null)
                {
                    continue;
                }

                string path = string.Format(maskOutputFormat, maskNumber++);

                readMask.Input = item.Mask;

                JsonSerializer.Instance.Serialize(Path.Combine(context.BaseDirectory, context.Directory, Path.ChangeExtension(path, "asset")), maskRecipe);
                context.Store(Path.Combine(context.Directory, Path.ChangeExtension(path, null)), item.Mask);
            }
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        public static void SaveTextureAssets(CookingContext context, IEnumerable <Bitmap> textures, string textureOutput, bool taggingEnabled)
        {
            string absoluteDirectory = Path.Combine(context.BaseDirectory, context.Directory);

            if (Directory.Exists(absoluteDirectory) == false)
            {
                Directory.CreateDirectory(absoluteDirectory);
            }

            int    textureNumber       = 0;
            string textureOutputFormat = context.ExpandVariables(textureOutput);

            foreach (Bitmap item in textures)
            {
                Trace.Assert(item.Tag == null); // 밑에서 Tag를 직접 사용할 것이기 때문에 확인합니다.

                string path = string.Format(textureOutputFormat, textureNumber++);

                string textureFilePath   = Path.ChangeExtension(path, "png");
                string fullPath          = Path.Combine(absoluteDirectory, textureFilePath);
                string fullPathDirectory = Path.GetDirectoryName(fullPath);
                if (Directory.Exists(fullPathDirectory) == false)
                {
                    Directory.CreateDirectory(fullPathDirectory);
                }

                item.Save(fullPath, ImageFormat.Png);
                if (taggingEnabled)
                {
                    item.Tag = textureFilePath;
                }

                using (var fs = new FileStream(Path.ChangeExtension(fullPath, "asset"), FileMode.Create, FileAccess.Write))
                {
                    // png 파일은 자동 추론 되기 때문에 그냥 빈 파일만 생성합니다.
                }
            }
        }
Ejemplo n.º 5
0
        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));
                }
        }
Ejemplo n.º 6
0
 public override object Cook(CookingContext context)
 {
     return(context.Kitchen.Cook(context, Path.Combine(context.Directory, context.ExpandVariables(Input))));
 }
Ejemplo n.º 7
0
        public override ParticleSystemSet Cook(CookingContext context)
        {
            string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(Input));

            Dictionary <string, ParticleSystem> items = new Dictionary <string, ParticleSystem>();

            foreach (var item in Directory.GetFiles(actualPath, "*.plist", SearchOption.TopDirectoryOnly))
            {
                string name = Path.GetFileNameWithoutExtension(item);
                var    o    = Bibim.Xml.XmlExtension.LoadPList(item);

                Func <string, bool>            b  = (key) => o.ContainsKey(key) ? Convert.ToBoolean(o[key], CultureInfo.InvariantCulture) : false;
                Func <string, int>             i  = (key) => o.ContainsKey(key) ? Convert.ToInt32(o[key], CultureInfo.InvariantCulture) : 0;
                Func <string, float>           f  = (key) => o.ContainsKey(key) ? Convert.ToSingle(o[key], CultureInfo.InvariantCulture) : 0.0f;
                Func <string, string, Vector2> v2 = (k1, k2) => new Vector2(f(k1), f(k2));
                Func <string, string, string, string, Vector4> v4 = (k1, k2, k3, k4) => new Vector4(f(k1), f(k2), f(k3), f(k4));
                var system = new ParticleSystem()
                {
                    Angle                    = f("angle"),
                    AngleVariance            = f("angleVariance"),
                    BlendFunctionDestination = i("blendFuncDestination"),
                    BlendFunctionSource      = i("blendFuncSource"),
                    Duration                 = f("duration"),
                    Mode                           = (ParticleSystem.EmitterMode)i("emitterType"),
                    FinishColor                    = v4("finishColorRed", "finishColorGreen", "finishColorBlue", "finishColorAlpha"),
                    FinishColorVariance            = v4("finishColorVarianceRed", "finishColorVarianceGreen", "finishColorVarianceBlue", "finishColorVarianceAlpha"),
                    FinishParticleRotation         = f("rotationEnd"),
                    FinishParticleRotationVariance = f("rotationEndVariance"),
                    FinishParticleSize             = f("finishParticleSize"),
                    FinishParticleSizeVariance     = f("finishParticleSizeVariance"),
                    Gravity                        = v2("gravityx", "gravityy"),
                    MaxParticles                   = i("maxParticles"),
                    MaxRadius                      = f("maxRadius"),
                    MaxRadiusVariance              = f("maxRadiusVariance"),
                    MinRadius                      = f("minRadius"),
                    MinRadiusVariance              = f("minRadiusVariance"),
                    ParticleLifespan               = f("particleLifespan"),
                    ParticleLifespanVariance       = f("particleLifespanVariance"),
                    RadialAccelVariance            = f("radialAccelVariance"),
                    RadialAcceleration             = f("radialAcceleration"),
                    Spin                           = f("rotatePerSecond"),
                    SpinVariance                   = f("rotatePerSecondVariance"),
                    RotationIsDirection            = b("rotationIsDir"),
                    SourcePosition                 = v2("sourcePositionx", "sourcePositiony"),
                    SourcePositionVariance         = v2("sourcePositionVariancex", "sourcePositionVariancey"),
                    Speed                          = f("speed"),
                    SpeedVariance                  = f("speedVariance"),
                    StartColor                     = v4("startColorRed", "startColorGreen", "startColorBlue", "startColorAlpha"),
                    StartColorVariance             = v4("startColorVarianceRed", "startColorVarianceGreen", "startColorVarianceBlue", "startColorVarianceAlpha"),
                    StartParticleRotation          = f("rotationStart"),
                    StartParticleRotationVariance  = f("rotationStartVariance"),
                    StartParticleSize              = f("startParticleSize"),
                    StartParticleSizeVariance      = f("startParticleSizeVariance"),
                    TangentialAccelVariance        = f("tangentialAccelVariance"),
                    TangentialAcceleration         = f("tangentialAcceleration"),
                };

                system.Gravity = new Vector2(system.Gravity.X, -system.Gravity.Y);

                var textureImageData = (string)o["textureImageData"];
                using (var stream = new MemoryStream(Convert.FromBase64String(textureImageData)))
                    using (var s = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        var bitmap = new Bitmap(s);
                        system.Image = new Image(string.Empty, Rectangle.Empty)
                        {
                            Tag = new ImageCookingTag(bitmap),
                        };

                        var dim = (float)Math.Min(bitmap.Width, bitmap.Height);
                        system.StartParticleSize          /= dim;
                        system.StartParticleSizeVariance  /= dim;
                        system.FinishParticleSize         /= dim;
                        system.FinishParticleSizeVariance /= dim;
                    }

                items.Add(name, system);
            }

            return(new ParticleSystemSet(items));
        }
Ejemplo n.º 8
0
        private void MergeAllImages(CookingContext context, ICollection <UIImage> images)
        {
            var imageBitmaps = new Dictionary <Bitmap, List <UIImage> >(images.Count);

            foreach (var item in images)
            {
                var tag = item.Source.Tag as ImageCookingTag;
                if (tag != null && tag.Bitmap != null)
                {
                    List <UIImage> values = null;
                    if (imageBitmaps.TryGetValue(tag.Bitmap, out values))
                    {
                        values.Add(item);
                    }
                    else
                    {
                        values = new List <UIImage>()
                        {
                            item
                        };
                        imageBitmaps.Add(tag.Bitmap, values);
                    }
                }
            }

            using (var bitmapSheet = BitmapSheet.Create(imageBitmaps.Keys,
                                                        BitmapSheetSize.Width, BitmapSheetSize.Height,
                                                        BitmapSheetClusterSize.Width, BitmapSheetClusterSize.Height,
                                                        BitmapSheet.Options.PowerOfTwoSize /* | BitmapSheet.Options.RotatableMerging*/))
            {
                #region Texture File과 Asset을 저장합니다.
                string absoluteDirectory = Path.Combine(context.BaseDirectory, context.Directory);
                if (Directory.Exists(absoluteDirectory) == false)
                {
                    Directory.CreateDirectory(absoluteDirectory);
                }

                int    textureNumber       = 0;
                string textureOutputFormat = context.ExpandVariables(TextureOutput);
                foreach (Bitmap item in bitmapSheet.Sheets)
                {
                    Trace.Assert(item.Tag == null); // 밑에서 Tag를 직접 사용할 것이기 때문에 확인합니다.

                    string path = string.Format(textureOutputFormat, textureNumber++);

                    string textureFilePath   = Path.ChangeExtension(path, "png");
                    string fullPath          = Path.Combine(absoluteDirectory, textureFilePath);
                    string fullPathDirectory = Path.GetDirectoryName(fullPath);
                    if (Directory.Exists(fullPathDirectory) == false)
                    {
                        Directory.CreateDirectory(fullPathDirectory);
                    }

                    item.Save(fullPath, ImageFormat.Png);
                    item.Tag = textureFilePath;

                    using (var fs = new FileStream(Path.ChangeExtension(fullPath, "asset"), FileMode.Create, FileAccess.Write))
                    {
                        // png 파일은 자동 추론 되기 때문에 그냥 빈 파일만 생성합니다.
                    }
                }
                #endregion

                #region Image Asset을 저장합니다
                // EMBEDDED UIIMAGE

                /*
                 * var readImage = new ReadGameAsset();
                 * var imageRecipe = new GameAssetRecipe()
                 * {
                 *  Cook = readImage,
                 *  Author = GetType().FullName,
                 *  Comment = "Automatically generated.",
                 * };
                 *
                 * int imageNumber = 0;
                 * string imageOutputFormat = context.ExpandVariables(ImageOutput);
                 */

                foreach (BitmapSheet.Element item in bitmapSheet.Elements)
                {
                    string textureURI = Path.Combine(context.Directory, Path.ChangeExtension((string)item.Sheet.Tag, null));

                    /*
                     * string path = string.Format(imageOutputFormat, imageNumber++);
                     *
                     * readImage.Input = new Image()
                     * {
                     *  TextureURI = Path.Combine(context.Directory, Path.ChangeExtension((string)item.Sheet.Tag, null)),
                     *  ClippingRectangle = new Rectangle(item.Bounds.X, item.Bounds.Y,
                     *                                    item.Bounds.Width, item.Bounds.Height),
                     *  AppliedTransform = item.AppliedTransform,
                     * };
                     *
                     * JsonSerializer.Instance.Serialize(Path.Combine(context.BaseDirectory, context.Directory, Path.ChangeExtension(path, "asset")), imageRecipe);
                     */

                    List <UIImage> values = null;
                    if (imageBitmaps.TryGetValue(item.Source, out values))
                    {
                        foreach (var image in values)
                        {
                            image.Source.TextureURI        = textureURI;
                            image.Source.ClippingRectangle = new Rectangle(item.Bounds.X, item.Bounds.Y,
                                                                           item.Bounds.Width, item.Bounds.Height);
                            image.Source.AppliedTransform = item.AppliedTransform;
                        }

                        /*
                         * context.Store(Path.Combine(context.Directory, Path.ChangeExtension(path, null)), values[0].Source);
                         *
                         * for (int i = 1; i < values.Count; i++)
                         *  values[i] = values[0];
                         */
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public override ImageSet Cook(CookingContext context)
        {
            string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(Input));

            Dictionary <string, Image> items = new Dictionary <string, Image>();

            foreach (var item in Directory.GetFiles(actualPath))
            {
                string name   = Path.GetFileNameWithoutExtension(item);
                Bitmap bitmap = BitmapExtension.CreateOne(item);
                if (bitmap == null)
                {
                    continue;
                }

                if (UniformSize.IsEmpty == false)
                {
                    bitmap = bitmap.ResizeAndDispose(UniformSize.Width, UniformSize.Height);
                }

                items.Add(name, new Image(string.Empty, Rectangle.Empty)
                {
                    Tag = new ImageCookingTag(bitmap)
                });
            }

            return(new ImageSet(items));
        }
Ejemplo n.º 11
0
        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));
        }