/// <summary>
 /// Deletes an ingredient group
 /// </summary>
 /// <param name="group">Reference to the group</param>
 public void DeleteIngredientGroup(IngredientGroup group)
 {
     if (products.Contains(group))
     {
         products.Remove(group);
     }
 }
Ejemplo n.º 2
0
 private static void UpdateTexts(IngredientGroup ingrGroup, Transform instance)
 {
     UI.ChildText(instance, "Name", ingrGroup.Ingredient.ingredientName);
     UI.ChildText(instance, "Amount", ingrGroup.Amount.ToString());
     UI.ChildText(instance, "ExpiresIn", ingrGroup.ExpireTime.ToString() + (ingrGroup.ExpireTime > 1 ? " days" : " day"));
     UI.ChildText(instance, "Quality", ingrGroup.Quality.ToString());
 }
    /// <summary>
    /// Adds ingredients to the storage
    /// </summary>
    /// <param name="name">Ingredient's name (must exist as ScriptableObject)</param>
    /// <param name="quantity">The amount of ingredients</param>
    /// <param name="quality">A quality number between 0 and 1</param>
    public void BuyIngredients(string name, float quantity, float quality)
    {
        //try
        {
            // Find the ingredient reference
            Ingredient ingredientToBuy = allIngredients.Find(ingr => ingr.ingredientName == name);

            // Check if there's an existing group of that ingredient with the same expiery date
            System.Predicate <IngredientGroup> match = ingGr =>
                                                       ingGr.Ingredient.ingredientName == name &&
                                                       ingGr.ExpireTime == ingredientToBuy.expireTime &&
                                                       ingGr.Quality == quality;
            IngredientGroup existingGroup = Storage.Instance.products.Find(match);

            // If yes add the quantity
            // Else create new ingredient group
            if (existingGroup != null)
            {
                existingGroup.Amount += quantity;
            }
            else
            {
                IngredientGroup ingredientGroup = new IngredientGroup(ingredientToBuy, quantity)
                {
                    Quality = quality
                };
                Storage.Instance.products.Add(ingredientGroup);
            }
        }
        //catch ( System.Exception e )
        {
            //Debug.Log("Error buying igredient " + name + "! " + e.Message);
        }
    }
Ejemplo n.º 4
0
        private static List <IngredientGroup> GetIngredientGroups(IDataReader reader)
        {
            var ingredientGroups = new List <IngredientGroup>();

            while (reader.Read())
            {
                var ingredientGroup = new IngredientGroup
                {
                    ExternalId = reader[0].ToString(),
                    GroupName  = reader[1].ToString(),
                };
                ingredientGroups.Add(ingredientGroup);
            }

            return(ingredientGroups);
        }
        //__Create a default recipe box if there is no data
        public static RecipeBox generateDefault()
        {
            var newBox = new RecipeBox();
            for (int i = 0; i < 5; i++)
            {
                string message;
                var sourdough = new SourdoughRecipe();
                sourdough.Name = "Sourdough " + i;

                var breadFlour = new Ingredient("Bread Flour", IngredientType.Dry);
                breadFlour.Percent = 53.9;
                sourdough.Preferment.AddIngredient(breadFlour, out message);
                Starter starter = new Starter("Standard", 166);
                starter.Percent = 46.1;
                sourdough.Preferment.AddIngredient(starter);
                sourdough.Preferment.Percent = 37.1;

                var Dry = new IngredientGroup(IngredientType.Dry, "Dry", 30.2, sourdough);
                var flour = new Ingredient("Bread Flour", IngredientType.Dry, Dry);
                flour.Percent = 67;
                Dry.AddIngredient(flour);
                var wwFlour = new Ingredient("Whole Wheat", IngredientType.Dry, Dry);
                Dry.AddIngredient(wwFlour);
                wwFlour.Percent = 33;
                sourdough.AddGroup(Dry, out message);

                var wet = new IngredientGroup(IngredientType.Wet, "Water", 31.9, sourdough);
                var water = new Ingredient("Water", IngredientType.Wet, wet);
                water.Percent = 100;
                wet.AddIngredient(water);
                sourdough.AddGroup(wet, out message);

                var salt = new IngredientGroup(IngredientType.Salt, "Salt", 2, sourdough);
                var s = new Ingredient("Pink Himalayan", IngredientType.Salt, salt);
                s.Percent = 100;
                salt.AddIngredient(s);
                sourdough.AddGroup(salt, out message);

                sourdough.Description = "This is one wicked SD, chock full of love and ready to party!!!";
                sourdough.Weight = 1000;

                newBox.SourdoughRecipes.Add(sourdough);
            }

            return newBox;
        }
Ejemplo n.º 6
0
    //*** Membrane Ingredients ****//



    public void AddMembrane(string filePath, Vector3 position, Quaternion rotation)
    {
        var groupName = "membrane";
        var groupPath = "root.envelope." + groupName;

        var nameInner = "inner_membrane";
        var nameOuter = "outer_membrane";

        var pathInner = groupPath + "." + nameInner;
        var pathOuter = groupPath + "." + nameOuter;


        RemoveElementFromHierarchy("membrane");
        RemoveIngredientGroupFromName("membrane");
        RemoveIngredientGroupFromName("membrane");

        _ingredientNames.Clear();
        LipidIngredientNames.Clear();
        RemoveIngredientGroup(groupPath);
        RemoveElementFromHierarchy(groupPath);

        CPUBuffers.Get.LipidAtomPositions.Clear();
        CPUBuffers.Get.LipidInstanceInfos.Clear();
        CPUBuffers.Get.LipidInstanceInfos2.Clear();
        CPUBuffers.Get.LipidInstancePositions.Clear();

        //*****//

        AddIngredientToHierarchy(pathInner);
        AddIngredientToHierarchy(pathOuter);
        LipidIngredientNames.Add(pathInner);
        LipidIngredientNames.Add(pathOuter);

        var ingredientIdInner = AllIngredientNames.IndexOf(pathInner);
        var ingredientIdOuter = AllIngredientNames.IndexOf(pathOuter);

        var envelopeSurfaceGroup  = GetIngredientGroup("root.envelope.surface");
        var envelopeMembraneGroup = new IngredientGroup();

        envelopeMembraneGroup.Ingredients    = new List <Ingredient>();
        envelopeMembraneGroup.compartment_id = envelopeSurfaceGroup.compartment_id;
        envelopeMembraneGroup.unique_id      = IngredientGroups.Count;
        envelopeMembraneGroup._groupType     = -1;
        envelopeMembraneGroup.name           = groupName;
        envelopeMembraneGroup.path           = groupPath;
        envelopeMembraneGroup.NumIngredients = 2;

        var innerMembraneIngredient = new Ingredient();

        innerMembraneIngredient.nbMol              = 1;
        innerMembraneIngredient._nbChains          = 1;
        innerMembraneIngredient._ingredientGroupId = envelopeMembraneGroup.unique_id;
        innerMembraneIngredient._ingredientId      = ingredientIdInner;
        innerMembraneIngredient.name = nameInner;
        innerMembraneIngredient.path = pathInner;

        var outerMembraneIngredient = new Ingredient();

        outerMembraneIngredient.nbMol               = 1;
        outerMembraneIngredient.nbChains            = 1;
        outerMembraneIngredient.ingredient_group_id = envelopeMembraneGroup.unique_id;
        outerMembraneIngredient._ingredientId       = ingredientIdOuter;
        outerMembraneIngredient.name = nameOuter;
        outerMembraneIngredient.path = pathOuter;

        envelopeMembraneGroup.Ingredients.Add(innerMembraneIngredient);
        envelopeMembraneGroup.Ingredients.Add(outerMembraneIngredient);
        IngredientGroups.Add(envelopeMembraneGroup);

        ColorManager.Get.InitColors();

        //int a = 0;

        var currentLipidAtoms = new List <Vector4>();
        var membraneData      = MyUtility.ReadBytesAsFloats(filePath);

        var step            = 5;
        var dataIndex       = 0;
        var lipidAtomStart  = 0;
        var previousLipidId = -1;

        while (true)
        {
            var flushCurrentBatch  = false;
            var breakAfterFlushing = false;

            if (dataIndex >= membraneData.Count())
            {
                flushCurrentBatch  = true;
                breakAfterFlushing = true;
            }
            else
            {
                var lipidId = (int)membraneData[dataIndex + 4];
                if (previousLipidId < 0)
                {
                    previousLipidId = lipidId;
                }
                if (lipidId != previousLipidId)
                {
                    flushCurrentBatch = true;
                    previousLipidId   = lipidId;
                }
            }

            if (flushCurrentBatch)
            {
                var bounds = AtomHelper.ComputeBounds(currentLipidAtoms);
                var center = new Vector4(bounds.center.x, bounds.center.y, bounds.center.z, 0);
                for (var j = 0; j < currentLipidAtoms.Count; j++)
                {
                    currentLipidAtoms[j] -= center;
                }

                var innerMembrane = Vector3.Magnitude(bounds.center) < 727;

                Vector4 batchPosition = position + bounds.center;
                batchPosition.w = Vector3.Magnitude(bounds.extents);

                CPUBuffers.Get.LipidInstancePositions.Add(batchPosition);
                CPUBuffers.Get.LipidInstanceInfos.Add(new Vector4(innerMembrane ? ingredientIdInner : ingredientIdOuter, lipidAtomStart, currentLipidAtoms.Count));
                CPUBuffers.Get.LipidInstanceInfos2.Add(new Vector4((int)InstanceState.Normal, 0, 0));

                lipidAtomStart += currentLipidAtoms.Count;
                CPUBuffers.Get.LipidAtomPositions.AddRange(currentLipidAtoms);
                currentLipidAtoms.Clear();

                if (breakAfterFlushing)
                {
                    break;
                }
            }

            var currentAtom = new Vector4(membraneData[dataIndex], membraneData[dataIndex + 1], membraneData[dataIndex + 2], membraneData[dataIndex + 3]);
            currentLipidAtoms.Add(currentAtom);
            dataIndex += step;
        }
    }
Ejemplo n.º 7
0
 public ActionResult Update(IngredientGroup request)
 {
     _ingredientGroupService.Update(request);
     return(RedirectToAction(Request.Form["View"], EntityType.IngredientGroup.ToString()));
 }
Ejemplo n.º 8
0
 public void Remove(IngredientGroup item)
 {
     _auditEventListener.OnPreDelete(item);
     _dataBaseSqlServerOrmLite.LogicRemove(item);
 }
Ejemplo n.º 9
0
 public void Update(IngredientGroup item)
 {
     _auditEventListener.OnPreUpdate(item);
     _dataBaseSqlServerOrmLite.Update(item);
 }
Ejemplo n.º 10
0
 public void Add(IngredientGroup item)
 {
     _auditEventListener.OnPreInsert(item);
     _dataBaseSqlServerOrmLite.Insert(item);
 }