ready to run

This commit is contained in:
Doman 2021-07-13 20:28:04 +02:00
parent 0551468a45
commit a88184caa2
4 changed files with 27 additions and 10 deletions

View file

@ -1,6 +1,5 @@
class Application:
def __init__(self, listener, user_buffer, reference_buffer, config):
self._running = False
self.listener = listener
self.user_buffer = user_buffer
self.reference_buffer = reference_buffer
@ -15,10 +14,10 @@ class Application:
self.stats = Stats()
def start(self):
self._running = True
self.state.signal_start()
def running(self):
return self._running
return self.state.running()
def valid_user_text_position(self):
if self.state.mistake_position is not None:
@ -38,9 +37,9 @@ class Application:
action, key = self.listener.listen(screen)
self.user_buffer.handle_action(action, key)
self.state.update(action, key)
self.stats.update(action, self.state.valid())
self.stats.update(action, self.state.valid(), self.state.running())
except StoppingSignal:
self._running = False
self.state.signal_stop()
self.stats.signal_stop()
def summarize(self):

View file

@ -15,6 +15,16 @@ class StateMachine:
self.mistake_position = None
self.application = application
def running(self):
return self.state != State.finished
def signal_stop(self):
self.state = State.finished
def signal_start(self):
self.state = State.valid
self.mistake_position = None
def update(self, action, char):
user_position = self.application.user_buffer.get_position()
if self.state == State.invalid:
@ -29,7 +39,6 @@ class StateMachine:
self.state = State.invalid
elif user_position == self.application.reference_buffer.get_lenght():
self.state = State.finished
raise StoppingSignal
def valid(self):
return self.state == State.valid
return self.state in (State.valid, State.finished)

View file

@ -19,8 +19,9 @@ class Stats:
if self.start_dtime is None:
self.start_dtime = datetime.now()
def update(self, action, valid):
self.signal_running()
def update(self, action, valid, running):
if running:
self.signal_running()
if action == Action.add_char and valid is True:
self.correct_chars += 1
@ -33,6 +34,14 @@ class Stats:
self.incorrect_chars += 1
self.incorrect_words += 1
if not running:
self.signal_stop()
if valid:
self.correct_words += 1
else:
self.incorrect_words += 1
def signal_stop(self):
self.stop_dtime = datetime.now()

View file

@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup(
name="fasttyper-pkg-ickyicky",
version="0.1",
version="1.0.0",
author="Piotr Domanski",
author_email="pi.domanski@gmail.com",
description="Minimalistic typing exercise",