Ejemplo n.º 1
0
    private void Start()
    {
        inventory       = FindObjectOfType <Inventory>();
        craftingManager = FindObjectOfType <CraftingManager>();

        currentCrafts = new List <CraftingTooltip>();
        ShowCraftingQueue(false);

        craftingManager.OnCraftAddedCallback     += AddToVisualCraftingQueue;
        craftingManager.OnCraftCompletedCallback += RemoveFromVisualCraftingQueue;

        for (int i = 0; i < craftingManager.AvailableRecipes.recipes.Count; i++)
        {
            CraftingRecipeSlot recipeSlot = Instantiate(recipeSlotPrefab, recipeSlotParent.transform).GetComponent <CraftingRecipeSlot>();
            recipeSlot.Initialize(craftingManager.AvailableRecipes.recipes[i], inventory);
        }
    }
Ejemplo n.º 2
0
        private void ParseIngredient(Span <char> ingredientSpan, CraftingRecipe recipe, List <CraftingRecipeSlot> recipeSlots)
        {
            var slot = new Slot {
                ItemCount = 1
            };
            var splitter = ingredientSpan.IndexOf(',');

            ParseItem(ingredientSpan.Slice(0, splitter), ref slot);
            var distributionSpan = ingredientSpan.Slice(splitter + 1);

            do
            {
                var positionSplitter = distributionSpan.IndexOf(',');
                var positionSpan     = positionSplitter == -1 ? distributionSpan : distributionSpan.Slice(0, positionSplitter);

                var recipeSlot = new CraftingRecipeSlot {
                    Slot = slot
                };
                if (positionSpan.Length == 1 && positionSpan[0] == '*')
                {
                    recipeSlot.X = -1;
                    recipeSlot.Y = -1;
                }
                else
                {
                    splitter = positionSpan.IndexOf(':');

                    int ParsePoint(ReadOnlySpan <char> span)
                    {
                        if (span.Length != 1)
                        {
                            throw new ArgumentOutOfRangeException(nameof(span));
                        }

                        switch (span[0])
                        {
                        case '1':
                            return(0);

                        case '2':
                            return(1);

                        case '3':
                            return(2);

                        case '*':
                            return(-1);

                        default:
                            throw new ArgumentOutOfRangeException(nameof(span));
                        }
                    }

                    recipeSlot.X = ParsePoint(positionSpan.Slice(0, splitter));
                    recipeSlot.Y = ParsePoint(positionSpan.Slice(splitter + 1));
                }

                recipeSlots.Add(recipeSlot);

                if (positionSplitter == -1)
                {
                    break;
                }
                else
                {
                    distributionSpan = distributionSpan.Slice(positionSplitter + 1);
                }
            }while (true);
        }