MenuState = class(Group, function(o)
	Group.init(o)
	bludG.camera:scrollTo(-bludG.camera.w/2, -bludG.camera.h/2)
	o.tiles = o:add(Group())
	o.boardGrid = {}
	o:setup()
end)
function MenuState:setup()
	local menuOptions = {{'hr', HexRoguePlayState}, {'md', MusicdefencePlayState}, {'bb', BrainPlayState}}
	self.boardGrid["0_0"] = self.tiles:add(MenuHex(0,0, ""))
	for i,v in ipairs(self:getNeighbors(Vec2(0,0))) do
		local pos = self:hexToWorld(Vec2(v[1], v[2]))
		self.boardGrid[v[1] .. "_" .. v[2]] = self.tiles:add(MenuHex(pos.x,pos.y, ""))
		if menuOptions[i] then
			self.boardGrid[v[1] .. "_" .. v[2]]:setType(menuOptions[i][1])
			self.boardGrid[v[1] .. "_" .. v[2]].onPress = menuOptions[i][2]
		end
	end
end
local narrow_w = 88
local height = 100
function MenuState:hexToWorld(v)
	return Vec2(narrow_w*v.x, height * (v.x*0.5 + v.y))
end
function MenuState:worldToHex(v)
	local u = v.x / narrow_w
	local v = v.y / height - u * 0.5
	return Vec2(math.round(u), math.round(v))
end
function MenuState:getNeighbors(v)
	local neighborReturn = {}
	for i,v in ipairs({{v.x, v.y+1}, {v.x+1, v.y}, {v.x+1, v.y-1}, {v.x, v.y-1}, {v.x-1, v.y}, {v.x-1, v.y+1}}) do
		table.insert(neighborReturn, v)
	end
	return neighborReturn
end
function MenuState:touchDown(x, y, id)
	x, y = bludG.camera:getPosition(x, y)
	local hp = self:worldToHex(Vec2(x, y))
	local hexPos = self:hexToWorld(Vec2(hp.x, hp.y))
	local minDist = {{hp.x, hp.y}, hexPos:distance(Vec2(x, y))}
	for i,v in ipairs(self:getNeighbors(hp)) do
		hexPos = self:hexToWorld(Vec2(v[1], v[2]))
		local newDist = hexPos:distance(Vec2(x, y))
		if newDist < minDist[2] then
			minDist = {v, newDist}
		end
	end
	-- should determine if the player can move here before committing the move
	local hash = minDist[1][1] .. "_" .. minDist[1][2]
	local tappedCell = self.boardGrid[hash]
	-- if there isn't currently a cell on the tapped cell, then add a blank one
	if tappedCell.onPress then
		mainState = WrapperState(Group());
		mainState:changeState(tappedCell.onPress())
	end
end
MenuHex = class(Hex, function(o, x, y, t)
	Hex.init(o, x, y, t)
	-- just display a text code for the time being
	o.t_text = StringObject(x, y, t)
	o.t_text:setColor(0,0,0)
	o.t = t
	o:setType(t)
end)

function MenuHex:draw()
	Hex.draw(self)
	self.t_text:draw()
end
function MenuHex:setType(_t)
	self.t = _t
	if self.t == 'hr' then
		self:setColor(255, 205, 111)
	elseif self.t == 'md' then
		self:setColor(255, 0, 183)
	elseif self.t == 'bb' then
		self:setColor(187, 202, 194)
	elseif self.t == '' then
		self:setColor(39, 48, 50)
	end
	-- fix the text
	self.t_text:setValue(self.t)
	self.t_text:setPosition(self.pos.x-self.t_text.w/2, self.pos.y-self.t_text.h/2)
end

-- mainState = WrapperState(Group());
-- mainState:changeState(MenuState())
