diff --git a/lib/console/console.rb b/lib/console/console.rb index 67c4c5f..05d357f 100644 --- a/lib/console/console.rb +++ b/lib/console/console.rb @@ -164,9 +164,7 @@ def handle_command(cmd, opt_arg, cmds, is_valid, cmd_err: D_MSG[:cmd_err]) def table_formatter(data_arr) row_counts = data_arr.size prefix_size = ol_prefix(row_counts).size - auto_pad = row_counts * 2 + D_MSG[:v_sep].size - max_length = data_arr.map { |arr| arr.max_by(&:size) }.sum(&:size) + auto_pad + prefix_size - max_length = 80 if max_length > 80 + max_length = 80 [prefix_size, max_length] end diff --git a/lib/console_game/chess/board.rb b/lib/console_game/chess/board.rb index a1212c5..b052bd2 100644 --- a/lib/console_game/chess/board.rb +++ b/lib/console_game/chess/board.rb @@ -11,7 +11,7 @@ class Board include Console include Display - attr_accessor :board_size, :board_side, :board_padding, :flip_board, :highlight, :live_board + attr_accessor :board_size, :board_side, :board_padding, :flip_board, :highlight attr_reader :level, :type_hl, :alg_pos_hl # @param level [Level] chess Level object @@ -42,16 +42,16 @@ def print_turn(event_msgs = [""]) system("clear") # print "\e[2J\e[H" - print_msg(*event_msgs, pre: "⠗ ") unless event_msgs.empty? + print_msg(*event_msgs, pre: "\n⠗ ") unless event_msgs.empty? print_chessboard level.event_msgs.clear - # self.live_board = 0 end # Print the chessboard def print_chessboard + puts "\n" print_msg(*build_chessboard, pre: "".ljust(board_padding), clear: false) - # self.live_board += 1 + puts "\n" end # Enable & disable board flipping @@ -79,7 +79,6 @@ def display_configs @board_side = :white @highlight = THEME[:classic].slice(:icon, :highlight) @type_hl, @alg_pos_hl = MSG_HIGHLIGHT[:std].values_at(:type, :alg_pos) - @live_board = 0 end # Pre-process turn data before sending it to display module diff --git a/lib/console_game/chess/level.rb b/lib/console_game/chess/level.rb index d13d797..a18964b 100644 --- a/lib/console_game/chess/level.rb +++ b/lib/console_game/chess/level.rb @@ -34,7 +34,7 @@ class Level attr_reader :controller, :w_player, :b_player, :session, :board, :kings, :castling_states, :threats_map, :usable_pieces, :opponent - # @param input [ChessInput] + # @param input [ChessInput]`` # @param sides [Hash] # @option sides [ChessPlayer, ChessComputer] :white Player who plays as White # @option sides [ChessPlayer, ChessComputer] :black Player who plays as Black @@ -67,7 +67,7 @@ def refresh(print_turn: true) update_board_state game_end_check add_check_marker - board.print_turn(event_msgs) if print_turn + board.print_turn(event_msgs) if print_turn || game_ended end # Board state refresher @@ -154,7 +154,9 @@ def init_level # greet player on load, message should change depending on load state def greet_player keypath = full_move == 1 ? "session.new" : "session.load" - event_msgs.push(board.s(keypath, { event: session[:event], p1: player.name })) + event_msgs.push(board.s(keypath, { + event: [session[:event].sub("Status", "| Status:"), "gold"], p1: player.name + })) end # Pre-turn flow @@ -204,8 +206,7 @@ def handle_result(type:, side: nil) save_turn winner = session[opposite_of(side)] kings[side].color = "#CC0000" if type == "checkmate" - event_msgs << board.s("level.endgame.#{type}", { win_player: winner }) - board.print_turn(event_msgs[-1]) + event_msgs << board.s("level.endgame.#{type}", { win_player: [winner, "gold"] }) @game_ended = true end diff --git a/lib/console_game/chess/utilities/session_builder.rb b/lib/console_game/chess/utilities/session_builder.rb index 48bdda6..6fa0376 100644 --- a/lib/console_game/chess/utilities/session_builder.rb +++ b/lib/console_game/chess/utilities/session_builder.rb @@ -33,7 +33,7 @@ def build_session session = { mode: mode, white: wp_name, black: bp_name, - event: "#{wp_name} vs #{bp_name} status-#{ongoing_txt}", + event: "#{wp_name} vs #{bp_name} Status #{ongoing_txt}", site: site_txt, date: Time.new.ceil.strftime(STR_TIME) } [id, session] diff --git a/spec/console/console_spec.rb b/spec/console/console_spec.rb index 9101102..9349298 100644 --- a/spec/console/console_spec.rb +++ b/spec/console/console_spec.rb @@ -19,15 +19,13 @@ end let(:expected_output) do - [ - "List of Sessions", - "---------------------------------------------------------------------------", - "Event | Date", - "---------------------------------------------------------------------------", - "* [1] - Q vs Picard 07/10/2025 12:00 AM", - "* [2] - Spock vs Data 07/15/2025 12:00 AM", - "* [3] - Voyager vs Enterprise 07/18/2025 12:00 AM" - ] + ["List of Sessions", + "--------------------------------------------------------------------------------", + "Event | Date", + "--------------------------------------------------------------------------------", + "* [1] - Q vs Picard 07/10/2025 12:00 AM", + "* [2] - Spock vs Data 07/15/2025 12:00 AM", + "* [3] - Voyager vs Enterprise 07/18/2025 12:00 AM"] end it "returns a table in a form of a string" do