From 9b160dcc0315aaf54a8b4588be9d2a0c98084cf0 Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Thu, 11 Apr 2024 07:13:48 +0300 Subject: Enha: make html elements to react; repeatable separation --- internal/models/models.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'internal/models') diff --git a/internal/models/models.go b/internal/models/models.go index 58191a2..a2b3628 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -12,7 +12,7 @@ const ( type ( UserScore struct { Username string - Actions []Action + Actions []*Action BurnTime time.Time Score int8 } @@ -26,3 +26,15 @@ type ( Username string } ) + +func (us *UserScore) UpdateScore(act *Action) { + switch act.Type { + case ActionTypePlus: + us.Score += int8(act.Magnitude) + if !act.Repeatable { + act.Done = true + } + case ActionTypeMinus: + us.Score -= int8(act.Magnitude) + } +} -- cgit v1.2.3