Skip to content

Commit

Permalink
fixed potential circular imports in formats
Browse files Browse the repository at this point in the history
- replaced "from m_e_d_s.formats import BaseResource" with "from
  m_e_d_s.formats.base_resource import BaseResource"
- replace "from m_e_d_s.formats import standard_format" with "from
  m_e_d_s.formats.standard_format import <create | game_model> and
  updated code to remove "standard_format." prefix
  • Loading branch information
steven11sjf committed Jul 15, 2024
1 parent 2bff8bc commit 52cc9bb
Show file tree
Hide file tree
Showing 32 changed files with 60 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bcmdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)

from mercury_engine_data_structures.common_types import Float, StrId
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

# Partial implementation to generate material variants
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bldef.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from construct import Construct, Container

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game


class Bldef(BaseResource):
@classmethod
def construct_class(cls, target_game: Game) -> Construct:
return standard_format.game_model('CLightManager', 0x02000001)
return game_model('CLightManager', 0x02000001)

Check warning on line 11 in src/mercury_engine_data_structures/formats/bldef.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/bldef.py#L11

Added line #L11 was not covered by tests

@property
def lightdefs(self) -> Container:
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/blsnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

from mercury_engine_data_structures.common_types import StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game, current_game_at_most

BLSND = Struct(
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bmbls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMBLS = standard_format.create('base::animation::CBlendSpaceResource', 0x02020001)
BMBLS = create('base::animation::CBlendSpaceResource', 0x02020001)


class Bmbls(BaseResource):
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)

from mercury_engine_data_structures.common_types import StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

EnemyStruct = Struct(
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bmmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from construct import Construct, Container

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMMAP = standard_format.create('CMinimapData', 0x02000001)
BMMAP = create('CMinimapData', 0x02000001)


class Bmmap(BaseResource):
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bmmdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from construct import Construct, Container

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMMDEF = standard_format.create('CMinimapDef', 0x02000001)
BMMDEF = create('CMinimapDef', 0x02000001)


class Bmmdef(BaseResource):
Expand Down
4 changes: 3 additions & 1 deletion src/mercury_engine_data_structures/formats/bmsad.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from mercury_engine_data_structures.construct_extensions.alignment import PrefixedAllowZeroLen
from mercury_engine_data_structures.construct_extensions.function_complex import ComplexIf, SwitchComplexKey
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage
from mercury_engine_data_structures.formats import BaseResource, dread_types
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.bmsas import BMSAS_SR, Bmsas
from mercury_engine_data_structures.formats.property_enum import PropertyEnum
from mercury_engine_data_structures.game_check import Game, GameSpecificStruct
Expand Down Expand Up @@ -80,6 +80,8 @@

@functools.cache
def fieldtypes(game: Game) -> dict[str, Construct]:
from mercury_engine_data_structures.formats import dread_types

if game == Game.DREAD:
return {k: v for k, v in vars(dread_types).items() if isinstance(v, Construct)}
raise ValueError(f"No field types defined for {game}")
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from mercury_engine_data_structures.common_types import Char, CVector3D, DictAdapter, Float, make_vector
from mercury_engine_data_structures.common_types import StrId as StrIdSR
from mercury_engine_data_structures.construct_extensions.strings import PascalStringRobust
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.property_enum import PropertyEnum, PropertyEnumDoubleUnsafe
from mercury_engine_data_structures.game_check import Game

Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmscc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mercury_engine_data_structures import game_check
from mercury_engine_data_structures.common_types import StrId, UInt, make_vector
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.collision import collision_formats
from mercury_engine_data_structures.game_check import Game

Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bmscu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from construct import Construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMSCU = standard_format.create('CCutSceneDef', 0x02030008)
BMSCU = create('CCutSceneDef', 0x02030008)


class Bmscu(BaseResource):
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

from mercury_engine_data_structures.common_types import StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

BMSEM = Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from mercury_engine_data_structures.common_types import StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

BMSES = Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsld.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage
from mercury_engine_data_structures.construct_extensions.strings import StaticPaddedString
from mercury_engine_data_structures.crc import crc32
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.collision import collision_formats
from mercury_engine_data_structures.game_check import Game

Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bmslgroup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMSLGROUP = standard_format.create('navmesh::CDynamicSmartLinkGroup', 0x02000001)
BMSLGROUP = create('navmesh::CDynamicSmartLinkGroup', 0x02000001)


class Bmslgroup(BaseResource):
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmslink.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

from mercury_engine_data_structures.common_types import Float, StrId
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

UnkStruct = Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from mercury_engine_data_structures.common_types import StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

BMSMD = Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from construct.core import Const, Construct, Enum, FlagsEnum, Float32l, Hex, Int32sl, Int32ul, Struct

from mercury_engine_data_structures.common_types import CVector2D, CVector3D, StrId, make_vector
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

TileBorders = FlagsEnum(Int32sl,
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsnav.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from construct.core import Array, Byte, Const, Construct, Flag, Hex, Int32ul, PrefixedArray, Struct, Terminated

from mercury_engine_data_structures.common_types import CVector2D, CVector3D, Float, StrId, make_dict
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

### A ton of barely-understood structs :]
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mercury_engine_data_structures import game_check
from mercury_engine_data_structures.common_types import CVector3D, StrId, make_vector
from mercury_engine_data_structures.construct_extensions.strings import StaticPaddedString
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

BMSSD = Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmtre.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from mercury_engine_data_structures.common_types import Float, StrId
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.property_enum import PropertyEnum
from mercury_engine_data_structures.game_check import Game

Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmtun.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from mercury_engine_data_structures.common_types import Char, CVector3D, Float, StrId, make_dict
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

# Functions
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/brem.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game


class Brem(BaseResource):
@classmethod
def construct_class(cls, target_game: Game) -> construct.Construct:
return standard_format.game_model('CEnvironmentMusicPresets', 0x02000004)
return game_model('CEnvironmentMusicPresets', 0x02000004)

Check warning on line 11 in src/mercury_engine_data_structures/formats/brem.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/brem.py#L11

Added line #L11 was not covered by tests
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/bres.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game


class Bres(BaseResource):
@classmethod
def construct_class(cls, target_game: Game) -> construct.Construct:
return standard_format.game_model('CEnvironmentSoundPresets', 0x02020001)
return game_model('CEnvironmentSoundPresets', 0x02020001)

Check warning on line 11 in src/mercury_engine_data_structures/formats/bres.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/bres.py#L11

Added line #L11 was not covered by tests
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/brev.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game


class Brev(BaseResource):
@classmethod
def construct_class(cls, target_game: Game) -> construct.Construct:
return standard_format.game_model('CEnvironmentVisualPresets', 0x02020004)
return game_model('CEnvironmentVisualPresets', 0x02020004)

Check warning on line 11 in src/mercury_engine_data_structures/formats/brev.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/brev.py#L11

Added line #L11 was not covered by tests
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/brfld.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import construct

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game

logger = logging.getLogger(__name__)
Expand All @@ -14,7 +15,7 @@ class Brfld(BaseResource):
@classmethod
@functools.lru_cache
def construct_class(cls, target_game: Game) -> construct.Construct:
return standard_format.game_model('CScenario', 0x02000031)
return game_model('CScenario', 0x02000031)

def actors_for_layer(self, name: str) -> dict:
return self.raw.Root.pScenario.rEntitiesLayer.dctSublayers[name].dctActors
Expand Down
5 changes: 3 additions & 2 deletions src/mercury_engine_data_structures/formats/brsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

from construct import Construct, Container

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import game_model
from mercury_engine_data_structures.game_check import Game


class Brsa(BaseResource):
@classmethod
@functools.lru_cache
def construct_class(cls, target_game: Game) -> Construct:
return standard_format.game_model('CSubAreaManager', 0x02010002)
return game_model('CSubAreaManager', 0x02010002)

Check warning on line 15 in src/mercury_engine_data_structures/formats/brsa.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/brsa.py#L15

Added line #L15 was not covered by tests

@property
def subarea_setups(self) -> Iterator[Container]:
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bsmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

from mercury_engine_data_structures.common_types import Char, Float, StrId
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

# these seem to be using Unity ShaderLab, or at least the gist I borrowed this from uses similar teminology
Expand Down
9 changes: 5 additions & 4 deletions src/mercury_engine_data_structures/formats/gui_files.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from construct import Construct, Container

from mercury_engine_data_structures.formats import BaseResource, standard_format
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.formats.standard_format import create
from mercury_engine_data_structures.game_check import Game

BMSCP = standard_format.create('GUI::CDisplayObjectContainer', 0x02020001, explicit_root=True)
BMSSK = standard_format.create('GUI::CGUIManager::SkinContainer', 0x02020001, explicit_root=True)
BMSSS = standard_format.create('GUI::CGUIManager::SpriteSheetContainer', 0x02020001, explicit_root=True)
BMSCP = create('GUI::CDisplayObjectContainer', 0x02020001, explicit_root=True)
BMSSK = create('GUI::CGUIManager::SkinContainer', 0x02020001, explicit_root=True)
BMSSS = create('GUI::CGUIManager::SpriteSheetContainer', 0x02020001, explicit_root=True)


class Bmscp(BaseResource):
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import construct

from mercury_engine_data_structures.common_types import StrId
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

if typing.TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions src/mercury_engine_data_structures/formats/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import construct

from mercury_engine_data_structures import common_types
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import NameOrAssetId, resolve_asset_id
from mercury_engine_data_structures.formats.base_resource import BaseResource, NameOrAssetId, resolve_asset_id
from mercury_engine_data_structures.game_check import Game

TOC_SR = construct.Struct(
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from mercury_engine_data_structures.common_types import DictAdapter, DictElement
from mercury_engine_data_structures.construct_extensions.strings import CStringRobust
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game, is_sr_or_else

_string_range = GreedyRange(DictElement(CStringRobust("utf-16-le")))
Expand Down

0 comments on commit 52cc9bb

Please sign in to comment.