def p_tracktypetable_item(self, t): """tracktypetable_item : ID | STRING_LITERAL | ID COLON LBRACKET expression_list RBRACKET""" if len(t) == 2: t[0] = t[1] else: t[0] = assignment.Assignment(t[1], t[4], t[1].pos)
def expand(self, default_file, default_mask_file, poslist, id_dict): # create new struct, needed for template expansion new_mapping = [] for old_assignment in self.mapping: from_min_value = old_assignment.name.min.reduce_constant([id_dict]) from_max_value = from_min_value if old_assignment.name.max is None else old_assignment.name.max.reduce_constant( [id_dict]) to_min_value = old_assignment.value.min.reduce_constant([id_dict]) to_max_value = None if old_assignment.value.max is None else old_assignment.value.max.reduce_constant( [id_dict]) new_mapping.append( assignment.Assignment( assignment.Range(from_min_value, from_max_value), assignment.Range(to_min_value, to_max_value), old_assignment.pos)) return [RecolourSprite(new_mapping, poslist=poslist)]
def pre_process(self): new_costs = [] for cost in self.costs: cost.value = cost.value.reduce(global_constants.const_list) if isinstance(cost.value, expression.ConstantNumeric): generic.check_range(cost.value.value, -8, 16, 'Base cost value', cost.value.pos) cost.value = expression.BinOp(nmlop.ADD, cost.value, expression.ConstantNumeric(8), cost.value.pos).reduce() if isinstance(cost.name, expression.Identifier): if cost.name.value in base_cost_table: cost.name = expression.ConstantNumeric( base_cost_table[cost.name.value][0]) new_costs.append(cost) elif cost.name.value in generic_base_costs: #create temporary list, so it can be sorted for efficiency tmp_list = [] for num, type in list(base_cost_table.values()): if type == cost.name.value: tmp_list.append( assignment.Assignment( expression.ConstantNumeric(num), cost.value, cost.name.pos)) tmp_list.sort(key=lambda x: x.name.value) new_costs.extend(tmp_list) else: raise generic.ScriptError( "Unrecognized base cost identifier '{}' encountered". format(cost.name.value), cost.name.pos) else: cost.name = cost.name.reduce() if isinstance(cost.name, expression.ConstantNumeric): generic.check_range(cost.name.value, 0, len(base_cost_table), 'Base cost number', cost.name.pos) new_costs.append(cost) self.costs = new_costs
def p_recolour_assignment_3(self, t): "recolour_assignment : expression RANGE expression COLON expression SEMICOLON" t[0] = assignment.Assignment(assignment.Range(t[1], t[3]), assignment.Range(t[5], None), t[1].pos)
def p_generic_assignment(self, t): "generic_assignment : expression COLON expression SEMICOLON" t[0] = assignment.Assignment(t[1], t[3], t.lineno(1))
def p_name_string_item(self, t): "name_string_item : expression COLON string SEMICOLON" t[0] = assignment.Assignment(t[1], t[3], t[1].pos)
def p_names_setting_value(self, t): "setting_value : ID COLON LBRACE name_string_list RBRACE SEMICOLON" t[0] = assignment.Assignment(t[1], t[4], t[1].pos)
def p_assignment(self, t): "assignment : ID COLON expression SEMICOLON" t[0] = assignment.Assignment(t[1], t[3], t[1].pos)
def p_recolour_assignment_2(self, t): 'recolour_assignment : expression RANGE expression COLON expression RANGE expression SEMICOLON' t[0] = assignment.Assignment(assignment.Range(t[1], t[3]), assignment.Range(t[5], t[7]), t[1].pos)
def p_recolour_assignment_1(self, t): 'recolour_assignment : expression COLON expression SEMICOLON' t[0] = assignment.Assignment(assignment.Range(t[1], None), assignment.Range(t[3], None), t[1].pos)