def dump_load_cache(_connection=None): mtg = get_manager() ref_dict = mtg.index_ref_record sorted_dict = sorted(ref_dict, key=lambda ref_entry: len(ref_dict[ref_entry])) file_path = os.path.join('C:\\', 'merged_tuning_log_{}.txt'.format(time.strftime('%y%m%d_%H_%M_%S'))) fd = os.open(file_path, os.O_RDWR | os.O_CREAT) for cache_key in sorted_dict: (cache_id, key) = cache_key ref_list = ref_dict[cache_key] ref_str = 'ID: {}, Key: {}, Ref: {}: \n'.format(cache_id, key, len(ref_list)) os.write(fd, bytes(ref_str, 'UTF-8')) _template_to_write = None _value_to_write = None for (source, tunable_template, tuned_value) in ref_list: if _template_to_write is None and _value_to_write is None: _template_to_write = tunable_template _value_to_write = tuned_value ref_str = 'Template: {}, Value: {} \n'.format(_template_to_write, _value_to_write) os.write(fd, bytes(ref_str, 'UTF-8')) substr = '' match = NAME_PATTERN.match(source) if match: substr = match.group(1) ref_str = ' File: {}, Template: {} \n'.format(substr, tunable_template) os.write(fd, bytes(ref_str, 'UTF-8')) sims4.commands.output('Dump done', _connection) return True
def create_class_instances(self): mtg = get_manager() res_id_list = mtg.get_all_res_ids(self.TYPE) logger.info('Creating {:4} tuning class instances managed by {}.', len(res_id_list), self, owner='manus') for (group_id, instance_id) in res_id_list: res_key = sims4.resources.Key(self.TYPE, instance_id, group_id) self._create_class_instance(res_key)
def _load_node(self, node, tunable_class): callback_infos = [] verify_callback_infos = [] mtg = get_manager() if node.tag == LoadingTags.Module: for child_node in node: name = child_node.get(LoadingAttributes.Name) child_class = self._inner_module(tunable_class, name) node_to_load = child_node if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) node_to_load = mtg.get_tunable_node(ref_index) self._load_node(node_to_load, child_class) else: if node.tag == LoadingTags.Class: tunable_datas = self._get_module_tunables_from_class(tunable_class) else: tunable_datas = tunable_class.get_tunables() for child_node in node: tunable_name = child_node.get(LoadingAttributes.Name, '') if tunable_datas is not None and tunable_name in tunable_datas: tunable = tunable_datas.get(tunable_name) if tunable is None or not isinstance(tunable, TunableBase): logger.error('Attempt to load a value from {0} that is no longer tunable: {1}'.format(self.source, tunable_name)) else: self._load_tunable(tunable_class, tunable_name, tunable, child_node, mtg) sub_child_class = self._inner_module(tunable_class, tunable_name) if sub_child_class is not None: node_to_load = child_node if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) node_to_load = mtg.get_tunable_node(ref_index) self._load_node(node_to_load, sub_child_class) else: logger.error('Attempt to load a value from {0} that is no longer tunable: {1}'.format(self.source, tunable_name)) else: sub_child_class = self._inner_module(tunable_class, tunable_name) if sub_child_class is not None: node_to_load = child_node if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) node_to_load = mtg.get_tunable_node(ref_index) self._load_node(node_to_load, sub_child_class) else: logger.error('Attempt to load a value from {0} that is no longer tunable: {1}'.format(self.source, tunable_name)) if self._loading_tag == LoadingTags.Instance: tunable_data = self.module.get_tunables() if tunable_data is not None: while True: for name in self._invoke_names: template = tunable_data.get(name) while template is not None: tuned_value = getattr(self.module, name) if template.has_callback: callback_infos.append(TuningCallbackHelper(template, name, self.source, tuned_value)) if template.has_verify_tunable_callback: verify_callback_infos.append(TuningCallbackHelper(template, name, self.source, tuned_value)) increment_tunable_callback_count(len(callback_infos)) increment_verify_tunable_callback_count(len(verify_callback_infos)) return (callback_infos, verify_callback_infos)
def _collection_load_etree_node(original_self, node, source, expect_error): (collection_type, collection_fn, final_type, is_final_node) = original_self._get_collection_types() if is_final_node(node): return original_self.default mtg = get_manager() tunable_instance = original_self._template tunable_name = node.get(LoadingAttributes.Name, '<Unnamed>') tunable_collection = collection_type() element_index = 0 for child_node in node: element_index += 1 value = None try: if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) value = mtg.get_tunable(ref_index, tunable_instance, source) else: current_tunable_tag = tunable_instance.LOADING_TAG_NAME if current_tunable_tag == Tags.TdescFragTag: current_tunable_tag = tunable_instance.FRAG_TAG_NAME if current_tunable_tag != child_node.tag: TuningWatcher.get().process_log_message( "Incorrectly matched tuning types found in tuning for {} in {}. Expected '{}', got '{}'", tunable_name, source, current_tunable_tag, child_node.tag) TuningWatcher.get().process_log_message( 'ATTRS: {}', child_node.items()) _CNTEIXMLValidator._log_etree_node(child_node) value = tunable_instance.load_etree_node( child_node, source, expect_error) if False and not original_self.allow_none and value is None: TuningWatcher.get().process_log_message( 'None entry found in tunable list in {}.\nName: {}\nIndex: {}\nContent:{}', source, tunable_name, element_index, child_node) TuningWatcher.get().process_log_message( 'Invalid value: {}', child_node.text) _CNTEIXMLValidator._log_etree_node(node) else: collection_fn(tunable_collection, value) except UnavailablePackSafeResourceError: continue except TunableMinimumLengthError: continue except: TuningWatcher.get().process_log_message( 'Error while parsing tuning in {}:', source) TuningWatcher.get().process_log_message( 'Failed to load element for {} (index {}): {}. Skipping.', tunable_name, element_index, child_node) if original_self.minlength is not None and len( tunable_collection) < original_self.minlength: TuningWatcher.get().process_log_message( 'Collection {} in {} has fewer than the minimum number of entries.', source, tunable_name) raise TunableMinimumLengthError return final_type(tunable_collection)
def _tuple_load_etree_node(original_self, node, source, expect_error): value = {} tuned = set() mtg = get_manager() if node is not None: for child_node in node: name = child_node.get(LoadingAttributes.Name) if name in original_self.tunable_items: template = original_self.tunable_items.get(name) if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) tuple_value = mtg.get_tunable(ref_index, template, source) else: current_tunable_tag = template.LOADING_TAG_NAME if current_tunable_tag == Tags.TdescFragTag: current_tunable_tag = template.FRAG_TAG_NAME if current_tunable_tag != child_node.tag: tunable_name = node.get(LoadingAttributes.Name, '<Unnamed>') TuningWatcher.get().process_log_message( "Incorrectly matched tuning types found in tuning for {} in {}. Expected '{}', got '{}'", tunable_name, source, current_tunable_tag, child_node.tag) TuningWatcher.get().process_log_message( 'ATTRS 2: {}', node.items()) _CNTEIXMLValidator._log_etree_node(child_node) tuple_value = template.load_etree_node( child_node, source, expect_error) value[name] = tuple_value tuned.add(name) else: TuningWatcher.get().process_log_message( 'Error in {}, parsing a {} tag', source, original_self.TAGNAME) if name in original_self.locked_args: TuningWatcher.get().process_log_message( "The tag name '{}' is locked for this tunable and should be removed from the tuning file.", name) else: TuningWatcher.get().process_log_message( "The tag name '{}' was unexpected. Valid tags: {}", name, ', '.join(original_self.tunable_items.keys())) if original_self.INCLUDE_UNTUNED_VALUES: leftovers = set(original_self.tunable_items.keys()) - tuned for name in leftovers: template = original_self.tunable_items[name] tuple_value = template.default value[name] = tuple_value constructed_value = original_self._create_dict( value, original_self.locked_args) return constructed_value
def register_change(self, setname, resource_key): if setname: changed_resources = self.change_sets[setname][1] if resource_key not in changed_resources: changed_resources.append(resource_key) else: for data in self.change_sets.values(): if data[1]: if resource_key not in data[1]: data[1].append(resource_key) mtg = get_manager() mtg.register_change(resource_key)
def show_load_cache_info(_connection=None): mtg = get_manager() ref_dict = mtg.index_ref_record c = Counter({k: len(v) for (k, v) in ref_dict.items()}) if not c: return False output = sims4.commands.Output(_connection) output('Cache size: {}'.format(len(c))) output('Average cache size: {}'.format(sum(c.values())/len(c))) output('Most common keys:') for (key, count) in c.most_common(32): output('\t{}: {}'.format(key, count)) return True
def _variant_load_etree_node(original_self, node, source, expect_error): if node is None: return original_self.default value = None mtg = get_manager() variant = node.get(LoadingAttributes.VariantType, original_self._variant_default) if variant is not None: if variant in original_self.locked_args: value = original_self.locked_args[variant] else: value = None template = original_self.tunable_items.get(variant) if template is None: TuningWatcher.get().process_log_message( 'Variant is set to a type that does not exist: {} in {}.', variant, source) return original_self._variant_default node_children = list(node) if node_children: child_node = node_children[0] name = child_node.get(LoadingAttributes.Name) if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) value = mtg.get_tunable(ref_index, template, source) child_node = None else: current_tunable_tag = template.LOADING_TAG_NAME if current_tunable_tag == Tags.TdescFragTag: current_tunable_tag = template.FRAG_TAG_NAME if current_tunable_tag != child_node.tag: tunable_name = node.get(LoadingAttributes.Name, '<Unnamed>') TuningWatcher.get().process_log_message( "Incorrectly matched tuning types found in tuning for {} in {}. Expected '{}', got '{}'", tunable_name, source, current_tunable_tag, child_node.tag) TuningWatcher.get().process_log_message( 'ATTRS 3: {}', child_node.items()) _CNTEIXMLValidator._log_etree_node(child_node) else: child_node = None if value is None: value = template.load_etree_node(child_node, source, expect_error) if value is not None: if template._has_callback: if original_self._variant_map is None: original_self._variant_map = {} original_self._variant_map[id(value)] = variant return value
def _load_node(self, node, tunable_class): callback_infos = [] verify_callback_infos = [] mtg = get_manager() if node.tag == LoadingTags.Module: for child_node in node: name = child_node.get(LoadingAttributes.Name) child_class = self._inner_module(tunable_class, name) node_to_load = child_node if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) node_to_load = mtg.get_tunable_node(ref_index) self._load_node(node_to_load, child_class) else: if node.tag == LoadingTags.Class: tunable_datas = self._get_module_tunables_from_class(tunable_class) else: tunable_datas = tunable_class.get_tunables() for child_node in node: tunable_name = child_node.get(LoadingAttributes.Name, '') if tunable_datas is not None and tunable_name in tunable_datas: tunable = tunable_datas.get(tunable_name) if tunable is None or not isinstance(tunable, TunableBase): logger.error('Attempt to load a value from {0} that is no longer tunable: {1}'.format(self.source, tunable_name)) else: self._load_tunable(tunable_class, tunable_name, tunable, child_node, mtg) else: sub_child_class = self._inner_module(tunable_class, tunable_name) if sub_child_class is not None: node_to_load = child_node if child_node.tag == MergedTuningAttr.Reference: ref_index = child_node.get(MergedTuningAttr.Index) node_to_load = mtg.get_tunable_node(ref_index) self._load_node(node_to_load, sub_child_class) else: logger.error('Attempt to load a value from {0} that is no longer tunable: {1}'.format(self.source, tunable_name)) if self._loading_tag == LoadingTags.Instance: tunable_data = self.module.get_tunables() if tunable_data is not None: for name in self._invoke_names: template = tunable_data.get(name) if template is not None: tuned_value = getattr(self.module, name) if template.has_callback: callback_infos.append(sims4.tuning.instance_manager.TuningCallbackHelper(template, name, self.source, tuned_value)) if template.has_verify_tunable_callback: verify_callback_infos.append(sims4.tuning.instance_manager.TuningCallbackHelper(template, name, self.source, tuned_value)) sims4.tuning.instance_manager.increment_tunable_callback_count(len(callback_infos)) sims4.tuning.instance_manager.increment_verify_tunable_callback_count(len(verify_callback_infos)) return (callback_infos, verify_callback_infos)
def create_class_instance(resource_key, resource_type): tuning_loader = ETreeClassCreator('Instance: {0}, Type: {1}'.format(resource_key, resource_type)) mtg = get_manager() if mtg.deleted_local_key_exists(resource_key): return if mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() tuning_loader.feed(tuning_file) else: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: tuning_loader.feed_node(root_node) return tuning_loader.module
def load_module_tuning(module, tuning_filename_or_key): schema_dict = {} has_tunables = _scan_module_rec(schema_dict, module, LoadingTags.Module, module.__name__, for_export=False) if not has_tunables: return True if not LOAD_MODULE_FOR_EXPORTING: tuning_loader = ETreeTuningLoader(module, tuning_filename_or_key) mtg = get_manager() if isinstance(tuning_filename_or_key, str): full_name = os.path.basename(tuning_filename_or_key) res_name = os.path.splitext(full_name)[0] res_key = sims4.resources.get_resource_key( res_name, sims4.resources.Types.TUNING) else: res_key = tuning_filename_or_key if mtg.local_key_exists(res_key): loader = ResourceLoader(res_key, sims4.resources.Types.TUNING) tuning_file = loader.load() tuning_loader.feed(tuning_file) else: root_node = mtg.get_tuning_res(res_key, silent_fail=True) if root_node is not None: tuning_loader.feed_node(root_node) for (name, tunable, parent) in _find_tunables_gen(None, schema_dict, module): if name in vars(parent): while not tunable.deferred: tuned_value = getattr(parent, name) tunable.invoke_callback(None, name, tuning_filename_or_key, tuned_value) value = tunable.default reload_context = getattr(parent, '__reload_context__', None) if reload_context: with reload_context(parent, parent): setattr(parent, name, value) else: setattr(parent, name, value) value = tunable.default reload_context = getattr(parent, '__reload_context__', None) if reload_context: with reload_context(parent, parent): setattr(parent, name, value) else: setattr(parent, name, value) return True
def load_from_xml(resource_key, resource_type, inst, from_reload=False): mtg = get_manager() tuning_loader = ETreeTuningLoader(inst, 'Instance: {0}, Type: {1}'.format(resource_key, resource_type), loading_tag=LoadingTags.Instance) if mtg.deleted_local_key_exists(resource_key): tuning_loader.module = None else: if from_reload or mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() if tuning_file is not None: return tuning_loader.feed(tuning_file) if mtg.has_combined_tuning_loaded: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: return tuning_loader.feed_node(root_node)
def load_value(self): if self.node is None: return try: self.tunable_name = self.node.get(LoadingAttributes.Name) if self.node.tag == MergedTuningAttr.Reference: ref_index = self.node.get(MergedTuningAttr.Index) mtg = get_manager() self.value = mtg.get_tunable(ref_index, self.template, source=self.source) else: self.value = self.template.load_etree_node(node=self.node, source=self.source) except Exception: logger.exception("Error parsing deferred tuning within the tag named '{}' (source: {})".format(self.tunable_name, self.source)) raise self.node = None
def create_class_instance(resource_key, resource_type): tuning_loader = ETreeClassCreator('Instance: {0}, Type: {1}'.format( resource_key, resource_type)) mtg = get_manager() if mtg.deleted_local_key_exists(resource_key): return if mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() tuning_loader.feed(tuning_file) else: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: tuning_loader.feed_node(root_node) return tuning_loader.module
def load_value(self): if self.node is None: return try: self.tunable_name = self.node.get(LoadingAttributes.Name) if self.node.tag == MergedTuningAttr.Reference: ref_index = self.node.get(MergedTuningAttr.Index) mtg = get_manager() self.value = mtg.get_tunable(ref_index, self.template, self.source) else: self.value = self.template.load_etree_node(self.node, self.source, False) _loaded_deferred_tunable.append(self) except UnavailablePackSafeResourceError: self.value = self.template.default except Exception: logger.exception("Error parsing deferred tuning within the tag named '{}' (source: {})".format(self.tunable_name, self.source)) raise self.node = None
def load_from_xml(resource_key, resource_type, inst, from_reload=False): mtg = get_manager() tuning_loader = ETreeTuningLoader(inst, 'Instance: {0}, Type: {1}'.format( resource_key, resource_type), loading_tag=LoadingTags.Instance) if mtg.deleted_local_key_exists(resource_key): tuning_loader.module = None else: if from_reload or mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() if tuning_file is not None: return tuning_loader.feed(tuning_file) if mtg.has_combined_tuning_loaded: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: return tuning_loader.feed_node(root_node)
def load_module_tuning(module, tuning_filename_or_key): schema_dict = {} has_tunables = _scan_module_rec(schema_dict, module, LoadingTags.Module, module.__name__, for_export=False) if not has_tunables: return True if not LOAD_MODULE_FOR_EXPORTING: tuning_loader = ETreeTuningLoader(module, tuning_filename_or_key) mtg = get_manager() if isinstance(tuning_filename_or_key, str): full_name = os.path.basename(tuning_filename_or_key) res_name = os.path.splitext(full_name)[0] res_key = sims4.resources.get_resource_key(res_name, sims4.resources.Types.TUNING) else: res_key = tuning_filename_or_key if mtg.local_key_exists(res_key): loader = ResourceLoader(res_key, sims4.resources.Types.TUNING) tuning_file = loader.load() tuning_loader.feed(tuning_file) else: root_node = mtg.get_tuning_res(res_key, silent_fail=True) if root_node is not None: tuning_loader.feed_node(root_node) for (name, tunable, parent) in _find_tunables_gen(None, schema_dict, module): if name in vars(parent): while not tunable.deferred: tuned_value = getattr(parent, name) tunable.invoke_callback(None, name, tuning_filename_or_key, tuned_value) value = tunable.default reload_context = getattr(parent, '__reload_context__', None) if reload_context: with reload_context(parent, parent): setattr(parent, name, value) else: setattr(parent, name, value) value = tunable.default reload_context = getattr(parent, '__reload_context__', None) if reload_context: with reload_context(parent, parent): setattr(parent, name, value) else: setattr(parent, name, value) return True
def load_from_xml(resource_key, resource_type, inst, from_reload=False): source = strformatter('Instance: {0} ({1}), {2}', resource_key.instance, inst.__name__, resource_type) tuning_loader = ETreeTuningLoader(inst, source, loading_tag=LoadingTags.Instance) mtg = get_manager() if mtg.deleted_local_key_exists(resource_key): tuning_loader.module = None elif from_reload or mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() if tuning_file is not None: return tuning_loader.feed(tuning_file) elif mtg.has_combined_tuning_loaded: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: return tuning_loader.feed_node(root_node) elif mtg.has_combined_tuning_loaded: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: return tuning_loader.feed_node(root_node) return (None, None)
def create_class_instance(resource_key, resource_type): try: tuning_loader = ETreeClassCreator() mtg = get_manager() if mtg.deleted_local_key_exists(resource_key): return if mtg.local_key_exists(resource_key): loader = ResourceLoader(resource_key, resource_type) tuning_file = loader.load() if tuning_file is None: return tuning_loader.feed(tuning_file) else: root_node = mtg.get_tuning_res(resource_key) if root_node is not None: tuning_loader.feed_node(root_node) return tuning_loader.module except Exception as e: logger.error('Exception while creating class instance for Resource {} (type: {})\n{}', resource_key, resource_type, e, owner='manus') return
def init(pathroot, localwork, from_archive, deploy_override=None, app_directory=None, debug_available=False, local_work_enabled=False, automation_mode=False): global IS_ARCHIVE, APP_ROOT, DEBUG_AVAILABLE, AUTOMATION_MODE, DATA_ROOT, TUNING_ROOTS, SCRIPT_ROOT, _CORE, USER_SCRIPT_ROOTS, LAYERS, USE_CACHED_CONSTRAINTS IS_ARCHIVE = from_archive APP_ROOT = app_directory if debug_available: try: import pydevd import debugger DEBUG_AVAILABLE = True except ImportError: pass AUTOMATION_MODE = automation_mode pathroot = os.path.abspath(os.path.normpath(pathroot + os.path.sep)) DATA_ROOT = os.path.join(pathroot, 'Data') TUNING_ROOTS = {} for definition in sims4.resources.INSTANCE_TUNING_DEFINITIONS: TUNING_ROOTS[definition.resource_type] = os.path.join( DATA_ROOT, definition.TypeNames) if not from_archive: SCRIPT_ROOT = os.path.join(pathroot, 'Scripts') core_path = os.path.join(pathroot, 'Scripts', 'Core') lib_path = os.path.join(pathroot, 'Scripts', 'lib') debug_path = os.path.join(pathroot, 'Scripts', 'Debug') tests_path = os.path.join(pathroot, 'Scripts', 'Tests') build_path = os.path.join(pathroot, 'Scripts', 'Build') native_tuning_path = os.path.join(pathroot, 'Scripts', 'NativeTuning') else: SCRIPT_ROOT = None core_path = os.path.join(pathroot, 'Gameplay', 'core.zip') lib_path = os.path.join(pathroot, 'Gameplay', 'lib.zip') debug_path = os.path.join(pathroot, 'Gameplay', 'debug.zip') tests_path = os.path.join(pathroot, 'Gameplay', 'tests.zip') build_path = os.path.join(pathroot, 'Gameplay', 'build.zip') native_tuning_path = os.path.join(pathroot, 'Gameplay', 'nativetuning.zip') _CORE = core_path google_path = os.path.join(core_path, 'google') dll_path = os.path.join(app_directory, 'Python', 'DLLs') generated_path = os.path.join(app_directory, 'Python', 'Generated') deployed_path = deploy_override if deploy_override else os.path.join( app_directory, 'Python', 'Deployed') USER_SCRIPT_ROOTS = [core_path] LAYERS = [ dll_path, lib_path, google_path, os.path.join(core_path, 'api_config.py'), generated_path, deployed_path, debug_path, core_path ] __app_paths__.configure_app_paths(pathroot, from_archive, USER_SCRIPT_ROOTS, LAYERS) LAYERS += [tests_path, build_path, native_tuning_path] from sims4.tuning.merged_tuning_manager import create_manager, get_manager create_manager() mtg = get_manager() mtg.load() CONSTRAINT_DEPENDENCIES = { sims4.resources.Types.STATEMACHINE, sims4.resources.Types.TUNING, sims4.resources.Types.POSTURE, sims4.resources.Types.SLOT, sims4.resources.Types.SLOT_TYPE, sims4.resources.Types.SUBROOT, sims4.resources.Types.SLOT_TYPE_SET, sims4.resources.Types.INTERACTION, sims4.resources.Types.OBJECT, sims4.resources.Types.ANIMATION, sims4.resources.Types.OBJECT_PART, sims4.resources.Types.CLIP, sims4.resources.Types.CLIP_HEADER, sims4.resources.Types.OBJDEF } if local_work_enabled: local_resource_tuple = sims4.resources.list_local(key=None) local_work_key_list = local_resource_tuple[0] if any(key.type in CONSTRAINT_DEPENDENCIES for key in local_work_key_list): USE_CACHED_CONSTRAINTS = False
def clear_merged_tuning_manager(_connection=None): output = sims4.commands.Output(_connection) from sims4.tuning.merged_tuning_manager import get_manager get_manager().clear() output('Merged tuning manager cleared. WARNING: Tuning reload may break.')
def start(self): finalize_deferred_loads() if not paths.SUPPORT_RELOADING_RESOURCES: merged_tuning_manager = get_manager() merged_tuning_manager.clear()
def init(pathroot, localwork, from_archive, deploy_override=None, app_directory=None, debug_available=False, local_work_enabled=False, automation_mode=False): global IS_ARCHIVE, APP_ROOT, DEBUG_AVAILABLE, AUTOMATION_MODE, DATA_ROOT, TUNING_ROOTS, SCRIPT_ROOT, _CORE, USER_SCRIPT_ROOTS, LAYERS, USE_CACHED_CONSTRAINTS IS_ARCHIVE = from_archive APP_ROOT = app_directory if debug_available: try: import pydevd import debugger DEBUG_AVAILABLE = True except ImportError: pass AUTOMATION_MODE = automation_mode pathroot = os.path.abspath(os.path.normpath(pathroot + os.path.sep)) DATA_ROOT = os.path.join(pathroot, 'Data') TUNING_ROOTS = {} for definition in sims4.resources.INSTANCE_TUNING_DEFINITIONS: TUNING_ROOTS[definition.resource_type] = os.path.join( DATA_ROOT, definition.TypeNames) if not from_archive: SCRIPT_ROOT = os.path.join(pathroot, 'Scripts') core_path = os.path.join(pathroot, 'Scripts', 'Core') lib_path = os.path.join(pathroot, 'Scripts', 'lib') debug_path = os.path.join(pathroot, 'Scripts', 'Debug') tests_path = os.path.join(pathroot, 'Scripts', 'Tests') build_path = os.path.join(pathroot, 'Scripts', 'Build') native_tuning_path = os.path.join(pathroot, 'Scripts', 'NativeTuning') else: SCRIPT_ROOT = None core_path = os.path.join(pathroot, 'Gameplay', 'core.zip') lib_path = os.path.join(pathroot, 'Gameplay', 'lib.zip') debug_path = os.path.join(pathroot, 'Gameplay', 'debug.zip') tests_path = os.path.join(pathroot, 'Gameplay', 'tests.zip') build_path = os.path.join(pathroot, 'Gameplay', 'build.zip') native_tuning_path = os.path.join(pathroot, 'Gameplay', 'nativetuning.zip') _CORE = core_path google_path = os.path.join(core_path, 'google') dll_path = os.path.join(app_directory, 'Python', 'DLLs') generated_path = os.path.join(app_directory, 'Python', 'Generated') deployed_path = deploy_override if deploy_override else os.path.join( app_directory, 'Python', 'Deployed') USER_SCRIPT_ROOTS = [core_path] LAYERS = [dll_path, lib_path, google_path, os.path.join(core_path, 'api_config.py'), generated_path, deployed_path, debug_path, core_path] __app_paths__.configure_app_paths(pathroot, from_archive, USER_SCRIPT_ROOTS, LAYERS) LAYERS += [tests_path, build_path, native_tuning_path] from sims4.tuning.merged_tuning_manager import create_manager, get_manager create_manager() mtg = get_manager() mtg.load() CONSTRAINT_DEPENDENCIES = { sims4.resources.Types.STATEMACHINE, sims4.resources.Types.TUNING, sims4.resources.Types.POSTURE, sims4.resources.Types.SLOT, sims4.resources.Types.SLOT_TYPE, sims4.resources.Types.SUBROOT, sims4.resources.Types.SLOT_TYPE_SET, sims4.resources.Types.INTERACTION, sims4.resources.Types.OBJECT, sims4.resources.Types.ANIMATION, sims4.resources.Types.OBJECT_PART, sims4.resources.Types.CLIP, sims4.resources.Types.CLIP_HEADER, sims4.resources.Types.OBJDEF } if local_work_enabled: local_resource_tuple = sims4.resources.list_local(key=None) local_work_key_list = local_resource_tuple[0] if any(key.type in CONSTRAINT_DEPENDENCIES for key in local_work_key_list): USE_CACHED_CONSTRAINTS = False
def start(self): self.finalize_deferred_loads() if not sims4.core_services.SUPPORT_RELOADING_RESOURCES: merged_tuning_manager = get_manager() merged_tuning_manager.clear()
def init(pathroot, localwork, from_archive, deploy_override=None, app_directory=None, debug_available=False, local_work_enabled=False, automation_mode=False, dump_root=None): global IS_ARCHIVE, APP_ROOT, DEBUG_AVAILABLE, AUTOMATION_MODE, DATA_ROOT, TUNING_ROOTS, SCRIPT_ROOT, _CORE, USER_SCRIPT_ROOTS, LAYERS, DUMP_ROOT parser = argparse.ArgumentParser() parser.add_argument('--enable_tuning_reload', default=False, action='store_true', help='Enable the tuning reload hooks') (args, unused_args) = parser.parse_known_args() IS_ARCHIVE = from_archive APP_ROOT = app_directory if debug_available: try: import pydevd import debugger DEBUG_AVAILABLE = True except ImportError: pass AUTOMATION_MODE = automation_mode pathroot = os.path.abspath(os.path.normpath(pathroot + os.path.sep)) DATA_ROOT = os.path.join(pathroot, 'Data') TUNING_ROOTS = {} for definition in sims4.resources.INSTANCE_TUNING_DEFINITIONS: TUNING_ROOTS[definition.resource_type] = os.path.join( DATA_ROOT, definition.TypeNames) if not from_archive: SCRIPT_ROOT = os.path.join(pathroot, 'Scripts') core_path = os.path.join(pathroot, 'Scripts', 'Core') lib_path = os.path.join(pathroot, 'Scripts', 'lib') debug_path = os.path.join(pathroot, 'Scripts', 'Debug') tests_path = os.path.join(pathroot, 'Scripts', 'Tests') build_path = os.path.join(pathroot, 'Scripts', 'Build') native_tuning_path = os.path.join(pathroot, 'Scripts', 'NativeTuning') else: SCRIPT_ROOT = None core_path = os.path.join(pathroot, 'Gameplay', 'core.zip') lib_path = os.path.join(pathroot, 'Gameplay', 'lib.zip') debug_path = os.path.join(pathroot, 'Gameplay', 'debug.zip') tests_path = os.path.join(pathroot, 'Gameplay', 'tests.zip') build_path = os.path.join(pathroot, 'Gameplay', 'build.zip') native_tuning_path = os.path.join(pathroot, 'Gameplay', 'nativetuning.zip') _CORE = core_path google_path = os.path.join(core_path, 'google') dll_path = os.path.join(app_directory, 'Python', 'DLLs') generated_path = os.path.join(app_directory, 'Python', 'Generated') deployed_path = deploy_override if deploy_override else os.path.join( app_directory, 'Python', 'Deployed') USER_SCRIPT_ROOTS = [core_path] LAYERS = [ dll_path, lib_path, google_path, os.path.join(core_path, 'api_config.py'), generated_path, deployed_path, debug_path, core_path ] __app_paths__.configure_app_paths(pathroot, from_archive, USER_SCRIPT_ROOTS, LAYERS) LAYERS += [tests_path, build_path, native_tuning_path] if dump_root: DUMP_ROOT = dump_root else: DUMP_ROOT = '.' from sims4.tuning.merged_tuning_manager import create_manager, get_manager create_manager() mtg = get_manager() mtg.load()