@lightningjs/blits 1.7.0 → 1.7.1
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 +7 -0
- package/docs/components/user_input.md +4 -4
- package/package.json +1 -1
- package/vite/msdfGenerator.js +24 -14
package/CHANGELOG.md
CHANGED
|
@@ -125,9 +125,9 @@ Blits comes with a default keycode mapping. This mapping is a sensible default t
|
|
|
125
125
|
|
|
126
126
|
But it's possible that the keycodes and mapping of your target device are slightly or even completely different.
|
|
127
127
|
|
|
128
|
-
In Blits, you can easily configure the key mapping to match your needs. In the `src/index.js` file where we instantiate the App via the `Blits.Launch` function, we can add an extra key, called `
|
|
128
|
+
In Blits, you can easily configure the key mapping to match your needs. In the `src/index.js` file where we instantiate the App via the `Blits.Launch` function, we can add an extra key, called `keymap`, to the _settings object_.
|
|
129
129
|
|
|
130
|
-
The `
|
|
130
|
+
The `keymap` should contain an object literal, where you map a `key` or `keyCode` (from the `KeyboardEvent`) to an event name that you can use in your Components.
|
|
131
131
|
|
|
132
132
|
> You can use a site like [keyjs.dev](https://keyjs.dev/) to find the appropriate key and keyCode for your device
|
|
133
133
|
|
|
@@ -137,7 +137,7 @@ Blits.Launch(App, 'app', {
|
|
|
137
137
|
w: 1920,
|
|
138
138
|
h: 1080,
|
|
139
139
|
//...
|
|
140
|
-
|
|
140
|
+
keymap: {
|
|
141
141
|
// switch left and right using the key
|
|
142
142
|
ArrowLeft: 'right',
|
|
143
143
|
ArrowRight: 'left',
|
|
@@ -152,7 +152,7 @@ Blits.Launch(App, 'app', {
|
|
|
152
152
|
})
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
The custom
|
|
155
|
+
The custom keymap object will be merged with the default key mapping, that looks like this:
|
|
156
156
|
|
|
157
157
|
```js
|
|
158
158
|
const defaultKeyMap = {
|
package/package.json
CHANGED
package/vite/msdfGenerator.js
CHANGED
|
@@ -49,9 +49,19 @@ export default function () {
|
|
|
49
49
|
if (!fs.existsSync(path.resolve(fontDir, file))) {
|
|
50
50
|
const fontName = match[1]
|
|
51
51
|
const ext = match[2]
|
|
52
|
-
const fontFile = path.join(fontDir, `${fontName}.ttf`)
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
// Attempt to find the font file with supported extensions
|
|
54
|
+
const supportedExtensions = ['ttf', 'otf', 'woff']
|
|
55
|
+
let fontFile = null
|
|
56
|
+
for (const fontExt of supportedExtensions) {
|
|
57
|
+
const potentialPath = path.join(fontDir, `${fontName}.${fontExt}`)
|
|
58
|
+
if (fs.existsSync(potentialPath)) {
|
|
59
|
+
fontFile = potentialPath
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (fontFile) {
|
|
55
65
|
const generatedFontFile = path.join(
|
|
56
66
|
msdfOutputDir,
|
|
57
67
|
fontPath,
|
|
@@ -83,7 +93,7 @@ export default function () {
|
|
|
83
93
|
next() // Handle case where generation might have failed
|
|
84
94
|
}
|
|
85
95
|
} else {
|
|
86
|
-
next() //
|
|
96
|
+
next() // No supported font file found
|
|
87
97
|
}
|
|
88
98
|
} else {
|
|
89
99
|
next() // file exists
|
|
@@ -95,18 +105,18 @@ export default function () {
|
|
|
95
105
|
},
|
|
96
106
|
// after build ends, the first hook is renderStart where we can modify the output
|
|
97
107
|
async renderStart() {
|
|
98
|
-
const
|
|
108
|
+
const fontFiles = findAllFontFiles(publicDir)
|
|
99
109
|
|
|
100
|
-
for (const
|
|
101
|
-
const relativePath = path.relative(publicDir, path.dirname(
|
|
102
|
-
const baseName = path.basename(
|
|
110
|
+
for (const fontFile of fontFiles) {
|
|
111
|
+
const relativePath = path.relative(publicDir, path.dirname(fontFile))
|
|
112
|
+
const baseName = path.basename(fontFile).replace(/\.(ttf|otf|woff)$/i, '')
|
|
103
113
|
const msdfJsonPath = path.join(msdfOutputDir, relativePath, `${baseName}.msdf.json`)
|
|
104
114
|
const msdfPngPath = path.join(msdfOutputDir, relativePath, `${baseName}.msdf.png`)
|
|
105
115
|
|
|
106
116
|
// Check if MSDF files are generated, if not, generate them
|
|
107
117
|
if (!fs.existsSync(msdfJsonPath) || !fs.existsSync(msdfPngPath)) {
|
|
108
|
-
console.log(`Generating missing MSDF files for ${
|
|
109
|
-
await generateSDF(
|
|
118
|
+
console.log(`Generating missing MSDF files for ${fontFile}`)
|
|
119
|
+
await generateSDF(fontFile, path.join(msdfOutputDir, relativePath))
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -129,17 +139,17 @@ const generateSDF = async (inputFilePath, outputDirPath) => {
|
|
|
129
139
|
else console.error('Failed to generate MSDF file')
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
//
|
|
133
|
-
const
|
|
142
|
+
// Finds all font files (.ttf, .otf, .woff) in a directory
|
|
143
|
+
const findAllFontFiles = (dir, filesList = []) => {
|
|
134
144
|
const files = fs.readdirSync(dir, { withFileTypes: true })
|
|
135
145
|
|
|
136
146
|
files.forEach((file) => {
|
|
137
147
|
if (file.isDirectory()) {
|
|
138
148
|
const dirPath = path.join(dir, file.name)
|
|
139
|
-
|
|
149
|
+
findAllFontFiles(dirPath, filesList)
|
|
140
150
|
} else {
|
|
141
|
-
// Check for
|
|
142
|
-
if (file.name.match(/\.ttf$/i)) {
|
|
151
|
+
// Check for supported font extensions
|
|
152
|
+
if (file.name.match(/\.(ttf|otf|woff)$/i)) {
|
|
143
153
|
filesList.push(path.join(dir, file.name))
|
|
144
154
|
}
|
|
145
155
|
}
|