maybeee??

This commit is contained in:
matty 2024-08-05 21:46:02 -04:00
parent 74566a895a
commit cfe2ac0607

View File

@ -58,9 +58,6 @@ const avatarPartsDef = {
fur: 10, fur: 10,
eyes: 15, eyes: 15,
mouth: 10 mouth: 10
},
'nctv': {
hat: 1
} }
} }
@ -109,69 +106,6 @@ function generateLegacyAvatars () {
} }
} }
// // 2024 avatars generation
// async function generateAvatars (part) {
// console.log('Starting generating ' + part)
// const parts = avatarPartsDef[part]
// if (!parts) {
// throw new Error('Missing part\'s conf: ' + part)
// }
// const inputDir = path.join('./assets/images/avatars/', part)
// const outputDir = path.join('./dist/server/avatars/', part)
// fs.mkdirSync(outputDir, { recursive: true })
// function computeFilename (part, count) {
// let a = (1 + (count % parts[part])).toString()
// if (a.length < 2) { a = '0' + a}
// return path.join(
// inputDir,
// part + '_' + a + '.png'
// )
// }
// // We can't generate all combinations! It would make 400 000 000 files!
// // So we arbitrary pick some combinations, using some modulus
// const nb = 200 // number of avatars to generate
// for (let i = 0; i < nb; i++) {
// const ouputFile = path.join(
// outputDir,
// i.toString() + '.png'
// )
// if (await fs.existsSync(ouputFile)) {
// console.log(`Skipping ${ouputFile}, file already exists`)
// continue
// }
// const partsToCombine = Object.keys(parts)
// const firstPart = partsToCombine.shift()
// const firstFile = computeFilename(firstPart, i)
// // We just have to combinate different parts into one file, then output at the wanted size.
// const composites = []
// let j = 0
// for (const part of partsToCombine) {
// j++ // introduce an offset so we don't get all empty parts at the same time
// composites.push({
// input: computeFilename(part, i + (j * 7))
// })
// }
// const buff = await sharp(firstFile)
// .composite(composites)
// .toBuffer()
// await sharp(buff)
// .resize(60, 60)
// .png({
// compressionLevel: 9,
// palette: true
// })
// .toFile(ouputFile)
// }
// }
// 2024 avatars generation // 2024 avatars generation
async function generateAvatars (part) { async function generateAvatars (part) {
console.log('Starting generating ' + part) console.log('Starting generating ' + part)
@ -193,93 +127,62 @@ async function generateAvatars (part) {
part + '_' + a + '.png' part + '_' + a + '.png'
) )
} }
// We can't generate all combinations! It would make 400 000 000 files!
// Function to generate "nigbot" files without composites // So we arbitrary pick some combinations, using some modulus
async function generateNigbotFiles(nb) {
for (let i = 0; i < nb; i++) {
const ouputFile = path.join(
outputDir,
'nigbot_' + i.toString() + '.png'
)
if (await fs.existsSync(ouputFile)) {
console.log(`Skipping ${ouputFile}, file already exists`)
continue
}
const firstPart = 'nigbot'
const firstFile = computeFilename(firstPart, i)
const buff = await sharp(firstFile)
.resize(60, 60)
.png({
compressionLevel: 9,
palette: true
})
.toBuffer()
await sharp(buff)
.toFile(ouputFile)
}
}
// Function to generate other files with composites
async function generateOtherFiles(nb) {
for (let i = 0; i < nb; i++) {
const ouputFile = path.join(
outputDir,
i.toString() + '.png'
)
if (await fs.existsSync(ouputFile)) {
console.log(`Skipping ${ouputFile}, file already exists`)
continue
}
const partsToCombine = Object.keys(parts)
const firstPart = partsToCombine.shift()
const firstFile = computeFilename(firstPart, i)
if (firstFile.includes('nigbot')) {
console.log(`Skipping ${firstFile}, file name contains "nigbot"`)
continue
}
const composites = []
let j = 0
for (const part of partsToCombine) {
j++ // introduce an offset so we don't get all empty parts at the same time
const filename = computeFilename(part, i + (j * 7))
if (filename.includes('nigbot')) {
console.log(`Skipping ${filename}, file name contains "nigbot"`)
continue
}
composites.push({
input: filename
})
}
const buff = await sharp(firstFile)
.composite(composites)
.toBuffer()
await sharp(buff)
.resize(60, 60)
.png({
compressionLevel: 9,
palette: true
})
.toFile(ouputFile)
}
}
const nb = 200 // number of avatars to generate const nb = 200 // number of avatars to generate
// Generate "nigbot" files for (let i = 0; i < nb; i++) {
await generateNigbotFiles(nb) const ouputFile = path.join(
outputDir,
i.toString() + '.png'
)
if (await fs.existsSync(ouputFile)) {
console.log(`Skipping ${ouputFile}, file already exists`)
continue
}
const partsToCombine = Object.keys(parts)
const firstPart = partsToCombine.shift()
const firstFile = computeFilename(firstPart, i)
// We just have to combinate different parts into one file, then output at the wanted size.
const composites = []
let j = 0
for (const part of partsToCombine) {
j++ // introduce an offset so we don't get all empty parts at the same time
composites.push({
input: computeFilename(part, i + (j * 7))
})
}
const buff = await sharp(firstFile)
.composite(composites)
.toBuffer()
await sharp(buff)
.resize(60, 60)
.png({
compressionLevel: 9,
palette: true
})
.toFile(ouputFile)
}
}
const generateNigbotAvatar = async () => {
console.log('Starting generating nigbot avatar');
const inputDir = './assets/images/avatars/nctv/';
const outputDir = './dist/server/avatars/nctv/';
fs.mkdirSync(outputDir, { recursive: true });
const buff = await sharp(path.join(inputDir, 'nigbot.png')).toBuffer();
await sharp(buff)
.resize(60, 60)
.png({ palette: true })
.toFile(path.join(outputDir, '1.png'));
// Generate other files with composites
await generateOtherFiles(nb)
} }
@ -466,6 +369,9 @@ if (isMainThread) {
throw err throw err
} }
) )
} else if (part === 'nctv') {
generateNigbotAvatar();
parentPort.postMessage('done');
} else { } else {
generateAvatars(part).then( generateAvatars(part).then(
() => { () => {