XRay = getClass("XRay")

XRay.minigameID = "XRAY"
XRay.minigameIdx = 3

XRay.levels = {}
XRay.levels[1] =
{
	duration = 16000,
	pieces=3,
}
XRay.levels[2] =
{
	duration = 16000,
	pieces=4,
}
XRay.levels[3] =
{
	duration = 18000,
	pieces=5,
}
XRay.levels[4] =
{
	duration = 21000,
	pieces=6,
}
XRay.levels[5] =
{
	duration = 21500,
	pieces=7,
}

XRay.layouts = {}
XRay.layouts[1] =
{	class="XRay",
	name="XRay MiniGame",
	versions=
	{
		{
			background="XRAY_1_BACKGROUND:minigames",
			mask="XRAY_1_MASK:minigames",
			objects={
				-- connects: 0 means connects to border
				{class="XRayObject", name="1", image_a="XRAY_1_P1:minigames", x=222, y=374, id=1, connects={3, 2, 4, 0}, },
				{class="XRayObject", name="2", image_a="XRAY_1_P2:minigames", x=306, y=330, id=2, connects={0, 1, 3}, },
				{class="XRayObject", name="3", image_a="XRAY_1_P3:minigames", x=222, y=332, id=3, connects={5, 1, 2}, },
				{class="XRayObject", name="4", image_a="XRAY_1_P4:minigames", x=141, y=323, id=4, connects={5, 3, 1}, },
				{class="XRayObject", name="5", image_a="XRAY_1_P5:minigames", x=68, y=289, id=5, connects={0, 4}, },
				{class="XRayObject", name="6", image_a="XRAY_1_P6:minigames", x=224, y=161, id=6, connects={0, 7}, },
				{class="XRayObject", name="7", image_a="XRAY_1_P7:minigames", x=123, y=152, id=7, connects={0, 6}, },
				{class="XRayObject", name="8", image_a="XRAY_1_P8:minigames", x=290, y=474, id=8, connects={0}, },
			},
		},
		{
			background="XRAY_2_BACKGROUND:minigames",
			mask="XRAY_2_MASK:minigames",
			objects={
				{class="XRayObject", name="1", image_a="XRAY_2_P1:minigames", x=67, y=306, id=1, connects={0, 2}, },
				{class="XRayObject", name="2", image_a="XRAY_2_P2:minigames", x=210, y=284, id=2, connects={1, 4, 3}, },
				{class="XRayObject", name="3", image_a="XRAY_2_P3:minigames", x=281, y=263, id=3, connects={2, 4, 5}, },
				{class="XRayObject", name="4", image_a="XRAY_2_P4:minigames", x=210, y=296, id=4, connects={2, 3, 5, 0}, },
				{class="XRayObject", name="5", image_a="XRAY_2_P5:minigames", x=400, y=240, id=5, connects={0, 3, 4}, },
				{class="XRayObject", name="6", image_a="XRAY_2_P6:minigames", x=204, y=396, id=6, connects={0, 7, 8}, },
				{class="XRayObject", name="7", image_a="XRAY_2_P7:minigames", x=248, y=427, id=7, connects={0, 6, 8}, },
				{class="XRayObject", name="8", image_a="XRAY_2_P8:minigames", x=313, y=348, id=8, connects={0, 6, 7}, },
			},
		},
		{
			background="XRAY_3_BACKGROUND:minigames",
			mask="XRAY_3_MASK:minigames",
			objects={
				{class="XRayObject", name="1", image_a="XRAY_3_P1:minigames", x=259, y=463, id=1, connects={0, 2}, },
				{class="XRayObject", name="2", image_a="XRAY_3_P2:minigames", x=336, y=421, id=2, connects={0, 1}, },
				{class="XRayObject", name="3", image_a="XRAY_3_P3:minigames", x=219, y=401, id=3, connects={0, 4, 5}, },
				{class="XRayObject", name="4", image_a="XRAY_3_P4:minigames", x=240, y=386, id=4, connects={0, 3, 5}, },
				{class="XRayObject", name="5", image_a="XRAY_3_P5:minigames", x=302, y=337, id=5, connects={0, 3, 4}, },
				{class="XRayObject", name="6", image_a="XRAY_3_P6:minigames", x=266, y=282, id=6, connects={7, 0}, },
				{class="XRayObject", name="7", image_a="XRAY_3_P7:minigames", x=218, y=310, id=7, connects={8, 6}, },
				{class="XRayObject", name="8", image_a="XRAY_3_P8:minigames", x=187, y=381, id=8, connects={0, 7}, },
			},
		},
	},
}

XRayObject = deriveLuaClass("XRayObject", "Object")
function XRayObject:init(desc)
	self.id = desc.id
	self.connects = desc.connects
	self.ox = desc.x
	self.oy = desc.y

	self:setImage(desc.image_a)
end

function XRayObject:connectsTo(obj)
	return table.contains(obj.connects, self.id)
end

function XRayObject:isBorder()
	return table.contains(self.connects, 0)
end

function XRayObject:isInRange(x, y)
	local dist = 30
	return math.abs(self.ox - x) < 30 and math.abs(self.oy - y) < 30
end

function XRayObject:snapToPosition()
	self:setLocation(self.ox, self.oy)
end