Ejemplo n.º 1
0
 def set_shader_color_str(self, str):
     if type(str) == dict:  # dictionary of colors
         self.__parse_json_color_str(str)
     else:
         i = str.find(':')
         if i < 0:
             raise ValueError(self.SHADERCOLOR_ERROR.format(str))
         key = str[:i]
         value = str[i + 1:]
         isConstant = True if 'constant' in key else False
         if not key[-1].isdigit():
             raise ValueError(self.SHADERCOLOR_ERROR.format(str))
         index = int(key[-1])
         if not 0 <= index <= 3 or (not isConstant) and index == 3:
             raise ValueError(self.SHADERCOLOR_ERROR.format(str))
         intVals = parse_color(value)
         if not intVals:
             raise ValueError(self.SHADERCOLOR_ERROR.format(str))
         list = self.constant_colors if isConstant else self.colors
         list[index] = intVals
     self.mark_modified()
Ejemplo n.º 2
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))
Ejemplo n.º 3
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