Skip to content

Commit

Permalink
Fix crash on clamp with zero quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Sep 22, 2024
1 parent ae45158 commit 3b1200d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/production_planner/cells/_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..core import (
get_path,
set_path,
smartround,
SummaryNode,
)
from dataclasses import dataclass
Expand All @@ -14,6 +15,8 @@
from rich.style import Style
from rich.color import Color

from numbers import Number


@dataclass
class Bounds:
Expand All @@ -30,7 +33,7 @@ class SetCellValue:
@dataclass
class CellValue:
value: float = 0
text = None
text: str = None
clamped: bool = False


Expand Down Expand Up @@ -78,7 +81,7 @@ def get_num(self):
def get_styled(self):
cell = self.get()
value = cell.value
txt = str(cell.text or cell.value)
txt = str(cell.text or (smartround(cell.value) if isinstance(cell.value, Number) else cell.value))
style = Style()

if self.style_summary:
Expand Down
10 changes: 7 additions & 3 deletions src/production_planner/cells/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ def text_postprocess(self, text: str, style: Style) -> (str, Style):

def get(self) -> CellValue:
if self.access_guard():
value = smartround(self.data.node_main.ingredients[self.vispath])

if self.data.node_main.clamp and self.data.node_main.clamp.name == self.vispath:
return CellValue(self.data.node_main.clamp.count, clamped=True)
if abs(value - self.data.node_main.clamp.count) > 0.01:
return CellValue(value, text=f"{value} !", clamped=True)
else:
return CellValue(value, clamped=True)
else:
value = self.data.node_main.ingredients[self.vispath]
return CellValue(smartround(value))
return CellValue(value)
else:
return CellValue(self.default_na)

Expand Down
6 changes: 2 additions & 4 deletions src/production_planner/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def update(self):
self.ingredients = {}
rate_mult = 60 / self.recipe.cycle_rate

if self.clamp:
if self.clamp and self.count:

for ingredient in self.recipe.inputs:
if ingredient.name == self.clamp.name:
# self.clock_rate = ((abs(int(clamped.count)) * 100) / (rate_mult / self.count)) / ingredient.count
Expand Down Expand Up @@ -127,9 +128,6 @@ def update(self):
else:
total = out.count * ingredient_mult
self.ingredients[out.name] = total
if self.clamp and self.clamp.name == out.name and abs(self.clamp.count - total) > 0.01:
from ..core import smartround
self.clamp.count = smartround(total)

if self.producer.is_pow_gen:
pass # TODO
Expand Down

0 comments on commit 3b1200d

Please sign in to comment.