Skip to content

Commit

Permalink
Fix Renaming Trees
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Mar 11, 2021
1 parent 92a9e91 commit 548adcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
30 changes: 20 additions & 10 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,25 @@ def _update_all_logic_tree_code():
utils.error("Unknown Error, abort generating Network code")


def _generate_on_game_start(*args):
def _generate_on_game_start(self, context):
if utils.is_compile_status(utils.TREE_MODIFIED):
bpy.ops.bge_netlogic.generate_logicnetwork_all()


def _consume_update_tree_code_queue():
edit_tree = getattr(bpy.context.space_data, "edit_tree", None)
if _generate_on_game_start not in bpy.app.handlers.game_pre:
bpy.app.handlers.game_pre.append(_generate_on_game_start)
if not _update_queue:
return
if hasattr(bpy.context.space_data, "edit_tree") and (bpy.context.space_data.edit_tree):
edit_tree = bpy.context.space_data.edit_tree
if edit_tree:
# edit_tree = bpy.context.space_data.edit_tree
old_name = _tree_to_name_map.get(edit_tree)
if not old_name:
_tree_to_name_map[edit_tree] = edit_tree.name
else:
if old_name != edit_tree.name:
update_tree_name(edit_tree, old_name)
if not _update_queue:
return
now = time.time()
last_event = _update_queue[-1]
delta = now - last_event
Expand Down Expand Up @@ -323,9 +324,11 @@ def request_tree_code_writer_start(dummy):
global _tree_code_writer_started
_tree_code_writer_started = False
generator = ops.tree_code_generator.TreeCodeGenerator()
utils.debug('Writing trees on file open...')
bpy.ops.bge_netlogic.generate_logicnetwork_all()
utils.debug('FINISHED')
print(getattr(bpy.context.scene.logic_node_settings, 'use_generate_on_open', False))
if getattr(bpy.context.scene.logic_node_settings, 'use_generate_on_open', False):
utils.debug('Writing trees on file open...')
bpy.ops.bge_netlogic.generate_logicnetwork_all()
utils.debug('FINISHED')


for f in [
Expand Down Expand Up @@ -368,6 +371,7 @@ class NLAddonSettings(bpy.types.PropertyGroup):
)
use_node_debug: bpy.props.BoolProperty(default=True)
use_node_notify: bpy.props.BoolProperty(default=True)
use_generate_on_open: bpy.props.BoolProperty(default=False)
use_generate_all: bpy.props.BoolProperty(default=True)
auto_compile: bpy.props.BoolProperty(default=False)
tree_compiled: bpy.props.StringProperty(default=utils.TREE_NOT_INITIALIZED)
Expand Down Expand Up @@ -425,15 +429,21 @@ def draw(self, context):
'use_node_debug',
text="Debug Mode (Print Errors to Console)"
)
code_col.label(text='Generate Code:')
code_col.prop(
context.scene.logic_node_settings,
'use_generate_all',
text="Generate All Code on Fail."
text="On Fail."
)
code_col.prop(
context.scene.logic_node_settings,
'auto_compile',
text="Generate Code after editing (Slow)."
text="After Editing (Slow)."
)
code_col.prop(
context.scene.logic_node_settings,
'use_generate_on_open',
text="On File Open."
)
col.separator()
link_row = col.row(align=True)
Expand Down
22 changes: 1 addition & 21 deletions ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,6 @@ class BGE_PT_LogicTreeGroups(bpy.types.Panel):
@classmethod
def poll(cls, context):
enabled = (context.space_data.tree_type == BGELogicTree.bl_idname)
if enabled and (context.space_data.edit_tree is not None):
bge_netlogic._consume_update_tree_code_queue()
if not bge_netlogic._tree_code_writer_started:
bge_netlogic._tree_code_writer_started = True
bpy.ops.bgenetlogic.treecodewriter_operator()
return enabled

def draw(self, context):
Expand Down Expand Up @@ -671,7 +666,7 @@ class BGE_PT_LogicTreeOptions(bpy.types.Panel):
@classmethod
def poll(cls, context):
enabled = (context.space_data.tree_type == BGELogicTree.bl_idname)
if enabled and (context.space_data.edit_tree is not None):
if getattr(context.space_data, 'edit_tree', None) is not None:
bge_netlogic._consume_update_tree_code_queue()
if not bge_netlogic._tree_code_writer_started:
bge_netlogic._tree_code_writer_started = True
Expand Down Expand Up @@ -795,11 +790,6 @@ class BGE_PT_LogicPanel(bpy.types.Panel):
@classmethod
def poll(cls, context):
enabled = (context.space_data.tree_type == BGELogicTree.bl_idname)
if enabled and (context.space_data.edit_tree is not None):
bge_netlogic._consume_update_tree_code_queue()
if not bge_netlogic._tree_code_writer_started:
bge_netlogic._tree_code_writer_started = True
bpy.ops.bgenetlogic.treecodewriter_operator()
return enabled

def draw(self, context):
Expand Down Expand Up @@ -829,11 +819,6 @@ class BGE_PT_HelpPanel(bpy.types.Panel):
@classmethod
def poll(cls, context):
enabled = (context.space_data.tree_type == BGELogicTree.bl_idname)
if enabled and (context.space_data.edit_tree is not None):
bge_netlogic._consume_update_tree_code_queue()
if not bge_netlogic._tree_code_writer_started:
bge_netlogic._tree_code_writer_started = True
bpy.ops.bgenetlogic.treecodewriter_operator()
return enabled

def draw(self, context):
Expand All @@ -849,11 +834,6 @@ def draw(self, context):
text="Manual",
icon='BLENDER'
)
# layout.operator(
# bge_netlogic.ops.NLDocsButton.bl_idname,
# text="Logic Nodes",
# icon='OUTLINER'
# )


class BGELogicTree(bpy.types.NodeTree):
Expand Down

0 comments on commit 548adcf

Please sign in to comment.