nft-art-engine
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -11,8 +11,8 @@ export interface dimention { | ||
export interface rarity { | ||
[layer: string]: layerRarity; | ||
export interface rarities { | ||
[layerName: string]: Rarity; | ||
} | ||
export interface layerRarity { | ||
[rarity: string]: number; | ||
export interface Rarity { | ||
[rarityName: string]: number; | ||
} | ||
@@ -24,3 +24,4 @@ | ||
image: string; | ||
rarity: string; | ||
rarity?: string; | ||
category?: string; | ||
} | ||
@@ -30,3 +31,3 @@ | ||
name: string; | ||
rarity?: layerRarity; | ||
rarity?: Rarity; | ||
elements: element[]; | ||
@@ -36,8 +37,8 @@ } | ||
export interface blackList { | ||
[path: string]: string[]; | ||
[elementId: string]: string[]; | ||
} | ||
export interface whiteList { | ||
[path: string]: { | ||
[dnaIndex: number]: string[]; | ||
[elementId: string]: { | ||
[layerIndex: string]: string[]; | ||
}; | ||
@@ -59,6 +60,5 @@ } | ||
export interface config { | ||
name: string; | ||
dimention: dimention; | ||
edition: edition; | ||
rarity: rarity; | ||
rarities?: rarities; | ||
layers: layer[]; | ||
@@ -78,3 +78,3 @@ blacklist?: blackList; | ||
sessionDir: string, | ||
progress: (num: number) => void | ||
progressCallback: (num: number) => void | ||
): Promise<void>; | ||
@@ -81,0 +81,0 @@ |
42
index.js
@@ -150,11 +150,14 @@ const fs = require("fs"); | ||
function generateNewDna(_layers, _rarity) { | ||
function generateNewDna(_layers, _categories) { | ||
const dnaStructure = []; | ||
_layers.forEach((layer) => { | ||
const rarityOptions = layer.rarity || _rarity | ||
const rarityOptions = layer.rarity | ||
const rarityProbability = Object.keys(rarityOptions).map(r => Array(rarityOptions[r]).fill(r)).reduce((c, v) => c.concat(v), []); | ||
const rarityIndex = randomIndex(100); | ||
const rarityIndex = randomIndex(rarityProbability.length); | ||
const raritySelected = rarityProbability[rarityIndex] | ||
const elementFilters = layer.elements.filter(element => element.rarity === raritySelected); | ||
const categoryIndex = randomIndex(_categories.length) | ||
const categorySelected = _categories[categoryIndex] | ||
const elementFilters = layer.elements.filter(element => element.rarity === raritySelected && (element.category == categorySelected || element.category == null)); | ||
const elementIndex = randomIndex(elementFilters.length) | ||
@@ -175,3 +178,18 @@ const elementSelected = elementFilters[elementIndex]; | ||
async function generate(_config, _outputDir, _sessionDir, _progress) { | ||
function getCategories(_layers) { | ||
const categories = {} | ||
for (const layer of _layers) { | ||
for (const element of layer.elements) { | ||
if (element.category) { | ||
categories[element.category] = {} | ||
} | ||
} | ||
} | ||
return Object.keys(categories) | ||
} | ||
async function generate(_config, _outputDir, _sessionDir, _progressCallback) { | ||
_config.categories = getCategories(_config.layers) | ||
const canvas = createCanvas(_config.dimention.width, _config.dimention.height); | ||
@@ -189,5 +207,5 @@ const ctx = canvas.getContext("2d"); | ||
while (editionFrom <= editionTotal) { | ||
let newDna = generateNewDna(_config.layers, _config.rarity); | ||
let newDna = generateNewDna(_config.layers, _config.categories); | ||
while (isNotEligible(dnaCollection, _config.whitelist, _config.blacklist, newDna)) { | ||
newDna = generateNewDna(_config.layers, _config.rarity); | ||
newDna = generateNewDna(_config.layers, _config.categories); | ||
} | ||
@@ -220,3 +238,3 @@ | ||
_progress(editionCount); | ||
_progressCallback(editionCount); | ||
} | ||
@@ -252,9 +270,11 @@ | ||
async function preview(_config) { | ||
_config.categories = getCategories(_config.layers) | ||
const canvas = createCanvas(_config.dimention.width, _config.dimention.height); | ||
const ctx = canvas.getContext("2d"); | ||
const dnaCollection = new Set(); | ||
let newDna = generateNewDna(_config.layers, _config.rarity); | ||
let newDna = generateNewDna(_config.layers, _config.categories); | ||
while (isNotEligible(dnaCollection, _config.whitelist, _config.blacklist, newDna)) { | ||
newDna = generateNewDna(_config.layers, _config.rarity); | ||
newDna = generateNewDna(_config.layers, _config.categories); | ||
} | ||
@@ -261,0 +281,0 @@ |
{ | ||
"name": "nft-art-engine", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "NFT ART Engine is a package used to create multiple different instances of artworks based on provided layers.", | ||
@@ -5,0 +5,0 @@ "author": "Bagus Abdul Kurniawan", |
11176
299