-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
98 lines (79 loc) · 2.84 KB
/
main.js
File metadata and controls
98 lines (79 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import inquirer from 'inquirer'
import promptSync from 'prompt-sync'
import { getLayers } from './utils/layerUtils.js'
import { mergePNGs, calculateUniqueCombinations } from './utils/pngUtils.js'
import { createLayersDirectory } from './utils/layerUtils.js'
import { createOutputDirectories } from './utils/fileUtils.js'
import { OUTPUT_DIR, LAYERS_DIR } from './global/constants.js'
import { welcomeMessage } from './common/welcomeMessage.js'
const prompt = promptSync()
createOutputDirectories(OUTPUT_DIR)
createLayersDirectory(LAYERS_DIR)
welcomeMessage()
const collectionName = prompt('Enter the collection name: ')
const collectionDescription = prompt('Enter the collection description: ')
let attempts = 0
let size
do {
size = parseInt(prompt('Enter the width. The height will be filled in automatically. Your value: '), 10)
if (isNaN(size) || size <= 0) {
console.error('Error: please enter a valid positive number for size.')
attempts++
} else {
break
}
if (attempts >= 5) {
console.error('Too many invalid attempts. Exiting...')
process.exit(1)
}
} while (true)
const layerSizes = {
width: size,
height: size
}
const layers = getLayers(LAYERS_DIR)
console.log('Available layers:', layers.join(', '))
const selectAllChoice = { name: 'Select All', value: '__all__' }
const choices = [selectAllChoice, ...layers.map(layer => ({ name: layer, value: layer }))]
const { layerOrder: selectedLayers } = await inquirer.prompt([
{
type: 'checkbox',
name: 'layerOrder',
message: 'Select layer order (Use SPACE to select and ENTER to confirm):',
choices: choices,
validate(answer) {
if (answer.length < 1) {
return 'You must choose at least one layer.'
}
return true
}
}
])
const layerOrder = selectedLayers.includes('__all__') ? layers : selectedLayers
console.log('Selected layer order:', layerOrder.join(', '))
const uniqueCount = calculateUniqueCombinations(layerOrder, LAYERS_DIR)
console.log(`Maximum number of unique NFTs: ${uniqueCount}`)
let nftCount
do {
nftCount = parseInt(prompt(`Enter number of NFTs to generate (maximum ${uniqueCount}): `), 10)
} while (isNaN(nftCount) || nftCount < 1 || nftCount > uniqueCount)
let startNumber
do {
startNumber = parseInt(prompt('Enter the starting number for JSON generation (default is 1): '), 10) || 1
} while (isNaN(startNumber) || startNumber < 1)
const usedCombinations = new Set()
for (let i = 0; i < nftCount; i++) {
const currentNumber = startNumber + i
process.stdout.write(`Generating NFT ${currentNumber}/${startNumber + nftCount - 1}... `)
await mergePNGs(
currentNumber,
usedCombinations,
layerSizes,
layerOrder,
collectionName,
collectionDescription,
LAYERS_DIR
)
process.stdout.write('✓\n')
}
console.log('Your PNGs have been compiled. Thank you for using.')