def __setitem__(self, key, value): key = validFloat(key, 0, self.framecount + .0001) if value in ('disabled', 'none', 'remove'): self.removeKeyFrame(key) else: delta = None if ':' in value: value, delta = splitKeyVal(value) delta = validFloat(value, -0x7FFFFFFF, 0x7FFFFFFF) value = validFloat(value, -0x7FFFFFFF, 0x7FFFFFFF) self.setKeyFrame(value, key, delta)
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 == '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 __getitem__(self, key): key = validFloat(key, 0, self.framecount + .0001) return self.getFrame(key)
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))