@@ -21,6 +21,8 @@ import com.lambda.Lambda.LOG
2121import com.lambda.config.Configurable
2222import com.lambda.config.configurations.FontConfig
2323import com.lambda.core.Loadable
24+ import com.lambda.event.events.ClientEvent
25+ import com.lambda.event.listener.SafeListener.Companion.listen
2426import com.lambda.util.FolderRegister
2527import java.util.concurrent.ConcurrentHashMap
2628import kotlin.io.path.notExists
@@ -49,17 +51,22 @@ object FontHandler : Loadable, Configurable(FontConfig) {
4951 getOrLoadFont(defaultFontInfo) ? : throw IllegalStateException (" Failed to load default font" )
5052 }
5153
52- private val selectedFont by setting(" Selected Font" , defaultFontInfo.path, description = " The local path (from the lambda folder) to the font file, including the .ttf file extension " )
54+ private val selectedFont by setting(" Selected Font" , defaultFontInfo.path, description = " The file name of the font you want to use. (The font must be placed in the fonts folder in the lambda directory) " )
5355 .onValueChangeUnsafe { _, to ->
54- activeFont = getFont (to) ? : defaultFont
56+ activeFont = getOrLoadFont (to) ? : defaultFont
5557 }
5658
5759 var activeFont = defaultFont
5860 private set
5961
6062 override fun load (): String {
6163 discoverFonts()
62- activeFont = getFont(selectedFont) ? : defaultFont
64+ activeFont = getOrLoadFont(selectedFont) ? : defaultFont
65+
66+ listen<ClientEvent .Shutdown > {
67+ cleanup()
68+ }
69+
6370 return " Loaded ${discoveredFonts.size} font definitions"
6471 }
6572
@@ -101,20 +108,10 @@ object FontHandler : Loadable, Configurable(FontConfig) {
101108 LOG .info(" [FontHandler] Discovered ${discoveredFonts.size} fonts" )
102109 }
103110
104- /* *
105- * Get all discoverable fonts (for settings UI)
106- */
107- fun getAvailableFonts (): List <FontInfo > = discoveredFonts.toList()
108-
109- /* *
110- * Get a specific font by its FontInfo (loads if not already loaded)
111- */
112- fun getFont (fontInfo : FontInfo ): SDFFontAtlas ? = getOrLoadFont(fontInfo)
113-
114111 /* *
115112 * Get a specific font by its path (loads if not already loaded)
116113 */
117- fun getFont (path : String , size : Float = 128f): SDFFontAtlas ? {
114+ fun getOrLoadFont (path : String , size : Float = 128f): SDFFontAtlas ? {
118115 val fontInfo = discoveredFonts.find { it.path.endsWith(path) && it.size == size }
119116 ? : FontInfo (path.substringAfterLast(" /" ), path = path, size = size)
120117 return getOrLoadFont(fontInfo)
@@ -137,24 +134,6 @@ object FontHandler : Loadable, Configurable(FontConfig) {
137134 }
138135 }
139136
140- /* *
141- * Set the active font to be used for rendering
142- */
143- fun setActiveFont (fontInfo : FontInfo ): Boolean {
144- val font = getFont(fontInfo)
145- if (font != null ) {
146- activeFont = font
147- return true
148- }
149- return false
150- }
151-
152- fun isFontLoaded (fontInfo : FontInfo ) = loadedAtlases.containsKey(fontInfo.key)
153-
154- fun isFontLoaded (path : String , size : Float = 128f) = loadedAtlases.containsKey(" $path @$size " )
155-
156- fun getLoadedFontKeys (): Set <String > = loadedAtlases.keys.toSet()
157-
158137 fun getStringWidthNormalized (text : String , normalizedSize : Float ) =
159138 activeFont.getStringWidthNormalized(text, normalizedSize)
160139
0 commit comments