-
Notifications
You must be signed in to change notification settings - Fork 4
/
generator.js
59 lines (42 loc) · 1.72 KB
/
generator.js
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
const { layers } = require('./config');
const drawer = require('./core/drawer')()
const dnaFactory = require('./core/dna')()
const dnaManager = require('./core/dna/dnaManager')
const metadataBuilder = require('./core/metadata-builder')()
const args = process.argv.slice(2)
const edition = args.length ? parseInt(args[0]) : 1
if (!edition) throw "Please provide an edition number"
const generator = () => {
const generateEdition = async (dnaLayers, currentEdition) => {
drawer.drawBackground()
for await (let dnaLayer of dnaLayers.layers) {
await drawer.drawLayer(dnaLayer)
}
await drawer.saveCanvas(currentEdition)
await metadataBuilder.createMetadataItem(dnaLayers, currentEdition)
dnaManager.addDNA(dnaLayers.dna)
console.log(`Generating edition ${currentEdition}`)
}
const execute = async (_edition) => {
let currentEdition = 1;
while (currentEdition <= _edition) {
const currentDNA = dnaFactory.generateDNA()
if (dnaManager.hasDNA(currentDNA)) {
console.log('DNA already exists, genereting a new one...')
continue
}
const dnaLayers = metadataBuilder.generateLayersFromDNA(layers, currentDNA)
await generateEdition(dnaLayers, currentEdition)
currentEdition++
}
console.log('\n\n------ Saving metadata -----\n\n')
await metadataBuilder.save(metadataBuilder.getMetadata())
console.log('------ Finished! ----- \n\n')
console.log('Please check your new collection on the following path:')
console.log(`${__dirname}/collection/`)
}
return {
execute
}
}
generator().execute(edition)