<commit_before>#include <allegro5/allegro.h>
#include <cstdio>
#include <fstream>

#include "inputcatcher.h"
#include "datastructures.h"
#include "renderer.h"
#include "ingameelements/character.h"
#include "global_constants.h"

#define LEFT_MOUSE_BUTTON 1
#define RIGHT_MOUSE_BUTTON 2

InputCatcher::InputCatcher(ALLEGRO_DISPLAY *display)
{
    // Create an event queue, and error if it fails
    event_queue = al_create_event_queue();
    if (!event_queue)
    {
        fprintf(stderr, "Fatal Error: Could not create event queue!");
        throw -1;
    }

    // Connect the window, keyboard and mouse events to this event queue
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
//    al_register_event_source(event_queue, al_get_mouse_event_source(display));

	std::ifstream configfile("config.json");
	config << configfile;
	configfile.close();
}

InputCatcher::~InputCatcher()
{
    al_destroy_event_queue(event_queue);
}

void InputCatcher::run(EntityPtr myself, Engine *engine, Renderer *renderer)
{
    // FIXME: Debugtool
    bool spawnplayer = false;

    INPUT_CONTAINER pressed_keys = {};
    INPUT_CONTAINER held_keys = {};

    ALLEGRO_EVENT event;
    // Catch all events that have stacked up this frame. al_get_next_event() returns false when event_queue is empty, and contents of event are undefined
    while (al_get_next_event(event_queue, &event))
    {
        switch (event.type)
        {
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                // Deliberate closing, not an error
                throw 0;

            case ALLEGRO_EVENT_KEY_DOWN:
                switch (event.keyboard.keycode)
                {
					if (event.keyboard.keycode== config["jump"]){
                        pressed_keys.JUMP = true;
                        //break;
					}
					if (event.keyboard.keycode== config["crouch"]){
                        pressed_keys.CROUCH = true;
                        //break;
					}
					if (event.keyboard.keycode== config["left"]){
                        pressed_keys.LEFT = true;
                        //break;
					}
					if (event.keyboard.keycode== config["right"]){
                        pressed_keys.RIGHT = true;
                        //break;
					}						
                    case ALLEGRO_KEY_LSHIFT:
                        pressed_keys.ABILITY_1 = true;
                        break;
                    case ALLEGRO_KEY_E:
                        pressed_keys.ABILITY_2 = true;
                        break;
                    case ALLEGRO_KEY_Q:
                        pressed_keys.ULTIMATE = true;
                        break;
                    case ALLEGRO_KEY_R:
                        pressed_keys.RELOAD = true;
                        break;

                    case ALLEGRO_KEY_1:<commit_msg>Spacing fixes<commit_after>#include <allegro5/allegro.h>
#include <cstdio>
#include <fstream>

#include "inputcatcher.h"
#include "datastructures.h"
#include "renderer.h"
#include "ingameelements/character.h"
#include "global_constants.h"

#define LEFT_MOUSE_BUTTON 1
#define RIGHT_MOUSE_BUTTON 2

InputCatcher::InputCatcher(ALLEGRO_DISPLAY *display)
{
    // Create an event queue, and error if it fails
    event_queue = al_create_event_queue();
    if (!event_queue)
    {
        fprintf(stderr, "Fatal Error: Could not create event queue!");
        throw -1;
    }

    // Connect the window, keyboard and mouse events to this event queue
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
//    al_register_event_source(event_queue, al_get_mouse_event_source(display));

	std::ifstream configfile("config.json");
	config << configfile;
	configfile.close();
}

InputCatcher::~InputCatcher()
{
    al_destroy_event_queue(event_queue);
}

void InputCatcher::run(EntityPtr myself, Engine *engine, Renderer *renderer)
{
    // FIXME: Debugtool
    bool spawnplayer = false;

    INPUT_CONTAINER pressed_keys = {};
    INPUT_CONTAINER held_keys = {};

    ALLEGRO_EVENT event;
    // Catch all events that have stacked up this frame. al_get_next_event() returns false when event_queue is empty, and contents of event are undefined
    while (al_get_next_event(event_queue, &event))
    {
        switch (event.type)
        {
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                // Deliberate closing, not an error
                throw 0;

            case ALLEGRO_EVENT_KEY_DOWN:
                switch (event.keyboard.keycode)
                {
					if (event.keyboard.keycode == config["jump"])
					{
                        pressed_keys.JUMP = true;
					}
					if (event.keyboard.keycode == config["crouch"])
					{
                        pressed_keys.CROUCH = true;
					}
					if (event.keyboard.keycode == config["left"])
					{
                        pressed_keys.LEFT = true;
					}
					if (event.keyboard.keycode == config["right"])
					{
                        pressed_keys.RIGHT = true;
					}						
                    case ALLEGRO_KEY_LSHIFT:
                        pressed_keys.ABILITY_1 = true;
                        break;
                    case ALLEGRO_KEY_E:
                        pressed_keys.ABILITY_2 = true;
                        break;
                    case ALLEGRO_KEY_Q:
                        pressed_keys.ULTIMATE = true;
                        break;
                    case ALLEGRO_KEY_R:
                        pressed_keys.RELOAD = true;
                        break;

                    case ALLEGRO_KEY_1:
{'fraction_non_alphanumeric': 0.08898305084745763, 'fraction_numerical': 0.002824858757062147, 'mean_word_length': 1.9628661087866108, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669599', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1638, 'n_words': 346}