You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-09-08 08:13:02 -07:00
move RomStr into a shared file
This commit is contained in:
@@ -230,31 +230,7 @@ def map_name_cleaner(input):
|
|||||||
replace("hooh", "HoOh").\
|
replace("hooh", "HoOh").\
|
||||||
replace(" ", "")
|
replace(" ", "")
|
||||||
|
|
||||||
class RomStr(str):
|
from romstr import RomStr
|
||||||
"""simple wrapper to prevent a giant rom from being shown on screen"""
|
|
||||||
|
|
||||||
def length(self):
|
|
||||||
"""len(self)"""
|
|
||||||
return len(self)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "RomStr(too long)"
|
|
||||||
|
|
||||||
def interval(self, offset, length, strings=True, debug=True):
|
|
||||||
"""returns hex values for the rom starting at offset until offset+length"""
|
|
||||||
returnable = []
|
|
||||||
for byte in self[offset:offset+length]:
|
|
||||||
if strings:
|
|
||||||
returnable.append(hex(ord(byte)))
|
|
||||||
else:
|
|
||||||
returnable.append(ord(byte))
|
|
||||||
return returnable
|
|
||||||
|
|
||||||
def until(self, offset, byte, strings=True, debug=False):
|
|
||||||
"""returns hex values from rom starting at offset until the given byte"""
|
|
||||||
return self.interval(offset, self.find(chr(byte), offset) - offset, strings=strings)
|
|
||||||
|
|
||||||
|
|
||||||
rom = RomStr(None)
|
rom = RomStr(None)
|
||||||
|
|
||||||
def direct_load_rom(filename="../baserom.gbc"):
|
def direct_load_rom(filename="../baserom.gbc"):
|
||||||
|
25
extras/romstr.py
Normal file
25
extras/romstr.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
class RomStr(str):
|
||||||
|
""" Simple wrapper to prevent a giant rom from being shown on screen
|
||||||
|
"""
|
||||||
|
|
||||||
|
def length(self):
|
||||||
|
"""len(self)"""
|
||||||
|
return len(self)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "RomStr(too long)"
|
||||||
|
|
||||||
|
def interval(self, offset, length, strings=True, debug=True):
|
||||||
|
"""returns hex values for the rom starting at offset until offset+length"""
|
||||||
|
returnable = []
|
||||||
|
for byte in self[offset:offset+length]:
|
||||||
|
if strings:
|
||||||
|
returnable.append(hex(ord(byte)))
|
||||||
|
else:
|
||||||
|
returnable.append(ord(byte))
|
||||||
|
return returnable
|
||||||
|
|
||||||
|
def until(self, offset, byte, strings=True, debug=False):
|
||||||
|
"""returns hex values from rom starting at offset until the given byte"""
|
||||||
|
return self.interval(offset, self.find(chr(byte), offset) - offset, strings=strings)
|
||||||
|
|
Reference in New Issue
Block a user