From ae5ff121d96f545e94576c957ff5c6c8fa333d55 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 3 Apr 2024 01:03:46 +0200 Subject: [PATCH] Moar lint --- game/scripts/01cds.rpy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/game/scripts/01cds.rpy b/game/scripts/01cds.rpy index 76c09dc4..9abe731c 100644 --- a/game/scripts/01cds.rpy +++ b/game/scripts/01cds.rpy @@ -91,6 +91,8 @@ python early hide: chibi = eval(f"{who}_chibi") except Exception: renpy.error(f"Character chibi not defined: {who}") + if not hasattr(chibi, action): + renpy.error(f"Chibi action not defined: {who} {action}") def predict(self): who, action = self @@ -142,6 +144,23 @@ python early hide: return {"blocks": blocks} + def lint(self): + any_true = False + for block, weight, condition in self["blocks"]: + if not isinstance(weight, (int, float)): + renpy.error(f"Weight must be a number, not {weight!r}") + + if condition == "True": + any_true = True + else: + try: + eval(condition) + except Exception: + renpy.error(f"Condition could not be evaluated: {condition!r}") + + if not any_true: + renpy.error("All blocks have a condition, which will raise an exception if all conditions are False at the same time at runtime") + def next(self): blocks = [(block, weight) for block, weight, condition in self["blocks"] if eval(condition)] total_weight = sum(weight for _, weight in blocks)