aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_events.c
blob: edacc4200a23ab14976de8277a065056ead6f64f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_key_events.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:28:55 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:28:55 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
#include <stdint.h>

static void
	ft_insert_key(uint16_t keycode, t_cub *clist)
{
	uint8_t	i;

	i = 0;
	while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1)
		i++;
	clist->key_input[i] = keycode;
}

int
	ft_key_event(int keycode, t_cub *clist)
{
	const int32_t	tmp_code = keycode;

	keycode = ft_convert_keycode(tmp_code);
	if (keycode == FT_ESC_KEY)
		return (ft_exit(0, (clist)));
	else if (keycode == FT_F1_KEY || keycode == FT_TAB_KEY)
		return (ft_f1_key(clist));
	else if (keycode == FT_SPC_KEY && clist->plist.handles_weapon > -1)
		return (ft_space_key(clist));
	ft_insert_key(keycode, clist);
	return (0);
}