@quenty/colorpalette 4.19.1 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +2 -2
- package/src/Shared/Font/FontPalette.lua +77 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.20.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.19.1...@quenty/colorpalette@4.20.0) (2023-04-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add FontPalette:GetFontFaceValue(fontName) ([3411e11](https://github.com/Quenty/NevermoreEngine/commit/3411e116f2d48453a016d9dc15eab6ea64fb1bc4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [4.19.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.19.0...@quenty/colorpalette@4.19.1) (2023-04-07)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/colorpalette
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/colorpalette",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.0",
|
|
4
4
|
"description": "Color palette system for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"@quenty/table": "^3.2.0",
|
|
41
41
|
"@quenty/valueobject": "^7.11.1"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "d31bf8d9390b1c339a15aa80130b099e39d5c5a4"
|
|
44
44
|
}
|
|
@@ -25,6 +25,7 @@ function FontPalette.new()
|
|
|
25
25
|
local self = setmetatable(BaseObject.new(), FontPalette)
|
|
26
26
|
|
|
27
27
|
self._fonts = {}
|
|
28
|
+
self._fontFaces = {}
|
|
28
29
|
self._defaultFontMap = {} -- [name] = Enum.Font.?
|
|
29
30
|
|
|
30
31
|
self.FontAdded = Signal.new() -- :Fire(name)
|
|
@@ -96,21 +97,38 @@ end
|
|
|
96
97
|
function FontPalette:ObserveFontFace(fontName, weight, style)
|
|
97
98
|
assert(type(fontName) == "string", "Bad fontName")
|
|
98
99
|
|
|
100
|
+
if weight == nil and style == nil then
|
|
101
|
+
return self:GetFontFaceValue(fontName):Observe()
|
|
102
|
+
end
|
|
103
|
+
|
|
99
104
|
return Rx.combineLatest({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
end);
|
|
104
|
-
});
|
|
105
|
-
weight = weight or Enum.FontWeight.Regular;
|
|
106
|
-
style = style or Enum.FontStyle.Normal;
|
|
105
|
+
font = self:GetFontFaceValue(fontName):Observe();
|
|
106
|
+
weight = weight;
|
|
107
|
+
style = style;
|
|
107
108
|
}):Pipe({
|
|
108
109
|
Rx.map(function(state)
|
|
109
|
-
return Font.new(state.
|
|
110
|
+
return Font.new(state.font.Family, state.weight or state.font.Weight, state.style or state.font.Style)
|
|
110
111
|
end);
|
|
111
112
|
})
|
|
112
113
|
end
|
|
113
114
|
|
|
115
|
+
--[=[
|
|
116
|
+
Gets a font value object for a given font.
|
|
117
|
+
|
|
118
|
+
@param fontName string
|
|
119
|
+
@return ValueObject<Enum.Font>
|
|
120
|
+
]=]
|
|
121
|
+
function FontPalette:GetFontFaceValue(fontName)
|
|
122
|
+
assert(type(fontName) == "string", "Bad fontName")
|
|
123
|
+
|
|
124
|
+
local fontValue = self._fontFaces[fontName]
|
|
125
|
+
if not fontValue then
|
|
126
|
+
error(("No font with name %q"):format(fontName))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
return fontValue
|
|
130
|
+
end
|
|
131
|
+
|
|
114
132
|
--[=[
|
|
115
133
|
Gets a font value object for a given font.
|
|
116
134
|
|
|
@@ -120,12 +138,12 @@ end
|
|
|
120
138
|
function FontPalette:GetFontValue(fontName)
|
|
121
139
|
assert(type(fontName) == "string", "Bad fontName")
|
|
122
140
|
|
|
123
|
-
local
|
|
124
|
-
if not
|
|
141
|
+
local fontValue = self._fonts[fontName]
|
|
142
|
+
if not fontValue then
|
|
125
143
|
error(("No font with name %q"):format(fontName))
|
|
126
144
|
end
|
|
127
145
|
|
|
128
|
-
return
|
|
146
|
+
return fontValue
|
|
129
147
|
end
|
|
130
148
|
|
|
131
149
|
--[=[
|
|
@@ -140,27 +158,68 @@ end
|
|
|
140
158
|
Defines a new font into the palette which can be changed over time.
|
|
141
159
|
|
|
142
160
|
@param fontName string
|
|
143
|
-
@param
|
|
144
|
-
@return ValueObject<Enum.Font>
|
|
161
|
+
@param defaultFont Enum.Font | Font
|
|
162
|
+
@return ValueObject<Enum.Font | Font>
|
|
145
163
|
]=]
|
|
146
|
-
function FontPalette:DefineFont(fontName,
|
|
164
|
+
function FontPalette:DefineFont(fontName, defaultFont)
|
|
147
165
|
assert(type(fontName) == "string", "Bad fontName")
|
|
148
|
-
assert(typeof(
|
|
166
|
+
assert(typeof(defaultFont) == "EnumItem" or typeof(defaultFont) == "Font", "Bad defaultFont")
|
|
149
167
|
|
|
150
168
|
if self._fonts[fontName] then
|
|
151
|
-
warn(("Already defined
|
|
169
|
+
warn(("Already defined defaultFont of name %q"):format(fontName))
|
|
152
170
|
return
|
|
153
171
|
end
|
|
154
172
|
|
|
155
|
-
local
|
|
173
|
+
local defaultFontEnum
|
|
174
|
+
local defaultFontFace
|
|
175
|
+
if typeof(defaultFont) == "EnumItem" then
|
|
176
|
+
defaultFontEnum = defaultFont
|
|
177
|
+
defaultFontFace = Font.fromEnum(defaultFont)
|
|
178
|
+
elseif typeof(defaultFont) == "Font" then
|
|
179
|
+
defaultFontEnum = defaultFont
|
|
180
|
+
defaultFontFace = defaultFont
|
|
181
|
+
else
|
|
182
|
+
error("Bad defaultFont")
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
local fontValue = ValueObject.new(defaultFontEnum)
|
|
156
186
|
self._maid:GiveTask(fontValue)
|
|
157
187
|
|
|
188
|
+
local fontFaceValue = ValueObject.new(defaultFontFace)
|
|
189
|
+
self._maid:GiveTask(fontFaceValue)
|
|
190
|
+
|
|
158
191
|
self._fonts[fontName] = fontValue
|
|
159
|
-
self.
|
|
192
|
+
self._fontFaces[fontName] = fontFaceValue
|
|
193
|
+
self._defaultFontMap[fontName] = defaultFont
|
|
194
|
+
|
|
195
|
+
self._maid:GiveTask(fontFaceValue.Changed:Connect(function(fontFace)
|
|
196
|
+
fontValue.Value = self:_tryToGetFontFace(fontFace)
|
|
197
|
+
end))
|
|
198
|
+
|
|
199
|
+
self._maid:GiveTask(fontValue.Changed:Connect(function(fontEnum)
|
|
200
|
+
local font = Font.fromEnum(fontEnum)
|
|
201
|
+
local current = fontFaceValue.Value
|
|
202
|
+
fontFaceValue.Value = Font.new(font.Family, current.Weight, current.Style)
|
|
203
|
+
end))
|
|
160
204
|
|
|
161
205
|
self.FontAdded:Fire(fontName)
|
|
162
206
|
|
|
163
207
|
return fontValue
|
|
164
208
|
end
|
|
165
209
|
|
|
210
|
+
function FontPalette:_tryToGetFontFace(fontFace)
|
|
211
|
+
local assetName = string.gmatch(fontFace.Family, "rbxasset://fonts/families/([%w]+).json$")()
|
|
212
|
+
|
|
213
|
+
local fontEnum
|
|
214
|
+
pcall(function()
|
|
215
|
+
fontEnum = Enum.Font[assetName]
|
|
216
|
+
end)
|
|
217
|
+
|
|
218
|
+
if fontEnum then
|
|
219
|
+
return fontEnum
|
|
220
|
+
else
|
|
221
|
+
return Enum.Font.Unknown
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
166
225
|
return FontPalette
|