Beispiel #1
0
def update_visual(screen: Screen, inputs: list[int], cursor_one: int,
                  cursor_two: int):
    x, y, index = 0, 0, 0
    row = 20
    for number in inputs:

        if cursor_one == index:
            bg = 3
            colour = 0
        elif cursor_two == index:
            bg = 13
            colour = 0
        else:
            bg = 0
            colour = 10

        screen.print_at(text=f'{number}', x=x, y=y, colour=colour, bg=bg)

        index += 1
        if (index % row) == 0:
            y = 0
            x += 7
        else:
            y += 1
    screen.refresh()
Beispiel #2
0
    def print_region_icons(self, screen: Screen):
        while True:
            y_index = 0
            for i in self.world:
                x_index = 0
                for j in i:
                    screen.print_at(f'{j.icon}', x_index * 2, y_index)
                    x_index += 1
                y_index += 1

            ev = screen.get_key()
            if ev in (ord('Q'), ord('q')):
                return
            screen.refresh()
Beispiel #3
0
 def disp_audio(screen: Screen) -> None:
     while True:
         screen.clear()
         b = ch.buff
         sw = len(b)//bw
         b = np.asarray([np.average(b[i:i+sw]) for i in range(0, len(b), sw)])
         for i, v in enumerate(b):
             screen.move((w-bw)//2+i, int(h//2-bh*v*scale))
             screen.draw((w-bw)//2+i, h//2, char=char, colour=1 if np.max(b) > .2 else 7)
         e = screen.get_key()
         if e in (ord('Q'), ord('q')):
             break
         screen.refresh()
         time.sleep(.01)
Beispiel #4
0
def run_emu(screen: Screen, render_method=render_halfchars) -> None:
    """
    Asciimatics runner function to wrap, render the screen

    """
    path = clean_path(sys.argv[1])
    try:
        vm = load_rom_to_vm(path)
    except IOError as e:
        exit_with_error(f"Could not read {path!r} : {e!r}")
    except IndexError as e:
        exit_with_error(f"Rom size appears incorrect: {e!r}")

    paused = False

    # load keymap in an ugly but functional way
    # later versions of this should be a function that
    # takes a converter function to map between keys and
    # their frontend-specific representation. this will
    # make loading generic while still retaining compatibility
    # with various frontends.
    final_keymap = build_hexkey_mapping()

    while True:

        ev = screen.get_key()
        if ev in (ord('H'), ord('h')):
            return

        if ev == ord('p'):
            paused = not paused

        if not paused:
            if ev in final_keymap:
                vm.press(final_keymap[ev])

            for i in range(vm.ticks_per_frame):
                vm.tick()

            if ev in final_keymap:
                vm.release(final_keymap[ev])

        render_method(screen, vm)
        screen.refresh()
Beispiel #5
0
    def print_world_tile_types(self, screen: Screen):
        while True:
            y_index = 0
            for i in self.world:
                x_index = 0
                for j in i:
                    if j.type == 'Land':
                        color = Screen.COLOUR_GREEN
                    else:
                        color = Screen.COLOUR_BLUE

                    screen.print_at(f'{j.height}', x_index * 2, y_index, color)
                    x_index += 1
                y_index += 1

            ev = screen.get_key()
            if ev in (ord('Q'), ord('q')):
                return
            screen.refresh()
Beispiel #6
0
    def print_world_heights(self, screen: Screen):
        for c in self.continents:
            c.set_tile_icons_to_continent_icon()

        forest_colors = [23, 29, 22, 28, 34, 40, 46, 83, 85]
        ocean_colors = [17, 18, 19, 20, 21, 33, 45, 201, 201, 201]
        mountain_colors = [201, 201, 201, 233, 235, 237, 241, 248, 252, 255]
        desert_colors = [
            3, 186, 190, 226, 227, 228, 229, 230, 252, 255
        ]  # [130, 136, 172, 178, 220, 226, 228, 230, 252, 255]

        color_table = [201, 201, 201, 201, 201, 201, 201, 201, 201]

        while True:
            y_index = 0
            for i in self.world:
                x_index = 0
                for j in i:
                    if j.type is not 'Land':
                        color_table = ocean_colors
                    elif j.terrain is 'Desert':
                        color_table = desert_colors
                    elif j.height < 6:
                        color_table = forest_colors
                    elif j.height >= 6:
                        color_table = mountain_colors

                    color = color_table[j.height]

                    screen.print_at(f'{j.height}{j.icon}',
                                    x_index * 2,
                                    y_index,
                                    colour=16,
                                    bg=color)
                    x_index += 1
                y_index += 1

            ev = screen.get_key()
            if ev in (ord('Q'), ord('q')):
                # for c in self.continents:
                # c.set_tile_icons_to_region_icon()
                return
            screen.refresh()
Beispiel #7
0
    def print_continent_icons(self, screen: Screen):
        for c in self.continents:
            c.set_tile_icons_to_continent_icon()

        while True:
            y_index = 0
            for i in self.world:
                x_index = 0
                for j in i:
                    screen.print_at(f'{j.icon}', x_index * 2, y_index)
                    x_index += 1
                y_index += 1

            ev = screen.get_key()
            if ev in (ord('Q'), ord('q')):
                for c in self.continents:
                    c.set_tile_icons_to_region_icon()
                return
            screen.refresh()
Beispiel #8
0
def pyre(screen: Screen):
    screen.clear()
    screen.print_at('Hello world!', 0, 0)
    screen.refresh()
    sleep(10)
    pass
Beispiel #9
0
def choose_build_type_with_screen(
        screen: Screen, build_type_options: List[BuildTypeOption]
) -> Optional[BuildTypeDecision]:
    '''
	TODOCUMENT

	:param screen             : TODOCUMENT
	:param build_type_options : TODOCUMENT
	'''
    # Seem to need to do this to prevent the first printed line always using white foreground color
    screen.print_at(
        '.',
        0,
        0,
    )
    screen.refresh()
    screen.print_at(
        ' ',
        0,
        0,
    )

    build_types = [x.build_type for x in build_type_options]

    active_index = 0
    cmake_it = False
    if 'BUILDTYPE' in os.environ and os.environ['BUILDTYPE'] in build_types:
        active_index = build_types.index(os.environ['BUILDTYPE'])

    # Run the event loop
    while True:

        # Print the build_type_options
        for option_idx, build_type_option in enumerate(build_type_options):
            max_build_type_len = max(len(x) for x in build_types)
            is_active = option_idx == active_index
            screen.print_at(
                (f' { build_type_option.build_type:{max_build_type_len}}      '
                 + (' ' if build_type_option.presence == BuildPresence.ABSENT
                    else '?' if build_type_option.presence
                    == BuildPresence.HAS_DIR else u'\u2713') +
                 (' ' if build_type_option.is_standard else
                  '   [not-in-standard-list] ')),
                x=4,
                y=option_idx,
                bg=(COLOUR_BRIGHT_RED if cmake_it else Screen.COLOUR_WHITE)
                if is_active else Screen.COLOUR_BLACK,
                colour=Screen.COLOUR_BLACK
                if is_active else Screen.COLOUR_WHITE,
            )

        for y_val, text in enumerate(
            ('', '[up/down]  : change selection', '[enter]    : select',
             '[spacebar] : toggle whether to also (re)run conan/cmake (indicated by red)',
             '[q]        : quit with no change', '', u'\u2713' +
             ' : ninja file exists in directory', '? : directory exists'),
                len(build_type_options)):
            screen.print_at(
                text,
                x=0,
                y=y_val,
            )

        # Get any event and respond to relevant keys
        event = screen.get_event()
        if isinstance(event, KeyboardEvent):
            if event.key_code == ord("\n"):
                return BuildTypeDecision(
                    build_type=build_type_options[active_index].build_type,
                    cmake_it=cmake_it)
            if event.key_code in (Screen.KEY_ESCAPE, ord('Q'), ord('q')):
                return None
            if event.key_code == Screen.KEY_DOWN:
                active_index = active_index + 1 if active_index + 1 < len(
                    build_type_options) else 0
            elif event.key_code == Screen.KEY_UP:
                active_index = active_index - 1 if active_index > 0 else len(
                    build_type_options) - 1
            elif event.key_code == ord(' '):
                cmake_it = not cmake_it

        # Refresh screen
        screen.refresh()