"""Handles conversion from QF keycode lists to keystrokes or DF macros."""

from copy import copy
from math import sqrt
import os
import re
import random

from filereader import load_json
from geometry import Area, Direction, add_points, scale_point, midpoint
import exetest
import util

# load global KEY_LIST which is used liberally below and would be inefficient to constantly reload
KEY_LIST = load_json(os.path.join(exetest.get_main_dir(), "config/keys.json"))


class KeystrokerError(Exception):
    """Base class for keystroker errors."""


class Keystroker:
    """
    Computes keycodes needed to go through route and transforms those keycodes
    into keystrokes or DF macro commands.
    Returns list keystrokes or DF macro lines.
    """

    def __init__(self, grid, buildconfig):
        self.grid = grid
        self.buildconfig = buildconfig
"""Handles conversion from QF keycode lists to keystrokes or DF macros."""

from copy import copy
from math import sqrt
import os
import re
import random

from filereader import load_json
from geometry import Area, Direction, add_points, scale_point, midpoint
import exetest
import util

# load global KEY_LIST which is used liberally below and would be inefficient to constantly reload
KEY_LIST = load_json(os.path.join(exetest.get_main_dir(), "config/keys.json"))


class KeystrokerError(Exception):
    """Base class for keystroker errors."""


class Keystroker:
    """
    Computes keycodes needed to go through route and transforms those keycodes
    into keystrokes or DF macro commands.
    Returns list keystrokes or DF macro lines.
    """
    def __init__(self, grid, buildconfig):
        self.grid = grid
        self.buildconfig = buildconfig
import os
import re

import exetest
from filereader import load_json

# load global BUILD_TYPE_CFG which is used liberally below
# and would be inefficient to constantly reload
BUILD_TYPE_CFG = load_json(
    os.path.join(exetest.get_main_dir(), "config/buildconfig.json"))


class BuildConfig:
    """Represents a build config dictionary and provides .get() for access."""

    def __init__(self, build_type):
        self.build_type = build_type
        self.config = BUILD_TYPE_CFG[build_type]

    def get(self, label, forkey=None):
        """
        Returns build configuration value for given label in the build_type
        section associated with this instance.

        When forkey is specified, the key from the build type section's
        "custom" subsection will be used if forkey matches said custom
        key when treating said custom key as a regex pattern.
        """
        if forkey:
            custom = self.config.get('custom') or {}
            for k in custom:
import os
import re

import exetest
from filereader import load_json

# load global BUILD_TYPE_CFG which is used liberally below
# and would be inefficient to constantly reload
BUILD_TYPE_CFG = load_json(
    os.path.join(exetest.get_main_dir(), "config/buildconfig.json"))


class BuildConfig:
    """Represents a build config dictionary and provides .get() for access."""
    def __init__(self, build_type):
        self.build_type = build_type
        self.config = BUILD_TYPE_CFG[build_type]

    def get(self, label, forkey=None):
        """
        Returns build configuration value for given label in the build_type
        section associated with this instance.

        When forkey is specified, the key from the build type section's
        "custom" subsection will be used if forkey matches said custom
        key when treating said custom key as a regex pattern.
        """
        if forkey:
            custom = self.config.get('custom') or {}
            for k in custom:
                if re.match(k, forkey):