Class: GitGameShow::GameServer

Inherits:
Object
  • Object
show all
Defined in:
lib/git_game_show/game_server.rb

Overview

Main Game Server class - now a lightweight coordinator of other components

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port:, password:, rounds:, repo:) ⇒ GameServer

Returns a new instance of GameServer.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/git_game_show/game_server.rb', line 6

def initialize(port:, password:, rounds:, repo:)
  @port = port
  @password = password
  @rounds = rounds
  @repo = repo

  # These are kept for backward compatibility but not used directly
  @players = {}
  @scores = {}
  @current_round = 0
  @game_state = :lobby
end

Instance Attribute Details

#current_roundObject (readonly)

Returns the value of attribute current_round.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def current_round
  @current_round
end

#game_stateObject (readonly)

Returns the value of attribute game_state.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def game_state
  @game_state
end

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def password
  @password
end

#playersObject (readonly)

Returns the value of attribute players.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def players
  @players
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def port
  @port
end

#repoObject (readonly)

Returns the value of attribute repo.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def repo
  @repo
end

#roundsObject (readonly)

Returns the value of attribute rounds.



4
5
6
# File 'lib/git_game_show/game_server.rb', line 4

def rounds
  @rounds
end

Instance Method Details

#draw_command_promptObject



73
74
75
76
# File 'lib/git_game_show/game_server.rb', line 73

def draw_command_prompt
  # Forward to renderer
  @server_handler&.instance_variable_get(:@renderer)&.draw_command_prompt
end


63
64
65
66
# File 'lib/git_game_show/game_server.rb', line 63

def draw_join_link
  # Forward to renderer
  @server_handler&.instance_variable_get(:@renderer)&.draw_join_link(@join_link) if @join_link
end

#draw_sidebarObject



68
69
70
71
# File 'lib/git_game_show/game_server.rb', line 68

def draw_sidebar
  # Forward to sidebar
  @server_handler&.instance_variable_get(:@sidebar)&.draw_header
end

#draw_ui_frameObject

Legacy method definitions for backwards compatibility



53
54
55
56
# File 'lib/git_game_show/game_server.rb', line 53

def draw_ui_frame
  # Forward to renderer
  @server_handler&.instance_variable_get(:@renderer)&.draw_ui_frame
end

#draw_welcome_bannerObject



58
59
60
61
# File 'lib/git_game_show/game_server.rb', line 58

def draw_welcome_banner
  # Forward to renderer
  @server_handler&.instance_variable_get(:@renderer)&.draw_welcome_banner
end

#log_message(message, color = :white) ⇒ Object



78
79
80
81
# File 'lib/git_game_show/game_server.rb', line 78

def log_message(message, color = :white)
  # Forward to renderer
  @server_handler&.instance_variable_get(:@renderer)&.log_message(message, color)
end

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/git_game_show/game_server.rb', line 19

def start
  # Legacy method for starting the server without UI
  EM.run do
    server_handler = ServerHandler.new(
      port: @port,
      password: @password,
      rounds: @rounds,
      repo: @repo
    )

    # Start server with minimal UI
    puts "Server running at ws://0.0.0.0:#{@port}".colorize(:green)
    server_handler.start_with_ui
  end
end

#start_with_ui(join_link = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/git_game_show/game_server.rb', line 35

def start_with_ui(join_link = nil)
  # Store the join_link
  @join_link = join_link

  # Initialize and start the server handler with UI
  @server_handler = ServerHandler.new(
    port: @port,
    password: @password,
    rounds: @rounds,
    repo: @repo
  )

  # Start the server with UI
  @server_handler.start_with_ui(@join_link)
end

#update_player_listObject



83
84
85
86
87
88
89
90
91
# File 'lib/git_game_show/game_server.rb', line 83

def update_player_list
  # Forward to sidebar
  player_manager = @server_handler&.instance_variable_get(:@player_manager)
  sidebar = @server_handler&.instance_variable_get(:@sidebar)

  if player_manager && sidebar
    sidebar.update_player_list(player_manager.player_names, player_manager.scores)
  end
end