From 3ebb5c53f4148f3e08293f255dd991fc7f856c0e Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:41:37 +0100 Subject: [PATCH] Factorize check (cherry picked from commit 40be2ccf181bf4eaf160c7e4711c79663ca650d3) --- game/scripts/wardrobe/functions.rpy | 50 +++++++++++------------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/game/scripts/wardrobe/functions.rpy b/game/scripts/wardrobe/functions.rpy index dc56eaa4..21243323 100644 --- a/game/scripts/wardrobe/functions.rpy +++ b/game/scripts/wardrobe/functions.rpy @@ -1,42 +1,38 @@ init -1 python: - def get_character_progression(key): + def __check_exists(key): if not key in states.dolls: raise KeyError("{!r} character is undefined.".format(key)) + + def get_character_progression(key): + __check_exists(key) return getattr(states, f"{key[:3]}").level def get_character_scheduling(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(states, f"{key[:3]}").wardrobe_scheduling def get_character_requirement(key, type): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(renpy.store, key[:3]+"_requirements").get(type, 0) def get_character_response(key, type): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(renpy.store, key[:3]+"_responses").get(type) def get_character_object(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(store, key) def get_character_outfit(key, type="default"): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(store, "{}_outfit_{}".format(key[:3], type)) def get_character_body(key, type="default"): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(store, "{}_body_{}".format(key[:3], type)) def get_character_outfit_req(key, item): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) if not isinstance(item, DollOutfit): raise TypeError("{!r} is not a DollOutfit instance.".format(item)) @@ -53,43 +49,35 @@ init -1 python: print("\n".join(req)) def get_character_tag(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return "{}_main".format(key) def get_character_sayer(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(store, key[:3]) def get_character_gift_label(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return "give_{}_gift".format(key[:3]) def get_character_potion_check_label(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return "{}_potion_check".format(key[:3]) def get_character_potion_check(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(store, "{}_potion_check".format(key[:3])) def get_character_unlock(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(states, f"{key[:3]}").unlocked def get_character_gifted(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(states, f"{key[:3]}").gifted def get_character_mood(key): - if not key in states.dolls: - raise KeyError("{!r} character is undefined.".format(key)) + __check_exists(key) return getattr(states, f"{key[:3]}").mood def get_outfit_score(outfit):