Skip to content

Commit

Permalink
Reduce number of created attributes (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored Jan 18, 2025
1 parent c87f206 commit e83b98c
Showing 1 changed file with 17 additions and 41 deletions.
58 changes: 17 additions & 41 deletions src/data_classes/Element.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,23 @@ func get_attribute_value(attribute_name: String, real := false) -> String:
return ""
return get_default(attribute_name)


func get_attribute_true_color(attribute_name: String) -> String:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.COLOR:
push_error("Attribute not the correct type.")
var attrib_value := get_attribute_value(attribute_name)
if attrib_value == "currentColor":
return get_default("color")
return attrib_value

func get_attribute_num(attribute_name: String) -> float:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.NUMERIC:
push_error("Attribute not the correct type.")
var attrib: AttributeNumeric = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
var num: float = _attributes[attribute_name].get_num() if\
has_attribute(attribute_name) else\
AttributeNumeric.text_to_num(get_default(attribute_name))
# Possibly adjust for percentage.
var num := attrib.get_num()
if attrib.is_percentage():
if is_attribute_percentage(attribute_name):
var percentage_handling := get_percentage_handling(attribute_name)
if percentage_handling == DB.PercentageHandling.FRACTION:
return num
Expand All @@ -173,50 +182,17 @@ func get_attribute_num(attribute_name: String) -> float:
DB.PercentageHandling.NORMALIZED: return svg.normalized_diagonal * num
return num

func get_attribute_true_color(attribute_name: String) -> String:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.COLOR:
push_error("Attribute not the correct type.")
var attrib: AttributeColor = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
var attrib_value := attrib.get_value()
if attrib_value == "currentColor":
return get_default("color")
return attrib_value

func is_attribute_percentage(attribute_name: String) -> bool:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.NUMERIC:
push_error("Attribute not the correct type.")
var attrib: AttributeNumeric = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
return attrib.is_percentage()

func get_attribute_rect(attribute_name: String) -> float:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.LIST:
push_error("Attribute not the correct type.")
var attrib: AttributeList = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
return attrib.get_rect()
return _attributes[attribute_name].is_percentage() if has_attribute(attribute_name) else\
AttributeNumeric.text_check_percentage(get_default(attribute_name))

func get_attribute_list(attribute_name: String) -> PackedFloat64Array:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.LIST:
push_error("Attribute not the correct type.")
var attrib: AttributeList = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
return attrib.get_list()

func get_attribute_commands(attribute_name: String) -> Array[PathCommand]:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.PATHDATA:
push_error("Attribute not the correct type.")
var attrib: AttributePathdata = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
return attrib.get_commands()

func get_attribute_transforms(attribute_name: String) -> Array[Transform]:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.TRANSFORM_LIST:
push_error("Attribute not the correct type.")
var attrib: AttributeTransformList = _attributes[attribute_name] if\
has_attribute(attribute_name) else new_default_attribute(attribute_name)
return attrib.get_transform_list()
return _attributes[attribute_name].get_list() if has_attribute(attribute_name) else\
AttributeList.text_to_list(get_default(attribute_name))

func get_attribute_final_precise_transform(attribute_name: String) -> PackedFloat64Array:
if DB.get_attribute_type(attribute_name) != DB.AttributeType.TRANSFORM_LIST:
Expand Down

0 comments on commit e83b98c

Please sign in to comment.