Conditions
minevent.conditions ¶
Implement some conditions that can be used in the event system.
minevent.conditions.BaseCondition ¶
Bases: ABC
Define the base class to implement a condition for
ConditionalEventHandler
.
A child class has to implement the following methods:
- ``evaluate``
- ``equal``
Example usage:
>>> from minevent import PeriodicCondition
>>> condition = PeriodicCondition(freq=3)
>>> condition.evaluate()
True
>>> condition.evaluate()
False
>>> condition.evaluate()
False
>>> condition.evaluate()
True
>>> condition.evaluate()
False
>>> condition.evaluate()
False
>>> condition.evaluate()
True
minevent.conditions.BaseCondition.equal
abstractmethod
¶
equal(other: Any) -> bool
Compare two conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
Specifies the other object to compare with. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
>>> from minevent import PeriodicCondition
>>> condition = PeriodicCondition(freq=3)
>>> condition.equal(PeriodicCondition(freq=3))
True
>>> condition.equal(PeriodicCondition(freq=2))
False
minevent.conditions.BaseCondition.evaluate
abstractmethod
¶
evaluate() -> bool
Evaluate the condition given the current state.
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
>>> from minevent import EventHandler
>>> def hello_handler() -> None:
... print("Hello!")
...
>>> handler = EventHandler(hello_handler)
>>> handler.handle()
Hello!
minevent.conditions.PeriodicCondition ¶
Bases: BaseCondition
Implement a periodic condition.
This condition is true every freq
events.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
freq
|
int
|
Specifies the frequency. |
required |
Example usage:
>>> from minevent import PeriodicCondition
>>> condition = PeriodicCondition(freq=3)
>>> condition.evaluate()
True
>>> condition.evaluate()
False
>>> condition.evaluate()
False
>>> condition.evaluate()
True
>>> condition.evaluate()
False
>>> condition.evaluate()
False
>>> condition.evaluate()
True