mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Finally get rid of bitfield_to_machines and parse it natively
This commit is contained in:
parent
4cd67b3787
commit
db1ddc68e7
1 changed files with 8 additions and 19 deletions
|
@ -21,11 +21,11 @@ from camel import Camel
|
||||||
from classtools import reify
|
from classtools import reify
|
||||||
from construct import (
|
from construct import (
|
||||||
# Simple fields
|
# Simple fields
|
||||||
BitsInteger, Byte, Bytes, CString, Const, Int8ul, Int16ub, Int16ul,
|
BitsInteger, Byte, Bytes, CString, Const, Flag, Int8ul, Int16ub, Int16ul,
|
||||||
Padding, String,
|
Padding, String,
|
||||||
# Structures and meta stuff
|
# Structures and meta stuff
|
||||||
Adapter, Array, Bitwise, Construct, Embedded, Enum, Peek, Pointer, Struct,
|
Adapter, Array, Bitwise, BitsSwapped, Construct, Embedded, Enum, Peek,
|
||||||
Subconstruct, Switch,
|
Pointer, Struct, Subconstruct, Switch,
|
||||||
)
|
)
|
||||||
|
|
||||||
from pokedex.extract.lib.gbz80 import find_code
|
from pokedex.extract.lib.gbz80 import find_code
|
||||||
|
@ -875,8 +875,7 @@ pokemon_struct = Struct(
|
||||||
# TODO somehow rig this to discard trailing zeroes; there's a paddedstring that does it
|
# TODO somehow rig this to discard trailing zeroes; there's a paddedstring that does it
|
||||||
'initial_moveset' / Array(4, IdentEnum(Byte, MOVE_IDENTIFIERS)),
|
'initial_moveset' / Array(4, IdentEnum(Byte, MOVE_IDENTIFIERS)),
|
||||||
'growth_rate' / IdentEnum(Byte, GROWTH_RATES),
|
'growth_rate' / IdentEnum(Byte, GROWTH_RATES),
|
||||||
# TODO argh, this is a single huge integer; i want an array, but then i lose the byteswapping!
|
'machines' / BitsSwapped(Bitwise(Array(7 * 8, Flag))),
|
||||||
'machines' / Bitwise(BitsInteger(7 * 8, swapped=True)),
|
|
||||||
Padding(1),
|
Padding(1),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1572,18 +1571,6 @@ class RBYCart:
|
||||||
return Array(self.NUM_MOVES, PokemonCString()).parse_stream(self.stream)
|
return Array(self.NUM_MOVES, PokemonCString()).parse_stream(self.stream)
|
||||||
|
|
||||||
|
|
||||||
# TODO would be slick to convert this to a construct... construct
|
|
||||||
def bitfield_to_machines(bits, machine_moves):
|
|
||||||
machines = []
|
|
||||||
for i, move in enumerate(machine_moves, start=1):
|
|
||||||
bit = bits & 0x1
|
|
||||||
bits >>= 1
|
|
||||||
if bit:
|
|
||||||
machines.append(move)
|
|
||||||
|
|
||||||
return machines
|
|
||||||
|
|
||||||
|
|
||||||
# TODO this is not correctly using my half-baked "slice" idea
|
# TODO this is not correctly using my half-baked "slice" idea
|
||||||
class WriterWrapper:
|
class WriterWrapper:
|
||||||
def __init__(self, locus, language):
|
def __init__(self, locus, language):
|
||||||
|
@ -1697,8 +1684,10 @@ def main(base_root):
|
||||||
})
|
})
|
||||||
writer.moves = {
|
writer.moves = {
|
||||||
'level-up': level_up_moves,
|
'level-up': level_up_moves,
|
||||||
'machines': bitfield_to_machines(
|
'machines': [
|
||||||
record.machines, cart.machine_moves),
|
move for (has_machine, move) in zip(
|
||||||
|
record.machines, cart.machine_moves)
|
||||||
|
if has_machine],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Evolution
|
# Evolution
|
||||||
|
|
Loading…
Reference in a new issue