Skip to content

Commit 6117993

Browse files
SnaveSutitgitbutler-client
authored andcommitted
🚧 WIP Blueprint settings rework
1 parent 25448a1 commit 6117993

81 files changed

Lines changed: 1828 additions & 104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.scripts/esbuild.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { TextDecoder } from 'util'
2323
import assetOverridePlugin from './plugins/assetOverridePlugin'
2424
import bufferPatchPlugin from './plugins/bufferPatchFunction.js'
25+
import langPlugin from './plugins/lang'
2526
import mcbCompressionPlugin from './plugins/mcbCompressionPlugin'
2627
import packagerPlugin from './plugins/packagerPlugin'
2728
const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
@@ -194,6 +195,9 @@ const COMMON_CONFIG: esbuild.BuildOptions = {
194195
external: ['node:*'],
195196
loader: { '.svg': 'dataurl', '.ttf': 'binary', '.css': 'text' },
196197
plugins: [
198+
langPlugin({
199+
languageFolder: 'src/lang',
200+
}),
197201
// @ts-expect-error broken default import
198202
vscodeProblemsPatch.default(),
199203
// @ts-expect-error broken default import

.scripts/plugins/lang.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
interface LangPluginOptions {
2+
languageFolder: string
3+
}
4+
5+
interface StructuredLanguageFile {
6+
[key: string]: string | StructuredLanguageFile
7+
}
8+
9+
interface LanguageDefinition {
10+
name: string
11+
structured: StructuredLanguageFile
12+
flattened: Record<string, string>
13+
}
14+
15+
declare module 'LANGUAGES' {
16+
export const LANGUAGES: Record<string, LanguageDefinition>
17+
export function flattenStructuredLanguageFile(
18+
file: StructuredLanguageFile
19+
): Record<string, string>
20+
}

.scripts/plugins/lang.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/// <reference path="./lang.d.ts"/>
2+
3+
import ESBuild from 'esbuild'
4+
import { existsSync } from 'fs'
5+
import { readdir, readFile } from 'fs/promises'
6+
import { load } from 'js-yaml'
7+
import { join } from 'path'
8+
9+
const filterYamlFiles = (file: string) => {
10+
return file.endsWith('.yml') || file.endsWith('.yaml')
11+
}
12+
13+
const flattenStructuredLanguageFile = (file: StructuredLanguageFile): Record<string, string> => {
14+
const result: Record<string, string> = {}
15+
for (const key in file) {
16+
if (typeof file[key] === 'string') {
17+
result[key] = file[key]
18+
continue
19+
}
20+
21+
for (const [subKey, value] of Object.entries(flattenStructuredLanguageFile(file[key]))) {
22+
result[`${key}.${subKey}`] = value
23+
}
24+
}
25+
return result
26+
}
27+
28+
const langPlugin = ({ languageFolder }: LangPluginOptions) =>
29+
({
30+
name: 'lang',
31+
setup(build) {
32+
if (!existsSync(languageFolder)) {
33+
throw new Error(`Language folder "${languageFolder}" does not exist.`)
34+
}
35+
36+
build.onResolve({ filter: /LANGUAGES/ }, () => {
37+
return {
38+
path: languageFolder,
39+
namespace: 'language-file',
40+
}
41+
})
42+
43+
build.onLoad({ filter: /.*/, namespace: 'language-file' }, async () => {
44+
const translations: Record<string, LanguageDefinition> = {}
45+
46+
const files = (await readdir(languageFolder)).filter(filterYamlFiles)
47+
if (files.length === 0) {
48+
console.warn(`No language files found in "${languageFolder}"`)
49+
}
50+
51+
const watchFiles: string[] = []
52+
53+
for (const file of files) {
54+
const path = join(languageFolder, file)
55+
watchFiles.push(path)
56+
57+
const name = file.replace(/\.(yml|yaml)$/, '')
58+
const structured: StructuredLanguageFile = await readFile(path, {
59+
encoding: 'utf-8',
60+
}).then(data => load(data, { filename: path }) as StructuredLanguageFile)
61+
const flattened = flattenStructuredLanguageFile(structured)
62+
63+
translations[name] = { name, structured, flattened }
64+
}
65+
66+
const contents =
67+
`export const LANGUAGES = ${JSON.stringify(translations)};` +
68+
`export const flattenStructuredLanguageFile = ${flattenStructuredLanguageFile.toString()};`
69+
70+
return {
71+
contents,
72+
loader: 'js',
73+
watchFiles,
74+
}
75+
})
76+
},
77+
}) satisfies ESBuild.Plugin
78+
79+
export default langPlugin

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "Animated Java",
55
"icon": "icon.svg",
66
"description": "Effortlessly craft complex animations for Minecraft: Java Edition",
7-
"version": "1.10.0-beta.1",
7+
"version": "1.10.0-beta.3",
88
"min_blockbench_version": "4.12.6",
99
"max_blockbench_version": "4.12.6",
1010
"variant": "desktop",
21.1 KB
Loading

src/assets/icons/papermc.svg

Lines changed: 1 addition & 0 deletions
Loading

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PACKAGEJSON from '../package.json'
2-
import { translate } from './util/translation'
2+
import { localize as translate } from './util/lang'
33
export const PACKAGE: typeof PACKAGEJSON = PACKAGEJSON
44

55
const FS_MODULE = requireNativeModule('fs', {

src/dialogs/about/about.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SvelteDialog } from 'svelte-patching-tools/blockbench'
22
import { PACKAGE } from '../../constants'
3-
import { translate } from '../../util/translation'
3+
import { localize as translate } from '../../util/lang'
44
import AboutSvelte from './about.svelte'
55

66
export function openAboutDialog() {

src/dialogs/animationProperties/animationProperties.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import NumberSlider from '../../svelteComponents/dialogItems/numberSlider.svelte'
44
55
import { type Observable } from 'svelte-observable-store'
6-
import { translate } from '../../util/translation'
6+
import { localize as translate } from '../../util/lang'
77
</script>
88

99
<script lang="ts">

src/dialogs/animationProperties/animationProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { observable } from 'svelte-observable-store'
22
import { SvelteDialog } from 'svelte-patching-tools/blockbench'
33
import { PACKAGE } from '../../constants'
4-
import { translate } from '../../util/translation'
4+
import { localize as translate } from '../../util/lang'
55
import AniamtionPropertiesSvelteComponent from './animationProperties.svelte'
66

77
export const DIALOG_ID = `${PACKAGE.name}:animationPropertiesDialog`

0 commit comments

Comments
 (0)