Skip to content

Commit

Permalink
Merge pull request #4 from ItzSkyReed/dev/0.4.3
Browse files Browse the repository at this point in the history
Dev/0.4.3
  • Loading branch information
ItzSkyReed authored Jan 11, 2025
2 parents e0c331f + 4a41b42 commit 6fb235f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
14 changes: 10 additions & 4 deletions src/BACAP_Parser/Criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,16 +28,20 @@ def trigger(self) -> str:
"""
return self._trigger

@property
def conditions(self) -> dict | None:
return self._conditions

def __repr__(self):
return f"<Criteria name={self._name}, trigger={self._trigger}"

def __str__(self):
return f"<Criteria name={self._name}, trigger={self._trigger}"

def __eq__(self, other: "Criteria") -> 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)
Expand Down
4 changes: 3 additions & 1 deletion src/BACAP_Parser/CriteriaList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6fb235f

Please sign in to comment.