versioning.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #Versioning Tasks
  2. # this will be the new versioning system, and will deprecate the old SOCKETS_ADDED and such
  3. from bpy.types import Node, NodeSocket
  4. from .utilities import prRed, prGreen, prPurple
  5. def version_upgrade_bone_0_12_0_from_older(*args, **kwargs):
  6. # we need to check if it has an array collection input and a color input
  7. # then we need to solve each task
  8. node = kwargs['node']
  9. current_major_version = node.id_data.mantis_version[0]
  10. current_minor_version = node.id_data.mantis_version[1]
  11. if current_major_version > 0: # major version must be 0
  12. return
  13. if current_minor_version >= 12: # minor version must be 11 or less
  14. return
  15. # sub version doesn't matter since any subversion of 11 should trigger this task
  16. try:
  17. collection_input_is_array = node.inputs['Bone Collection'].is_multi_input
  18. if not collection_input_is_array: # it must be made into an array!
  19. prPurple(f"Updating \"Bone Collection\" Socket in {node.name}")
  20. from .utilities import get_socket_maps
  21. socket_maps = get_socket_maps(node)
  22. socket_map = socket_maps[0]
  23. for i, socket in enumerate(node.inputs):
  24. if socket.name == 'Bone Collection': break
  25. old_id = socket.identifier
  26. # it is an input
  27. node.inputs.remove(socket)
  28. s = node.inputs.new('BoneCollectionSocket', 'Bone Collection',
  29. identifier='Bone Collection', use_multi_input=True)
  30. node.inputs.move(len(node.inputs)-1, i)
  31. socket_map_from_old_socket = socket_map[old_id]
  32. # there seems to be an error in do_relink
  33. # gonna do it directly instead
  34. if isinstance(socket_map_from_old_socket, list):
  35. for map_info in socket_map_from_old_socket:
  36. if isinstance(map_info, Node ):
  37. l = node.id_data.links.new(input=map_info.outputs[0], output=s)
  38. elif isinstance(map_info, NodeSocket):
  39. l = node.id_data.links.new(input=map_info, output=s)
  40. else:
  41. s.default_value = socket_map_from_old_socket
  42. if node.inputs.get('Color') is None:
  43. prPurple(f"Adding \"Color\" Socket to {node.name}")
  44. s = node.inputs.new('ColorSetSocket', 'Color',)
  45. node.inputs.move(len(node.inputs)-1, 22)
  46. except Exception as e:
  47. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  48. print(e)
  49. def up_0_12_1_add_inherit_color(*args, **kwargs):
  50. # add an inherit color input.
  51. node = kwargs['node']
  52. current_major_version = node.id_data.mantis_version[0]
  53. current_minor_version = node.id_data.mantis_version[1]
  54. current_sub_version = node.id_data.mantis_version[2]
  55. if current_major_version > 0: return# major version must be 0
  56. if current_minor_version > 12: return# minor version must be 12 or less
  57. if current_minor_version == 12 and current_sub_version < 1: return # sub version must be 0
  58. # sub version doesn't matter since any subversion of 11 should trigger this task
  59. prPurple(f"Adding \"Inherit Color\" socket to {node.name}")
  60. try:
  61. if node.inputs.get('Inherit Color') is None:
  62. s = node.inputs.new('BooleanSocket', 'Inherit Color',)
  63. node.inputs.move(len(node.inputs)-1, 23)
  64. s.default_value=True
  65. except Exception as e:
  66. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  67. print(e)
  68. versioning_tasks = [
  69. # node bl_idname task required keyword arguments
  70. (['xFormBoneNode'], version_upgrade_bone_0_12_0_from_older, ['node'],),
  71. (['xFormBoneNode'], up_0_12_1_add_inherit_color, ['node'],),
  72. ]