|
2 | 2 |
|
3 | 3 | import re
|
4 | 4 | from ntpath import basename
|
5 |
| -from typing import TYPE_CHECKING, Dict, Generator, Iterator, List, Optional, Tuple |
| 5 | +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple |
6 | 6 |
|
7 | 7 | from attrs import define
|
8 | 8 |
|
9 | 9 | from .. import config
|
10 | 10 | from ..enums import BuildTarget, ClassIDType, CommonString
|
| 11 | +from ..helpers.ContainerHelper import ContainerHelper |
11 | 12 | from ..helpers.TypeTreeHelper import TypeTreeNode
|
12 | 13 | from ..streams import EndianBinaryWriter
|
13 | 14 | from . import BundleFile, File, ObjectReader
|
14 | 15 |
|
15 | 16 | if TYPE_CHECKING:
|
16 |
| - from ..classes import AssetBundle, AssetInfo, Object, PPtr |
| 17 | + from ..classes import AssetBundle, Object |
17 | 18 | from ..files import ObjectReader
|
18 | 19 | from ..streams.EndianBinaryReader import EndianBinaryReader
|
19 | 20 |
|
@@ -338,7 +339,7 @@ def __init__(self, reader: EndianBinaryReader, parent=None, name=None, **kwargs)
|
338 | 339 | break
|
339 | 340 | else:
|
340 | 341 | self.assetbundle = None
|
341 |
| - self._container = ContainerHelper() |
| 342 | + self._container = ContainerHelper([]) |
342 | 343 |
|
343 | 344 | @property
|
344 | 345 | def container(self):
|
@@ -521,55 +522,3 @@ def read_string(string_buffer_reader: EndianBinaryReader, value: int) -> str:
|
521 | 522 |
|
522 | 523 | offset = value & 0x7FFFFFFF
|
523 | 524 | return CommonString.get(offset, str(offset))
|
524 |
| - |
525 |
| - |
526 |
| -@define(slots=True) |
527 |
| -class ContainerHelper: |
528 |
| - """Helper class to allow multidict containers |
529 |
| - without breaking compatibility with old versions""" |
530 |
| - |
531 |
| - container: List[Tuple[str, AssetInfo]] |
532 |
| - container_dict: Dict[str, PPtr[Object]] |
533 |
| - path_dict: Dict[int, str] |
534 |
| - |
535 |
| - def __init__(self, assetbundle: Optional[AssetBundle] = None) -> None: |
536 |
| - if assetbundle is None: |
537 |
| - self.container = [] |
538 |
| - else: |
539 |
| - self.container = assetbundle.m_Container |
540 |
| - # support for getitem |
541 |
| - self.container_dict = {key: value.asset for key, value in self.container} |
542 |
| - self.path_dict = {value.asset.m_PathID: key for key, value in self.container} |
543 |
| - |
544 |
| - def items(self) -> Generator[Tuple[str, PPtr[Object]], None, None]: |
545 |
| - return ((key, value.asset) for key, value in self.container) |
546 |
| - |
547 |
| - def keys(self) -> list[str]: |
548 |
| - return list({key for key, value in self.container}) |
549 |
| - |
550 |
| - def values(self) -> list[PPtr[Object]]: |
551 |
| - return list({value.asset for key, value in self.container}) |
552 |
| - |
553 |
| - def __getitem__(self, key) -> PPtr[Object]: |
554 |
| - return self.container_dict[key] |
555 |
| - |
556 |
| - def __setitem__(self, key, value) -> None: |
557 |
| - raise NotImplementedError("Assigning to container is not allowed!") |
558 |
| - |
559 |
| - def __delitem__(self, key) -> None: |
560 |
| - raise NotImplementedError("Deleting from the container is not allowed!") |
561 |
| - |
562 |
| - def __iter__(self) -> Iterator[str]: |
563 |
| - return iter(self.keys()) |
564 |
| - |
565 |
| - def __len__(self) -> int: |
566 |
| - return len(self.container) |
567 |
| - |
568 |
| - def __getattr__(self, name: str) -> PPtr[Object]: |
569 |
| - return self.container_dict[name] |
570 |
| - |
571 |
| - def __str__(self) -> str: |
572 |
| - return f"{{{', '.join(f'{key}: {value}' for key, value in self.items())}}}" |
573 |
| - |
574 |
| - def __dict__(self) -> Dict[str, PPtr[Object]]: |
575 |
| - return self.container_dict |
0 commit comments