Coverage for src/rift_console/rift_console.py: 0%

58 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-08 09:36 +0000

1import datetime 

2from typing import Optional 

3 

4from rift_console.melvin_api import MelvonautTelemetry 

5import shared.constants as con 

6from shared.models import ( 

7 Achievement, 

8 BaseTelemetry, 

9 BeaconObjective, 

10 Event, 

11 Slot, 

12 State, 

13 ZonedObjective, 

14) 

15 

16 

17class RiftConsole: 

18 """State of a currently running Console, including live data from CIARC/Melvonaut API.""" 

19 

20 last_backup_date: Optional[datetime.datetime] = None 

21 is_network_simulation: Optional[bool] = None 

22 user_speed_multiplier: Optional[int] = None 

23 

24 live_telemetry: Optional[BaseTelemetry] = None 

25 prev_state: State = State.Unknown 

26 next_state: State = State.Unknown 

27 slots_used: Optional[int] = None 

28 slots: list[Slot] = [] 

29 zoned_objectives: list[ZonedObjective] = [] 

30 beacon_objectives: list[BeaconObjective] = [] 

31 completed_ids: list[int] = [] 

32 achievements: list[Achievement] = [] 

33 past_traj: list[tuple[int, int]] = [] 

34 future_traj: list[tuple[int, int]] = [] 

35 live_melvonaut_api: Optional[MelvonautTelemetry] = None 

36 melvonaut_image_count: int = -1 # -1 indicates no data 

37 console_image_count: int = -1 # -1 indicates no data 

38 console_image_dates: list[tuple[str, int]] = [] 

39 ebt_ping_list: list[tuple[int, int]] = [] 

40 console_found_events: list[Event] = [] 

41 melvin_task: str = "" 

42 melvin_lens: str = "" 

43 

44 def get_draw_zoned_obj(self) -> list[dict[str, object]]: 

45 """Picks objectives to be drawn later from its telemetry.""" 

46 get_draw_zoned_obj = [] 

47 for obj in self.zoned_objectives: 

48 if obj.zone is not None: 

49 draw = { 

50 "name": obj.id, 

51 "zone": [ 

52 int(obj.zone[0]), 

53 int(obj.zone[1]), 

54 int(obj.zone[2]), 

55 int(obj.zone[3]), 

56 ], 

57 } 

58 get_draw_zoned_obj.append(draw) 

59 if len(get_draw_zoned_obj) >= 5: # only collect 5 for visual clarity 

60 break 

61 return get_draw_zoned_obj 

62 

63 def predict_trajektorie( 

64 self, 

65 ) -> tuple[list[tuple[int, int]], list[tuple[int, int]]]: 

66 """Calculate the points that melvin goes through next""" 

67 past = [] 

68 future = [] 

69 

70 if self.live_telemetry: 

71 for i in range(0, con.TRAJ_TIME, con.TRAJ_STEP): 

72 (x, y) = RiftConsole.fix_overflow( 

73 int(self.live_telemetry.width_x + self.live_telemetry.vx * i), 

74 int(self.live_telemetry.height_y + self.live_telemetry.vy * i), 

75 ) 

76 future.append((x, y)) 

77 (x, y) = RiftConsole.fix_overflow( 

78 int(self.live_telemetry.width_x - self.live_telemetry.vx * i), 

79 int(self.live_telemetry.height_y - self.live_telemetry.vy * i), 

80 ) 

81 past.append((x, y)) 

82 

83 return (past, future) 

84 

85 @staticmethod 

86 def fix_overflow(x: int, y: int) -> tuple[int, int]: 

87 """Helper for trajektorie predition. Does "teleportation" when MELVIN reaches one side of the map.""" 

88 if x > con.WORLD_X: 

89 x = x % con.WORLD_X 

90 

91 while x < 0: 

92 x += con.WORLD_X 

93 

94 if y > con.WORLD_Y: 

95 y = y % con.WORLD_Y 

96 while y < 0: 

97 y += con.WORLD_Y 

98 

99 return (x, y)