mirror of
https://github.com/rr-/pq-cli.git
synced 2026-11-12 22:40:36 -07:00
lingo: add to_arabic, the inverse of to_roman
Ported from upstream's toArabic, including the T, MT, A and MA numerals. Web saves store spell levels as roman numerals, so the .pqw importer needs it.
This commit is contained in:
2 files changed
+45
-1
No files matched your search
@@ -79,6 +79,43 @@ def to_roman(num: int) -> str:
|
||||
return ret
|
||||
|
||||
|
||||
def to_arabic(roman: str) -> int:
|
||||
num = 0
|
||||
rest = roman.upper()
|
||||
|
||||
def _arab(ds: str, dn: int) -> bool:
|
||||
nonlocal num, rest
|
||||
if not rest.startswith(ds):
|
||||
return False
|
||||
rest = rest[len(ds) :]
|
||||
num += dn
|
||||
return True
|
||||
|
||||
while _arab("T", 10000):
|
||||
pass
|
||||
_arab("MT", 9000)
|
||||
_arab("A", 5000)
|
||||
_arab("MA", 4000)
|
||||
while _arab("M", 1000):
|
||||
pass
|
||||
_arab("CM", 900)
|
||||
_arab("D", 500)
|
||||
_arab("CD", 400)
|
||||
while _arab("C", 100):
|
||||
pass
|
||||
_arab("XC", 90)
|
||||
_arab("L", 50)
|
||||
_arab("XL", 40)
|
||||
while _arab("X", 10):
|
||||
pass
|
||||
_arab("IX", 9)
|
||||
_arab("V", 5)
|
||||
_arab("IV", 4)
|
||||
while _arab("I", 1):
|
||||
pass
|
||||
return num
|
||||
|
||||
|
||||
def act_name(act: int) -> str:
|
||||
if act == 0:
|
||||
return "Prologue"
|
||||
|
||||
Reference in new issue
Block a user