Example #1
0
 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()
Example #2
0
 def __setitem__(self, key, value):
     if 'material' in key:
         i = indexListItem(self.LIGHT_SOURCE, value, self.materialSourceVertex)
         if i >= 0:
             self.materialSourceVertex = i
     elif 'enable' in key:
         val = validBool(value)
         self.enabled = val
     elif 'ambient' in key:
         i = indexListItem(self.LIGHT_SOURCE, value, self.ambientSourceVertex)
         if i >= 0:
             self.ambientSourceVertex = i
     elif 'diffuse' in key:
         i = indexListItem(self.DIFFUSE_FUNCTION, value, self.diffuseFunction)
         if i >= 0:
             self.diffuseFunction = i
     elif 'attenuation' in key:
         try:
             i = indexListItem(self.ATTENUATION, value, self.attenuationFunction)
             if i >= 0:
                 self.attenuationFunction = i
             if not self.attenuationEnabled:
                 self.attenuationEnabled = True
         except ValueError:
             val = validBool(value)
             self.attenuationEnabled = val
     else:
         raise ValueError(LightChannel.LC_ERROR.format(key))
Example #3
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
Example #4
0
 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()
Example #5
0
 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()
Example #6
0
 def __setitem__(self, key, value):
     is_color = True if "color" in key else False
     if "control" in key:
         key2, value = splitKeyVal(value)
         if not key2:
             raise ValueError(self.LC_ERROR.format(key))
         if is_color:
             self.colorLightControl[key2] = value
         else:
             self.alphaLightControl[key2] = value
     elif 'enable' in key:
         val = validBool(value)
         if "material" in key:
             if is_color:
                 self.materialColorEnabled = val
             else:
                 self.materialAlphaEnabled = val
         elif "ambient" in key:
             if is_color:
                 self.ambientColorEnabled = val
             else:
                 self.ambientAlphaEnabled = val
         elif "raster" in key:
             if is_color:
                 self.rasterColorEnabled = val
             else:
                 self.rasterAlphaEnabled = val
     else:
         int_vals = parse_color(value)
         if not int_vals:
             raise ValueError(self.LC_ERROR.format(key))
         if "material" in key:
             self.materialColor = int_vals
         elif "ambient" in key:
             self.ambientColor = int_vals
         else:
             raise ValueError(self.LC_ERROR.format(key))
Example #7
0
 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()
Example #8
0
def set_remove_unused(val):
    try:
        Shader.REMOVE_UNUSED_LAYERS = Stage.REMOVE_UNUSED_LAYERS = Mdl0.REMOVE_UNUSED_REFS = validBool(
            val)
    except ValueError:
        pass
Example #9
0
 def set_blend_str(self, str):
     val = validBool(str)
     if val != self.blend_enabled:
         self.blend_enabled = val
         self.mark_modified()
Example #10
0
 def set_enable_blend_logic_str(self, s):
     self.enable_blend_logic(validBool(s))
Example #11
0
 def setNormalizeStr(self, value):
     val = validBool(value)
     if val != self.normalize:
         self.normalize = val
         self.mark_modified()
Example #12
0
 def setTexelInterpolateStr(self, value):
     val = validBool(value)
     if val != self.texel_interpolate:
         self.texel_interpolate = val
         self.mark_modified()
Example #13
0
 def setClampBiasStr(self, value):
     val = validBool(value)
     if val != self.clamp_bias:
         self.clamp_bias = val
         self.mark_modified()
Example #14
0
 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))
Example #15
0
 def set_enable_depth_test_str(self, str):
     self.set_enable_depth_test(validBool(str))
Example #16
0
 def set_compare_before_tex_str(self, str):
     self.set_compare_before_tex(validBool(str))
Example #17
0
def set_remove_unknown(val):
    try:
        Mdl0.REMOVE_UNKNOWN_REFS = Layer.REMOVE_UNKNOWN_REFS = Pat0.REMOVE_UNKNOWN_REFS = Srt0.REMOVE_UNKNOWN_REFS = \
            validBool(val)
    except ValueError:
        pass
Example #18
0
def set_rename_unknown(val):
    try:
        Mdl0.RENAME_UNKNOWN_REFS = Layer.RENAME_UNKNOWN_REFS = Pat0.RENAME_UNKNOWN_REFS = validBool(
            val)
    except ValueError:
        pass
Example #19
0
 def set_enable_depth_update_str(self, str):
     self.set_enable_depth_update(validBool(str))
Example #20
0
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
Example #21
0
 def set_xlu_str(self, str_value):
     val = validBool(str_value)
     if self.xlu != val:
         self.xlu = val
         self.set_draw_xlu(val)
         self.mark_modified()