def remap_css_to_match_hud(): # Try to load the users gfx changes if they exist if os.path.exists(HudColourAdjuster.default_config_file): log.info( f"Looking for HUD overrides in {HudColourAdjuster.default_config_file}" ) original_css_path = os.path.join(static_path, "style.css") try: colour_matrix = HudColourAdjuster.get_matrix_values( HudColourAdjuster.default_config_file) except Exception as e: log.error( "Failed to interpret HUD overrides; Please check your file is of the format described in https://arkku.com/elite/hud_editor/" ) log.exception(e) colour_matrix = None else: if colour_matrix: remapped_css_file = "css-overrides.css" remapped_css_file_path = os.path.join(temp_dir.name, remapped_css_file) HudColourAdjuster.remap_style_file(original_css_path, colour_matrix, remapped_css_file_path) log.info("Successfully remapped styles to match Elite HUD") else: log.info( f"No HUD overrides detected in ({HudColourAdjuster.default_config_file})" ) else: log.info( f"No HUD overrides file detected ({HudColourAdjuster.default_config_file})" )
def test_can_read_values_correctly(): data_file = "TestData\\example.xml" matrix_values = HudColourAdjuster.get_matrix_values(data_file) assert matrix_values is not None assert matrix_values['MatrixRed'] == [1, 0, 0] assert matrix_values['MatrixGreen'] == [0, 1, 0] assert matrix_values['MatrixBlue'] == [0, 0, 1]
def test_css_conversion_values_are_set_crrectly(monkeypatch): original_data = ".charted { color: #FF0000; background: #00FFFF; }" colour_matrix = { 'MatrixRed': [0.0, 1.0, 0.0], # Shift red to green 'MatrixGreen': [0.0, 1.0, 0.0], 'MatrixBlue': [0.0, 0.0, 1.0], } converted = HudColourAdjuster.remap_styles(original_data, colour_matrix) assert converted == ".charted { color: #00FF00; background: #00FFFF; }"
def test_colour_conversion_make_red_green(): colour_matrix = { 'MatrixRed': [0.0, 1.0, 0.0], 'MatrixGreen': [0.0, 1.0, 0.0], 'MatrixBlue': [0.0, 0.0, 1.0], } original_colour = [0.5, 0.5, 0.5] new_colour = HudColourAdjuster.adjust_colours(original_colour, colour_matrix) assert new_colour == [0.0, 1.0, 0.5]
def test_colour_conversion_with_identity_does_no_change_colours(): colour_matrix = { 'MatrixRed': [1, 0, 0], 'MatrixGreen': [0, 1, 0], 'MatrixBlue': [0, 0, 1], } original_colour = [0.5, 0.5, 0.5] new_colour = HudColourAdjuster.adjust_colours(original_colour, colour_matrix) assert new_colour == [0.5, 0.5, 0.5]
def test_colour_conversion_make_red_green_as_hex(): colour_matrix = { 'MatrixRed': [0.0, 1.0, 0.0], 'MatrixGreen': [0.0, 1.0, 0.0], 'MatrixBlue': [0.0, 0.0, 1.0], } original_colour = "#808080" new_colour = HudColourAdjuster.hex_colour_shift(original_colour, colour_matrix) assert new_colour == "#00FF80"
def test_css_conversion_values_are_replaced(monkeypatch): original_data = ".charted { color: #9f9f9f; background: #333333; }" colour_matrix = { 'MatrixRed': [0.0, 1.0, 0.0], 'MatrixGreen': [0.0, 1.0, 0.0], 'MatrixBlue': [0.0, 0.0, 1.0], } def mock_hex_colour_shift(original_data, colour_matrix): return '#123456' monkeypatch.setattr(HudColourAdjuster, "hex_colour_shift", mock_hex_colour_shift) converted = HudColourAdjuster.remap_styles(original_data, colour_matrix) assert converted == ".charted { color: #123456; background: #123456; }"
global thread if thread is None: thread = socketio.start_background_task(target=receive_and_forward) if __name__ == '__main__': try: # Try to load the users gfx changes if they exist if os.path.exists(HudColourAdjuster.default_config_file): log.info( f"Looking for HUD overrides in {HudColourAdjuster.default_config_file}" ) original_css_path = os.path.join(static_path, "style.css") colour_matrix = HudColourAdjuster.get_matrix_values( HudColourAdjuster.default_config_file) if colour_matrix: remapped_css_file = "css-overrides.css" remapped_css_file_path = os.path.join(temp_dir.name, remapped_css_file) HudColourAdjuster.remap_style_file(original_css_path, colour_matrix, remapped_css_file_path) else: log.info( f"No HUD overrides detected in ({HudColourAdjuster.default_config_file})" ) else: log.info( f"No HUD overrides file detected ({HudColourAdjuster.default_config_file})"