public bool Put(IngredientBase item)
	{
		if (baseMusicMaster != null)
		{
			baseMusicMaster.OneShot("drop", transform.position);
		}

		// Am I full?
		if (contents != null)
			return false;

		// Can I receive this item?
		if (!CanIReceive(item))
			return false;

		// Move it
		item.gameObject.transform.parent = transform;
		StartCoroutine(LerpItemPosition(item, item.gameObject.transform.position, IngredientOffsetTransform.position, 0.2f));

		// Get it
		GetItem(item);

        var ritual = FindObjectOfType<RitualMaster>().RemainingRituals<PutItemsRitual>().Where(r => r.GetBenchesCompleted() >= r.NumBenches).FirstOrDefault();
        if (ritual != null)
        {
            ritual.Satisfied = true;
        }


        return true;
	}
	private bool IngredientMatches(IngredientBase item, Ingredient ingredient)
	{
        if (item.burnt)
        {
            return false;
        }

		// not right type
		if (ingredient.Type != item.Type) return false;

		// incorrect number of operations done
		if (ingredient.Tasks.Count != item.TasksDone.Count) return false;

		for (int i = 0; i < item.TasksDone.Count; i++)
		{
			if (item.TasksDone[i] != ingredient.Tasks[i])
			{
				// wrong operation done
				return false;
			}
		}

		// aaaaaaaaaaaaallllllllllllllllgggggggggggggggg
		return true;
	}
        private void OnRefreshInfredients(object p)
        {
            var ingredients = GetIngredients();

            IngredientBase.Clear();
            ingredients.ToList().ForEach(i => IngredientBase.Add(i));
        }
	public override bool CanIReceive(IngredientBase item)
	{
		currentSound = musicMaster.PlaySound(TaskType.ToLowerInvariant(), transform.position);
        if (item.burnt)
        {
            return false;
        }
        return true;
	}
Exemple #5
0
        public async Task <ActionResult> Put([FromBody] IngredientBase input)
        {
            var ingredient = this._mapper.Map <IngredientBase, Ingredient>(input);
            var isSuccess  = await this._ingredientsService.UpdateOne(ingredient);

            if (!isSuccess)
            {
                return(UnprocessableEntity(input));
            }
            return(Ok());
        }
	public virtual IngredientBase Interact(Player player, Vector2 input)
	{
		var temp = contents;
		contents = null;
		if (temp != null && baseMusicMaster != null)
		{
			baseMusicMaster.OneShot("pick", transform.position);
		}

		return temp;
	}
Exemple #7
0
 private void Recalc(IngredientBase ingredient, long serving_weight_grams)
 {
     foreach (var propertyInfo in ingredient.GetType().GetProperties())
     {
         if (propertyInfo.PropertyType.Name == "Single")
         {
             float currentValue = (float)propertyInfo.GetValue(ingredient);
             float newValue     = currentValue * (100f / (float)serving_weight_grams);
             var   rounded      = Math.Round(newValue, 2);
             propertyInfo.SetValue(ingredient, (float)rounded);
         }
     }
 }
	public override bool CanIReceive(IngredientBase item)
	{
		if (Recipe == null)
		{
			return false;
		}

		if (MatchesRecipe(item))
		{
			return true;
		}

		return false;
	}
Exemple #9
0
        public async Task <ActionResult> Post([FromBody] IngredientBase input)
        {
            //TODO: add standard on naming
            var ingredient = this._mapper.Map <IngredientBase, Ingredient>(input);
            var response   = await this._ingredientsService.AddOne(ingredient);

            // this._context.Ingredients.Add(ingredient);
            // FIXME: Bug on saving new ingredient..
            // var result = this._context.SaveChanges();
            if (!response.Success)
            {
                return(UnprocessableEntity(response));
            }
            //return Ok($"Object added. ID:{createdEntityId}");
            return(Ok(response));
        }
	private bool MatchesRecipe(IngredientBase item)
	{
		var pendingIngredients = Recipe.Ingredients.Where(i => !i.IsSatisfied);
		foreach (var ingredient in pendingIngredients)
		{
			if (IngredientMatches(item, ingredient))
			{
				ingredient.IsSatisfied = true;
				Ingredients.Add(item);

				return true;
			}
		}

		return false;
	}
Exemple #11
0
        public async Task <IngredientBase> SearchIngredientAsync(string name)
        {
            using (var client = new ApiClient())
            {
                var body    = new { query = name, timezone = "US/Eastern" };
                var request = new RequestBuilder()
                              .SetUri("https://trackapi.nutritionix.com/v2/natural/nutrients")
                              .SetMethod(HttpMethod.Post)
                              .AddHeader("x-app-id", "e0f10739")
                              .AddHeader("x-app-key", "05ab0d773ba54b5661b68ae4e7aec65d")
                              .SetStringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json")
                              .Build();
                var response = await client
                               .SetTimeout(15000)
                               .SendRequestAsync(request);

                dynamic responseBody = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                if (DynamicUtil.HasProperty(responseBody, "foods"))
                {
                    var foods      = responseBody.foods[0];
                    var ingredient = new IngredientBase();
                    var mapping    = new Dictionary <string, string>();
                    mapping.Add("name", "food_name");
                    mapping.Add("kcal", "nf_calories");
                    mapping.Add("protein", "nf_protein");
                    mapping.Add("carbohydrates", "nf_total_carbohydrate");
                    mapping.Add("sugar", "nf_sugars");
                    mapping.Add("fat", "nf_total_fat");
                    mapping.Add("saturated", "nf_saturated_fat");
                    DynamicUtil.UpdateModel(ingredient, foods, mapping: mapping);
                    var serving_weight_grams = (long)foods.serving_weight_grams.Value;
                    Recalc(ingredient, serving_weight_grams);
                    return(ingredient);
                }
                else
                {
                    return(null);
                }
            }
        }
        private async void OnAddIngredientAsync(object parameters)
        {
            object[] res        = parameters as object[];
            var      ingredient = new IngredientBase()
            {
                Name          = res[0].ToString(),
                Kcal          = float.Parse(res[1].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture),
                Protein       = float.Parse(res[2].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture),
                Carbohydrates = float.Parse(res[3].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture),
                Sugar         = float.Parse(res[4].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture),
                Fat           = float.Parse(res[5].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture),
                Saturated     = float.Parse(res[6].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture)
            };

            _ingredientRepository.Add(ingredient);
            var result = await _ingredientRepository.SaveChangesAsync();

            if (result == 1)
            {
                Ingredients.Add(ingredient);
            }
        }
Exemple #13
0
    private bool Interact()
    {
       // Debug.Log("Current Interactable: " + CurrentInteractable);
       
        if (HeldItem != null)
		{
            //print("put");
			if (CurrentInteractable != null && CurrentInteractable.Put(HeldItem))
			{
                SpriteRenderer[] renderers = HeldItem.GetComponentsInChildren<SpriteRenderer>();
                foreach (SpriteRenderer renderer in renderers)
                {
                    if (renderer.name.StartsWith("TaskIcon"))
                    {
                        renderer.enabled = false;
                    }
                }

                // not holding anymore
                HeldItem = null;
				JustInteracted = true;
                StartCoroutine(TransitionToPose_Idle(TransitionToIdleDuration));    //Animate arms                      
            }
			else
			{
				//print("failed");
			}

            return true;
		}
		else
		{
            if (CurrentInteractable == null || (CurrentInteractable != null && 
                                                CurrentInteractable.LastInteractedPlayer != null && 
                                                CurrentInteractable.LastInteractedPlayer.Interacting && 
                                                CurrentInteractable.LastInteractedPlayer.CurrentInteractable == CurrentInteractable))
            {
                return false;
            }     
                  
            var item = CurrentInteractable.Interact(this, GetInput());
			if (item != null)
			{
				// hold item above head
				HeldItem = item;

                SpriteRenderer[] renderers = HeldItem.GetComponentsInChildren<SpriteRenderer>();
                foreach (SpriteRenderer renderer in renderers)
                {
                    if (renderer.name.StartsWith("TaskIcon"))
                    {
                        renderer.enabled = true;
                    }
                }

                HeldItem.transform.parent = HeldObjectTransform.transform;         
                StartCoroutine(DoItemPickupTransition(HeldItem, 0.2f));
                StartCoroutine(TransitionToPose_HoldItem(TransitionToHoldDuration));    //Animate arms
                JustInteracted = true;
			}
			else
			{
				//print("failed");                
			}

            return true;
        }
	}
	public override bool CanIReceive(IngredientBase item)
	{
		musicMaster.OneShot("bin", transform.position);
		return true;
	}
	IEnumerator LerpItemPosition(IngredientBase itemToLerp, Vector3 startPos, Vector3 endPos, float duration)
	{
		float t_elapsed = 0;
		do
		{
			t_elapsed += Time.deltaTime;
			itemToLerp.gameObject.transform.position = Vector3.Lerp(startPos, endPos, t_elapsed / duration);
			yield return null;
		}
		while (t_elapsed / duration < 1f);
	}
Exemple #16
0
    IEnumerator DoItemPickupTransition(IngredientBase itemToLerp, float duration)
    {
        Vector3 ItemStartPos = itemToLerp.transform.position;

        float t_elapsed = 0;
        do
        {
            t_elapsed += Time.deltaTime;
            itemToLerp.gameObject.transform.position = Vector3.Lerp(ItemStartPos, HeldObjectTransform.transform.position, t_elapsed / duration);
            yield return null;
        }
        while (t_elapsed / duration < 1f);        
    }
	public virtual bool CanIReceive(IngredientBase item)
	{
		return true;
	}
	public virtual void GetItem(IngredientBase item)
	{
		contents = item;
	}
Exemple #19
0
        public async Task RecipeUpdate_DeleteAddAndUpdateIngredients_WorkAsExpected()
        {
            // each test creates new Connection / Options / DbSchema
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <RecipesContext>()
                              .UseSqlite(connection)
                              .Options;

                SetupBasicContext(options);

                using (var context = new RecipesContext(options))
                {
                    var service = new RecipesService(context, this._loggerMock.Object, this._mediaHelper.Object, this._mapper);
                    // todo: is this bad practice? Should I just recreate an object Recipe here, with same Id? (Since we want to reproduce offline example). To avoid tracked/extra entities..
                    // get recipe with Id 4
                    var recipeToUpdate = await service.GetOne(4);

                    // Removing ingredient with id 1
                    var ingredient1 = recipeToUpdate.Ingredients.FirstOrDefault(i => i.Id == 1);
                    recipeToUpdate.Ingredients.Remove(ingredient1);

                    // Modify ingredient with Id 2
                    var ingredient2 = recipeToUpdate.Ingredients.FirstOrDefault(i => i.Id == 2);
                    recipeToUpdate.Ingredients.Remove(ingredient2);
                    recipeToUpdate.Ingredients.Add(new IngredientBase {
                        Id = ingredient2.Id, Name = "Strawberry", Quantity = 1, Unit_Id = 3, Recipe_Id = ingredient2.Recipe_Id
                    });

                    // Add new ingredient
                    var ingredient3 = new IngredientBase()
                    {
                        Id = 0, Name = "Flour", Quantity = 3, Unit_Id = 1, Recipe_Id = 4
                    };
                    recipeToUpdate.Ingredients.Add(ingredient3);

                    // Get recipe again from db and verify all changes worked
                    await service.UpdateOne(recipeToUpdate);

                    var dbrecipe = await service.GetOne(4);

                    Assert.AreEqual(2, dbrecipe.Ingredients.Count());
                    // recipe should have 2 ingredient with id:2 and id:3 (new)
                    var ingredientIds = dbrecipe.Ingredients.Select(i => i.Id).ToList();
                    Assert.AreEqual(new int[2] {
                        2, 3
                    }, ingredientIds);
                    // check modif in ingredient with Id:2
                    ingredient2 = dbrecipe.Ingredients.FirstOrDefault(i => i.Id == 2);
                    Assert.AreEqual("Strawberry", ingredient2.Name);
                    Assert.AreEqual(1, ingredient2.Quantity);
                    Assert.AreEqual(3, ingredient2.Unit_Id);
                }
            }
            finally
            {
                connection.Close();
            }
        }
	public override bool CanIReceive(IngredientBase item)
	{
		return false;
	}
	public override void GetItem(IngredientBase item)
    {
        var ritual = FindObjectOfType<RitualMaster>().RemainingRituals<TrashItemRitual>().Where(r => r.ItemType == item.Type.ToLower()).FirstOrDefault();
        if (ritual != null)
            ritual.Satisfied = true;
    }
	public override bool CanIReceive(IngredientBase item)
	{
        if (item.burnt)
        {
            return false;
        }
        currentSound = musicMaster.PlaySound(TaskType.ToLowerInvariant(), transform.position);
		ParticleSystem.startColor = item.Color;
		return true;
	}
	public override void GetItem(IngredientBase item)
	{
		musicMaster.OneShot("bin", transform.position);
	}