Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if otherStack can be stacked
        /// onto this stack
        /// </summary>
        /// <param name="otherStack">The `Stackable` that may or may not
        /// be able to be stacked</param>
        /// <returns>True if passed `Stackable` can be stacked
        /// on this `Stackable`</returns>
        public bool CanStack(Stackable otherStack)
        {
            if (otherStack.GetType() != GetType()) {
                return false;
            }

            if (Size() >= max - 1 || Size() + otherStack.Size() >= max - 1) {
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if otherStack can be stacked
        /// onto this stack
        /// </summary>
        /// <param name="otherStack">The `Stackable` that may or may not
        /// be able to be stacked</param>
        /// <returns>True if passed `Stackable` can be stacked
        /// on this `Stackable`</returns>
        public bool CanStack(Stackable otherStack)
        {
            if (otherStack.GetType() != GetType())
            {
                return(false);
            }

            if (Size() >= max - 1 || Size() + otherStack.Size() >= max - 1)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add an item to this stack.If a `Stackable` item
        /// is added that has several children, will iterate
        /// through the children first and add them. Then,
        /// it will add the container of the stack. 
        /// If the size of both stacks is larger than the max
        /// allowed, will throw a `NotStackableException`.
        /// </summary>
        /// <param name="stackable">The `Stackable` item to stack</param>
        public void Add(Stackable stackable)
        {
            if (stackable.GetType() != GetType()) {
                throw new NotStackableException("Unable to stack, these items are not of the same type");
            }

            if (Size() >= max - 1 || Size() + stackable.Size() >= max - 1) {
                throw new NotStackableException("Unable to stack: " + this + " with " + stackable);
            }

            foreach(Stackable s in stackable.Stack) {
                Add(s);
            }

            stackable.transform.SetParent(transform);
            stackable.gameObject.SetActive(false);
            stackable.Stack.Clear();
            Stack.Add(stackable);
            UpdateCountLabel();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add an item to this stack.If a `Stackable` item
        /// is added that has several children, will iterate
        /// through the children first and add them. Then,
        /// it will add the container of the stack.
        /// If the size of both stacks is larger than the max
        /// allowed, will throw a `NotStackableException`.
        /// </summary>
        /// <param name="stackable">The `Stackable` item to stack</param>
        public void Add(Stackable stackable)
        {
            if (stackable.GetType() != GetType())
            {
                throw new NotStackableException("Unable to stack, these items are not of the same type");
            }

            if (Size() >= max - 1 || Size() + stackable.Size() >= max - 1)
            {
                throw new NotStackableException("Unable to stack: " + this + " with " + stackable);
            }

            foreach (Stackable s in stackable.Stack)
            {
                Add(s);
            }

            stackable.transform.SetParent(transform);
            stackable.gameObject.SetActive(false);
            stackable.Stack.Clear();
            Stack.Add(stackable);
            UpdateCountLabel();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns true if otherStack is of same
 /// type. This should eventually be replaced
 /// by a custom comparator
 /// </summary>
 /// <param name="otherStack">The `Stackable` to compare types with</param>
 /// <returns>True if passed `Stackable` is of same type</returns>
 public bool IsSameType(Stackable otherStack)
 {
     return otherStack.GetType() == GetType();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if otherStack is of same
 /// type. This should eventually be replaced
 /// by a custom comparator
 /// </summary>
 /// <param name="otherStack">The `Stackable` to compare types with</param>
 /// <returns>True if passed `Stackable` is of same type</returns>
 public bool IsSameType(Stackable otherStack)
 {
     return(otherStack.GetType() == GetType());
 }