From f87855c1c97954d0c7c8d2813cee6d1f2b05639e Mon Sep 17 00:00:00 2001 From: Jake Dube Date: Fri, 22 Jun 2018 22:05:49 -0400 Subject: [PATCH 1/3] Add context-based help for image maze conversion The prep_manager.check_list_dimensions() could be improved by parsing the text block name to compare both x and y dimensions separately instead of the area-based test for "reasonableness". --- maze_gen.py | 8 +++++++- prep_manager.py | 23 +++++++++++++++++++++++ txt_img_converter.py | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/maze_gen.py b/maze_gen.py index 5e8d97b..870f843 100644 --- a/maze_gen.py +++ b/maze_gen.py @@ -69,11 +69,17 @@ def make_maze(context): if mg.use_list_maze: list_exist = prep_manager.check_list_exist() - # if missing list: terminate operator + good_dimensions = prep_manager.check_list_dimensions() + + # if either goes wrong: terminate operator if not list_exist: messages += ["List missing! Please assign a valid text data block or disable 'Generate Maze From List'."] message_lvls += ['ERROR'] return messages, message_lvls, 'CANCELLED' + elif not good_dimensions: + messages += ["List has wrong dimensions! Please assign a valid text data block, change maze \ndimensions to match the text block's or disable 'Generate Maze From List'."] + message_lvls += ['ERROR'] + return messages, message_lvls, 'CANCELLED' # save files save_return, bad_file = prep_manager.always_save() diff --git a/prep_manager.py b/prep_manager.py index 58f1e89..a68e627 100644 --- a/prep_manager.py +++ b/prep_manager.py @@ -108,6 +108,29 @@ def check_list_exist(): return list_exist +def check_list_dimensions(): + """Check if list has the same area as maze. + + Returns: + True if list does have the same area, otherwise, False + """ + + # TODO - also parse the text block name and check x- and y-dimensions + + # get text maze + list_maze = bpy.context.scene.mg.list_maze + text = bpy.data.texts[list_maze].as_string() + + # get maze settings in Blender UI + mg = bpy.context.scene.mg + + # check if area is reasonable + if mg.mg_width * mg.mg_height == len(text): + return True + + return False + + def save_text(text): """Saves Blender text block that is stored externally. diff --git a/txt_img_converter.py b/txt_img_converter.py index 4cbcfeb..8c5c828 100644 --- a/txt_img_converter.py +++ b/txt_img_converter.py @@ -189,8 +189,22 @@ def execute(self, context): "valid path or disable save texts in user prefs") return {'CANCELLED'} + # size of the images in the UV/Image editor x_dim = bpy.data.images[mg.maze_image].size[0] y_dim = bpy.data.images[mg.maze_image].size[1] + + # warn the user if the image dimensions are not the same as the maze + maze_width = bpy.context.scene.mg.mg_width + maze_height = bpy.context.scene.mg.mg_height + if x_dim != maze_width or y_dim != maze_height: + self.report({'ERROR'}, "Image dimensions are not the same as your maze dimensions. \nImage dimensions are: " + "(x:{}, y:{}), while maze settings are: (x:{}, y:{}). \nThis will cause issues if you " + "try to convert the resulting text block to a maze without changing the maze layout " + "settings.".format(x_dim, + y_dim, + maze_width, + maze_height + )) maze = "" From 42c4bfd56dfe18160d535bfc168336489ec3d16e Mon Sep 17 00:00:00 2001 From: Jake Dube Date: Fri, 22 Jun 2018 22:13:10 -0400 Subject: [PATCH 2/3] Cleanup comments --- txt_img_converter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/txt_img_converter.py b/txt_img_converter.py index 8c5c828..d07a3ec 100644 --- a/txt_img_converter.py +++ b/txt_img_converter.py @@ -207,18 +207,19 @@ def execute(self, context): )) maze = "" - count = 0 + + # iterate over all pixels while making one long line for the maze str while count < len(bpy.data.images[mg.maze_image].pixels): # if value is white, its a path, otherwise a wall + # more specifically, if the red channel's value is > 0.5 if bpy.data.images[mg.maze_image].pixels[count] > 0.5: maze += "1" else: maze += "0" - # if image has alpha channel... - # this actually seems to work without alpha channel :( + # factor in RGBA channels for each real pixel count += 4 # the maze at this point is a mirror of what it should be From e9e5834d2ca12db81bdd898d2d512f92b4fa0c32 Mon Sep 17 00:00:00 2001 From: Jake Dube Date: Fri, 22 Jun 2018 22:16:03 -0400 Subject: [PATCH 3/3] Bump version number --- __init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 5756193..6b00c1d 100644 --- a/__init__.py +++ b/__init__.py @@ -18,7 +18,7 @@ # ##### END GPL LICENSE BLOCK ##### """ -===== MAZE GENERATOR [PRO] V.2.3.3 ===== +===== MAZE GENERATOR [PRO] V.2.3.4 ===== This __init__ module handles some UI and also registers all classes and properties. """ @@ -51,7 +51,7 @@ bl_info = { "name": "UltiMaze [PRO]", "author": "Jake Dube", - "version": (2, 3, 3), + "version": (2, 3, 4), "blender": (2, 76, 0), "location": "3D View > Tools > Maze Gen", "description": "Generates 3-dimensional mazes.",