From 2e342866ce63f882aae76b4b29837870e23bf069 Mon Sep 17 00:00:00 2001 From: SkyReed Date: Sat, 11 Jan 2025 16:39:25 +0500 Subject: [PATCH 1/2] Add conditions parameter to Criteria class and update instantiation logic - Modify the `Criteria` class to include an optional `conditions` parameter in the initializer. - Add a new property method for `conditions` to retrieve the criteria's conditions. - Update the equality comparison to include `conditions`. - Adjust the instantiation of `Criteria` in `CriteriaList` to pass conditions from a dictionary. --- src/BACAP_Parser/Criteria.py | 14 ++++++++++---- src/BACAP_Parser/CriteriaList.py | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/BACAP_Parser/Criteria.py b/src/BACAP_Parser/Criteria.py index 823aabc..d8c4919 100644 --- a/src/BACAP_Parser/Criteria.py +++ b/src/BACAP_Parser/Criteria.py @@ -2,14 +2,16 @@ class Criteria: - def __init__(self, name: str, trigger: str): + def __init__(self, name: str, trigger: str, conditions: dict | None = None): """ Class of the advancement criteria. :param name: Name of the criteria. - :param trigger: trigger of the criteria. + :param trigger: Trigger of the criteria. + :param conditions: Conditions of the criteria as raw dict object. """ self._name = name self._trigger = cut_namespace(trigger) + self._conditions = conditions self._is_impossible = None @property @@ -26,6 +28,10 @@ def trigger(self) -> str: """ return self._trigger + @property + def conditions(self) -> dict | None: + return self._conditions + def __repr__(self): return f" bool: - if other.__class__ != self.__class__: + if not isinstance(other, Criteria): raise TypeError("Element must be an instance of the Criteria class") - return (self._name == other._name) and (self._trigger == other._trigger) + return (self._name == other._name) and (self._trigger == other._trigger) and (self._conditions == other._conditions) def __ne__(self, other: "Criteria") -> bool: return not self.__eq__(other) diff --git a/src/BACAP_Parser/CriteriaList.py b/src/BACAP_Parser/CriteriaList.py index bf51e9b..7356d2b 100644 --- a/src/BACAP_Parser/CriteriaList.py +++ b/src/BACAP_Parser/CriteriaList.py @@ -18,7 +18,7 @@ def __init__(self, adv_criteria: Union[dict, Criteria, list, "CriteriaList", Non elif isinstance(adv_criteria, dict): for name, crit in adv_criteria.items(): - criteria = Criteria(name, crit["trigger"]) + criteria = Criteria(name, crit["trigger"], conditions=crit.get("conditions")) self.append(criteria) elif isinstance(adv_criteria, Criteria): @@ -86,6 +86,8 @@ def remove(self, criteria: Criteria | str, **kwargs): self.remove(criteria) def __eq__(self, other: "CriteriaList") -> bool: + if not isinstance(other, CriteriaList): + return NotImplemented return super().__eq__(other) def __contains__(self, criteria: Criteria) -> bool: From 4a41b42975d46a2626a4a61e502db95fdc387fdd Mon Sep 17 00:00:00 2001 From: SkyReed Date: Sat, 11 Jan 2025 16:40:20 +0500 Subject: [PATCH 2/2] Bump version to 0.4.3 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8664aba..2b346dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "BACAP_Parser" -version = "0.4.2" +version = "0.4.3" description = "Library to parse BlazeAndCavesAdvancementsPack and Addons for it" readme = "README.md" license = {file = "LICENSE"}