public void IngredientDataSerializationTest()
        {
            var complete = new IngredientData
            {
                Id      = "a_test_id_42",
                Text    = "lorem ipsum dolor sit amet",
                Rank    = 42,
                Percent = 42.42f,
            };
            var json = JsonConvert.SerializeObject(complete);

            json.Should().Be(completeJsonData.ToString(Formatting.None));

            var incomplete = new IngredientData
            {
                Id   = "a_test_id_42",
                Text = "lorem ipsum dolor sit amet",
            };

            json = JsonConvert.SerializeObject(incomplete);
            var incompleteJsonStr = incompleteJsonData.ToString(Formatting.None);
            var i = incompleteJsonStr.LastIndexOf('}');

            incompleteJsonStr = incompleteJsonStr.Remove(i, 1);
            json.StartsWith(incompleteJsonStr).Should().Be(true);
        }
    void Update()
    {
        if (attacking)
        {
            Debug.Log("attacking");
            // todo: add food preparation
            Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayer);
            Debug.LogFormat("{0} objects hit", hitEnemies.Length);
            foreach (Collider2D enemy in hitEnemies)
            {
                Debug.LogFormat("Enemy: {0}", enemy.tag);
                // Calculate Angle Between the collision point and the player
                Vector2 dir = (Vector2)enemy.gameObject.transform.position - new Vector2(transform.position.x, transform.position.y);
                // We then get the opposite (-Vector3) and normalize it
                dir = -dir.normalized;
                // And finally we add force in the direction of dir and multiply it by force.

                enemy.GetComponent <Rigidbody2D>().AddForce(-dir * (bouceForce + 330));

                enemy.GetComponent <EnemyHealthManager>().DealDamage(1);
            }
            attacking = hitEnemies.Length == 0;
            Collider2D[] hitIngreds = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, ingredientLayer);
            foreach (Collider2D ingred in hitIngreds)
            {
                IngredientData ingredientData = levelManager.GetIngredientData(ingred.GetComponent <IngredientObject>().ingredient.id);
                if (ingredientData.preperable)
                {
                    ingred.GetComponent <IngredientObject>().ingredient.prepared = true;
                    ingred.GetComponent <SpriteRenderer>().sprite = ingredientData.preparedSprite;
                }
            }
        }
    }
    // ------------------------------------------------------------------------
    // Functions
    // ------------------------------------------------------------------------
    public void StartGame(
        CharacterData character,
        DrinkRequestData request,
        SpellData[] spells,
        IngredientData[] ingredients
        )
    {
        Assert.IsTrue(ingredients.Length >= c_handSize);

        m_character = character;
        m_request   = request;

        // shuffle ingredients and draw starting hand
        m_ingredients = new Deck <IngredientData>();
        foreach (IngredientData ingredient in ingredients)
        {
            m_ingredients.Push(ingredient);
        }
        m_ingredients.Shuffle();

        IngredientData[] startingHand = new IngredientData[c_handSize];
        for (int i = 0; i < c_handSize; i++)
        {
            startingHand[i] = m_ingredients.Pop();
        }

        // populate all UI
        CardGameUI.StartGame(spells, startingHand);
    }
    /// <summary>
    /// Would be called when the player cooks their food, probably in the inventory
    /// manager script.
    /// This will take in a stack (inventory skewer) and compare the flavors on it to the
    /// recipe book. If it finds a match, it returns that RecipeData.
    ///
    /// </summary>
    public RecipeData CompareToRecipes(Stack <IngredientData> currentSkewer)
    {
        //create a backup copy of the array to be restored, as elements are removed to prevent
        //double-checking.
        IngredientData[] ingredientArray     = currentSkewer.ToArray();
        IngredientData[] ingredientArrayCopy = new IngredientData[ingredientArray.Length];
        Array.Copy(ingredientArray, ingredientArrayCopy, ingredientArray.Length);

        bool recipeLookupFailed = false;

        //iterate over all recipes
        for (int i = 0; i < recipes.Length; i++)
        {
            RecipeData currentRecipe = recipes[i];
            recipeLookupFailed = false;
            Array.Copy(ingredientArrayCopy, ingredientArray, ingredientArray.Length);

            //Debug.Log("Checking recipe: " + currentRecipe.displayName);

            //iterate over each flavor of the current recipe
            for (int currentFlavor = 0; currentFlavor < currentRecipe.flavors.Length; currentFlavor++)
            {
                //If we failed to find the last ingredient, abandon this recipe and try the next
                if (recipeLookupFailed)
                {
                    //Debug.Log("Ingredient missing, recipe failed. Try next.");
                    break;
                }

                //Debug.Log("Checking for presence of flavor " + currentRecipe.flavors[currentFlavor]);

                //iterate over each ingredient on the active skewer
                for (int currentIngredient = 0; currentIngredient < ingredientArray.Length; currentIngredient++)
                {
                    //Debug.Log("Scanning ingredient " + currentIngredient + " of active skewer");
                    //if the flavor of the current ingredient matches the recipe flavor currently being tested...
                    if ((ingredientArray[currentIngredient] == null ? 0 : ingredientArray[currentIngredient].flavors & currentRecipe.flavors[currentFlavor]) > 0)
                    {
                        //this flavor is on the skewer, so continue but remove it from the skewer so it isn't counted twice
                        ingredientArray[currentIngredient] = null;
                        recipeLookupFailed = false;

                        //break the loop to check the next flavor on the recipe
                        break;
                    }
                    recipeLookupFailed = true;
                }
            }
            //if you got here without failing, the recipe is a match, so return it
            if (!recipeLookupFailed)
            {
                Debug.Log("found recipe match: " + currentRecipe.displayName);
                return(currentRecipe);
            }
        }

        //if you get through all the recipes without a match, return null
        Debug.Log("No matches found");
        return(null);
    }
Exemple #5
0
    public void AddIngredient(IngredientData iData)
    {
        var ingredientPrefab = Resources.Load <GameObject>("IngridientsModelsAsPrefabs/" + iData.viewModel.name);

        var newIngredientSpawned = Instantiate(ingredientPrefab, transform);

        ingredientsInDish.Add(newIngredientSpawned);

        _currentRecipe.Add(iData);

        if (_currentRecipe.Count == 0)
        {
            newIngredientSpawned.transform.position = stackOriginPoint;

            return;
        }

        Vector3 originPoint = transform.position + Vector3.up;

        Ray ray = new Ray(originPoint, Vector3.down);

        RaycastHit hit;

        Physics.Raycast(ray, out hit, 100f, raycastMask);

        newIngredientSpawned.transform.position = hit.point;
    }
Exemple #6
0
    /// <summary>
    /// Remove an ingredient from the active skewer
    /// </summary>
    public IngredientData RemoveFromSkewer()
    {
        IngredientData topIngredient = quiver[activeSkewer].PopIngredient();

        UpdateUI();
        return(topIngredient);
    }
Exemple #7
0
    void Awake()
    {
        // Singleton pattern
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        // Reading JSONs
        var ingredientDataJSONs = JsonHelper.FromJson <IngredientDataJSON>(StringFromFile("ingredients"));

        comboData = JsonUtility.FromJson <ComboData>(StringFromFile("combos"));

        // Filling dictionaries
        foreach (var element in ingredientDataJSONs)
        {
            var ingredientData = new IngredientData(element);
            ingredientDict[ingredientData.type] = ingredientData;

            var sprite = Resources.Load <Sprite>
                             ($"IngredientSprites/Ingredient{ingredientData.type.ToString()}") as Sprite;
            ingredientSpritesDict[ingredientData.type] = sprite;
        }
    }
        public void TestCreateIngredient()
        {
            var ingredientData = new IngredientData();

            var result = ingredientData.CreateIngredient("myName", "myDescription");

            Assert.IsNotNull(result);
        }
        public void TestDeleteIngredient()
        {
            var ingredientData = new IngredientData();

            var result = ingredientData.DeleteIngredient(5);

            Assert.IsTrue(result);
        }
        public void TestUpdateIngredient()
        {
            var ingredientData = new IngredientData();

            var result = ingredientData.UpdateIngredient(8, "MyNewName2", "myNewDescription2");

            Assert.IsNotNull(result);
        }
        public void TestRetrieveIngredients()
        {
            var ingredientData = new IngredientData();

            var result = ingredientData.RetrieveIngredients();

            Assert.IsNotNull(result);
        }
Exemple #12
0
    private void SetData()
    {
        data = IngredientData.GetRandomIngredient();
        this.spriteRenderer.sprite = ingredientSprites.GetSpriteFromName(data.name);
        Vector3 newSize = spriteRenderer.sprite.bounds.size;

        GetComponent <BoxCollider2D> ().size = new Vector2(newSize.x, newSize.y);
    }
    public void UpdatePlantCard(IngredientData ingredientData)
    {
        Translator translator = GameManager.instance.GetComponent <Translator>();

        plantName.text    = ingredientData.plantName;
        plantTrait.text   = translator.GetTranslation(ingredientData.trait);
        plantImage.sprite = UIController.CreateSpriteFromTexture(ingredientData.ingredientTexture);
    }
Exemple #14
0
    public void InitialiseIngredientData(IngredientData data)
    {
        ingredient = data;

        GameObject prefab = IngredientDataLookupManager.Instance.GetPrefabForIngredientType(ingredient);

        Instantiate(prefab, visualRoot);
    }
Exemple #15
0
    private void Show()
    {
        if (show)
        {
            if (reset)
            {
                // get random favorite

                RecipeDatabase rdb = player.GetComponentInChildren <RecipeDatabase>();
                Sprite         s;
                //if (Random.Range(0f, 1.0f) < 0.5f)
                //{
                // random ingredient
                int    len = flavors.favoriteIngredients.Length;
                string fav = flavors.favoriteIngredients[Random.Range(0, len - 1)];
                // get from ingredients
                IngredientData d = rdb.allIngredients[fav];
                // display
                s = d.image;
                //}

                /*else
                 * {
                 *  // favorite flavor
                 *  Debug.Log(flavors.favoriteFlavors);
                 *  string ff = rdb.flavorToString[flavors.favoriteFlavors];
                 *  Debug.Log(ff);
                 *  // get image from database
                 *  //s = rdb.allFlavors[ff];
                 *  s = rdb.allFlavors[ff];
                 * }*/

                Debug.Log(s.name);
                fruitRender.sprite = s;

                // set sprite
                StartCoroutine(EndAfterSeconds(2));

                if (audio != null)
                {
                    GameObject sfx = Instantiate(audioPlayer, transform.position, Quaternion.identity);
                    sfx.GetComponent <PlayAndDestroy>().Play(audio);
                    sfx.GetComponent <AudioSource>().volume /= 2;
                }
                reset = false;
            }

            fruitRender.enabled  = true;
            bubbleRender.enabled = true;
        }
        else
        {
            fruitRender.enabled  = false;
            bubbleRender.enabled = false;
            reset = true;
        }
    }
Exemple #16
0
 public IngredientData(IngredientData data, int qty)
 {
     Ingredient = data.Ingredient;
     Capacity   = data.Capacity;
     Durability = data.Durability;
     Flavor     = data.Flavor;
     Texture    = data.Texture;
     Calories   = data.Calories;
     Qty        = qty;
 }
 public void SpawnText(IngredientData data, Vector2 position)
 {
     q.Enqueue(new CallData {
         data = data, position = position
     });
     if (q.Count == 1)
     {
         StartCoroutine(SpawnAndWait());
     }
 }
Exemple #18
0
 public Ingredient()
 {
     EditorID      = new SimpleSubrecord <String>("EDID");
     ObjectBounds  = new ObjectBounds("OBND");
     Model         = new Model();
     EquipmentType = new SimpleSubrecord <EquipmentType>("ETYP");
     Weight        = new SimpleSubrecord <Single>("DATA");
     Data          = new IngredientData("ENIT");
     Effects       = new List <Effect>();
 }
Exemple #19
0
    public void StartChopping(IngredientData data, Action callback)
    {
        InUse          = true;
        mData          = data;
        OnChoppingDone = callback;

        mCurrentObject = Instantiate <GameObject>(mData.MainObject, mSpawn.position, Quaternion.identity, transform);
        mCurrentObject.transform.localScale *= mObjectScaleMultiplier;
        StartCoroutine(DoChopping());
    }
Exemple #20
0
    public void Setup(IngredientData ingredient)
    {
        var aoh = ResourceManager.instance.GetAtomSpriteAOH(ingredient.atomEnum, (int)ingredient.level);

        aoh.Completed += _ =>
        {
            ingredientImage.sprite = aoh.Result as Sprite;
        };
        ingredientName.SetText($"{ingredient.atomEnum}\n{ingredient.level:0}");
        ingredientCount.SetText($"x{ingredient.count:0}");
    }
Exemple #21
0
    private void OnTransferDone()
    {
        mData        = null;
        InUse        = false;
        mRedyToServe = true;

        if (OnPepDone != null)
        {
            OnPepDone();
        }
    }
 public GameObject GetPrefabForIngredientType(IngredientData data)
 {
     if (lookup.IngredientPrefabDictionary.ContainsKey(data.ProcessedIngredient))
     {
         return(lookup.IngredientPrefabDictionary[data.ProcessedIngredient]);
     }
     else
     {
         return(lookup.GarbagePrefab);
     }
 }
Exemple #23
0
    public void Setup(IngredientData _ingredientData)
    {
        ingredientData = _ingredientData;
        var aoh = ResourceManager.instance.GetAtomSpriteAOH(ingredientData.atomEnum, (int)ingredientData.level);

        aoh.Completed += _ =>
        {
            ingredientImage.sprite = aoh.Result as Sprite;
        };
        RefreshRequirement();
    }
Exemple #24
0
    public void Reset()
    {
        for (int Idx = 0; Idx < ItemsInPlate.Count; Idx++)
        {
            Destroy(ItemsInPlate[Idx].GetObject());
        }

        mCurrentData      = null;
        OnTrasferringDone = null;
        ItemsInPlate.Clear();
    }
Exemple #25
0
    public Backend()
    {
        Sprite[] sprites = Resources.LoadAll <Sprite>("SpriteAtlas");

        for (int i = 0; i < sprites.Length; i++)
        {
            IngredientData data = ScriptableObject.CreateInstance <IngredientData>();
            string         Id   = string.Format("ID-{0}", (i).ToString("D2"));
            data.Init(Id, (IngredientType)(i), sprites[i]);
            _ingredientData.Add(Id, data);
        }
    }
    void Start()
    {
        if (GameManager.Instance != null && GameManager.Instance.SaladIngredientConfig != null)
        {
            mIngredientData = GameManager.Instance.SaladIngredientConfig.IngredientData.Find(s => s.Type == Ingredient);
        }

        if (mIngredientData != null)
        {
            InitIngredient();
        }
    }
Exemple #27
0
    public bool ApplyIngredient(Ingredient ingredient, out bool stayHere)
    {
        if (!wig || (!ingredient && !actionStarted) || (ingredient && !wig.HasValidNextStepWith(ingredient)))
        {
            stayHere = false;
            return(false);
        }

        if (!actionStarted)
        {
            actionStarted = true;
            canvas.gameObject.SetActive(true);
            this.ingredient = ingredient;

            recipeBar.sprite = ingredient.data.progressionBar;

            ingredient.icon.gameObject.SetActive(false);
            ingredient.gameObject.SetActive(true);

            stayHere = true;

            return(true);
        }

        actionCounter += Time.deltaTime;

        float percent = Mathf.Clamp(actionCounter / this.ingredient.data.actionPressSeconds, 0f, 1f);

        progressBar.anchoredPosition = new Vector2(-mask.rect.width * (1 - percent), progressBar.anchoredPosition.y);

        if (actionCounter >= this.ingredient.data.actionPressSeconds)
        {
            actionStarted = false;
            actionCounter = 0f;

            IngredientData newIngredientData = RecipeManager.Instance.GetResultingIngredient(wig.data, this.ingredient.data);
            HairReferencer refer             = wig.GetComponent <HairReferencer>();

            hairMeshes[wig.data.wigIndex].gameObject.SetActive(false);
            refer.hairs[wig.data.wigIndex].gameObject.SetActive(false);
            wig.data = newIngredientData;
            hairMeshes[wig.data.wigIndex].gameObject.SetActive(true);
            refer.hairs[wig.data.wigIndex].gameObject.SetActive(true);

            Destroy(this.ingredient.gameObject);
            this.ingredient = null;
        }

        stayHere = true;

        return(false);
    }
    //Update the UI elements with data
    public void UpdatePlantTutorial(IngredientData ingredientData)
    {
        Translator translator;

        translator                = UIController.Instance.translator;
        plantNameText.text        = ingredientData.plantName;
        plantDescriptionText.text = translator.GetTranslation(ingredientData.description);
        flavorText.text           = translator.GetTranslation(ingredientData.flavor);
        traitText.text            = translator.GetTranslation(ingredientData.trait);
        cookTimeText.text         = ingredientData.cookTime + " seconds";

        plantImage.sprite = UIController.CreateSpriteFromTexture(ingredientData.ingredientTexture);
    }
    public static bool ShouldShowPlantCard(IngredientData ingredientData)
    {
        GlobalSaveData data = GameManager.instance.globalSaveData;

        if (data.encounteredIngredients.Contains(ingredientData.plantName))
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemple #30
0
    void Drop()
    {
        GameObject heldObj;

        heldObj       = rightHandObj;
        rightHandFree = true;

        heldObj.transform.parent = null;


        if (Physics.Raycast(playerCam.position, playerCam.forward, out hit, grabRange))
        {
            if (hit.collider.tag == "Intake")
            {
                Debug.Log("Intake Drop.");

                InstaPresser insta = hit.collider.transform.parent.GetComponent <InstaPresser>();
                if (insta == null)
                {
                    Debug.Log("Instapresser not found...");
                }
                IngredientData ingData = heldObj.GetComponent <Ingredient>().data;
                if (ingData == null)
                {
                    Debug.Log("Ingredient data null.");
                }
                insta.AddIngredient(ingData); // this line is awful
                // Drop ingredient into intake
                Destroy(heldObj);
            }
            else
            {
                heldObj.transform.position    = hit.point + hit.normal * 0.2f;
                heldObj.transform.eulerAngles = hit.normal;
            }
        }

        else
        {
            heldObj.transform.position = dropPoint.transform.position;
        }
        Rigidbody heldObjRB = heldObj.GetComponent <Rigidbody>();
        Rigidbody playerRB  = player.GetComponent <Rigidbody>();

        heldObjRB.isKinematic     = false;
        heldObjRB.velocity        = playerRB.velocity;
        heldObjRB.angularVelocity = playerRB.angularVelocity;

        heldObj.layer = 0;
        heldObj       = null;
    }
 private void updateWarningIcon(IngredientData data, GameObject lineItemInstance)
 {
     GameObject warningIcon = lineItemInstance.transform.Find("Warning").gameObject;
     warningIcon.SetActive(data.hasMultiplePrimaryGuesses() || data.hasMultipleSecondaryGuesses());
 }
Exemple #32
0
 private static bool RemoveIngredientFromList(List<Ingredient> list, IngredientData data, ref List<Ingredient> returnList)
 {
     foreach (Ingredient current in list)
     {
         if (data.IsIngredientMeOrAChildOfMe(current, null))
         {
             list.Remove(current);
             if (returnList != null)
             {
                 returnList.Add(current);
             }
             return true;
         }
     }
     return false;
 }