Auto-add libraries

This commit is contained in:
Lubos Lenco 2017-09-05 00:36:16 +02:00
parent 2238ee90be
commit 991eb7118d
6 changed files with 22 additions and 193 deletions

View file

@ -231,14 +231,16 @@ def on_load_post(context):
wrd = bpy.data.worlds['Arm']
wrd.arm_recompile = True
for lib in wrd.arm_librarylist:
if lib.enabled_prop:
fp = arm.utils.get_fp() + '/Libraries/' + lib.name
if fp not in appended_py_paths and os.path.exists(fp + '/blender.py'):
sys.path.append(fp)
appended_py_paths.append(fp)
import blender
blender.register()
if os.path.exists(arm.utils.get_fp() + '/Libraries'):
libs = os.listdir(arm.utils.get_fp() + '/Libraries')
for lib in libs:
if os.path.isdir(arm.utils.get_fp() + '/Libraries/' + lib):
fp = arm.utils.get_fp() + '/Libraries/' + lib
if fp not in appended_py_paths and os.path.exists(fp + '/blender.py'):
sys.path.append(fp)
appended_py_paths.append(fp)
import blender
blender.register()
@persistent
def on_save_pre(context):

View file

@ -2,7 +2,6 @@ import bpy
from bpy.props import *
import os
import shutil
from arm.props_library import *
import arm.props_ui as props_ui
import arm.assets as assets
import arm.log as log

View file

@ -1,136 +0,0 @@
import shutil
import bpy
import os
import json
from bpy.types import Menu, Panel, UIList
from bpy.props import *
class ArmLibraryListItem(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(
name="Name",
description="A name for this item",
default="Untitled")
enabled_prop = bpy.props.BoolProperty(
name="",
description="A name for this item",
default=True)
class ArmLibraryList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
# We could write some code to decide which icon to use here...
custom_icon = 'OBJECT_DATAMODE'
# Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.prop(item, "enabled_prop")
#layout.label(item.name, icon = custom_icon)
layout.prop(item, "name", text="", emboss=False, icon=custom_icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label("", icon = custom_icon)
class ArmLibraryListNewItem(bpy.types.Operator):
# Add a new item to the list
bl_idname = "arm_librarylist.new_item"
bl_label = "Add a new item"
def execute(self, context):
trait = bpy.data.worlds['Arm']
trait.arm_librarylist.add()
trait.arm_librarylist_index = len(trait.arm_librarylist) - 1
return{'FINISHED'}
class ArmLibraryListDeleteItem(bpy.types.Operator):
# Delete the selected item from the list
bl_idname = "arm_librarylist.delete_item"
bl_label = "Deletes an item"
@classmethod
def poll(self, context):
""" Enable if there's something in the list """
trait = bpy.data.worlds['Arm']
return len(trait.arm_librarylist) > 0
def execute(self, context):
trait = bpy.data.worlds['Arm']
list = trait.arm_librarylist
index = trait.arm_librarylist_index
list.remove(index)
if index > 0:
index = index - 1
trait.arm_librarylist_index = index
return{'FINISHED'}
class ArmLibraryListMoveItem(bpy.types.Operator):
# Move an item in the list
bl_idname = "arm_librarylist.move_item"
bl_label = "Move an item in the list"
direction = bpy.props.EnumProperty(
items=(
('UP', 'Up', ""),
('DOWN', 'Down', ""),))
@classmethod
def poll(self, context):
""" Enable if there's something in the list. """
trait = bpy.data.worlds['Arm']
return len(trait.arm_librarylist) > 0
def move_index(self):
# Move index of an item render queue while clamping it
trait = bpy.data.worlds['Arm']
index = trait.arm_librarylist_index
list_length = len(trait.arm_librarylist) - 1
new_index = 0
if self.direction == 'UP':
new_index = index - 1
elif self.direction == 'DOWN':
new_index = index + 1
new_index = max(0, min(new_index, list_length))
index = new_index
def execute(self, context):
trait = bpy.data.worlds['Arm']
list = trait.arm_librarylist
index = trait.arm_librarylist_index
if self.direction == 'DOWN':
neighbor = index + 1
#queue.move(index,neighbor)
self.move_index()
elif self.direction == 'UP':
neighbor = index - 1
#queue.move(neighbor, index)
self.move_index()
else:
return{'CANCELLED'}
return{'FINISHED'}
def register():
bpy.utils.register_class(ArmLibraryListItem)
bpy.utils.register_class(ArmLibraryList)
bpy.utils.register_class(ArmLibraryListNewItem)
bpy.utils.register_class(ArmLibraryListDeleteItem)
bpy.utils.register_class(ArmLibraryListMoveItem)
bpy.types.World.arm_librarylist = bpy.props.CollectionProperty(type=ArmLibraryListItem)
bpy.types.World.arm_librarylist_index = bpy.props.IntProperty(name="Library index", default=0)
def unregister():
bpy.utils.unregister_class(ArmLibraryListItem)
bpy.utils.unregister_class(ArmLibraryList)
bpy.utils.unregister_class(ArmLibraryListNewItem)
bpy.utils.unregister_class(ArmLibraryListDeleteItem)
bpy.utils.unregister_class(ArmLibraryListMoveItem)

View file

@ -1,7 +1,5 @@
import bpy
import subprocess
import webbrowser
import threading
from bpy.types import Menu, Panel, UIList
from bpy.props import *
import arm.utils
@ -418,28 +416,7 @@ class ArmoryProjectPanel(bpy.types.Panel):
layout.prop(wrd, 'arm_project_name')
layout.prop(wrd, 'arm_project_package')
layout.prop_search(wrd, 'arm_khafile', bpy.data, 'texts', 'Khafile')
layout.prop_search(wrd, 'arm_khamake', bpy.data, 'texts', 'Khamake')
layout.separator()
layout.label("Libraries:")
rows = 2
if len(wrd.arm_librarylist) > 1:
rows = 4
row = layout.row()
row.template_list("ArmLibraryList", "The_List", wrd, "arm_librarylist", wrd, "arm_librarylist_index", rows=rows)
col = row.column(align=True)
col.operator("arm_librarylist.new_item", icon='ZOOMIN', text="")
col.operator("arm_librarylist.delete_item", icon='ZOOMOUT', text="")
if len(wrd.arm_librarylist) > 1:
col.separator()
col.operator("arm_librarylist.move_item", icon='TRIA_UP', text="").direction = 'UP'
col.operator("arm_librarylist.move_item", icon='TRIA_DOWN', text="").direction = 'DOWN'
# if wrd.arm_librarylist_index >= 0 and len(wrd.arm_librarylist) > 0:
# libitem = wrd.arm_librarylist[wrd.arm_librarylist_index]
layout.prop_search(wrd, 'arm_khamake', bpy.data, 'texts', 'Khamake')
layout.label('Armory v' + wrd.arm_version)

View file

@ -55,26 +55,22 @@ project.addSources('Sources');
if os.path.exists('Bundled'):
f.write(add_assets("Bundled/**"))
if os.path.exists('Libraries/armory'):
f.write('project.addLibrary("armory");\n')
else:
if not os.path.exists('Libraries/armory'):
f.write(add_armory_library(sdk_path, 'armory'))
if os.path.exists('Libraries/iron'):
f.write('project.addLibrary("iron");\n')
else:
if not os.path.exists('Libraries/iron'):
f.write(add_armory_library(sdk_path, 'iron'))
# Project libraries
for lib in wrd.arm_librarylist:
if lib.enabled_prop:
f.write('project.addLibrary("{0}");\n'.format(lib.name))
if os.path.exists('Libraries'):
libs = os.listdir('Libraries')
for lib in libs:
if os.path.isdir('Libraries/' + lib):
f.write('project.addLibrary("{0}");\n'.format(lib))
if export_physics:
assets.add_khafile_def('arm_physics')
if os.path.exists('Libraries/haxebullet'):
f.write('project.addLibrary("haxebullet");\n')
else:
if not os.path.exists('Libraries/haxebullet'):
f.write(add_armory_library(sdk_path + '/lib/', 'haxebullet'))
if state.target == 'krom' or state.target == 'html5' or state.target == 'node':
ammojs_path = sdk_path + '/lib/haxebullet/js/ammo/ammo.js'
@ -83,9 +79,7 @@ project.addSources('Sources');
if export_navigation:
assets.add_khafile_def('arm_navigation')
if os.path.exists('Libraries/haxerecast'):
f.write('project.addLibrary("haxerecast");\n')
else:
if not os.path.exists('Libraries/haxerecast'):
f.write(add_armory_library(sdk_path + '/lib/', 'haxerecast'))
if state.target == 'krom' or state.target == 'html5':
recastjs_path = sdk_path + '/lib/haxerecast/js/recast/recast.js'
@ -136,18 +130,14 @@ project.addSources('Sources');
assets.add_khafile_def('arm_profile')
if export_ui:
if os.path.exists('Libraries/zui'):
f.write('project.addLibrary("zui");\n')
else:
if not os.path.exists('Libraries/zui'):
f.write(add_armory_library(sdk_path, 'lib/zui'))
p = sdk_path + '/armory/Assets/droid_sans.ttf'
f.write(add_assets(p.replace('\\', '/')))
assets.add_khafile_def('arm_ui')
if wrd.arm_hscript == 'Enabled':
if os.path.exists('Libraries/hscript'):
f.write('project.addLibrary("hscript");\n')
else:
if not os.path.exists('Libraries/hscript'):
f.write(add_armory_library(sdk_path, 'lib/hscript'))
assets.add_khafile_def('arm_hscript')

View file

@ -1,7 +1,6 @@
import arm.nodes_logic
import arm.nodes_renderpath
import arm.make_renderer
import arm.props_library
import arm.props_traits_params
import arm.props_traits_props
import arm.props_traits
@ -27,7 +26,6 @@ def register():
arm.props_lod.register()
arm.props_exporter.register()
arm.props_renderpath.register()
arm.props_library.register()
arm.props.register()
arm.props_ui.register()
arm.nodes_logic.register()
@ -48,7 +46,6 @@ def unregister():
arm.handlers.unregister()
arm.props_ui.unregister()
arm.props.unregister()
arm.props_library.unregister()
arm.props_traits_params.unregister()
arm.props_traits_props.unregister()
arm.props_traits.unregister()