def set_str(self, key, value): if key == 'framecount': i = validInt(value, 1, 0x7FFFFFFF) if i != self.framecount: self.framecount = i for x in self.tex_animations: x.set_frame_count(i) self.mark_modified() elif key == 'loop': loop = validBool(value) if self.loop != loop: self.loop = loop self.mark_modified() elif key == 'layerenable': if value.startswith('[') or value.startswith('('): # list/iterable items = parseValStr(value) for i in range(len(items)): val = validBool(items[i]) if val: self.tex_enable(i) else: self.tex_disable(i) else: key, value = splitKeyVal(value) key = validInt(key, 0, 8) value = validBool(value) if value != self.tex_is_enabled(key): self.tex_enable(key) if value else self.tex_disable(key) self.mark_modified()
def set_indirect_matrix_str(self, str_value): if type(str_value) == dict: self.__parse_json_ind_matrix(str_value) else: matrix_index = 0 colon_index = str_value.find(':') if colon_index > -1: matrix_index = validInt(str_value[0], 0, 3) str_value = str_value[colon_index + 1:] if ',' not in str_value: try: enable = validBool(str_value) self.set_ind_matrix_enable(matrix_index, enable) return except ValueError as e: raise ValueError(self.MATRIX_ERR.format(str_value)) str_values = str_value.replace('scale', '').split(',') if len(str_values) != 7: raise ValueError(self.MATRIX_ERR.format(str_value)) scale = validInt(str_values.pop(0).strip(':'), -17, 47) matrix = [validFloat(x.strip('()'), -1, 1) for x in str_values] ind_matrix = self.indirect_matrices[matrix_index] ind_matrix.matrix = matrix ind_matrix.scale = scale ind_matrix.enabled = True self.mark_modified()
def set_str(self, key, value): if key == 'dimensions': width, height = parseValStr(value) width = validInt(width, 1, self.MAX_IMG_SIZE + 1) height = validInt(height, 1, self.MAX_IMG_SIZE + 1) self.set_dimensions(width, height) elif key == 'format': return self.set_format(value) elif key == 'mipmapcount': return self.set_mipmap_count(validInt(value, 0, 20)) elif key == 'name': return self.parent.rename_texture(value)
def set_draw_priority_str(self, str): if str[0].isdigit(): i = validInt(str, 0, 255) for x in self.polygons: x.set_draw_priority(i) else: priorities = str.strip('()[]').split(',') for i in range(len(priorities)): if i >= len(self.polygons): break self.polygons[i].set_draw_priority( validInt(priorities[i].strip(), 0))
def set_anim_str(animation, key, value): if key == 'framecount': # framecount val = validInt(value, 1) animation.framecount = val elif key == 'loop': # loop val = validBool(value) animation.loop = val
def add(self, type, type_id): """Add command""" if self.SELECT_ID_NUMERIC and type_id == 0: type_id = 1 if type == 'material': if self.type == 'srt0': for x in self.SELECTED: x.add_srt0() elif self.type == 'pat0': for x in self.SELECTED: x.add_pat0() else: # layers if self.SELECT_ID_NUMERIC: for x in self.SELECTED: for i in range(type_id): x.addEmptyLayer() else: for x in self.SELECTED: x.addLayer(type_id) elif type == 'shader': # add stage case for x in self.SELECTED: for i in range(type_id): x.addStage() elif type == 'srt0': # add srt0 layer if self.SELECT_ID_NUMERIC: for x in self.SELECTED: for i in range(type_id): x.addLayer() else: for x in self.SELECTED: x.addLayerByName(type_id) elif type == 'brres': if self.type == 'tex0': resize = convert_fmt = None num_mips = -1 try: key = self.key if key == 'format': convert_fmt = self.value elif key == 'mipmapcount': num_mips = validInt(self.value, -1, 20) else: resize = self.value except AttributeError: pass files = self.getFiles(type_id) for file in files: tex = self.import_texture(file, None, convert_fmt, num_mips) if tex: if resize: tex.set_str(self.key, self.value) for x in self.SELECTED: x.add_tex0(tex) elif self.type == 'mdl0': self.import_model(type_id) else: raise ParsingException(self.txt, 'command "Add" not supported for type {}'.format(type))
def set_str(self, key, value): if key == 'framecount': i = validInt(value, 1, 0x7FFFFFFF) if i != self.framecount: self.framecount = i for x in self.tex_animations: x.setFrameCount(i) self.mark_modified() elif key == 'loop': loop = validBool(value) if self.loop != loop: self.loop = loop self.mark_modified() elif key == 'layerenable': key, value = splitKeyVal(value) key = validInt(key, 0, 8) value = validBool(value) if value != self.texIsEnabled(key): self.texEnable(key) if value else self.texDisable(key) self.mark_modified()
def setType(self, val): """Returns true if the type is set by val (consumed)""" if self.cmd == 'preset': self.type = 'material' return False elif self.cmd in ('select', 'save'): return False i = val.find(':') type_id = None if i >= 0: type_id = val[i + 1:] val = val[:i] val = val.lower() if val in ('material', 'shader'): if self.cmd == 'add' or self.cmd == 'remove': raise ParsingException(self.txt, 'Add/Remove not supported for {}.'.format(val)) elif val in ('layer', 'srt0layer', 'stage', 'mdl0', 'tex0'): self.has_type_id = True try: self.type_id = validInt(type_id, 0, 16) if type_id else None self.type_id_numeric = True except ValueError: self.type_id = type_id self.type_id_numeric = False # elif 'srt0' in val: # self.type = 'srt0' elif val == 'brres': if self.cmd == 'add' or self.cmd == 'remove': raise ParsingException(self.txt, 'Add/Remove not supported for {}.'.format(val)) if type_id: self.has_type_id = True self.type_id_numeric = False self.type_id = type_id else: self.type_id = '*' elif val in ('srt0', 'pat0'): pass else: self.type = None return False self.type = val return True
def set_str(self, key, value): if key == 'loop': loop = validBool(value) if loop != self.loop: self.loop = loop self.mark_modified() elif key == 'framecount': framecount = validInt(value, 0, 0x7FFFFFFF) if framecount != self.framecount: self.framecount = framecount self.mark_modified() elif key == 'keyframe': frame_ids = [] names = [] # gather/validate ids and names keyframes = value.strip('()').split(',') max = self.framecount + .001 for x in keyframes: frame_id, tex_name = splitKeyVal(x) frame_ids.append(validFloat(frame_id, 0, max)) names.append(tex_name) for i in range(len(frame_ids)): self.set_frame(frame_ids[i], names[i]) self.mark_modified()
def set_str(self, key, value): s = self.SETTINGS if key == s[0]: self.set_enabled(validBool(value)) elif key == s[1]: self.set_map_id(validInt(value, 0, 7)) elif key == s[2]: self.set_coord_id(validInt(value, 0, 7)) elif key == s[3]: self.set_tex_swap_sel(validInt(value, 0, 4)) elif key == s[4]: if value == '0': self.set_raster_color(RASTER_ZERO) else: i = indexListItem(RASTER_COLORS, value) if i > 1: i += 3 self.set_raster_color(i) elif key == s[5]: self.set_raster_swap_sel(validInt(value, 0, 4)) elif key in s[6:8]: value = value.replace('constant', '') i = indexListItem(COLOR_CONSTANTS, value) if i > 7: i += 4 self.set_constant_color(i) elif key in s[8:12]: if value == '0': val = COLOR_SEL_NONE elif value == '1': val = COLOR_SEL_ONE elif value in ('0.5', '1/2'): val = COLOR_SEL_HALF else: val = indexListItem(COLOR_SELS, value) if key == s[8]: self.set_color_a(val) elif key == s[9]: self.set_color_b(val) elif key == s[10]: self.set_color_c(val) elif key == s[11]: self.set_color_d(val) elif key == s[12]: self.set_color_bias(indexListItem(BIAS, value)) elif key == s[13]: self.set_color_oper(indexListItem(OPER, value)) elif key == s[14]: self.set_color_clamp(validBool(value)) elif key in (s[15], s[26]): try: val = indexListItem(SCALE, value) except ValueError: f = validFloat(value, 0.5, 4) val = indexListItem(SCALEN, f) if key == s[15]: self.set_color_scale(val) elif key == s[26]: self.set_alpha_scale(val) elif key == s[16]: self.set_color_dest(indexListItem(COLOR_DEST, value)) elif key in s[17:19]: value = value.replace('constant', '') i = indexListItem(ALPHA_CONSTANTS, value) if i > 7: i += 8 self.set_constant_alpha(i) elif key in s[19:23]: if value == '0': val = ALPHA_SEL_NONE else: val = indexListItem(ALPHA_SELS, value) if key == s[19]: self.set_alpha_a(val) elif key == s[20]: self.set_alpha_b(val) elif key == s[21]: self.set_alpha_c(val) elif key == s[22]: self.set_alpha_d(val) elif key == s[23]: self.set_alpha_bias(indexListItem(BIAS, value)) elif key == s[24]: self.set_alpha_oper(indexListItem(OPER, value)) elif key == s[25]: self.set_alpha_clamp(validBool(value)) elif key == s[27]: self.set_alpha_dest(indexListItem(ALPHA_DEST, value)) elif key == s[28]: self.set_ind_stage(validInt(value, 0, 4)) elif key == s[29]: self.set_ind_format(indexListItem(TEX_FORMAT, value)) elif key == s[30]: self.set_ind_alpha(indexListItem(IND_ALPHA, value)) elif key == s[31]: self.set_ind_bias(indexListItem(IND_BIAS, value)) elif key == s[32]: if len(value) < 6: value = 'matrix' + value i = indexListItem(IND_MATRIX, value) if i > 3: i += 1 if i > 7: i += 1 self.set_ind_matrix(i) elif key == s[33]: self.set_s_wrap(indexListItem(WRAP, value)) elif key == s[34]: self.set_t_wrap(indexListItem(WRAP, value)) elif key == s[35]: self.set_ind_use_prev(validBool(value)) elif key == s[36]: self.set_ind_unmodified_lod(validBool(value))
def load_config(app_dir=None, loudness=None, autofix_level=None): if app_dir is None: app_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'etc', 'abmatt') conf = Config.get_instance(os.path.join(app_dir, 'config.conf')) tmp_dir = os.path.join(app_dir, 'temp_files') converter = ImgConverter(tmp_dir) Tex0.converter = converter if not loudness: loudness = conf['loudness'] if loudness: try: AutoFix.set_loudness(loudness) except ValueError: AutoFix.warn('Invalid loudness level {}'.format(loudness)) AutoFix.set_fix_level(autofix_level, turn_off_fixes) if not len(conf): AutoFix.warn('No configuration detected (etc/abmatt/config.conf).') return Command.set_max_brres_files(conf) # Matching stuff MATCHING.set_case_sensitive(conf['case_sensitive']) MATCHING.set_partial_matching(conf['partial_matching']) MATCHING.set_regex_enable(conf['regex_matching']) # Autofixes try: SubFile.FORCE_VERSION = validBool(conf['force_version']) except ValueError: pass try: Brres.REMOVE_UNUSED_TEXTURES = validBool( conf['remove_unused_textures']) except ValueError: pass try: Layer.MINFILTER_AUTO = validBool(conf['minfilter_auto']) except ValueError: pass set_rename_unknown(conf['rename_unknown_refs']) set_remove_unknown(conf['remove_unknown_refs']) set_remove_unused(conf['remove_unused_refs']) try: Mdl0.DETECT_MODEL_NAME = validBool(conf['detect_model_name']) except ValueError: pass try: Shader.MAP_ID_AUTO = validBool(conf['map_id_auto']) except ValueError: pass try: Material.DEFAULT_COLOR = parse_color(conf['default_material_color']) except ValueError: pass try: Tex0.RESIZE_TO_POW_TWO = validBool(conf['resize_pow_two']) except ValueError: pass try: Tex0.set_max_image_size(validInt(conf['max_image_size'], 0, 10000)) except (TypeError, ValueError): pass try: Geometry.ENABLE_VERTEX_COLORS = validBool(conf['enable_vertex_colors']) except ValueError: pass Converter.ENCODE_PRESET = conf['encode_preset'] resample = conf['img_resample'] if resample is not None: ImgConverterI.set_resample(resample) if conf['material_library']: MaterialLibrary.LIBRARY_PATH = conf.config.get('material_library') else: MaterialLibrary.LIBRARY_PATH = os.path.join(app_dir, 'mat_lib.brres') return conf
def set_layer_count_str(self, str_value): self.set_layer_count(validInt(str_value, 0, 8))