Merge remote-tracking branch 'origin/next' into webgpu-true

This commit is contained in:
Vitaly Turovsky 2024-07-10 20:26:04 +03:00
commit 92afdf54fb
243 changed files with 11112 additions and 1090 deletions

View file

@ -1,6 +1,6 @@
import fs from 'fs'
const url = 'https://github.com/zardoy/prismarine-web-client/raw/sounds-generated/sounds.js'
const url = 'https://github.com/zardoy/minecraft-web-client/raw/sounds-generated/sounds.js'
const savePath = 'dist/sounds.js'
fetch(url).then(res => res.text()).then(data => {
fs.writeFileSync(savePath, data, 'utf8')

View file

@ -7,7 +7,9 @@ import { filesize } from 'filesize'
import MCProtocol from 'minecraft-protocol'
import MCData from 'minecraft-data'
import { throttle } from 'lodash-es'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(new URL(import.meta.url)))
const { supportedVersions } = MCProtocol
const prod = process.argv.includes('--prod')
@ -34,8 +36,27 @@ export const startWatchingHmr = () => {
}
}
/** @type {import('esbuild').Plugin[]} */
const mesherSharedPlugins = [
{
name: 'minecraft-data',
setup(build) {
build.onLoad({
filter: /data[\/\\]pc[\/\\]common[\/\\]legacy.json$/,
}, async (args) => {
const data = fs.readFileSync(join(__dirname, '../src/preflatMap.json'), 'utf8')
return {
contents: `module.exports = ${data}`,
loader: 'js',
}
})
}
}
]
/** @type {import('esbuild').Plugin[]} */
const plugins = [
...mesherSharedPlugins,
{
name: 'strict-aliases',
setup(build) {
@ -108,7 +129,7 @@ const plugins = [
})
const removeNodeModulesSourcemaps = (map) => {
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft']
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft', 'three']
map.sourcesContent.forEach((_, i) => {
if (map.sources[i].includes('node_modules') && !doNotRemove.some(x => map.sources[i].includes(x))) {
map.sourcesContent[i] = null
@ -344,4 +365,4 @@ const plugins = [
})
]
export { plugins, connectedClients as clients }
export { plugins, connectedClients as clients, mesherSharedPlugins }

View file

@ -0,0 +1,16 @@
import fs from 'fs'
const icons = fs.readdirSync('node_modules/pixelarticons/svg')
const addIconPath = '../../node_modules/pixelarticons/svg/'
let str = 'export type PixelartIconsGenerated = {\n'
for (const icon of icons) {
const name = icon.replace('.svg', '')
// jsdoc
const jsdocImage = '![image](' + addIconPath + icon + ')'
str += ` /** ${jsdocImage} */\n`
str += ` '${name}': string;\n`
}
str += '}\n'
fs.writeFileSync('./src/react/pixelartIcons.generated.ts', str, 'utf8')

View file

@ -0,0 +1,41 @@
//@ts-check
// tsx ./scripts/getMissingRecipes.mjs
import MinecraftData from 'minecraft-data'
import supportedVersions from '../src/supportedVersions.mjs'
import fs from 'fs'
console.time('import-data')
const { descriptionGenerators } = await import('../src/itemsDescriptions')
console.timeEnd('import-data')
const data = MinecraftData(supportedVersions.at(-1))
const hasDescription = name => {
for (const [key, value] of descriptionGenerators) {
if (Array.isArray(key) && key.includes(name)) {
return true
}
if (key instanceof RegExp && key.test(name)) {
return true
}
}
return false
}
const result = []
for (const item of data.itemsArray) {
const recipes = data.recipes[item.id]
if (!recipes) {
if (item.name.endsWith('_slab') || item.name.endsWith('_stairs') || item.name.endsWith('_wall')) {
console.warn('Must have recipe!', item.name)
continue
}
if (hasDescription(item.name)) {
continue
}
result.push(item.name)
}
}
fs.writeFileSync('./generated/noRecipies.json', JSON.stringify(result, null, 2))

View file

@ -61,7 +61,7 @@ const downloadAllSounds = async () => {
}
prevSounds = soundAssets
}
async function downloadSound ({ name, hash, size }, namePath, log) {
async function downloadSound({ name, hash, size }, namePath, log) {
const savePath = path.resolve(`generated/sounds/${namePath}`)
if (fs.existsSync(savePath)) {
// console.log('skipped', name)
@ -86,7 +86,7 @@ const downloadAllSounds = async () => {
}
writer.close()
}
async function downloadSounds (assets, addPath = '') {
async function downloadSounds(assets, addPath = '') {
for (let i = 0; i < assets.length; i += 5) {
await Promise.all(assets.slice(i, i + 5).map((asset, j) => downloadSound(asset, `${addPath}${asset.name}`, () => {
console.log('downloading', addPath, asset.name, i + j, '/', assets.length)
@ -135,7 +135,7 @@ const convertSounds = async () => {
}
const CONCURRENCY = 5
for(let i = 0; i < toConvert.length; i += CONCURRENCY) {
for (let i = 0; i < toConvert.length; i += CONCURRENCY) {
await Promise.all(toConvert.slice(i, i + CONCURRENCY).map((oggPath, j) => convertSound(i + j)))
}
}
@ -221,7 +221,7 @@ const makeSoundsBundle = async () => {
const allSoundsMeta = {
format: 'mp3',
baseUrl: 'https://raw.githubusercontent.com/zardoy/prismarine-web-client/sounds-generated/sounds/'
baseUrl: 'https://raw.githubusercontent.com/zardoy/minecraft-web-client/sounds-generated/sounds/'
}
await build({

View file

@ -0,0 +1,8 @@
import fs from 'fs'
const faviconUrl = process.argv[2]
// save to assets/favicon.png
fetch(faviconUrl).then(res => res.arrayBuffer()).then(buffer => {
fs.writeFileSync('assets/favicon.png', Buffer.from(buffer))
})