-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from randovania/bmsmsd
Add classes to BMSMSD
- Loading branch information
Showing
4 changed files
with
232 additions
and
49 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/mercury_engine_data_structures/adapters/flagsenum_adapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
from construct import Adapter, FlagsEnum, Int32ub | ||
|
||
|
||
class FlagsEnumAdapter(Adapter): | ||
def __init__(self, enum_class, subcon=Int32ub): | ||
super().__init__(FlagsEnum(subcon, enum_class)) | ||
self._enum_class = enum_class | ||
|
||
def _decode(self, obj, context, path): | ||
return {self._enum_class[k]: v for k, v in obj.items() if k != "_flagsenum" and v is True} | ||
|
||
def _encode(self, obj, context, path): | ||
return {k.name: v for k, v in obj.items()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters