Skip to content

Commit

Permalink
Adds asNumeric to Key class
Browse files Browse the repository at this point in the history
Fixes #746
  • Loading branch information
hobnob committed Oct 25, 2024
1 parent d808b53 commit 4115496
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion indigo/indigo/src/main/scala/indigo/shared/constants/Key.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ final case class Key(code: KeyCode, key: String, location: KeyLocation) derives
def isPrintable: Boolean =
(key != "") && KeyCode.printable.contains(this.code)

def isNumber: Boolean =
def isNumeric: Boolean =
code match {
case KeyCode.Digit0 | KeyCode.Digit1 | KeyCode.Digit2 | KeyCode.Digit3 | KeyCode.Digit4 | KeyCode.Digit5 |
KeyCode.Digit6 | KeyCode.Digit7 | KeyCode.Digit8 | KeyCode.Digit9 =>
Expand All @@ -13,6 +13,21 @@ final case class Key(code: KeyCode, key: String, location: KeyLocation) derives
false
}

def asNumeric: Option[Int] =
code match {
case KeyCode.Digit0 => Some(0)
case KeyCode.Digit1 => Some(1)
case KeyCode.Digit2 => Some(2)
case KeyCode.Digit3 => Some(3)
case KeyCode.Digit4 => Some(4)
case KeyCode.Digit5 => Some(5)
case KeyCode.Digit6 => Some(6)
case KeyCode.Digit7 => Some(7)
case KeyCode.Digit8 => Some(8)
case KeyCode.Digit9 => Some(9)
case _ => None
}

// DO NOT REMOVE
def ===(other: Key): Boolean =
code == other.code
Expand Down

0 comments on commit 4115496

Please sign in to comment.