-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructureFolder.py
51 lines (40 loc) · 1.82 KB
/
StructureFolder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from StructureBase import Structure
from pathlib import Path
from importlib import import_module
from StructureFile import StructureFile
class StructureFolder:
structureClass: Structure
name: str
structureFile: StructureFile
decorationStructureFiles: dict[str, StructureFile]
transitionStructureFiles: dict[str, StructureFile]
def __init__(
self,
structureFolder: Path,
name: str,
namespace: str
):
self.name = name
self.namespace = namespace
self.structureFile = StructureFile(structureFolder / name)
self.transitionStructureFiles = dict()
for connectorStructureFile in structureFolder.glob('transitions/*'):
if connectorStructureFile.is_file() and connectorStructureFile.name.endswith('.nbt'):
self.transitionStructureFiles[connectorStructureFile.name] = StructureFile(connectorStructureFile)
self.decorationStructureFiles = dict()
for decorationStructionFile in structureFolder.glob('decorations/*'):
if decorationStructionFile.is_file() and decorationStructionFile.name.endswith('.nbt'):
self.decorationStructureFiles[decorationStructionFile.name] = StructureFile(decorationStructionFile)
structureModulePath = f'structures.{self.namespace}.{self.name}.{self.name}'
structureModule = import_module(structureModulePath)
if structureModule is None:
raise FileNotFoundError(f'No module found at {structureModulePath}')
self.structureClass = getattr(
structureModule,
name.replace('_', ' ').title().replace(' ', '')
)
def __repr__(self):
return f'{__class__.__name__} {self.namespace}.{self.name}'