File size: 7,418 Bytes
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
"""

Test Enhanced MMORPG Features



This script verifies the implementation of:

1. Player Glow Implementation (current player gets yellow border highlight)

2. Player Names Display Implementation (show player names above sprites with level info)

3. Status Line Implementation (game info bar with player count, time, controls info)

4. Current Player Tracking (proper assignment and cleanup)

"""

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

from src.facades.game_facade import GameFacade
from src.ui.interface_manager import InterfaceManager
from src.ui.huggingface_ui import HuggingFaceUI

def test_enhanced_features():
    """Test all enhanced MMORPG features."""
    print("🧪 Testing Enhanced MMORPG Features")
    print("=" * 50)
    
    # Initialize components
    game_facade = GameFacade()
    ui = HuggingFaceUI(game_facade)
    interface_manager = InterfaceManager(game_facade, ui)
    
    print("✅ Components initialized successfully")
    
    # Test 1: Current Player Tracking Initialization
    print("\n1. Testing Current Player Tracking...")
    assert hasattr(interface_manager, 'current_player_id'), "current_player_id attribute missing"
    assert interface_manager.current_player_id is None, "current_player_id should be None initially"
    print("✅ Current player tracking properly initialized")
      # Test 2: Join Game and Current Player Assignment
    print("\n2. Testing Join Game with Current Player Assignment...")
    # Test the interface manager join handler directly
    current_state = {}
    result = interface_manager._handle_join_game("TestPlayer1", current_state)
    updated_state, status, player_list, world_html = result
    
    # The join handler should have created a player and set current_player_id
    player1_id = updated_state.get("player_id")
    assert player1_id is not None, "Failed to join game via interface manager"
    
    # Verify current player ID is set
    assert interface_manager.current_player_id == player1_id, f"current_player_id not set correctly. Expected: {player1_id}, Got: {interface_manager.current_player_id}"
    assert updated_state["player_id"] == player1_id, "Player state not updated correctly"
    print(f"✅ Current player ID set correctly: {interface_manager.current_player_id}")
    
    # Test 3: World HTML Generation with Player Glow
    print("\n3. Testing World HTML Generation with Enhanced Features...")
    world_html = interface_manager._generate_world_html_with_players()
    
    # Check for enhanced features in HTML
    assert "border: 2px solid yellow; border-radius: 50%;" in world_html, "Player glow effect missing"
    assert "TestPlayer1" in world_html, "Player name missing from display"
    assert "Lv." in world_html, "Level display missing"
    assert "Fantasy Realm" in world_html, "Status line missing"
    assert "Use WASD or Arrow Keys" in world_html, "Controls info missing"
    print("✅ World HTML contains all enhanced features")
      # Test 4: Multiple Players with Glow Distinction
    print("\n4. Testing Multiple Players with Glow Distinction...")
    # Add a second player via interface manager
    current_state2 = {}
    result2 = interface_manager._handle_join_game("TestPlayer2", current_state2)
    updated_state2, status2, player_list2, world_html2 = result2
    player2_id = updated_state2.get("player_id")
    
    # The second player should now be the current player
    assert interface_manager.current_player_id == player2_id, "Current player should be updated to latest joiner"
    
    world_html_multi = interface_manager._generate_world_html_with_players()
    
    # Count yellow borders (should be only 1 for current player)
    yellow_border_count = world_html_multi.count("border: 2px solid yellow; border-radius: 50%;")
    assert yellow_border_count == 1, f"Expected 1 yellow border, found {yellow_border_count}"
    print("✅ Only current player has glow effect")
      # Test 5: Leave Game and Current Player Cleanup
    print("\n5. Testing Leave Game and Current Player Cleanup...")
    leave_result = interface_manager._handle_leave_game(updated_state2)  # Use the second player's state
    new_state, leave_status, player_list_after, world_html_after = leave_result
    
    # Verify current player ID is cleared
    assert interface_manager.current_player_id is None, "current_player_id not cleared on leave"
    assert new_state == {}, "Player state not cleared on leave"
    print("✅ Current player tracking cleared on leave")
      # Test 6: Status Line Dynamic Content
    print("\n6. Testing Status Line Dynamic Content...")
    # Join again to test status line
    current_state3 = {}
    result3 = interface_manager._handle_join_game("StatusTestPlayer", current_state3)
    updated_state3, status3, player_list3, world_html3 = result3
    player3_id = updated_state3.get("player_id")
    
    world_html_status = interface_manager._generate_world_html_with_players()
    
    # Check for dynamic status line content
    assert "Players:" in world_html_status, "Player count missing from status"
    assert "Last Update:" in world_html_status, "Timestamp missing from status"
    import re
    time_pattern = r'\d{2}:\d{2}:\d{2}'
    assert re.search(time_pattern, world_html_status), "Time format not found in status"
    print("✅ Status line contains dynamic content")
    
    # Test 7: Player Name Background Opacity
    print("\n7. Testing Player Name Background Opacity...")
    assert "rgba(255,215,0,0.9)" in world_html_status, "Current player name background missing"
    assert "rgba(255,215,0,0.6)" in world_html_status, "Other player name background missing"
    print("✅ Player name backgrounds have correct opacity")
    
    # Test 8: Z-Index Layering
    print("\n8. Testing Z-Index Layering...")
    assert "z-index: 10" in world_html_status, "Sprite z-index missing"
    assert "z-index: 11" in world_html_status, "Name z-index missing"
    assert "z-index: 12" in world_html_status, "Status z-index missing"
    print("✅ Z-index layering implemented correctly")
    
    print("\n" + "=" * 50)
    print("🎉 ALL ENHANCED FEATURES TESTS PASSED!")
    print("=" * 50)
    
    # Summary of implemented features
    print("\n📋 Enhanced Features Successfully Implemented:")
    print("✅ 1. Player Glow Effect - Current player gets yellow border highlight")
    print("✅ 2. Player Names Display - Names with level info shown above sprites")
    print("✅ 3. Status Line - Game info bar with player count, time, controls")
    print("✅ 4. Current Player Tracking - Proper assignment and cleanup")
    print("✅ 5. Dynamic Background Opacity - Different opacity for current vs other players")
    print("✅ 6. Proper Z-Index Layering - Sprites, names, and status properly layered")
    print("✅ 7. Enhanced HTML Generation - All features integrated into world view")
    print("✅ 8. Keyboard Controls Integration - Controls info in status line")
    
    return True

if __name__ == "__main__":
    try:
        test_enhanced_features()
        sys.exit(0)
    except Exception as e:
        print(f"❌ Test failed with error: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)