Skip to content

Commit

Permalink
Closes #471. Unit test, code, and a few API fixes too. _move_global_m…
Browse files Browse the repository at this point in the history
…aterial_props is not working for some reason
  • Loading branch information
tngreene committed Oct 27, 2020
1 parent 5afa666 commit acdecee
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 251 deletions.
11 changes: 7 additions & 4 deletions io_xplane2blender/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
FLOAT_TOLERANCE = 0.0001

__dirname__ = os.path.dirname(__file__)
TMP_DIR = os.path.realpath(os.path.join(__dirname__, "../../tests/tmp"))

FilterLinesCallback = Callable[[List[Union[float, str]]], bool]

Expand Down Expand Up @@ -564,7 +563,7 @@ def exportExportableRoot(
xplane_file._all_keyframe_infos.clear()

if dest:
with open(os.path.join(TMP_DIR, dest + ".obj"), "w") as tmp_file:
with open(os.path.join(get_tmp_folder(), dest + ".obj"), "w") as tmp_file:
tmp_file.write(out)

return out
Expand Down Expand Up @@ -640,18 +639,22 @@ def filterLine(line):

def get_source_folder() -> pathlib.Path:
"""Returns the full path to the addon folder"""
return os.path.dirname(pathlib.Path("..", __file__))
return pathlib.Path(__file__).parent


def get_project_folder() -> pathlib.Path:
"""Returns the full path to the project folder"""
return os.path.dirname(pathlib.Path("..", "..", __file__))
return pathlib.Path(__file__).parent.parent.parent


def get_tests_folder() -> pathlib.Path:
return pathlib.Path(get_project_folder(), "tests")


def get_tmp_folder() -> pathlib.Path:
return pathlib.Path(get_tests_folder(), "tmp")


def make_fixture_path(dirname, filename, sub_dir=""):
return os.path.join(dirname, "fixtures", sub_dir, filename + ".obj")

Expand Down
29 changes: 22 additions & 7 deletions io_xplane2blender/xplane_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ def vec_x_to_b(v) -> mathutils.Vector:
class VerStruct:
def __init__(
self,
addon_version: Tuple[int, int, int] = None,
build_type: str = None,
build_type_version: int = None,
data_model_version: int = None,
build_number=None,
addon_version: Optional[Tuple[int, int, int]] = None,
build_type: Optional[str] = None,
build_type_version: Optional[int] = None,
data_model_version: Optional[int] = None,
build_number: Optional[str] = None,
):
# fmt: off
self.addon_version = tuple(addon_version) if addon_version is not None else (0,0,0)
Expand Down Expand Up @@ -373,8 +373,11 @@ def is_valid(self):
return False

@staticmethod
def add_to_version_history(version_to_add):
history = bpy.context.scene.xplane.xplane2blender_ver_history
def add_to_version_history(
scene: bpy.types.Scene,
version_to_add: Union["VerStruct", "xplane_props.XPlane2BlenderVersion"],
):
history = scene.xplane.xplane2blender_ver_history

if len(history) == 0 or history[-1].name != repr(version_to_add):
new_hist_entry = history.add()
Expand Down Expand Up @@ -410,6 +413,18 @@ def current():
xplane_config.CURRENT_BUILD_NUMBER,
)

@staticmethod
def from_version_entry(
version_entry: "xplane_props.XPlane2BlenderVersion",
) -> "VerStruct":
return VerStruct(
version_entry.addon_version,
version_entry.build_type,
version_entry.build_type_version,
version_entry.data_model_version,
version_entry.build_number,
)

@staticmethod
def make_new_build_number():
# Use the UNIX Timestamp in UTC
Expand Down
2 changes: 1 addition & 1 deletion io_xplane2blender/xplane_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def safe_set_version_data(
self.build_number = build_number
_version_safety_off = False
if debug_add_to_history:
xplane_helpers.VerStruct.add_to_version_history(self)
xplane_helpers.VerStruct.add_to_version_history(bpy.context.scene, self)
return True
else:
return False
Expand Down
Loading

0 comments on commit acdecee

Please sign in to comment.