Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.1 kB
10
Indexable
Never
 @staticmethod
    def format_skill_values(skill_desc, params, skill_type):
        formatted_desc = skill_desc.replace("\\n", " ").replace("\n", " ")
        formatted_desc = formatted_desc.replace("</u>", "__").replace("<u>", "__")

        # Remove color tags and </unbreak> tags
        formatted_desc = re.sub(r"<color=.*?>|</color>|</unbreak>", "", formatted_desc)

        for i, param in enumerate(params):
            if isinstance(param, list):  # Check if param is a list
                for j, value in enumerate(param):
                    if isinstance(value, float):
                        if value.is_integer() and value % 1 == 0:
                            value_str = str(int(value * 100)) + "%"
                        else:
                            value_str = "{:.1f}%".format(value * 100)
                    elif isinstance(value, int):
                        value_str = str(value)
                    else:
                        continue

                    if skill_type == "Basic ATK" and (j == 0 or j == 5 or j == 6):
                        value_str += "/"

                    formatted_desc = formatted_desc.replace(f"<unbreak>#{j+1}[i]", value_str)

            else:
                if isinstance(param, float):
                    if param.is_integer() and param % 1 == 0:
                        value_str = str(int(param * 100)) + "%"
                    else:
                        value_str = "{:.1f}%".format(param * 100)
                elif isinstance(param, int):
                    value_str = str(param)
                else:
                    continue

                formatted_desc = formatted_desc.replace(f"<unbreak>#{i+1}[i]", value_str)

        # Replace remaining parameter placeholders
        formatted_desc = formatted_desc.replace("<unbreak>#", "").replace("[i]", "")

        # Replace double percent signs with a single percent sign
        formatted_desc = formatted_desc.replace("%%", "%")

        # Replace </u> with __ on both sides
        formatted_desc = formatted_desc.replace("</u>", "__").replace("<u>", "__")

        return formatted_desc