package konstructs.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * View is a class that represents the HUD as shown to the user
 * The HUD has 14 rows and 17 columns. To populate the View
 * one can place Inventories into the View with the help of
 * the InventoryView class.
 *
 * The different parts of the HUD is accessed through the HUD index
 * this index is a simple index treating the HUD as a flat array,
 * rather than a 2 dimensional surface. View and InventoryView automatically
 * takes care of all the conversions between HUD indexes and the 2 dimensional
 * coordinates of the actual on screen HUD.
 *
 * @see Inventory
 * @see InventoryView
 */
public final class View {
    public static final int COLUMNS = 17;
    public static final int ROWS = 14;

    private static final Map<Integer, Stack> EMPTY_MAP = Collections.emptyMap();
    /**
     * Definition of an empty view with no content. This is
     * the starting point to create a view.
     */
    public static final View EMPTY = new View(EMPTY_MAP);
    private final Map<Integer, Stack> items;

    private View(Map<Integer, Stack> items) {
        this.items = items;
    }

    /**
     * Get the mapping between HUD indexes and stacks of this view
     * @return A mapping from HUD index to Stack
     * @see Stack
     */
    public Map<Integer, Stack> getItems() {
        return items;
    }

    /**
     * Add an inventory to this View
     * Returns a new view to which the Inventory has been added
     * @param inventoryView The InventoryView that defines where in the HUD
     *                      the inventory should be shown as well as the dimensions
     *                      of it
     * @param inventory The Inventory to show in the HUD
     * @return A new View that shows the given inventory at the given position
     * @see Inventory
     * @see InventoryView
     */
    public View add(InventoryView inventoryView, Inventory inventory) {
        Map<Integer, Stack> newItems = new HashMap<>(items);
        for(int row = 0; row < inventoryView.getRows(); row++) {
            for (int column = 0; column < inventoryView.getColumns(); column++) {
                int r = row + inventoryView.getRowOffset();
                int c = column + inventoryView.getColumnOffset();
                newItems.put(r * COLUMNS + c, inventory.getStacks()[row * inventoryView.getColumns() + column]);
            }
        }
        return new View(newItems);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        View view = (View) o;

        return items.equals(view.items);

    }

    @Override
    public int hashCode() {
        return items.hashCode();
    }

    @Override
    public String toString() {
        return "View(" +
                "items=" + items +
                ')';
    }
}

@@ -1434,27 +1434,22 @@
  * Add a
-n inventory
+ block
  to this
@@ -1493,25 +1493,21 @@
 ich the 
-Inventory
+block
  has bee
@@ -1622,25 +1622,21 @@
     the 
-inventory
+block
  should 
@@ -1707,46 +1707,57 @@
 f it
-%0A     * @param inventory The Inventory
+ (must be 1x1 here)%0A     * @param block The block
  to 
@@ -1817,170 +1817,1369 @@
 the 
-given inventory at the given position%0A     * @see Inventory%0A     * @see InventoryView%0A     */%0A    public View add(InventoryView inventoryView, Inventory inventory
+block at the given positios%0A     * @see InventoryView%0A     */%0A    public View add(InventoryView inventoryView, Block block) %7B%0A        return add(inventoryView, Stack.createFromBlock(block));%0A    %7D%0A%0A    /**%0A     * Add a stack to this View%0A     * Returns a new view to which the stack has been added%0A     * @param inventoryView The InventoryView that defines where in the HUD%0A     *                      the stack should be shown as well as the dimensions%0A     *                      of it (must be 1x1 here)%0A     * @param stack The stack to show in the HUD%0A     * @return A new View that shows the stack at the given positios%0A     * @see InventoryView%0A     */%0A    public View add(InventoryView inventoryView, Stack stack) %7B%0A        Stack%5B%5D stacks = %7Bstack%7D;%0A        return add(inventoryView, stacks);%0A    %7D%0A%0A    /**%0A     * Add an array of stacks to this View%0A     * Returns a new view to which the array stacks has been added%0A     * @param inventoryView The InventoryView that defines where in the HUD%0A     *                      the inventory should be shown as well as the dimensions%0A     *                      of it%0A     * @param stacks The array of stacks to show in the HUD%0A     * @return A new View that shows the given array of stacks at the given positios%0A     * @see InventoryView%0A     */%0A    public View add(InventoryView inventoryView, Stack%5B%5D stacks
 ) %7B%0A
@@ -3562,29 +3562,14 @@
  c, 
-inventory.getS
+s
 tacks
-()
 %5Brow
@@ -3668,32 +3668,664 @@
 wItems);%0A    %7D%0A%0A
+    /**%0A     * Add an inventory to this View%0A     * Returns a new view to which the Inventory has been added%0A     * @param inventoryView The InventoryView that defines where in the HUD%0A     *                      the inventory should be shown as well as the dimensions%0A     *                      of it%0A     * @param inventory The Inventory to show in the HUD%0A     * @return A new View that shows the given inventory at the given position%0A     * @see Inventory%0A     * @see InventoryView%0A     */%0A    public View add(InventoryView inventoryView, Inventory inventory) %7B%0A        return add(inventoryView, inventory.getStacks());%0A    %7D%0A%0A
     @Override%0A  

Add methods to add stacks and blocks to View