fixup enum-dict

This commit is contained in:
Semjon Kerner 2021-05-07 14:13:55 +02:00
parent 734477dc28
commit f790a83acf
2 changed files with 33 additions and 19 deletions

View File

@ -28,7 +28,7 @@ class FishEvent:
hole_start_time = 0
FishingStarted = False
jitter = False
previousState = "IDLE"
previousState = State.IDLE
# initialize these
action_key = 'e'
@ -80,23 +80,23 @@ def subscribe():
if fisher_callback not in fishing_mode.subscribers:
fishing_mode.subscribers.append(fisher_callback)
if FishingMode.CurrentMode == ["LOOKING"]:
if FishingMode.CurrentMode == State.LOOKING:
fisher_callback(FishingMode.CurrentMode)
def fisher_callback(event: State):
callbacks_map = {
"IDLE": on_idle,
"LOOKAWAY": on_lookaway,
"LOOKING": on_looking,
"DEPLETED": on_depleted,
"NOBAIT": on_nobait,
"FISHING": on_fishing,
"REELIN": on_reelin,
"LOOT": on_loot,
"INVFULL": on_invfull,
"FIGHT": on_fight,
"DEAD": on_dead
State.IDLE: on_idle,
State.LOOKAWAY: on_lookaway,
State.LOOKING: on_looking,
State.DEPLETED: on_depleted,
State.NOBAIT: on_nobait,
State.FISHING: on_fishing,
State.REELIN: on_reelin,
State.LOOT: on_loot,
State.INVFULL: on_invfull,
State.FIGHT: on_fight,
State.DEAD: on_dead
}
try:
callbacks_map[event]()
@ -108,7 +108,7 @@ def fisher_callback(event: State):
def on_idle():
if FishEvent.previousState in ("FISHING", "REELIN"):
if FishEvent.previousState in (State.FISHING, State.REELIN):
logging.info("FISHING INTERRUPTED")
_sound_and_send_fishy_data()

View File

@ -1,9 +1,23 @@
import time
from enum import Enum
subscribers = []
State = {
class State(Enum):
IDLE = 0
LOOKAWAY = 1
LOOKING = 2
DEPLETED = 3
NOBAIT = 5
FISHING = 6
REELIN = 7
LOOT = 8
INVFULL = 9
FIGHT = 14
DEAD = 15
Colors = {
"IDLE" : [255, 255, 255],
"LOOKAWAY" : [ 76, 0, 76],
"LOOKING" : [101, 69, 0],
@ -24,8 +38,8 @@ def _notify(event):
class FishingMode:
CurrentMode = "IDLE"
PrevMode = "IDLE"
CurrentMode = State.IDLE
PrevMode = State.IDLE
def loop(rgb):
@ -35,9 +49,9 @@ def loop(rgb):
:param rgb: rgb read by the bot
"""
FishingMode.CurrentMode = "IDLE"
FishingMode.CurrentMode = State.IDLE
for s in State:
if all(rgb == State[s]):
if all(rgb == Colors[s.name]):
FishingMode.CurrentMode = s
if FishingMode.CurrentMode != FishingMode.PrevMode: