local druid = require("druid.druid")


function init(self)
	self.druid = druid.new(self)
	local prefab = gui.get_node("prefab")
	gui.set_enabled(prefab, false)

	local grid_nw = self.druid:new_static_grid("grid_NW_anchor", prefab, 3)
	local grid_ne = self.druid:new_static_grid("grid_NE_anchor", prefab, 3)
	local grid_n = self.druid:new_static_grid("grid_N_anchor", prefab, 3)
	local grid_sw = self.druid:new_static_grid("grid_SW_anchor", prefab, 3)
	local grid_se = self.druid:new_static_grid("grid_SE_anchor", prefab, 3)
	local grid_s = self.druid:new_static_grid("grid_S_anchor", prefab, 3)
	local grid_w = self.druid:new_static_grid("grid_C_anchor", prefab, 3)
	local grid_e = self.druid:new_static_grid("grid_W_anchor", prefab, 3)
	local grid_c = self.druid:new_static_grid("grid_E_anchor", prefab, 3)

	local update_pos_func = function(node, pos) gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2) end
	grid_nw:set_position_function(update_pos_func)
	grid_ne:set_position_function(update_pos_func)
	grid_n:set_position_function(update_pos_func)
	grid_sw:set_position_function(update_pos_func)
	grid_se:set_position_function(update_pos_func)
	grid_s:set_position_function(update_pos_func)
	grid_w:set_position_function(update_pos_func)
	grid_e:set_position_function(update_pos_func)
	grid_c:set_position_function(update_pos_func)

	local grids = {
		grid_nw,
		grid_ne,
		grid_n,
		grid_sw,
		grid_se,
		grid_s,
		grid_c,
		grid_w,
		grid_e,
	}

	for i = 1, #grids do
		grids[i].style.IS_DYNAMIC_NODE_POSES = true
	end


	local animate_grides = function()
		for _, grid in ipairs(grids) do
			for i = 1, #grid.nodes do
				gui.delete_node(grid.nodes[i])
			end
			grid:clear()

			for i = 1, 9 do
				timer.delay(i, false, function()
					local node = gui.clone(prefab)
					gui.set_enabled(node, true)
					grid:add(node)
				end)
			end
		end
	end

	animate_grides()
	timer.delay(10, true, animate_grides)

end


function final(self)
	self.druid:final()
end


function update(self, dt)
	self.druid:update(dt)
end


function on_message(self, message_id, message, sender)
	self.druid:on_message(message_id, message, sender)
end


function on_input(self, action_id, action)
	return self.druid:on_input(action_id, action)
end
