diff --git a/inventory.py b/inventory.py index e4467eee..5e885d92 100644 --- a/inventory.py +++ b/inventory.py @@ -185,12 +185,10 @@ def __init__( super().__init__(campaign, data, claimed_benefits) self._manager: GUIManager = self._twitch.gui self._gui_inv: InventoryOverview = self._manager.inv - self.current_minutes: int = 0 - if "self" in data: - self.current_minutes = data["self"]["currentMinutesWatched"] + self.current_minutes: int = "self" in data and data["self"]["currentMinutesWatched"] or 0 self.required_minutes: int = data["requiredMinutesWatched"] if self.is_claimed: - # claimed drops report 0 current minutes, so we need to make a correction + # claimed drops may report inconsistent current minutes, so we need to overwrite them self.current_minutes = self.required_minutes def __repr__(self) -> str: @@ -224,9 +222,11 @@ def total_remaining_minutes(self) -> int: @cached_property def progress(self) -> float: - if self.required_minutes > 0: - return self.current_minutes / self.required_minutes - return 0.0 # Drops with 0 required minutes are filtered via _base_can_earn + if self.current_minutes <= 0 or self.required_minutes <= 0: + return 0.0 + elif self.current_minutes >= self.required_minutes: + return 1.0 + return self.current_minutes / self.required_minutes def _base_can_earn(self) -> bool: return self.required_minutes > 0 and super()._base_can_earn() @@ -248,7 +248,12 @@ async def claim(self) -> bool: return result def update_minutes(self, minutes: int): - self.current_minutes = minutes + if minutes < 0: + return + elif minutes <= self.required_minutes: + self.current_minutes = minutes + else: + self.current_minutes = self.required_minutes self._on_minutes_changed() self.display()