Skip to content

Commit 320f672

Browse files
committed
fix: better font loading
No longer requires a restart after enabling the mod for the first time. Also avoids scenarios where the font could be referenced before being loaded, which could cause crashes with other font mods.
1 parent 565c3dc commit 320f672

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

modinfo.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Item Meta"
22
description = "Displays extra metadata in item tooltips."
33
author = "gimmeh"
4-
version = "0.1.1"
4+
version = "0.2.0"
55
forumthread = ""
66
api_version = 10
77
api_version_dst = 10

modmain.lua

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ for _, modName in pairs(GLOBAL.KnownModIndex:GetModsToLoad()) do if CHECK_MODS[m
77

88
-- IMPORTS
99
local pcall = GLOBAL.pcall
10-
local modRoot = env.MODROOT
1110
local require = GLOBAL.require
11+
local TheSim = GLOBAL.TheSim
12+
local resolvefilepath = GLOBAL.resolvefilepath
13+
local LoadFonts = GLOBAL.LoadFonts
1214
local DEFAULT_FALLBACK_TABLE = GLOBAL.DEFAULT_FALLBACK_TABLE
1315
local DEFAULT_FALLBACK_TABLE_OUTLINE = GLOBAL.DEFAULT_FALLBACK_TABLE_OUTLINE
1416
local FONTS = GLOBAL.FONTS
@@ -18,10 +20,26 @@ local Inv = require("widgets/inventorybar")
1820
local HoverText = require("widgets/hoverer")
1921

2022
-- ASSETS
21-
local ICONS_FONT = "itemmeta_icons"
22-
table.insert(DEFAULT_FALLBACK_TABLE, 1, ICONS_FONT)
23-
table.insert(DEFAULT_FALLBACK_TABLE_OUTLINE, 1, ICONS_FONT)
24-
table.insert(FONTS, { filename = modRoot .. "fonts/icons.zip", alias = ICONS_FONT, disable_color = true })
23+
local ICONS_FONT_ALIAS = "itemmeta_icons"
24+
local ICONS_FONT_PATH = resolvefilepath("fonts/icons.zip")
25+
26+
-- Declare the font asset in the mod asset table
27+
Assets = {
28+
Asset("FONT", ICONS_FONT_PATH),
29+
}
30+
31+
-- Load the icons font
32+
AddSimPostInit(function()
33+
-- Add icons to the list of fonts to load
34+
table.insert(FONTS, { filename = ICONS_FONT_PATH, alias = ICONS_FONT_ALIAS, disable_color = true })
35+
36+
-- Add icons (as fallback) to other fonts
37+
table.insert(DEFAULT_FALLBACK_TABLE, 1, ICONS_FONT_ALIAS)
38+
table.insert(DEFAULT_FALLBACK_TABLE_OUTLINE, 1, ICONS_FONT_ALIAS)
39+
40+
-- Reload all fonts
41+
LoadFonts()
42+
end)
2543

2644
-- CONFIG
2745
GLOBAL.MOD_ITEMMETA = {

0 commit comments

Comments
 (0)