#ifndef GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086
#define GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086

#include "types.h"

#ifdef __EMSCRIPTEN__

#define SW_MAX_GAMEPADS 1
#define SW_MAX_GAMEPAD_AXES 6
#define SW_MAX_GAMEPAD_BUTTONS 16

#define SW_GAMEPAD_BUTTON_FACE_DOWN 0
#define SW_GAMEPAD_BUTTON_FACE_RIGHT 1
#define SW_GAMEPAD_BUTTON_FACE_LEFT 2
#define SW_GAMEPAD_BUTTON_FACE_UP 3
#define SW_GAMEPAD_BUTTON_LEFT_SHOULDER 4
#define SW_GAMEPAD_BUTTON_RIGHT_SHOULDER 5
#define SW_GAMEPAD_BUTTON_LEFT_TRIGGER 6
#define SW_GAMEPAD_BUTTON_RIGHT_TRIGGER 7
#define SW_GAMEPAD_BUTTON_BACK 8
#define SW_GAMEPAD_BUTTON_START 9
#define SW_GAMEPAD_BUTTON_LEFT_STICK 11
#define SW_GAMEPAD_BUTTON_RIGHT_STICK 10
#define SW_GAMEPAD_BUTTON_DPAD_UP 12
#define SW_GAMEPAD_BUTTON_DPAD_RIGHT 15
#define SW_GAMEPAD_BUTTON_DPAD_DOWN 13
#define SW_GAMEPAD_BUTTON_DPAD_LEFT 14

#define SW_GAMEPAD_AXIS_LEFT_X 0
#define SW_GAMEPAD_AXIS_RIGHT_X 1
#define SW_GAMEPAD_AXIS_LEFT_Y 2
#define SW_GAMEPAD_AXIS_RIGHT_Y 3
#define SW_GAMEPAD_AXIS_LEFT_TRIGGER 4
#define SW_GAMEPAD_AXIS_RIGHT_TRIGGER 5

#else /* __EMSCRIPTEN__ */

#define SW_MAX_GAMEPADS 4
#define SW_MAX_GAMEPAD_AXES 6
#define SW_MAX_GAMEPAD_BUTTONS 15

#define SW_GAMEPAD_BUTTON_FACE_DOWN 0
#define SW_GAMEPAD_BUTTON_FACE_RIGHT 1
#define SW_GAMEPAD_BUTTON_FACE_LEFT 2
#define SW_GAMEPAD_BUTTON_FACE_UP 3
#define SW_GAMEPAD_BUTTON_LEFT_SHOULDER 4
#define SW_GAMEPAD_BUTTON_RIGHT_SHOULDER 5
#define SW_GAMEPAD_BUTTON_BACK 6
#define SW_GAMEPAD_BUTTON_START 7
#define SW_GAMEPAD_BUTTON_GUIDE 8
#define SW_GAMEPAD_BUTTON_LEFT_STICK 9
#define SW_GAMEPAD_BUTTON_RIGHT_STICK 10
#define SW_GAMEPAD_BUTTON_DPAD_UP 11
#define SW_GAMEPAD_BUTTON_DPAD_RIGHT 12
#define SW_GAMEPAD_BUTTON_DPAD_DOWN 13
#define SW_GAMEPAD_BUTTON_DPAD_LEFT 14

#define SW_GAMEPAD_AXIS_LEFT_X 0
#define SW_GAMEPAD_AXIS_RIGHT_X 1
#define SW_GAMEPAD_AXIS_LEFT_Y 2
#define SW_GAMEPAD_AXIS_RIGHT_Y 3
#define SW_GAMEPAD_AXIS_LEFT_TRIGGER 4
#define SW_GAMEPAD_AXIS_RIGHT_TRIGGER 5

#endif /* __EMSCRIPTEN__ */

struct sw_gamepad {
	f32 axes[SW_MAX_GAMEPAD_AXES];
	bool button_down[SW_MAX_GAMEPAD_BUTTONS];
	bool button_pressed[SW_MAX_GAMEPAD_BUTTONS];
};

extern struct sw_gamepad sw_gamepads[SW_MAX_GAMEPADS];

void sw_gamepad_static_init();
void sw_gamepad_tick();

#endif /* GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086 */
