-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain_font.lua
98 lines (87 loc) · 2.43 KB
/
main_font.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- Live Simulator: 2 main font
-- Part of Live Simulator: 2
-- See copyright notice in main.lua
local love = require("love")
local AssetCache = require("asset_cache")
local Async = require("async")
local Cache = require("cache")
local lily = require("lily")
local log = require("logging")
local Util = require("util")
local MainFont = {}
MainFont.roboto = love.filesystem.newFileData("fonts/Roboto-Regular.ttf")
MainFont.notoSansCJK = love.filesystem.newFileData("fonts/NotoSansCJKjp-Regular.woff")
MainFont.sarabun = love.filesystem.newFileData("fonts/Sarabun-Regular.ttf")
MainFont.dpiScale = Util.getFontDPIScale()
---@param ... integer
---@return love.Font ...
function MainFont.get(...)
local arg = {...}
local result = {}
local isNull = {}
local fontsQueue = {}
local j = 1
for i = 1, #arg do
local p = Cache.get("MainFont"..arg[i])
if not(p) then
if AssetCache.enableSync then
p = love.graphics.newFont(MainFont.roboto, arg[i], "normal", MainFont.dpiScale)
p:setFallbacks(
love.graphics.newFont(MainFont.notoSansCJK, arg[i], "normal", MainFont.dpiScale),
love.graphics.newFont(MainFont.sarabun, arg[i], "normal", MainFont.dpiScale)
)
Cache.set("MainFont"..arg[i], p)
else
isNull[i] = j
j = j + 1
fontsQueue[#fontsQueue + 1] = {
lily.newFont,
MainFont.roboto,
arg[i],
"normal",
MainFont.dpiScale
}
fontsQueue[#fontsQueue + 1] = {
lily.newFont,
MainFont.notoSansCJK,
arg[i],
"normal",
MainFont.dpiScale
}
fontsQueue[#fontsQueue + 1] = {
lily.newFont,
MainFont.sarabun,
arg[i],
"normal",
MainFont.dpiScale
}
p = false
end
end
result[i] = p
end
if #fontsQueue > 0 then
local multi = lily.loadMulti(fontsQueue)
local time = love.timer.getTime()
while multi:isComplete() == false do
Async.wait()
if time and love.timer.getTime() - time >= 1 then
log.warn("font", "font loading took longer than 1 second. Is Lily okay?")
time = nil
end
end
for i = 1, #arg do
if isNull[i] then
local index = isNull[i]
local f1 = multi:getValues(index * 3 - 2)
local f2 = multi:getValues(index * 3 - 1)
local f3 = multi:getValues(index * 3)
f1:setFallbacks(f2, f3)
Cache.set("MainFont"..arg[i], f1)
result[i] = f1
end
end
end
return unpack(result)
end
return MainFont