Created
October 29, 2018 13:54
-
-
Save Day0Dreamer/21221f1cfe746d783a9136ad6f28489d to your computer and use it in GitHub Desktop.
Just some pullstring stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project.current_category | |
['add_entry', 'copy', 'cut', 'delete_entry', 'enabled', 'entries', 'move', 'name', 'paste', 'toplevel_entries'] | |
SCRIPT_INFO = {'name': '0'} | |
import sys | |
from time import sleep | |
# if not ui.selection: | |
# ui.error("Nothing selected") | |
# sys.exit() | |
print('=' * 50) | |
print('{:-^50}'.format('Running your DayDream')) | |
print('=' * 50) | |
def error(code, entry='', postfix='Do you want to stop the script?'): | |
if code: | |
if entry: | |
intro = 'Error found!\n'+'='*25+'\n' | |
category_name = entry.category.name | |
category_name = '{:<15}\t{}\n'.format('Category->', entry.category_name) if category_name else '' | |
root_entry = get_topmost_parent(entry) | |
root_entry = '{:<15}\t{}: {}\n'.format('Root->', root_entry.type.capitalize(), root_entry.text) | |
entry_desc = '{:<15}\t{}: {}\n'.format('Entry->', entry.type.capitalize(), entry.text) | |
prefix = intro + category_name + root_entry + entry_desc | |
error_message = '{:<15}\t{}\n'.format('Error code->', code)+'='*25+'\n' | |
error_message = prefix+error_message+postfix | |
else: | |
error_message = 'EMPTY ERROR MESSAGE' | |
log('ERROR: ' + code, entry) | |
button_pressed = ui.yes_no(error_message) | |
if button_pressed: | |
sys.exit() | |
def log(message, entry): | |
print('{:<12}\t{}'.format('Category->', entry.category_name)) | |
print('{:<12}\t{}'.format('Root->', get_topmost_parent(entry).text)) | |
print('{:<12}\t{}'.format(entry.type.capitalize()+'->', entry.text)) | |
print('{:<12}\t{}'.format('Message->', message)) | |
print('^'*50) | |
def get_children(root_entry): | |
root_name = root_entry.get_display_text() | |
children_list = root_entry.children | |
return children_list | |
# children_tree = get_children(ui.selection[0]) | |
# children_tree = [entry.type+" -> "+entry.text+" -> "+entry.get_display_text() for entry in children_tree] | |
# children_tree = '\n'.join(children_tree) | |
entries = project.current_category.entries | |
top_entries = project.current_category.toplevel_entries | |
def get_topmost_parent(entry): | |
if entry.depth == 0: | |
return entry | |
parent = get_topmost_parent(entry.parent) | |
return parent | |
def find_rules(entries=entries): | |
rules = [] | |
for entry in entries: | |
if entry.type == TYPE_RULE: | |
rules.append(entry) | |
return rules | |
def check_rules(rules): | |
def start_listen_check(rule): | |
""" | |
Checks if there is (start_listen) prior to the rule | |
:param rule: rule-object in question | |
""" | |
parent = rule.parent | |
error(0) if parent.text.startswith( '(start_listen' ) else error('start_listen', rule) | |
error(0) if parent.type == TYPE_RESPONSE else error('start_listen', rule) | |
def check_for_three_types(rule): | |
""" | |
Checks if there are fallback and cancel event with the rule together | |
:param rule: rule-object in question | |
""" | |
parent = rule.parent | |
parent_children = [child.type for child in parent.children] | |
# Check if there are at least 3 sub-nodes | |
if len(parent_children) < 3: | |
error('Something\'s missing with that rule', rule) | |
else: | |
# Check order | |
if parent_children[0] != 'rule': | |
error('rule out of place', rule) | |
elif parent_children[-2] != 'fallback': | |
error('fallback out of place', rule) | |
elif parent_children[-1] != 'event': | |
error('event out of place', rule) | |
def check_yes_rules(rule): | |
""" | |
Checks if every yes rule has IGNORE_PHONETICS | |
:param rule: rule-object in question | |
""" | |
if 'yes' in rule.text: | |
if rule.notes != 'IGNORE_PHONETICS': | |
rule.notes = 'IGNORE_PHONETICS' | |
log('IGNORE_PHONETICS added', rule) | |
for rule in rules: | |
start_listen_check(rule) | |
check_for_three_types(rule) | |
check_yes_rules(rule) | |
ui.info('Rule check is complete') | |
def walk(category=project.current_category): | |
a_list = [] | |
blacklist = [] | |
bad_entries = [] | |
def get_last_child(parent): | |
if parent.children: # has children | |
for child in parent.children: | |
a_list.append(child) | |
if child.type == TYPE_REFERENCE: | |
if child.mode == 'no_return': | |
if child.reference_id not in blacklist: | |
blacklist.append(child.reference_id) | |
child = child.reference | |
# PAUSE FOR FOLLOWING THE CURSOR | |
# ui.info(child.get_display_text()) | |
ui.selection = child | |
get_last_child(child) | |
elif parent.type == TYPE_REFERENCE: | |
if parent.mode == 'no_return': | |
if parent.reference_id not in blacklist: | |
blacklist.append(child.reference_id) | |
child = parent.reference | |
ui.selection = child | |
get_last_child(child) | |
else: | |
# ui.info('blacklist: '+str(blacklist)) | |
if not '(finish_dialog)' in [item.text for item in a_list[-2:]]: | |
bad_entries.append(parent) | |
error('\n'.join([item.get_display_text() for item in a_list]), parent) | |
# ui.info('There are no more children. We did all we could. Here\'s the history.\n\n'+'\n'.join(a_list)) | |
a_list.clear() | |
pass | |
branches = category.toplevel_entries | |
for branch in branches: | |
entry = branch | |
a_list.append(branch) | |
get_last_child(entry) | |
# for child in entry: | |
# get_children() | |
# | |
# ui.info(entry.children) | |
ui.selection = bad_entries | |
ui.info('Walk is complete') | |
# break | |
# walk() | |
check_rules(find_rules()) | |
# ui.info(get_topmost_parent(ui.selection[0])) | |
# def find_forks(root_entry): | |
# todo add note IGNORE_PHONETICS to all ~yes rules | |
# todo add fallback1 reference to first previous (start_listen tip=yes,_no) | |
# todo add fallback2 reference to first entry before (start_listen tip=yes,_no) | |
# todo add autorenaming of fallbacks with the question f2 refers to | |
# todo after resume_video check for (move target=offscreen_6) | |
# todo after start conversation check for move commentary | |
# todo after every (move target=) check for the right commentary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment