Skip to content

Commit

Permalink
fixed scale stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed Dec 2, 2023
1 parent 747ccda commit be4c0af
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sizebot/lib/proportions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ def __init__(self, stat: Stat, value: Any):
self.value = value

def scale(self, scale: Decimal, found: dict):
# None * 2 is None
if self.value is None:
return StatValue(self, None) # None * 2 is None
if self.stat.power is not None:
value = self.value * (scale ** self.stat.power)
else:
value = None
elif self.stat.power is not None:
T = type(self.value)
value = T(self.value * (scale ** self.stat.power))
elif self.stat.default_from:
if any(r not in found for r in self.stat.requires):
return
value = self.stat.default_from(found)
else:
value = self.value
if self.stat.sets:
found[self.stat.sets] = value
return StatValue(self, value)
return StatValue(self.stat, value)

def __str__(self):
return f"{self.stat.name}: {self.value}"
Expand Down Expand Up @@ -139,6 +143,10 @@ def __str__(self):
Stat("Visibility", sets="visibility", requires=["height"], default_from=lambda s: calcVisibility(s["height"]))
]

# Example display code
# display_stats = [
# DisplayStat(key="width", name="Width", statout="You're a {} wide chonker!", embedname="Width:", embedvalue="{} :widthicon:")
# ]

class StatBox:
def __init__(self, stats: list[StatValue] = None):
Expand All @@ -164,7 +172,7 @@ def load(cls, playerStats: PlayerStats) -> StatBox:
processed.append(sv)
# If no progress
if len(queued) == len(processing):
raise errors.UnfoundStatException(["Load"] + [s.name for s in queued])
raise errors.UnfoundStatException([s.name for s in queued])
return cls(processed)

def scale(self, scale_value: Decimal) -> StatBox:
Expand All @@ -186,7 +194,7 @@ def scale(self, scale_value: Decimal) -> StatBox:
processed.append(sv)
# If no progress
if len(queued) == len(processing):
raise errors.UnfoundStatException(["Scale"] + [s.stat.name for s in queued])
raise errors.UnfoundStatException([s.stat.name for s in queued])
return StatBox(processed)

def get(self, stat_name: str) -> StatValue | None:
Expand Down

0 comments on commit be4c0af

Please sign in to comment.