kopia lustrzana https://github.com/torrinworx/Blend_My_NFTs
Fixing Logic.py if statements for THEN rule
rodzic
28b052ef16
commit
e905d126b6
|
@ -58,12 +58,7 @@ def apply_rules_to_dna(hierarchy, deconstructed_dna, if_dict, result_dict, resul
|
|||
if attribute in result_dict: # Check if Attribute from DNA is in 'result_dict'
|
||||
|
||||
# If 'a' is a full Attribute and Variants in if_dict not selected, set 'a' to empty (0):
|
||||
if list(result_dict[attribute].keys()) == list(hierarchy[attribute].keys()) and not if_list_selected:
|
||||
deconstructed_dna[attribute_index] = "0"
|
||||
|
||||
# If 'a' is a full Attribute and result_dict_type = "NOT", set 'a' to empty (0):
|
||||
if list(result_dict[attribute].keys()) == list(
|
||||
hierarchy[attribute].keys()) and if_list_selected and result_dict_type == "NOT":
|
||||
if list(result_dict[attribute].keys()) == list(hierarchy[attribute].keys()) and if_list_selected and result_dict_type == "NOT":
|
||||
deconstructed_dna[attribute_index] = "0"
|
||||
|
||||
# If Variants in if_dict are selected, set each attribute in 'result_dict' to a random or rarity selected Variant
|
||||
|
@ -84,7 +79,7 @@ def apply_rules_to_dna(hierarchy, deconstructed_dna, if_dict, result_dict, resul
|
|||
for i in var_selected_list:
|
||||
var_selected_list_complete[i] = get_var_info(i, hierarchy)
|
||||
result_dict[a] = var_selected_list_complete
|
||||
|
||||
else:
|
||||
for a in result_dict:
|
||||
attribute_index = list(hierarchy.keys()).index(a)
|
||||
attribute = list(hierarchy.keys())[attribute_index]
|
||||
|
@ -272,13 +267,9 @@ def logicafy_dna_single(hierarchy, single_dna, logic_file, enable_rarity):
|
|||
# Items from 'IF' key for a given rule
|
||||
if_dict = create_dicts(hierarchy, logic_file[rule]["IF"], "IF")
|
||||
|
||||
result_dict_type = ""
|
||||
# TODO: This needs to be made more efficient with less repeating code, but it works I guess:
|
||||
if "THEN" in logic_file[rule]:
|
||||
result_dict_type = "THEN"
|
||||
|
||||
if "NOT" in logic_file[rule]:
|
||||
result_dict_type = "NOT"
|
||||
|
||||
result_dict = create_dicts(hierarchy, logic_file[rule][result_dict_type], result_dict_type)
|
||||
|
||||
# Change 'then_bool' to 'result_bool'
|
||||
|
@ -289,6 +280,58 @@ def logicafy_dna_single(hierarchy, single_dna, logic_file, enable_rarity):
|
|||
result_dict,
|
||||
result_dict_type,
|
||||
)
|
||||
|
||||
# Check THEN rule again but swap IF and THEN dicts.
|
||||
if not violates_rule:
|
||||
violates_rule, if_bool, then_bool, full_att_bool = get_rule_break_type(
|
||||
hierarchy,
|
||||
deconstructed_dna,
|
||||
result_dict,
|
||||
if_dict,
|
||||
result_dict_type,
|
||||
)
|
||||
|
||||
if violates_rule:
|
||||
log.debug(f"======={deconstructed_dna} VIOLATES RULE======")
|
||||
|
||||
deconstructed_dna = apply_rules_to_dna(
|
||||
hierarchy,
|
||||
deconstructed_dna,
|
||||
if_dict,
|
||||
result_dict,
|
||||
result_dict_type,
|
||||
enable_rarity
|
||||
)
|
||||
|
||||
new_dna = reconstruct_dna(deconstructed_dna)
|
||||
if new_dna != original_dna:
|
||||
original_dna = str(new_dna)
|
||||
did_reconstruct = True
|
||||
break
|
||||
|
||||
if "NOT" in logic_file[rule]:
|
||||
result_dict_type = "NOT"
|
||||
result_dict = create_dicts(hierarchy, logic_file[rule][result_dict_type], result_dict_type)
|
||||
|
||||
# Change 'then_bool' to 'result_bool'
|
||||
violates_rule, if_bool, then_bool, full_att_bool = get_rule_break_type(
|
||||
hierarchy,
|
||||
deconstructed_dna,
|
||||
if_dict,
|
||||
result_dict,
|
||||
result_dict_type,
|
||||
)
|
||||
|
||||
# Check NOT rule again but swap IF and NOT dicts.
|
||||
if not violates_rule:
|
||||
violates_rule, if_bool, then_bool, full_att_bool = get_rule_break_type(
|
||||
hierarchy,
|
||||
deconstructed_dna,
|
||||
result_dict,
|
||||
if_dict,
|
||||
result_dict_type,
|
||||
)
|
||||
|
||||
if violates_rule:
|
||||
log.debug(f"======={deconstructed_dna} VIOLATES RULE======")
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue