git_game_show 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git_game_show/cli.rb +1 -0
- data/lib/git_game_show/game_server.rb +38 -38
- data/lib/git_game_show/updater.rb +8 -8
- data/lib/git_game_show/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0eaec4e8df244f6bce785020f5e51e64c3ce2a4a4a0f34e24b35067d00ff46b
|
4
|
+
data.tar.gz: 1370dec1ae250bce28fc021353353a1a3fcf31b19e376128065377a5e7d0b280
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b32957cf357b2cd3d1d04c48fc285307cc948e7fcb150ec364a1e7ec2d41a552e894207935b8912729ffa6d763a42006508b741afe65af8dab0110227cd3c6e
|
7
|
+
data.tar.gz: 1993c667e5c49e90c4c36a7f2888e61573bfda38113be4fa41dd91d095a339023bfd242d5fcbf87c07fae4f3da563815862d103e7b5cfce3665acccf85c15e13
|
data/lib/git_game_show/cli.rb
CHANGED
@@ -523,6 +523,7 @@ module GitGameShow
|
|
523
523
|
|
524
524
|
def display_game_logo
|
525
525
|
clear_screen
|
526
|
+
puts ""
|
526
527
|
puts (" ██████╗ ██╗████████╗".colorize(:red) + " ██████╗ █████╗ ███╗ ███╗███████╗".colorize(:green)).center(110)
|
527
528
|
puts ("██╔════╝ ██║╚══██╔══╝".colorize(:red) + " ██╔════╝ ██╔══██╗████╗ ████║██╔════╝".colorize(:green)).center(110)
|
528
529
|
puts ("██║ ███╗██║ ██║ ".colorize(:red) + " ██║ ███╗███████║██╔████╔██║█████╗ ".colorize(:green)).center(110)
|
@@ -426,10 +426,10 @@ module GitGameShow
|
|
426
426
|
# For regular quizzes, calculate points immediately
|
427
427
|
correct = answer == current_question[:correct_answer]
|
428
428
|
points = 0
|
429
|
-
|
429
|
+
|
430
430
|
if correct
|
431
431
|
points = 10 # Base points for correct answer
|
432
|
-
|
432
|
+
|
433
433
|
# Bonus points for fast answers
|
434
434
|
if time_taken < 5
|
435
435
|
points += 5
|
@@ -476,7 +476,7 @@ module GitGameShow
|
|
476
476
|
correct_answer: question[:correct_answer],
|
477
477
|
points: points # Include points in the feedback
|
478
478
|
}
|
479
|
-
|
479
|
+
|
480
480
|
# For ordering quizzes, we can't determine correctness immediately
|
481
481
|
# Instead we'll indicate that scoring will be calculated after timeout
|
482
482
|
if question[:question_type] == 'ordering'
|
@@ -505,7 +505,7 @@ module GitGameShow
|
|
505
505
|
return if @question_already_evaluated
|
506
506
|
|
507
507
|
@question_already_evaluated = true
|
508
|
-
|
508
|
+
|
509
509
|
# Safety check - make sure we have a current question
|
510
510
|
begin
|
511
511
|
current_question = @round_questions[@current_question_index]
|
@@ -516,7 +516,7 @@ module GitGameShow
|
|
516
516
|
end
|
517
517
|
|
518
518
|
results = {}
|
519
|
-
|
519
|
+
|
520
520
|
begin
|
521
521
|
# For ordering quizzes or other special types, use the mini-game's evaluation method
|
522
522
|
if current_question[:question_type] == 'ordering'
|
@@ -524,13 +524,13 @@ module GitGameShow
|
|
524
524
|
mini_game_answers = {}
|
525
525
|
@player_answers.each do |player_name, answer_data|
|
526
526
|
next unless player_name && answer_data # Skip nil entries
|
527
|
-
|
527
|
+
|
528
528
|
mini_game_answers[player_name] = {
|
529
529
|
answer: answer_data[:answer],
|
530
530
|
time_taken: answer_data[:time_taken] || 20
|
531
531
|
}
|
532
532
|
end
|
533
|
-
|
533
|
+
|
534
534
|
# Call the mini-game's evaluate_answers method with error handling
|
535
535
|
begin
|
536
536
|
results = @current_mini_game.evaluate_answers(current_question, mini_game_answers) || {}
|
@@ -540,7 +540,7 @@ module GitGameShow
|
|
540
540
|
results = {}
|
541
541
|
@player_answers.each do |player_name, answer_data|
|
542
542
|
next unless player_name
|
543
|
-
|
543
|
+
|
544
544
|
results[player_name] = {
|
545
545
|
answer: answer_data[:answer] || [],
|
546
546
|
correct: false,
|
@@ -554,7 +554,7 @@ module GitGameShow
|
|
554
554
|
results = {}
|
555
555
|
@player_answers.each do |player_name, answer_data|
|
556
556
|
next unless player_name && answer_data # Skip nil entries
|
557
|
-
|
557
|
+
|
558
558
|
results[player_name] = {
|
559
559
|
answer: answer_data[:answer] || "No answer",
|
560
560
|
correct: answer_data[:correct] || false,
|
@@ -570,7 +570,7 @@ module GitGameShow
|
|
570
570
|
results[player_name][:correct] = !!result[:correct] # Convert to boolean
|
571
571
|
results[player_name][:points] = result[:points] || 0
|
572
572
|
end
|
573
|
-
|
573
|
+
|
574
574
|
# Update scores
|
575
575
|
results.each do |player, result|
|
576
576
|
@scores[player] = (@scores[player] || 0) + (result[:points] || 0)
|
@@ -591,7 +591,7 @@ module GitGameShow
|
|
591
591
|
partial_score: result[:partial_score] || ""
|
592
592
|
}
|
593
593
|
end
|
594
|
-
|
594
|
+
|
595
595
|
# Sort scores safely
|
596
596
|
safe_scores = {}
|
597
597
|
begin
|
@@ -600,7 +600,7 @@ module GitGameShow
|
|
600
600
|
log_message("Error sorting scores: #{e.message}", :red)
|
601
601
|
safe_scores = @scores.dup # Use unsorted if sorting fails
|
602
602
|
end
|
603
|
-
|
603
|
+
|
604
604
|
# For ordering questions, format the correct_answer as a list with numbers
|
605
605
|
formatted_correct_answer = current_question[:correct_answer] || []
|
606
606
|
if current_question[:question_type] == 'ordering'
|
@@ -608,7 +608,7 @@ module GitGameShow
|
|
608
608
|
"#{idx + 1}. #{item}" # Add numbers for easier reading
|
609
609
|
end
|
610
610
|
end
|
611
|
-
|
611
|
+
|
612
612
|
broadcast_message({
|
613
613
|
type: MessageType::ROUND_RESULT,
|
614
614
|
question: current_question,
|
@@ -623,7 +623,7 @@ module GitGameShow
|
|
623
623
|
# Log current scores for the host - with error handling
|
624
624
|
begin
|
625
625
|
log_message("Current scores:", :cyan)
|
626
|
-
|
626
|
+
|
627
627
|
# Safety check for scores
|
628
628
|
if @scores.nil? || @scores.empty?
|
629
629
|
log_message("No scores available", :yellow)
|
@@ -635,13 +635,13 @@ module GitGameShow
|
|
635
635
|
log_message("Error sorting scores for display: #{e.message}", :red)
|
636
636
|
sorted_scores = @scores.to_a
|
637
637
|
end
|
638
|
-
|
638
|
+
|
639
639
|
# Display each score with error handling
|
640
640
|
sorted_scores.each do |player_entry|
|
641
641
|
# Extract player and score safely
|
642
642
|
player = player_entry[0].to_s
|
643
643
|
score = player_entry[1] || 0
|
644
|
-
|
644
|
+
|
645
645
|
# Truncate player names if too long
|
646
646
|
truncated_name = player.length > 15 ? "#{player[0...12]}..." : player
|
647
647
|
log_message("#{truncated_name}: #{score} points", :light_blue)
|
@@ -855,7 +855,7 @@ module GitGameShow
|
|
855
855
|
safe_scores[player.to_s] = score.to_i
|
856
856
|
end
|
857
857
|
end
|
858
|
-
|
858
|
+
|
859
859
|
# Sort scores safely
|
860
860
|
sorted_scores = {}
|
861
861
|
begin
|
@@ -864,7 +864,7 @@ module GitGameShow
|
|
864
864
|
log_message("Error sorting scores for scoreboard: #{e.message}", :red)
|
865
865
|
sorted_scores = safe_scores # Use unsorted if sorting fails
|
866
866
|
end
|
867
|
-
|
867
|
+
|
868
868
|
broadcast_message({
|
869
869
|
type: MessageType::SCOREBOARD,
|
870
870
|
scores: sorted_scores
|
@@ -879,7 +879,7 @@ module GitGameShow
|
|
879
879
|
|
880
880
|
# Initialize winner variable outside the begin block so it's visible throughout the method
|
881
881
|
winner = nil
|
882
|
-
|
882
|
+
|
883
883
|
# Wrap the main logic in a begin/rescue block
|
884
884
|
begin
|
885
885
|
# Safety check - make sure we have scores and they're not nil
|
@@ -908,7 +908,7 @@ module GitGameShow
|
|
908
908
|
next unless player && player != ""
|
909
909
|
safe_scores[player] = score || 0
|
910
910
|
end
|
911
|
-
|
911
|
+
|
912
912
|
# Determine the winner with safety checks
|
913
913
|
begin
|
914
914
|
winner = safe_scores.max_by { |_, score| score || 0 }
|
@@ -1000,7 +1000,7 @@ module GitGameShow
|
|
1000
1000
|
begin
|
1001
1001
|
# Safety check - make sure we have a main_width value
|
1002
1002
|
main_width = @main_width || 80
|
1003
|
-
|
1003
|
+
|
1004
1004
|
# Use log messages instead of clearing screen
|
1005
1005
|
divider = "=" * (main_width - 5)
|
1006
1006
|
log_message(divider, :yellow)
|
@@ -1036,7 +1036,7 @@ module GitGameShow
|
|
1036
1036
|
rescue => e
|
1037
1037
|
log_message("Error copying scores: #{e.message}", :red)
|
1038
1038
|
end
|
1039
|
-
|
1039
|
+
|
1040
1040
|
# Safety check for scores
|
1041
1041
|
if safe_scores.empty?
|
1042
1042
|
log_message("No scores available to display", :yellow)
|
@@ -1060,19 +1060,19 @@ module GitGameShow
|
|
1060
1060
|
end
|
1061
1061
|
|
1062
1062
|
max_to_show = 10
|
1063
|
-
|
1063
|
+
|
1064
1064
|
# Show limited entries in console with extra safety checks
|
1065
1065
|
begin
|
1066
1066
|
# Ensure we don't try to take more entries than exist
|
1067
1067
|
entries_to_show = [sorted_scores.size, max_to_show].min
|
1068
|
-
|
1068
|
+
|
1069
1069
|
sorted_scores.take(entries_to_show).each_with_index do |score_entry, index|
|
1070
1070
|
# Extra safety check for each entry
|
1071
1071
|
next unless score_entry && score_entry.is_a?(Array) && score_entry.size >= 2
|
1072
|
-
|
1072
|
+
|
1073
1073
|
name = score_entry[0]
|
1074
1074
|
score = score_entry[1]
|
1075
|
-
|
1075
|
+
|
1076
1076
|
# Safely handle name and score
|
1077
1077
|
player_name = name.to_s
|
1078
1078
|
player_score = score.to_i
|
@@ -1106,7 +1106,7 @@ module GitGameShow
|
|
1106
1106
|
sorted_scores.each_with_index do |score_entry, index|
|
1107
1107
|
# Skip invalid entries
|
1108
1108
|
next unless score_entry && score_entry.is_a?(Array) && score_entry.size >= 2
|
1109
|
-
|
1109
|
+
|
1110
1110
|
# Use safe values
|
1111
1111
|
player_name = score_entry[0].to_s
|
1112
1112
|
player_score = score_entry[1].to_i
|
@@ -1152,7 +1152,7 @@ module GitGameShow
|
|
1152
1152
|
log_message("Error: Invalid winner data for leaderboard file", :red)
|
1153
1153
|
return nil
|
1154
1154
|
end
|
1155
|
-
|
1155
|
+
|
1156
1156
|
if !leaderboard_entries || !leaderboard_entries.is_a?(Array) || leaderboard_entries.empty?
|
1157
1157
|
log_message("Error: Invalid entries data for leaderboard file", :red)
|
1158
1158
|
return nil
|
@@ -1266,7 +1266,7 @@ module GitGameShow
|
|
1266
1266
|
|
1267
1267
|
def broadcast_message(message, exclude: nil)
|
1268
1268
|
return if message.nil?
|
1269
|
-
|
1269
|
+
|
1270
1270
|
begin
|
1271
1271
|
# Convert message to JSON safely
|
1272
1272
|
json_message = nil
|
@@ -1274,7 +1274,7 @@ module GitGameShow
|
|
1274
1274
|
json_message = message.to_json
|
1275
1275
|
rescue => e
|
1276
1276
|
log_message("Error converting message to JSON: #{e.message}", :red)
|
1277
|
-
|
1277
|
+
|
1278
1278
|
# Try to simplify the message to make it JSON-compatible
|
1279
1279
|
simplified_message = {
|
1280
1280
|
type: message[:type] || "unknown",
|
@@ -1282,17 +1282,17 @@ module GitGameShow
|
|
1282
1282
|
}
|
1283
1283
|
json_message = simplified_message.to_json
|
1284
1284
|
end
|
1285
|
-
|
1285
|
+
|
1286
1286
|
return unless json_message
|
1287
|
-
|
1287
|
+
|
1288
1288
|
# Send to each player with error handling
|
1289
1289
|
@players.each do |player_name, ws|
|
1290
1290
|
# Skip excluded player if specified
|
1291
1291
|
next if exclude && player_name == exclude
|
1292
|
-
|
1292
|
+
|
1293
1293
|
# Skip nil websockets
|
1294
1294
|
next unless ws
|
1295
|
-
|
1295
|
+
|
1296
1296
|
# Send with error handling for each individual player
|
1297
1297
|
begin
|
1298
1298
|
ws.send(json_message)
|
@@ -1558,7 +1558,7 @@ module GitGameShow
|
|
1558
1558
|
log_message("Only one mini-game type available: #{selected_game.name}", :light_black)
|
1559
1559
|
return selected_game
|
1560
1560
|
end
|
1561
|
-
|
1561
|
+
|
1562
1562
|
# If we have no more available mini-games, reset the cycle
|
1563
1563
|
if @available_mini_games.empty?
|
1564
1564
|
# Handle the case where we might have only one game left after excluding the last used
|
@@ -1591,9 +1591,9 @@ module GitGameShow
|
|
1591
1591
|
def load_mini_games
|
1592
1592
|
# Enable all mini-games
|
1593
1593
|
[
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1594
|
+
GitGameShow::AuthorQuiz,
|
1595
|
+
GitGameShow::CommitMessageQuiz,
|
1596
|
+
GitGameShow::CommitMessageCompletion,
|
1597
1597
|
GitGameShow::DateOrderingQuiz
|
1598
1598
|
]
|
1599
1599
|
end
|
@@ -61,14 +61,14 @@ module GitGameShow
|
|
61
61
|
# Clear the terminal for better visibility
|
62
62
|
puts "\n\n"
|
63
63
|
|
64
|
-
puts "
|
65
|
-
puts "
|
66
|
-
puts "
|
67
|
-
puts "│
|
68
|
-
puts "│
|
69
|
-
puts "│
|
70
|
-
puts "│
|
71
|
-
puts "
|
64
|
+
puts ("╭" + "─" * 60 + "╮").colorize(:light_blue)
|
65
|
+
puts "│#{"Update Available for Git Game Show!".center(60)}│".colorize(:light_blue)
|
66
|
+
puts ("├" + "─" * 60 + "┤").colorize(:light_blue)
|
67
|
+
puts "│".colorize(:light_blue) + " " * 60 + "│".colorize(:light_blue)
|
68
|
+
puts "│".colorize(:light_blue) + "Current version: #{current_version}".center(60) + "│".colorize(:light_blue)
|
69
|
+
puts "│".colorize(:light_blue) + "Latest version: #{latest_version}".center(60) + "│".colorize(:light_blue)
|
70
|
+
puts "│".colorize(:light_blue) + " " * 60 + "│".colorize(:light_blue)
|
71
|
+
puts ("╰" + "─" * 60 + "╯").colorize(:light_blue)
|
72
72
|
puts "\n"
|
73
73
|
|
74
74
|
update_now = prompt.yes?("Would you like to update now?")
|