Skip to content

Commit

Permalink
backup, cache, archive & restore
Browse files Browse the repository at this point in the history
  • Loading branch information
datboi-1337 committed Jul 7, 2024
1 parent bb26d4b commit a1fd5ef
Show file tree
Hide file tree
Showing 10 changed files with 1,836 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,5 @@ dist
/build
package-lock.json
/backup
/cache
/archive
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const runScript = async () => {

countAndSave();

buildSetup();
await buildSetup();
await startCreating();
await rarityBreakdown();

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datlips_art_engine",
"version": "1.4.0",
"version": "1.4.1",
"description": "Datlips Art Engine (Hashlips fork) is a tool used to create genrative artworks based on provided layers.",
"main": "index.js",
"bin": "index.js",
Expand All @@ -23,7 +23,9 @@
"generate_metadata": "node utils/generate_metadata.js",
"clean": "node utils/cleanMetadata.js",
"remove": "node utils/removeAttributes",
"rename": "node utils/renameAttributes"
"rename": "node utils/renameAttributes",
"archive": "node utils/archiveCollection.js",
"restore": "node utils/restoreCollection.js"
},
"author": "Daniel Eugene Botha (HashLips) & Datboi 1337",
"license": "MIT",
Expand Down
33 changes: 31 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const basePath = process.cwd();
const { NETWORK } = require(`${basePath}/constants/network.js`);
const fs = require("fs");
// const fs = require("fs");
const fs = require('fs-extra');
const sha1 = require(`${basePath}/node_modules/sha1`);
const { createCanvas, loadImage } = require(`${basePath}/node_modules/canvas`);
const buildDir = `${basePath}/build`;
Expand Down Expand Up @@ -54,7 +55,35 @@ let incompatibilities;
let hashlipsGiffer = null;
let allTraitsCount;

const buildSetup = () => {
const cachePreviousRun = async () => {
if (fs.existsSync(`${basePath}/build/json/_imgData.json`)) {
// Cache previous run data
let cacheDir = `${basePath}/cache`;
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir, { recursive: true });
}
let cacheFolders = fs.readdirSync(cacheDir);

if (cacheFolders.length > 10) {
let oldestFolder = cacheFolders.sort((a, b) => a.localeCompare(b))[0];
fs.removeSync(`${cacheDir}/${oldestFolder}`);
}

// Cache any existing imgData
const dateTime = new Date().toISOString().replace(/[-:.]/g, '_');
const sourceFile = `${basePath}/build/json/_imgData.json`;
const destinationDir = `${basePath}/cache/${dateTime}`;

fs.mkdirSync(destinationDir, { recursive: true });
await fs.copy(sourceFile, `${destinationDir}/_imgData.json`);

console.log('Previous run cached');
}
}

const buildSetup = async () => {
await cachePreviousRun();

if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
fs.mkdirSync(`${buildDir}/assets`);
Expand Down
292 changes: 292 additions & 0 deletions srcTemplate/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
const basePath = process.cwd();
const { MODE } = require(`${basePath}/constants/blend_mode.js`);
const { NETWORK } = require(`${basePath}/constants/network.js`);

const collectionSize = 65;

/*
* Set this to true if you want to use EXACT weights.
* Note that your weights must add up to the total number
* you want of that trait in the particular layer configuration it's in.
*/
const exactWeight = false;

// Options: eth, sol, sei
// NOTE: using 'eth' will generate metadata compatible with most EVM chains
const network = NETWORK.eth;

// General metadata. collectionName and description can be unique to each layer configuration if desired
const collectionName = "Your Collection";
const symbol = "YC";
const description = "Remember to replace this description";
const baseUri = "ipfs://TESTING";

const solanaMetadata = {
seller_fee_basis_points: 1000, // Define how much % you want from secondary market sales 1000 = 10%
external_url: "https://linktr.ee/datboi1337",
creators: [
{
address: "8DsAhDisG5eYjBwedSiakTKwrYCWpQ4tNDRuZyniMXaX",
share: 100,
},
],
collection: {
name: "Your Collection",
family: "Your Collection Family",
}
};

// It's suggested to keep shuffle enabled to avoid the same traits generating for spans of images
const shuffleLayerConfigurations = false;

// Populate with TRAITS you want to exclude from metadata. "None" is the default value, remove if you want "None" to appear in final metadata
const excludeFromMetadata = ["None"];

const layerConfigurations = [
{
// NOTE!! growEditionSizeTo should be set to the number of images you want generate within each layer configuration
growEditionSizeTo: 50, // << This will generate 50 images with this layersOrder
namePrefix: collectionName,
description: description,
layersOrder: [
{ name: "Variant", options: { displayName: "Color" } },
{ name: "Arms" },
{ name: "Back" },
{ name: "Body",
options: {
subTraits: [
{
blend: MODE.multiply,
opacity: 0.5,
zindex: 25,
}
]
}
},
{ name: "Eyes",
options: {
subTraits: [
{
name: "Shadow",
blend: MODE.multiply,
opacity: 0.5,
zindex: 35,
}
]
}
},
{ name: "Head" },
{ name: "Legs" },
{ name: "Mouth" },
],
},
{
growEditionSizeTo: 15, // This will generate 15 images with this layersOrder
namePrefix: `Skeletal ${collectionName}`,
description: 'Alternate Description for this set of tokens',
layersOrder: [
{ name: "SkeletalArms", options: { exclude: true } },
{ name: "SkeletalBack" },
{ name: "SkeletalBody" },
{ name: "SkeletalLegs" },
{ name: "SkeletalAccessories",
options: {
subTraits: [
{
zindex: 35,
}
]
}
}
],
},
];

const format = {
width: 512,
height: 512,
dpi: 72,
smoothing: false,
};

const extraMetadata = {};

const extraAttributes = [];

const rarityDelimiter = "#";

const zindexDelimiter = "$";

const uniqueDnaTorrance = 10000;

const enableStats = false;
const statBlocks = [
/*
* These are all examples with different display_types.
* Please refer to Opensea metadata standards for visual examples.
*/
{
minValue: 1,
maxValue: 50,
attribute:
{
trait_type: "Stamina",
value: 0
},
},
{
minValue: 1,
maxValue: 50,
attribute:
{
trait_type: "Stamina",
value: 0
},
},
{
minValue: 1,
maxValue: 999,
attribute:
{
display_type: "number",
trait_type: "Stamina",
value: 0
},
},
{
minValue: 1,
maxValue: 100,
attribute:
{
display_type: "boost_percentage",
trait_type: "Stamina Increase",
value: 0
},
},
{
minValue: 25,
maxValue: 75,
attribute:
{
display_type: "boost_number",
trait_type: "Stamina Boost",
value: 0
},
},
];

const debugLogs = false;

const gif = {
export: false,
repeat: 0,
quality: 100,
delay: 500,
};

// Currently disabled
const text = {
only: true,
color: "#ffffff",
size: 20,
xGap: 40,
yGap: 40,
align: "left",
baseline: "top",
weight: "regular",
family: "Courier",
spacer: " => ",
};

const pixelFormat = {
ratio: 2 / 128,
};

const background = {
generate: false,
brightness: "80%",
static: false,
default: "#000000",
};

const preview = {
thumbPerRow: 5,
thumbWidth: 50,
imageRatio: format.height / format.width,
imageName: "preview.png",
};

const preview_gif = {
numberOfImages: 5,
order: "ASC", // ASC, DESC, MIXED
repeat: 0,
quality: 100,
delay: 500,
imageName: "preview.gif",
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Rarity distribution can be adjusted. The main thing to keep in mind
* when editing is the rarities relationship to eachother.
* Common vs Mythic is 100:1 in the default state, for example.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
const rarity_config = {
Mythic: 1,
Legendary: 6,
Epic: 15,
Rare: 31,
Uncommon: 56,
Common: 100,
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Do not use this unless 100% necessary and you understand the risk
* Generating collection in stages leads to potential duplicates.
* 99% of the time, regenerating is the appropriate option.
* This is here for the 1%
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
const resumeNum = 0;
const importOldDna = false;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* NOTE: As the name implies, this will allow duplicates to be
* generated in the collection. Do not set this to true unless
* you specifically want duplicates in your collection.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
const allowDuplicates = false;

const bypassZeroProtection = false;

module.exports = {
format,
baseUri,
description,
background,
uniqueDnaTorrance,
layerConfigurations,
rarityDelimiter,
zindexDelimiter,
preview,
shuffleLayerConfigurations,
excludeFromMetadata,
debugLogs,
extraMetadata,
pixelFormat,
text,
collectionName,
symbol,
network,
solanaMetadata,
gif,
preview_gif,
resumeNum,
rarity_config,
collectionSize,
exactWeight,
importOldDna,
allowDuplicates,
enableStats,
statBlocks,
extraAttributes,
bypassZeroProtection,
};
Loading

0 comments on commit a1fd5ef

Please sign in to comment.