# Path: BGE/bghelper/mesh.py
# def get_dimensions(object=None, roundit=3, offset=1, meshnum=0, factor_in_scale=1):
#     """
#     Gets the dimensions of the object (what you see under dimensions in the properties window in the 3D menu).
#     mesh = which mesh to use to get the object's dimensions.
#     roundit = how far down to round the returned dimension values; set it to a negative number to not round the numbers off at all.
#     offset = Whether or not to return the offset point of the dimensions (the center point);
#     This negated (-offset, literally) is the origin point, generally.
#     meshnum = The index of the mesh to use. Usually 0 is okay.
#     factor_in_scale = If it should multiply the dimensions by the object's world scale.
#     """
# 
#     if object == None:
#         object = logic.getCurrentController().owner
# 
#     s = object.worldScale
# 
#     mesh = object.meshes[meshnum]
# 
#     # print (dir(mesh))
# 
#     verts = [[], [], []]
# 
#     originpos = [0, 0, 0]
# 
#     for mat in range(len(mesh.materials)):
# 
#         for v in range(mesh.getVertexArrayLength(mat)):
#             vert = mesh.getVertex(mat, v)
# 
#             pos = vert.getXYZ()
# 
#             verts[0].append(pos[0])
#             verts[1].append(pos[1])
#             verts[2].append(pos[2])
# 
#     verts[0].sort()
#     verts[1].sort()
#     verts[2].sort()
# 
#     if offset != 0:
#         offsetpos = [
#             (verts[0][len(verts[0]) - 1] + verts[0][0]) / 2,
#             (verts[1][len(verts[1]) - 1] + verts[1][0]) / 2,
#             (verts[2][len(verts[2]) - 1] + verts[2][0]) / 2,
#         ]
# 
#     size = [(verts[0][len(verts[0]) - 1] - verts[0][0]),
#             (verts[1][len(verts[0]) - 1] - verts[1][0]),
#             (verts[2][len(verts[0]) - 1] - verts[2][0])]
# 
#     if factor_in_scale:
#         size = [size[0] * s[0],
#                 size[1] * s[1],
#                 size[2] * s[2]]
# 
#     if roundit >= 0:
#         size = [
#             round(size[0], roundit),
#             round(size[1], roundit),
#             round(size[2], roundit),
#         ]
# 
#     if offset:
#         return (mathutils.Vector(size), mathutils.Vector(offsetpos))
# 
#     else:
#         return (mathutils.Vector(size), None)
# 
# Path: BGE/bghelper/math.py
# def clamp(value, minimum, maximum):
#     """
#     Clamp: Clamps the specified 'value' between the maximum and minimum values.
#     Returns 'max' when 'value' is greater than 'max', 'min' when 'value' is less than 'min',
#     and 'value' itself when neither is true.
#     """
#     return (min(max(value, minimum), maximum))


import random
import math
import copy
import mathutils
from bge import logic
from .mesh import get_dimensions
from .math import clamp

    NOTE: Each game object that gets spawned gets a property called rlg_info with information about its place in the
    level generation recorded in it. The rlg_info property has three keys: "shape", "pos", and "type".

    The "shape" key equals one of the RLG_POP_xxxxx constants, which dictates what shape the object spawned was supposed to be.
    The "pos" key equals the grid position in the random level map, with the Y-coordinate (or row) first, and the X-coordinate second.
    The "type" key equals what type of object was spawned based on the random level map's numbers (i.e. it's a 1 if it was spawned
    where a 1 was on the random level map).

    Returns a dictionary comprised of two keys:
    "spawned: A list of all room objects spawned
    "room_map": The room_list that you fed in, but with the values replaced by references to the room objects spawned
    (useful for storage and looking up a room in the list later)

    """

    sce = logic.getCurrentScene()
    cont = logic.getCurrentController()
    obj = cont.owner

    spawned = []

    rl = copy.deepcopy(room_list)

    if not varying_size:

        i = list(room_4way.keys())[0]

        r = room_4way[i]


# Path: BGE/bghelper/mesh.py
# def get_dimensions(object=None, roundit=3, offset=1, meshnum=0, factor_in_scale=1):
#     """
#     Gets the dimensions of the object (what you see under dimensions in the properties window in the 3D menu).
#     mesh = which mesh to use to get the object's dimensions.
#     roundit = how far down to round the returned dimension values; set it to a negative number to not round the numbers off at all.
#     offset = Whether or not to return the offset point of the dimensions (the center point);
#     This negated (-offset, literally) is the origin point, generally.
#     meshnum = The index of the mesh to use. Usually 0 is okay.
#     factor_in_scale = If it should multiply the dimensions by the object's world scale.
#     """
# 
#     if object == None:
#         object = logic.getCurrentController().owner
# 
#     s = object.worldScale
# 
#     mesh = object.meshes[meshnum]
# 
#     # print (dir(mesh))
# 
#     verts = [[], [], []]
# 
#     originpos = [0, 0, 0]
# 
#     for mat in range(len(mesh.materials)):
# 
#         for v in range(mesh.getVertexArrayLength(mat)):
#             vert = mesh.getVertex(mat, v)
# 
#             pos = vert.getXYZ()
# 
#             verts[0].append(pos[0])
#             verts[1].append(pos[1])
#             verts[2].append(pos[2])
# 
#     verts[0].sort()
#     verts[1].sort()
#     verts[2].sort()
# 
#     if offset != 0:
#         offsetpos = [
#             (verts[0][len(verts[0]) - 1] + verts[0][0]) / 2,
#             (verts[1][len(verts[1]) - 1] + verts[1][0]) / 2,
#             (verts[2][len(verts[2]) - 1] + verts[2][0]) / 2,
#         ]
# 
#     size = [(verts[0][len(verts[0]) - 1] - verts[0][0]),
#             (verts[1][len(verts[0]) - 1] - verts[1][0]),
#             (verts[2][len(verts[0]) - 1] - verts[2][0])]
# 
#     if factor_in_scale:
#         size = [size[0] * s[0],
#                 size[1] * s[1],
#                 size[2] * s[2]]
# 
#     if roundit >= 0:
#         size = [
#             round(size[0], roundit),
#             round(size[1], roundit),
#             round(size[2], roundit),
#         ]
# 
#     if offset:
#         return (mathutils.Vector(size), mathutils.Vector(offsetpos))
# 
#     else:
#         return (mathutils.Vector(size), None)
# 
# Path: BGE/bghelper/math.py
# def clamp(value, minimum, maximum):
#     """
#     Clamp: Clamps the specified 'value' between the maximum and minimum values.
#     Returns 'max' when 'value' is greater than 'max', 'min' when 'value' is less than 'min',
#     and 'value' itself when neither is true.
#     """
#     return (min(max(value, minimum), maximum))


# Path: BGE/bghelper/rlg.py
import random
import math
import copy
import mathutils
from bge import logic
from .mesh import get_dimensions
from .math import clamp


    NOTE: Each game object that gets spawned gets a property called rlg_info with information about its place in the
    level generation recorded in it. The rlg_info property has three keys: "shape", "pos", and "type".

    The "shape" key equals one of the RLG_POP_xxxxx constants, which dictates what shape the object spawned was supposed to be.
    The "pos" key equals the grid position in the random level map, with the Y-coordinate (or row) first, and the X-coordinate second.
    The "type" key equals what type of object was spawned based on the random level map's numbers (i.e. it's a 1 if it was spawned
    where a 1 was on the random level map).

    Returns a dictionary comprised of two keys:
    "spawned: A list of all room objects spawned
    "room_map": The room_list that you fed in, but with the values replaced by references to the room objects spawned
    (useful for storage and looking up a room in the list later)

    """

    sce = logic.getCurrentScene()
    cont = logic.getCurrentController()
    obj = cont.owner

    spawned = []

    rl = copy.deepcopy(room_list)

    if not varying_size:

        i = list(room_4way.keys())[0]

        r = room_4way[i]


        roomsize = get_dimensions(r[0])[0]