Skip to content

Commit

Permalink
Merge branch 'release-2.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaj2 committed Jun 23, 2018
2 parents 913642b + e9e5834 commit a4fc99d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.",
Expand Down
8 changes: 7 additions & 1 deletion maze_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions prep_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 18 additions & 3 deletions txt_img_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,37 @@ 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 = ""

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
Expand Down

0 comments on commit a4fc99d

Please sign in to comment.