Skip to content

Commit

Permalink
Updated the sqlite_bedrock_packs module used by mcblend to the newest…
Browse files Browse the repository at this point in the history
… verison.
  • Loading branch information
Nusiq committed Aug 27, 2023
1 parent 84f3089 commit fbfc0bd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion mcblend/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import_model_form_project, apply_materials, prepare_physics_simulation,
merge_models)
from .operator_func.rp_importer import get_pks_for_model_improt
from .operator_func.sqlite_bedrock_packs.better_json import (
from .operator_func.sqlite_bedrock_packs.better_json_tools import (
CompactEncoder, JSONCDecoder)
from .operator_func.exception import NotEnoughTextureSpace, ImporterException
from .operator_func.texture_generator import (
Expand Down
2 changes: 1 addition & 1 deletion mcblend/operator_func/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
get_data_materials, get_pixels, set_view_layer_objects_active,
get_view_layer_objects_active)

from .sqlite_bedrock_packs.better_json import load_jsonc
from .sqlite_bedrock_packs.better_json_tools import load_jsonc

from .animation import AnimationExport
from .common import (
Expand Down
63 changes: 31 additions & 32 deletions mcblend/operator_func/db_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from pathlib import Path
from .sqlite_bedrock_packs import load_rp, create_db, open_db
from .sqlite_bedrock_packs import Database
# load_rp
from typing import Optional

# Don't use lru_cache(maxsize=1) sometimes there are more than 1 lists of the
Expand All @@ -15,13 +16,13 @@ def get_db_handler() -> DbHandler:

class DbHandler:
def __init__(self):
self.db = create_db()
self.db = Database.create()
self.is_loaded = False

def load_db_from_file(self, path: Path):
'''Loads existing database from a file.'''
self.db.close()
self.db = open_db(path) # type: ignore
self.db = Database.open(path) # type: ignore
self.is_loaded = True

def _clear_cache(self):
Expand All @@ -48,7 +49,7 @@ def _clear_cache(self):
def delete_db(self):
'''Delete all data from the database.'''
self._clear_cache()
self.db.execute('DELETE FROM ResourcePack;')
self.db.connection.execute('DELETE FROM ResourcePack;')
self.is_loaded = False

def load_resource_pack(self, path: Path):
Expand All @@ -57,17 +58,15 @@ def load_resource_pack(self, path: Path):
# otherwise load_rp() function would fail if the RP with that path is
# already loaded.
self._clear_cache()
self.db.execute(
self.db.connection.execute(
'DELETE FROM ResourcePack WHERE path = ?;', (path.as_posix(),))
load_rp(
self.db, path,
include=(
self.db.load_rp(
path, include=(
"client_entities",
"attachables",
"geometries",
"render_controllers",
"textures",
)
"textures")
)
self.is_loaded = True

Expand Down Expand Up @@ -110,7 +109,7 @@ def gui_enum_entity_materials(
return [
(str(identifier), str(name), str(description))
for identifier, name, description in
self.db.execute(query, (rc_pk, entity_pk, bone_name_pattern))
self.db.connection.execute(query, (rc_pk, entity_pk, bone_name_pattern))
]

@cache
Expand Down Expand Up @@ -152,7 +151,7 @@ def gui_enum_attachable_materials(
return [
(str(identifier), str(name), str(description))
for identifier, name, description in
self.db.execute(query, (rc_pk, attachable_pk, bone_name_pattern))
self.db.connection.execute(query, (rc_pk, attachable_pk, bone_name_pattern))
]

@cache
Expand Down Expand Up @@ -182,7 +181,7 @@ def gui_enum_entity_fake_material_patterns(
return [
(str(identifier), str(name), str(description))
for identifier, name, description in
self.db.execute(query, (entity_pk,))
self.db.connection.execute(query, (entity_pk,))
]

@cache
Expand Down Expand Up @@ -212,7 +211,7 @@ def gui_enum_attachable_fake_material_patterns(
return [
(str(identifier), str(name), str(description))
for identifier, name, description in
self.db.execute(query, (attachable_pk,))
self.db.connection.execute(query, (attachable_pk,))
]

@cache
Expand Down Expand Up @@ -271,7 +270,7 @@ def gui_enum_entity_geometries(
return [
(str(geometry_pk), str(short_name), str(identifier))
for geometry_pk, short_name, identifier in
self.db.execute(query, (rc_pk, entity_pk))
self.db.connection.execute(query, (rc_pk, entity_pk))
]

@cache
Expand Down Expand Up @@ -330,7 +329,7 @@ def gui_enum_attachable_geometries(
return [
(str(geometry_pk), str(short_name), str(identifier))
for geometry_pk, short_name, identifier in
self.db.execute(query, (rc_pk, attachable_pk))
self.db.connection.execute(query, (rc_pk, attachable_pk))
]

@cache
Expand Down Expand Up @@ -372,7 +371,7 @@ def gui_enum_entity_geometries_for_fake_rc(
return [
(str(geometry_pk), str(short_name), str(identifier))
for geometry_pk, short_name, identifier in
self.db.execute(query, (entity_pk,))
self.db.connection.execute(query, (entity_pk,))
]

@cache
Expand Down Expand Up @@ -414,7 +413,7 @@ def gui_enum_attachable_geometries_for_fake_rc(
return [
(str(geometry_pk), str(short_name), str(identifier))
for geometry_pk, short_name, identifier in
self.db.execute(query, (attachable_pk,))
self.db.connection.execute(query, (attachable_pk,))
]

@cache
Expand Down Expand Up @@ -468,7 +467,7 @@ def gui_enum_entity_textures(
'''
result = []
not_found_counter = 0
for texture_pk, short_name, path in self.db.execute(
for texture_pk, short_name, path in self.db.connection.execute(
query, (rc_pk, entity_pk)):
if texture_pk is None:
texture_pk = f'not_found_{not_found_counter}'
Expand Down Expand Up @@ -532,7 +531,7 @@ def gui_enum_attachable_textures(
'''
result = []
not_found_counter = 0
for texture_pk, short_name, path in self.db.execute(
for texture_pk, short_name, path in self.db.connection.execute(
query, (rc_pk, attachable_pk)):

if texture_pk is None:
Expand Down Expand Up @@ -592,7 +591,7 @@ def gui_enum_entity_textures_for_fake_rc(
path.as_posix()
)
for texture_pk, short_name, path in
self.db.execute(query, (entity_pk,))
self.db.connection.execute(query, (entity_pk,))
]

@cache
Expand Down Expand Up @@ -640,7 +639,7 @@ def gui_enum_attachable_textures_for_fake_rc(
path.as_posix()
)
for texture_pk, short_name, path in
self.db.execute(query, (attachable_pk,))
self.db.connection.execute(query, (attachable_pk,))
]

@cache
Expand Down Expand Up @@ -686,7 +685,7 @@ def list_entity_render_controllers(
return [
(rc_pk, identifier)
for rc_pk, identifier in
self.db.execute(query, (entity_pk,))
self.db.connection.execute(query, (entity_pk,))
]

@cache
Expand Down Expand Up @@ -732,7 +731,7 @@ def list_attachable_render_controllers(
return [
(rc_pk, identifier)
for rc_pk, identifier in
self.db.execute(query, (attachable_pk,))
self.db.connection.execute(query, (attachable_pk,))
]

@cache
Expand All @@ -749,7 +748,7 @@ def list_bone_name_patterns(self, render_controller_pk: int) -> list[str]:
return [
bone_name_pattern
for bone_name_pattern, in
self.db.execute(query, (render_controller_pk,))
self.db.connection.execute(query, (render_controller_pk,))
]

@cache
Expand Down Expand Up @@ -788,7 +787,7 @@ def list_entities_with_models_and_rc(self) -> list[tuple[int, str]]:
return [
(entity_pk, identifier)
for entity_pk, identifier in
self.db.execute(query)
self.db.connection.execute(query)
]

@cache
Expand Down Expand Up @@ -827,7 +826,7 @@ def list_attachables_with_models_and_rc(self) -> list[tuple[int, str]]:
return [
(entity_pk, identifier)
for entity_pk, identifier in
self.db.execute(query)
self.db.connection.execute(query)
]

def get_texture_file_path(self, texture_file_pk: int) -> Path:
Expand All @@ -839,7 +838,7 @@ def get_texture_file_path(self, texture_file_pk: int) -> Path:
FROM TextureFile
WHERE TextureFile_pk == ?;
'''
return self.db.execute(query, (texture_file_pk,)).fetchone()[0]
return self.db.connection.execute(query, (texture_file_pk,)).fetchone()[0]

def get_geometry(self, geometry_pk: int) -> tuple[Path, str]:
'''
Expand All @@ -859,7 +858,7 @@ def get_geometry(self, geometry_pk: int) -> tuple[Path, str]:
Geometry_pk == ?;
'''
return tuple( # type: ignore
self.db.execute(query, (geometry_pk,)
self.db.connection.execute(query, (geometry_pk,)
).fetchone())

def get_entity_material_pattern_and_material(
Expand All @@ -883,7 +882,7 @@ def get_entity_material_pattern_and_material(
ClientEntityMaterialField.ClientEntity_fk = ?
AND RenderControllerMaterialsField_pk = ?;
'''
return tuple(self.db.execute( # type: ignore
return tuple(self.db.connection.execute( # type: ignore
query,
(entity_pk, rc_material_field_pk)).fetchone()
)
Expand All @@ -909,7 +908,7 @@ def get_attachable_material_pattern_and_material(
AttachableMaterialField.Attachable_fk = ?
AND RenderControllerMaterialsField_pk = ?;
'''
return tuple(self.db.execute( # type: ignore
return tuple(self.db.connection.execute( # type: ignore
query,
(attachable_pk, rc_material_field_pk)).fetchone()
)
Expand All @@ -927,4 +926,4 @@ def get_full_material_identifier(self, material_field_pk: int) -> str:
WHERE
ClientEntityMaterialField_pk = ?;
'''
return self.db.execute(query, (material_field_pk,)).fetchone()[0]
return self.db.connection.execute(query, (material_field_pk,)).fetchone()[0]

0 comments on commit fbfc0bd

Please sign in to comment.