Example #1
0
        public object Cook(CookingContext parent, string recipePath)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (string.IsNullOrEmpty(recipePath))
            {
                throw new ArgumentNullException("recipePath");
            }

            GameAssetRecipe recipe = BeginCook(parent.BaseDirectory, recipePath);

            if (recipe != null)
            {
                CookingContext context = new CookingContext(parent, recipePath, recipe);
                context.AddDependency(Path.Combine(parent.BaseDirectory, recipePath));
                object asset = recipe.Cook.CookObject(context);
                parent.Reference(context);
                return(asset);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public CookingReport Cook(string baseDirectory, string recipePath)
        {
            if (string.IsNullOrEmpty(baseDirectory))
            {
                throw new ArgumentNullException("baseDirectory");
            }
            if (string.IsNullOrEmpty(recipePath))
            {
                throw new ArgumentNullException("recipePath");
            }

            GameAssetRecipe recipe = BeginCook(baseDirectory, recipePath);

            if (recipe != null)
            {
                CookingContext context = new CookingContext(this, baseDirectory, recipePath, recipe);
                context.AddDependency(Path.Combine(baseDirectory, recipePath));
                context.SetVariable("AssetName", Path.GetFileNameWithoutExtension(recipePath));
                return(new CookingReport(recipe.Cook.CookObject(context), context));
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private GameAssetRecipe FindBuiltinRecipe(string path)
        {
            string firstExtension = GuessFirstExtension(path);

            GameAssetRecipe recipe = null;

            if (builtinRecipes.TryGetValue(firstExtension, out recipe))
            {
                return(recipe);
            }
            else
            {
                return(null);
            }
        }
Example #4
0
        private GameAssetRecipe BeginCook(string baseDirectory, string recipePath)
        {
            GameAssetRecipe recipe       = null;
            string          absolutePath = Path.Combine(baseDirectory, recipePath);

            if (File.Exists(absolutePath) == false)
            {
                throw new FileNotFoundException("Recipe file not found.", absolutePath);
            }

            recipe = JsonSerializer.Instance.Deserialize(absolutePath) as GameAssetRecipe;
            if (recipe != null && recipe.Cook != null)
            {
                return(recipe);
            }

            using (var fs = new FileStream(absolutePath, FileMode.Open, FileAccess.Read))
            {
                var data = JsonSerializer.DeserializeData(fs) as Dictionary <string, object>;
                if (data != null)
                {
                    recipe = CreateBuiltinRecipe(absolutePath, data);
                }

                if (recipe != null)
                {
                    return(recipe);
                }
            }

            recipe = FindBuiltinRecipe(absolutePath);
            if (recipe != null)
            {
                return(recipe);
            }
            else
            {
                throw new InvalidDataException(string.Format("couldn't guess recipe. ({0})", absolutePath));
            }
        }
Example #5
0
        private CookingContext(GameAssetKitchen kitchen, GameAssetStorage storage, CookingContext parent, string baseDirectory, string recipePath, GameAssetRecipe recipe)
        {
            int    variableCapacity = 4;
            string directory        = Path.GetDirectoryName(recipePath);

            this.Kitchen             = kitchen;
            this.Storage             = storage;
            this.Parent              = parent;
            this.baseDirectory       = baseDirectory ?? string.Empty;
            this.directory           = directory ?? string.Empty;
            this.variables           = new Dictionary <string, string>(variableCapacity);
            this.expandableVariables = new Dictionary <string, string>(variableCapacity);
            this.readonlyVariables   = new ReadOnlyDictionary <string, string>(this.variables);

            this.dependencies = new SortedSet <string>();
            this.CanHotload   = recipe != null ? recipe.CanHotload : false;

            SetVariable("Directory", directory);
            SetVariable("Path", recipePath);
        }
Example #6
0
 public CookingContext(CookingContext parent, string recipePath, GameAssetRecipe recipe)
     : this(parent.Kitchen, parent.Storage, parent, parent.baseDirectory, recipePath, recipe)
 {
 }
Example #7
0
 public CookingContext(GameAssetKitchen kitchen, string baseDirectory, string recipePath, GameAssetRecipe recipe)
     : this(kitchen, kitchen.Storage, null, baseDirectory, recipePath, recipe)
 {
 }