<commit_before>#include <cstdio>
#include <fstream>

#include <SFML/Window/Event.hpp>

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

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

InputCatcher::~InputCatcher()
{

}

void InputCatcher::updatekey(std::string keylabel, bool &key)
{
    int code1 = config.at(keylabel);
    int code2 = config.at(keylabel+"_alt1");
    int code3 = config.at(keylabel+"_alt2");

    if (sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code1))
        or sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code2))
        or sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code3)))
    {
        key = true;
    }
    else
    {
        key = false;
    }
}

void InputCatcher::run(sf::RenderWindow &window, Gamestate &state, Networker &networker, Renderer &renderer,
                       EntityPtr myself)
{
    InputContainer heldkeys;
    heldkeys.reset();

    Player &player = state.get<Player>(myself);

    sf::Event event;
    // Go through all events that have been stacking up since last time
    while (window.pollEvent(event))
    {
        // FIXME: This newclass thing is an ugly placeholder,
        // when you replace it with a real class menu don't do it like this
        Heroclass newclass = player.heroclass;
        switch (event.type)
        {
            case sf::Event::Closed:
                window.close();
                break;

            case sf::Event::Resized:
                renderer.WINDOW_WIDTH = event.size.width;
                renderer.WINDOW_HEIGHT = event.size.height;
                renderer.resetcamera();
                break;

            case sf::Event::KeyPressed:
                switch (event.key.code)
                {
                    case sf::Keyboard::Escape:
                        window.close();
                        break;

                    case sf::Keyboard::F9:
                        // Zooming in for sprite analysis purposes
                        if (renderer.VIEWPORT_WIDTH != 960)
                        {
                            renderer.VIEWPORT_WIDTH = 960;
                        }
                        else
                        {
                            renderer.VIEWPORT_WIDTH = 300;
                        }
                        renderer.resetcamera();

                    case sf::Keyboard::Num1:
                        newclass = MCCREE;
                        break;
<commit_msg>Added hack to make game close on escape.<commit_after>#include <cstdio>
#include <fstream>

#include <SFML/Window/Event.hpp>

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

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

InputCatcher::~InputCatcher()
{

}

void InputCatcher::updatekey(std::string keylabel, bool &key)
{
    int code1 = config.at(keylabel);
    int code2 = config.at(keylabel+"_alt1");
    int code3 = config.at(keylabel+"_alt2");

    if (sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code1))
        or sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code2))
        or sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(code3)))
    {
        key = true;
    }
    else
    {
        key = false;
    }
}

void InputCatcher::run(sf::RenderWindow &window, Gamestate &state, Networker &networker, Renderer &renderer,
                       EntityPtr myself)
{
    InputContainer heldkeys;
    heldkeys.reset();

    Player &player = state.get<Player>(myself);

    sf::Event event;
    // Go through all events that have been stacking up since last time
    while (window.pollEvent(event))
    {
        // FIXME: This newclass thing is an ugly placeholder,
        // when you replace it with a real class menu don't do it like this
        Heroclass newclass = player.heroclass;
        switch (event.type)
        {
            case sf::Event::Closed:
                window.close();
                Global::logging().panic(__FILE__, __LINE__, "Game closed.");
                break;

            case sf::Event::Resized:
                renderer.WINDOW_WIDTH = event.size.width;
                renderer.WINDOW_HEIGHT = event.size.height;
                renderer.resetcamera();
                break;

            case sf::Event::KeyPressed:
                switch (event.key.code)
                {
                    case sf::Keyboard::Escape:
                        window.close();
                        Global::logging().panic(__FILE__, __LINE__, "Game closed.");
                        break;

                    case sf::Keyboard::F9:
                        // Zooming in for sprite analysis purposes
                        if (renderer.VIEWPORT_WIDTH != 960)
                        {
                            renderer.VIEWPORT_WIDTH = 960;
                        }
                        else
                        {
                            renderer.VIEWPORT_WIDTH = 300;
                        }
                        renderer.resetcamera();

                    case sf::Keyboard::Num1:
                        newclass = MCCREE;
                        break;

{'fraction_non_alphanumeric': 0.10987632192149131, 'fraction_numerical': 0.006811256497580211, 'mean_word_length': 1.7393225331369662, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '1030644', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1531, 'n_words': 323}