示例#1
0
        public SRecipe DetailRecipe([FromQuery] Guid?recipeID)
        {
            if (recipeID == null)
            {
                return(new SRecipe());
            }

            Recipe auxRecipe = recipesDAWContext.Recipes.FirstOrDefault(db => db.Id == recipeID);

            List <Ingredient>  ingredients  = recipesDAWContext.Ingredients.Where(i => i.Recipe.Id == auxRecipe.Id).ToList();
            List <Instruction> instructions = recipesDAWContext.Instructions.Where(i => i.Recipe.Id == auxRecipe.Id).ToList();

            auxRecipe.Ingredients  = ingredients;
            auxRecipe.Instructions = instructions;

            SRecipe currentRecipe = new SRecipe()
            {
                Title       = auxRecipe.Title,
                Description = auxRecipe.Description,
                Serves      = auxRecipe.Serves,
                ImageUrl    = auxRecipe.ImageUrl,
                Id          = auxRecipe.Id
            };

            List <SIngredient> currentIngredients = new List <SIngredient>();

            foreach (Ingredient ingredient in ingredients)
            {
                currentIngredients.Add(new SIngredient()
                {
                    Id     = ingredient.Id,
                    name   = ingredient.name,
                    amount = ingredient.amount
                });
            }

            List <SInstruction> currentInstructions = new List <SInstruction>();

            foreach (Instruction instruction in instructions)
            {
                currentInstructions.Add(new SInstruction()
                {
                    Id          = instruction.Id,
                    instruction = instruction.instruction
                });
            }
            auxRecipe.Ingredients  = ingredients;
            auxRecipe.Instructions = instructions;

            currentRecipe.Ingredients  = currentIngredients;
            currentRecipe.Instructions = currentInstructions;

            return(currentRecipe);
        }
示例#2
0
        public void SaveRecipe([FromBody] SRecipe recipe)
        {
            if (recipe.Id == Guid.Empty)
            {
                recipe.Id = Guid.NewGuid();
                Recipe RecipeToSave = new Recipe
                {
                    Id          = recipe.Id,
                    Title       = recipe.Title,
                    Description = recipe.Description,
                    Serves      = recipe.Serves,
                    ImageUrl    = recipe.ImageUrl
                };

                List <Ingredient> ingredients = new List <Ingredient>();
                foreach (SIngredient ingredient in recipe.Ingredients)
                {
                    ingredients.Add(new Ingredient()
                    {
                        name   = ingredient.name,
                        amount = ingredient.amount
                    });
                }

                List <Instruction> instructions = new List <Instruction>();
                foreach (SInstruction instruction in recipe.Instructions)
                {
                    instructions.Add(new Instruction()
                    {
                        instruction = instruction.instruction
                    });
                }

                RecipeToSave.Ingredients  = ingredients;
                RecipeToSave.Instructions = instructions;
                recipesDAWContext.Recipes.Add(RecipeToSave);
            }
            else
            {
                Recipe currentRecipe = recipesDAWContext.Recipes.FirstOrDefault(Recipe => Recipe.Id == recipe.Id);
                currentRecipe.Title       = recipe.Title;
                currentRecipe.Serves      = recipe.Serves;
                currentRecipe.ImageUrl    = recipe.ImageUrl;
                currentRecipe.Description = recipe.Description;

                UpdateIngredients(recipe.Ingredients, recipe.Id);
                UpdateInstructions(recipe.Instructions, recipe.Id);
            }

            recipesDAWContext.SaveChanges();
        }
    public void Start()
    {
        //int ResCount | string Name | int Duration | Sprite OutputIcon |  Sprite resIcon1 | Sprite resIcon2 | Sprite resIcon3 | int resAmount1 | int resIdx1 |int resAmount2 | int resIdx1 | int resAmount3 | int resIdx1 | bool isUnlocked |int UnlockCost)
        // ResIdx 0 = copper, 1 = tin etc
        var SRecipe1 = new SRecipe(1, "Copper Bar", 30, Resources.Load <Sprite>("Bars/1CopperBar"), Resources.Load <Sprite>("Ores/1CopperOre"), null, null, 1000, 0, 0, 0, 0, 0, true, 0);
        var SRecipe2 = new SRecipe(1, "Tin Bar", 45, Resources.Load <Sprite>("Bars/2TinBar"), Resources.Load <Sprite>("Ores/2TinOre"), null, null, 1000, 1, 0, 0, 0, 0, false, 1700);
        var SRecipe3 = new SRecipe(2, "Bronze Bar", 90, Resources.Load <Sprite>("Bars/3BronzeBar"), Resources.Load <Sprite>("Ores/1CopperOre"), Resources.Load <Sprite>("Ores/2TinOre"), null, 500, 0, 500, 1, 0, 0, false, 2500);
        var SRecipe4 = new SRecipe(3, "Iron Bar", 120, Resources.Load <Sprite>("Bars/4IronBar"), Resources.Load <Sprite>("Ores/1CopperOre"), Resources.Load <Sprite>("Ores/2TinOre"), Resources.Load <Sprite>("Ores/3IronOre"), 750, 0, 650, 1, 550, 2, false, 5000);


        SRecipes.Add(SRecipe1);
        SRecipes.Add(SRecipe2);
        SRecipes.Add(SRecipe3);
        SRecipes.Add(SRecipe4);


        for (int SRecipeIndex = 0; SRecipeIndex < SRecipes.Count; SRecipeIndex++)
        {
            if (SRecipes[SRecipeIndex].ResCount == 1)
            {
                var copy = (GameObject)Instantiate(SRecipeUIRes1);
                //na to kanei disable an ta proigoumena den einai unlocked, thelw na fenete ena choice available gia unlock kathe fora
                if (SRecipeIndex > 1)
                {
                    copy.gameObject.SetActive(false);
                }
                RefRecipeList.Add(copy);

                copy.gameObject.name = SRecipes[SRecipeIndex].Name;
                copy.transform.SetParent(RecipeContent.transform, false);
                copy.transform.localPosition = Vector3.zero;

                //input 1 image & amount
                copy.GetComponentsInChildren <Image>()[1].sprite = (SRecipes[SRecipeIndex].resIcon1);
                copy.GetComponentsInChildren <Text>()[0].text    = (SRecipes[SRecipeIndex].resAmount1).ToString();
                //duration
                copy.GetComponentsInChildren <Text>()[1].text = (SRecipes[SRecipeIndex].Duration).ToString() + "s";
                //name
                copy.GetComponentsInChildren <Text>()[2].text = (SRecipes[SRecipeIndex].Name);
                //output image
                copy.GetComponentsInChildren <Image>()[2].sprite = (SRecipes[SRecipeIndex].OutputIcon);
                //cost text 3 giati exoume 5texts (ksekina apo 0)
                copy.GetComponentsInChildren <Text>()[3].text = (SRecipes[SRecipeIndex].UnlockCost).ToString();

                var localindex = SRecipeIndex;
                if (SRecipes[SRecipeIndex].isUnlocked == true)
                {
                    //na kanei disable to unlockpanel/button an to recipe einai unlocked
                    copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                }
                else
                {
                    //listener gia na kanei disable to "Buy Panel" kai na kanei enable to epomeno "available to buy recipe"
                    copy.GetComponentsInChildren <Button>()[1].onClick.AddListener(() => {
                        if (CurrencyControl.Cash >= SRecipes[localindex].UnlockCost)
                        {
                            CurrencyControl.Cash -= SRecipes[localindex].UnlockCost;
                            copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                            //check gia na vlepei an einai to telefteo ths listas, giati allios out of bounds
                            //h prwth timh tou count den einai 0, opote +1 sto index
                            if (localindex + 1 != SRecipes.Count)
                            {
                                RefRecipeList[localindex + 1].SetActive(true);
                            }
                            //xreiazete na kanw remove to listener gia perfomance?
                        }
                    });
                }
                copy.GetComponent <Button>().onClick.AddListener(() => {
                    // na pernei to selection,oti thelw na kanw smelt
                    SRecipePanel.SetActive(false);
                    BuySmelterScript.TestIndex1 = localindex;
                }
                                                                 );

                ////------ end resource 1 prefab
            }
            else if (SRecipes[SRecipeIndex].ResCount == 2)
            {
                var copy = (GameObject)Instantiate(SRecipeUIRes2);
                //na to kanei disable an ta proigoumena den einai unlocked, thelw na fenete ena choice available gia unlock kathe fora
                if (SRecipeIndex > 1)
                {
                    copy.gameObject.SetActive(false);
                }
                RefRecipeList.Add(copy);

                copy.gameObject.name = SRecipes[SRecipeIndex].Name;
                copy.transform.SetParent(RecipeContent.transform, false);
                copy.transform.localPosition = Vector3.zero;
                //input 1 image & amount
                copy.GetComponentsInChildren <Image>()[1].sprite = (SRecipes[SRecipeIndex].resIcon1);
                copy.GetComponentsInChildren <Text>()[0].text    = (SRecipes[SRecipeIndex].resAmount1).ToString();
                //input 2 image & amount
                copy.GetComponentsInChildren <Image>()[2].sprite = (SRecipes[SRecipeIndex].resIcon2);
                copy.GetComponentsInChildren <Text>()[1].text    = (SRecipes[SRecipeIndex].resAmount2).ToString();
                //duration
                copy.GetComponentsInChildren <Text>()[2].text = (SRecipes[SRecipeIndex].Duration).ToString() + "s";
                //name
                copy.GetComponentsInChildren <Text>()[3].text = (SRecipes[SRecipeIndex].Name);
                //output image
                copy.GetComponentsInChildren <Image>()[3].sprite = (SRecipes[SRecipeIndex].OutputIcon);
                //cost text 4 giati exoume 5texts (ksekina apo 0)
                copy.GetComponentsInChildren <Text>()[4].text = (SRecipes[SRecipeIndex].UnlockCost).ToString();

                var localindex = SRecipeIndex;
                if (SRecipes[SRecipeIndex].isUnlocked == true)
                {
                    //na kanei disable to unlockpanel/button an to recipe einai unlocked
                    copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                }
                else
                {
                    //listener gia na kanei disable to "Buy Panel" kai na kanei enable to epomeno "available to buy recipe"
                    copy.GetComponentsInChildren <Button>()[1].onClick.AddListener(() => {
                        if (CurrencyControl.Cash >= SRecipes[localindex].UnlockCost)
                        {
                            CurrencyControl.Cash -= SRecipes[localindex].UnlockCost;
                            copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                            //check gia na vlepei an einai to telefteo ths listas, giati allios out of bounds
                            //h prwth timh tou count den einai 0, opote +1 sto index
                            if (localindex + 1 != SRecipes.Count)
                            {
                                RefRecipeList[localindex + 1].SetActive(true);
                            }
                            //xreiazete na kanw remove to listener gia perfomance?
                        }
                    });
                }
                copy.GetComponent <Button>().onClick.AddListener(() => {
                    // na pernei to selection,oti thelw na kanw smelt
                    SRecipePanel.SetActive(false);
                    BuySmelterScript.TestIndex1 = localindex;
                }
                                                                 );
                ////------ end resource 2 prefab
            }
            else
            {
                var copy = (GameObject)Instantiate(SRecipeUIRes3);
                //na to kanei disable an ta proigoumena den einai unlocked, thelw na fenete ena choice available gia unlock kathe fora
                if (SRecipeIndex > 1)
                {
                    copy.gameObject.SetActive(false);
                }
                RefRecipeList.Add(copy);

                copy.gameObject.name = SRecipes[SRecipeIndex].Name;
                copy.transform.SetParent(RecipeContent.transform, false);
                copy.transform.localPosition = Vector3.zero;

                //input 1 image & amount
                copy.GetComponentsInChildren <Image>()[1].sprite = (SRecipes[SRecipeIndex].resIcon1);
                copy.GetComponentsInChildren <Text>()[0].text    = (SRecipes[SRecipeIndex].resAmount1).ToString();
                //input 2 image & amount
                copy.GetComponentsInChildren <Image>()[2].sprite = (SRecipes[SRecipeIndex].resIcon2);
                copy.GetComponentsInChildren <Text>()[1].text    = (SRecipes[SRecipeIndex].resAmount2).ToString();
                //input 3 image & amount
                copy.GetComponentsInChildren <Image>()[3].sprite = (SRecipes[SRecipeIndex].resIcon3);
                copy.GetComponentsInChildren <Text>()[2].text    = (SRecipes[SRecipeIndex].resAmount3).ToString();

                //duration
                copy.GetComponentsInChildren <Text>()[3].text = (SRecipes[SRecipeIndex].Duration).ToString() + "s";
                //name
                copy.GetComponentsInChildren <Text>()[4].text = (SRecipes[SRecipeIndex].Name);
                //output image
                copy.GetComponentsInChildren <Image>()[4].sprite = (SRecipes[SRecipeIndex].OutputIcon);
                //cost text 5 giati exoume 5texts (ksekina apo 0)
                copy.GetComponentsInChildren <Text>()[5].text = (SRecipes[SRecipeIndex].UnlockCost).ToString();

                var localindex = SRecipeIndex;
                if (SRecipes[SRecipeIndex].isUnlocked == true)
                {
                    //na kanei disable to unlockpanel/button an to recipe einai unlocked
                    copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                }
                else
                {
                    //listener gia na kanei disable to "Buy Panel" kai na kanei enable to epomeno "available to buy recipe"
                    copy.GetComponentsInChildren <Button>()[1].onClick.AddListener(() => {
                        if (CurrencyControl.Cash >= SRecipes[localindex].UnlockCost)
                        {
                            CurrencyControl.Cash -= SRecipes[localindex].UnlockCost;
                            copy.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);
                            //check gia na vlepei an einai to telefteo ths listas, giati allios out of bounds
                            //h prwth timh tou count den einai 0, opote +1 sto index
                            if (localindex + 1 != SRecipes.Count)
                            {
                                RefRecipeList[localindex + 1].SetActive(true);
                            }
                            //xreiazete na kanw remove to listener gia perfomance?
                        }
                    });
                }
                copy.GetComponent <Button>().onClick.AddListener(() => {
                    // na pernei to selection,oti thelw na kanw smelt
                    SRecipePanel.SetActive(false);
                    BuySmelterScript.TestIndex1 = localindex;
                }
                                                                 );



                ////------ end resource 3 prefab
            }
        }
    }