-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tdotholla/khb/tryforvercel
Khb/tryforvercel
- Loading branch information
Showing
33 changed files
with
13,656 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/.idea | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"outDir": "dist", | ||
"allowJs": true, | ||
"importHelpers": true, | ||
"removeComments": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// const layersOrder = [ | ||
// { name: 'background', number: 1 }, | ||
// { name: 'shine', number: 1 }, | ||
// { name: 'ball', number: 2 }, | ||
// { name: 'iris', number: 3 }, | ||
// { name: 'bottom lid', number: 3 }, | ||
// { name: 'top lid', number: 3 }, | ||
// { name: 'eye color', number: 12 }, | ||
// ]; | ||
|
||
const layersOrder = [ | ||
{ name: 'nameplate', number: 1 }, | ||
// { name: 'background', number: 2 }, | ||
{ name: 'face', number: 1 }, | ||
{ name: 'hair', number: 1 }, | ||
{ name: 'moustache', number: 1 }, | ||
{ name: 'eyebrows', number: 1 }, | ||
{ name: 'goatee', number: 2 }, | ||
{ name: 'nose', number: 1 }, | ||
{ name: 'eyes', number: 1 }, | ||
{ name: 'teeth', number: 1 }, | ||
{ name: 'pupils', number: 1 }, | ||
{ name: 'lips', number: 1 }, | ||
{ name: 'blunt_body', number: 4 }, | ||
{ name: 'blunt_smoke', number: 4 }, | ||
]; | ||
|
||
// const format = { | ||
// width: 230, | ||
// height: 230 | ||
// }; | ||
|
||
const format = { | ||
width: 540,// 10800, | ||
height: 720// 14400 | ||
} | ||
|
||
const rarity = [ | ||
{ key: "", val: "original" }, | ||
{ key: "_r", val: "rare" }, | ||
{ key: "_sr", val: "super rare" }, | ||
]; | ||
|
||
const defaultEdition = 4; | ||
|
||
export { layersOrder, format, rarity, defaultEdition }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defaultEdition } from "./config"; | ||
import { buildSetup, createFiles, createMetaData } from "./main"; | ||
const myArgs = process.argv.slice(2); | ||
const edition = myArgs.length > 0 ? Number(myArgs[0]) : defaultEdition; | ||
|
||
(() => { | ||
buildSetup(); | ||
createFiles(edition); | ||
createMetaData(); | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import * as fs from "fs"; | ||
import { createCanvas, loadImage } from "canvas"; | ||
import console from "console"; | ||
import { layersOrder, format, rarity } from "./config"; | ||
|
||
const canvas = createCanvas(format.width, format.height); | ||
const ctx = canvas.getContext("2d"); | ||
|
||
if (!process.env.PWD) { | ||
process.env.PWD = process.cwd(); | ||
} | ||
|
||
const buildDir = `${process.env.PWD}/build`; | ||
const metDataFile = '_metadata.json'; | ||
const layersDir = `${process.env.PWD}/layers`; | ||
|
||
let metadata: any[] = []; | ||
let attributes: any[] = []; | ||
let hash: any[] = []; | ||
let decodedHash: any[] = []; | ||
|
||
const addRarity = (_str: string) => { | ||
let itemRarity; | ||
|
||
rarity.forEach((r) => { | ||
if (_str.includes(r.key)) { | ||
itemRarity = r.val; | ||
} | ||
}); | ||
|
||
return itemRarity; | ||
}; | ||
|
||
const cleanName = (_str: string) => { | ||
let name = _str.slice(0, -4); | ||
rarity.forEach((r) => { | ||
name = name.replace(r.key, ""); | ||
}); | ||
return name; | ||
}; | ||
|
||
const getElements = (path: string) => { | ||
return fs | ||
.readdirSync(path) | ||
.filter((item) => !/(^|\/)\.[^\/\.]/g.test(item)) | ||
.map((i, index) => { | ||
return { | ||
id: index + 1, | ||
name: cleanName(i), | ||
fileName: i, | ||
rarity: addRarity(i), | ||
}; | ||
}); | ||
}; | ||
|
||
const layersSetup = (layersOrder: any[]) => { | ||
const layers = layersOrder.map((layerObj, index) => ({ | ||
id: index, | ||
name: layerObj.name, | ||
location: `${layersDir}/${layerObj.name}/`, | ||
elements: getElements(`${layersDir}/${layerObj.name}/`), | ||
position: { x: 0, y: 0 }, | ||
size: { width: format.width, height: format.height }, | ||
number: layerObj.number | ||
})); | ||
|
||
return layers; | ||
}; | ||
|
||
const buildSetup = () => { | ||
if (fs.existsSync(buildDir)) { | ||
fs.rmdirSync(buildDir, { recursive: true }); | ||
} | ||
fs.mkdirSync(buildDir); | ||
}; | ||
|
||
const saveLayer = (_canvas: any, _edition: number) => { | ||
fs.writeFileSync(`${buildDir}/${_edition}.png`, _canvas.toBuffer("image/png")); | ||
}; | ||
|
||
const addMetadata = (_edition: number) => { | ||
let dateTime = Date.now(); | ||
let tempMetadata = { | ||
hash: hash.join(""), | ||
decodedHash: decodedHash, | ||
edition: _edition, | ||
date: dateTime, | ||
attributes: attributes, | ||
}; | ||
metadata.push(tempMetadata); | ||
attributes = []; | ||
hash = []; | ||
decodedHash = []; | ||
}; | ||
|
||
const addAttributes = (_element: any, _layer: any) => { | ||
let tempAttr = { | ||
id: _element.id, | ||
layer: _layer.name, | ||
name: _element.name, | ||
rarity: _element.rarity, | ||
}; | ||
attributes.push(tempAttr); | ||
hash.push(_layer.id); | ||
hash.push(_element.id); | ||
decodedHash.push({ [_layer.id]: _element.id }); | ||
}; | ||
|
||
const drawLayer = async (_layer: any, _edition: number) => { | ||
const rand = Math.random(); | ||
let element = | ||
_layer.elements[Math.floor(rand * _layer.number)] ? _layer.elements[Math.floor(rand * _layer.number)] : null; | ||
if (element) { | ||
addAttributes(element, _layer); | ||
const image = await loadImage(`${_layer.location}${element.fileName}`); | ||
|
||
ctx.drawImage( | ||
image, | ||
_layer.position.x, | ||
_layer.position.y, | ||
_layer.size.width, | ||
_layer.size.height | ||
); | ||
saveLayer(canvas, _edition); | ||
} | ||
}; | ||
|
||
const createFiles = (edition: number) => { | ||
const layers = layersSetup(layersOrder); | ||
|
||
for (let i = 1; i <= edition; i++) { | ||
layers.forEach((layer) => { | ||
drawLayer(layer, i); | ||
}); | ||
addMetadata(i); | ||
console.log("Creating edition " + i); | ||
} | ||
}; | ||
|
||
const createMetaData = () => { | ||
fs.stat(`${buildDir}/${metDataFile}`, (err) => { | ||
if (err == null || err.code === 'ENOENT') { | ||
fs.writeFileSync(`${buildDir}/${metDataFile}`, JSON.stringify(metadata, null, 2)); | ||
// console.log(JSON.stringify(metadata, null, 2)) | ||
} else { | ||
console.log('Oh no, error: ', err.code); | ||
} | ||
}); | ||
}; | ||
|
||
export { buildSetup, createFiles, createMetaData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
{ | ||
"name": "art_generator", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"name": "app", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@chakra-ui/react": "^1.6.9", | ||
"@emotion/react": "11", | ||
"@emotion/styled": "11", | ||
"@testing-library/jest-dom": "^5.11.4", | ||
"@testing-library/react": "^11.1.0", | ||
"@testing-library/user-event": "^12.1.10", | ||
"canvas": "^2.8.0", | ||
"esm": "^3.2.25", | ||
"framer-motion": "4", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-scripts": "4.0.3", | ||
"typescript": "^4.1.2", | ||
"web-vitals": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^16.10.3", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0" | ||
}, | ||
"scripts": { | ||
"build": "node index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"code-gen": "node gen/generate.js", | ||
"start": "react-scripts start", | ||
"build": "yarn code-gen && react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"author": "Daniel Eugene Botha", | ||
"license": "ISC", | ||
"dependencies": { | ||
"canvas": "^2.8.0" | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
5e3d34d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: