diff --git a/build.gradle.kts b/build.gradle.kts index 2c5d7d7..99cf039 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ plugins { } group = "dev.dediamondpro" -version = "1.2.0" +version = "1.2.1" repositories { mavenCentral() diff --git a/minecraft/gradle.properties b/minecraft/gradle.properties index a53d054..129b7f7 100644 --- a/minecraft/gradle.properties +++ b/minecraft/gradle.properties @@ -1,6 +1,6 @@ # Mod Configuration mod_name=MineMark mod_id=minemark -mod_version=1.2.0 +mod_version=1.2.1 mod_description=Markdown rendering library mod_license=LGPL \ No newline at end of file diff --git a/src/main/java/dev/dediamondpro/minemark/LayoutStyle.java b/src/main/java/dev/dediamondpro/minemark/LayoutStyle.java index 4c9d96f..d49bf4d 100644 --- a/src/main/java/dev/dediamondpro/minemark/LayoutStyle.java +++ b/src/main/java/dev/dediamondpro/minemark/LayoutStyle.java @@ -18,8 +18,10 @@ package dev.dediamondpro.minemark; import dev.dediamondpro.minemark.style.Style; +import dev.dediamondpro.minemark.utils.StyleType; import java.awt.*; +import java.util.HashMap; /** * Class that will be given to an element at parsing time @@ -36,8 +38,9 @@ public class LayoutStyle { private boolean partOfLink; private boolean partOfCodeBlock; private boolean preFormatted; + private final HashMap, Object> customStyles; - public LayoutStyle(Alignment alignment, float fontSize, Color textColor, boolean bold, boolean italic, boolean underlined, boolean strikethrough, boolean partOfLink, boolean partOfCodeBlock, boolean preFormatted) { + public LayoutStyle(Alignment alignment, float fontSize, Color textColor, boolean bold, boolean italic, boolean underlined, boolean strikethrough, boolean partOfLink, boolean partOfCodeBlock, boolean preFormatted, HashMap, Object> customStyles) { this.alignment = alignment; this.fontSize = fontSize; this.textColor = textColor; @@ -48,14 +51,15 @@ public LayoutStyle(Alignment alignment, float fontSize, Color textColor, boolean this.preFormatted = preFormatted; this.partOfCodeBlock = partOfCodeBlock; this.strikethrough = strikethrough; + this.customStyles = customStyles; } public LayoutStyle(Style style) { - this(Alignment.LEFT, style.getTextStyle().getDefaultFontSize(), style.getTextStyle().getDefaultTextColor(), false, false, false, false, false, false, false); + this(Alignment.LEFT, style.getTextStyle().getDefaultFontSize(), style.getTextStyle().getDefaultTextColor(), false, false, false, false, false, false, false, new HashMap<>()); } public LayoutStyle clone() { - return new LayoutStyle(alignment, fontSize, new Color(textColor.getRGB()), bold, italic, underlined, strikethrough, partOfLink, partOfCodeBlock, preFormatted); + return new LayoutStyle(alignment, fontSize, new Color(textColor.getRGB()), bold, italic, underlined, strikethrough, partOfLink, partOfCodeBlock, preFormatted, (HashMap, Object>) customStyles.clone()); } public Alignment getAlignment() { @@ -138,6 +142,22 @@ public void setPartOfCodeBlock(boolean partOfCodeBlock) { this.partOfCodeBlock = partOfCodeBlock; } + public void put(StyleType styleType, T value) { + customStyles.put(styleType, value); + } + + public boolean has(StyleType styleType) { + return customStyles.containsKey(styleType); + } + + public T get(StyleType styleType) { + return styleType.getStyleClass().cast(customStyles.get(styleType)); + } + + public T getOrDefault(StyleType styleType, T defaultValue) { + return styleType.getStyleClass().cast(customStyles.getOrDefault(styleType, defaultValue)); + } + public enum Alignment { CENTER, LEFT, RIGHT } diff --git a/src/main/java/dev/dediamondpro/minemark/utils/StyleType.java b/src/main/java/dev/dediamondpro/minemark/utils/StyleType.java new file mode 100644 index 0000000..c332eee --- /dev/null +++ b/src/main/java/dev/dediamondpro/minemark/utils/StyleType.java @@ -0,0 +1,40 @@ +/* + * This file is part of MineMark + * Copyright (C) 2024 DeDiamondPro + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License Version 3 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package dev.dediamondpro.minemark.utils; + +public class StyleType { + private final String id; + private final Class styleClass; + + public StyleType(String id, Class styleClass) { + this.id = id; + this.styleClass = styleClass; + } + + public String getId() { + return id; + } + + public Class getStyleClass() { + return styleClass; + } + + public static StyleType of(String id, Class styleClass) { + return new StyleType(id, styleClass); + } +}