Ensure drops cannot end up with inconsistent current minutes and progress
This commit is contained in:
1 parent
da050828c1
commit
5ade35d6a5
1 file changed
+11
-6
+11
-6
@@ -185,12 +185,10 @@ class TimedDrop(BaseDrop):
|
||||
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 @@ class TimedDrop(BaseDrop):
|
||||
|
||||
@cached_property
|
||||
def progress(self) -> float:
|
||||
if self.required_minutes > 0:
|
||||
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
|
||||
return 0.0 # Drops with 0 required minutes are filtered via _base_can_earn
|
||||
|
||||
def _base_can_earn(self) -> bool:
|
||||
return self.required_minutes > 0 and super()._base_can_earn()
|
||||
@@ -248,7 +248,12 @@ class TimedDrop(BaseDrop):
|
||||
return result
|
||||
|
||||
def update_minutes(self, minutes: int):
|
||||
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()
|
||||
|
||||
|
||||
Reference in new issue
Block a user