-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeverEventBase.py
More file actions
54 lines (44 loc) · 1.85 KB
/
LeverEventBase.py
File metadata and controls
54 lines (44 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import annotations
from typing import Type
class LeverEventBase:
'''
The LeverEventBase class contains different callback functions for the lever that can be overrided for custom use.
Args:
event_name (str): The name of the event. Used in order to prevent duplicate events from being ran on an event.
lever (LeverBase): The LeverBase object that will run this event.
Attributes:
name (str): The name of the event.
lever (LeverBase) The Lever that this event is attached to.
'''
def __init__(self, event_name:str, lever):
self.name:str = event_name
self.lever:LeverBase = lever
def on_lever_initialize(self):
'''Runs as soon as the lever initializes.'''
pass
def on_lever_update(self):
'''Called continuously while the lever is active.'''
pass
def on_lever_state_change(self, new_lever_state, time_since_last_change):
"""
Called when the state of the lever changes (Pressed or Unpressed).
Parameters
----------
new_lever_state : int
The new state of the lever. 0 if the lever is not being pressed, 1 if the lever is being pressed.
time_since_last_change : float
The time in seconds since the last state change.
"""
pass
def on_lever_stopped():
"""
Called when the lever is stopped(usually at the end of a training).
"""
pass
class DebugEvent(LeverEventBase):
def on_lever_initialize(self):
print("The lever has been created")
def on_lever_state_change(self, new_lever_state, time_since_last_change):
print(f"Lever {self.lever.name} state changed to {new_lever_state} after {time_since_last_change:.3f} seconds")
def on_lever_stopped(self):
print("Lever is no longer active")