Skip to content

Commit

Permalink
Improvement/second evolution (#1913)
Browse files Browse the repository at this point in the history
* Added config for the second evolution

* Fixed names config

* Fix

* Fixed level name
  • Loading branch information
smakhtin authored Oct 31, 2024
1 parent f6e7100 commit 2ad2345
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"moonbase",
"moonsama",
"multipass",
"naia",
"nameprep",
"nanoid",
"NFTSCAN",
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function getRandomInt(min: number, max: number): number {
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
* @returns a random id generated using nanoid
*/
Expand Down
29 changes: 27 additions & 2 deletions apps/api/src/routes/dotphin/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { UniqueNetwork } from '@sni/types';
import { CollectionConfig } from '../claims/config'; //TODO: Move to shared
import { DOTphinLevel } from './types';
import { getRandomInt } from '$lib/utils';

export const MAX_DOTPHIN_LEVEL = 2;
export const MAX_DOTPHIN_LEVEL = 3;

const baseAttributes = [
{ trait_type: 'level', value: '1' },
Expand All @@ -28,7 +29,7 @@ const orboImages = {
],
};

const levelNames = ['orbo', 'nix'];
export const levelNames: DOTphinLevel[] = ['orbo', 'nix', 'naia'];

export function getLevelName(level: number): string {
return levelNames[level - 1];
Expand Down Expand Up @@ -79,6 +80,30 @@ export const evolutionImages: DOTphinEvolutions = {
],
},
},
naia: {
dotphin: {
air: `${cdnFolder}/dotphin-naia/dotphins/dotphin-naia-air.png`,
earth: `${cdnFolder}/dotphin-naia/dotphins/dotphin-naia-earth.png`,
water: `${cdnFolder}/dotphin-naia/dotphins/dotphin-naia-water.png`,
},
elements: {
air: [
`${cdnFolder}/dotphin-naia/elements/air/element-naia-air-01.png`,
`${cdnFolder}/dotphin-naia/elements/air/element-naia-air-02.png`,
`${cdnFolder}/dotphin-naia/elements/air/element-naia-air-03.png`,
],
earth: [
`${cdnFolder}/dotphin-naia/elements/earth/element-naia-earth-01.png`,
`${cdnFolder}/dotphin-naia/elements/earth/element-naia-earth-02.png`,
`${cdnFolder}/dotphin-naia/elements/earth/element-naia-earth-03.png`,
],
water: [
`${cdnFolder}/dotphin-naia/elements/water/element-naia-water-01.png`,
`${cdnFolder}/dotphin-naia/elements/water/element-naia-water-02.png`,
`${cdnFolder}/dotphin-naia/elements/water/element-naia-water-03.png`,
],
},
},
};

export function getDotphinCollectionConfig(
Expand Down
22 changes: 14 additions & 8 deletions apps/api/src/routes/dotphin/lib/image.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { CFImageUploadResponseSchema } from '../schemas';
import { evolutionImages, MAX_DOTPHIN_LEVEL } from '../config';
import { evolutionImages, levelNames, MAX_DOTPHIN_LEVEL } from '../config';
import { DOTphinElement, DOTphinLevel } from '../types';
import { getRandomInt } from '$lib/utils';

function levelToName(level: number) {
return ['orbo', 'nix'][
Math.min(level, MAX_DOTPHIN_LEVEL) - 1
] as DOTphinLevel;
function levelToName(level: number): DOTphinLevel {
return levelNames[Math.min(level, MAX_DOTPHIN_LEVEL) - 1] as DOTphinLevel;
}

export async function generateEvolutionImage(
Expand All @@ -24,12 +22,20 @@ export async function generateEvolutionImage(
'https://api.cloudflare.com/client/v4/accounts/2ca8f087834868e70427f43cb09afcce/images/v1';

const evolutionName = levelToName(level);
const mainImage = evolutionImages[evolutionName].dotphin[mainElement];

console.log('Evolution Name', evolutionName);

//Deep copy the images object
const images = JSON.parse(JSON.stringify(evolutionImages));

const mainImage = images[evolutionName].dotphin[mainElement];

const draw = [];
for (const element of proofsElements) {
const imageUrl =
evolutionImages[evolutionName].elements[element][getRandomInt(0, 2)];
const elementImages = images[evolutionName].elements[element];

const elementIndex = getRandomInt(0, elementImages.length - 1);
const imageUrl = elementImages.splice(elementIndex, 1)[0];

draw.push({ url: imageUrl });
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/dotphin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export type EvolutionQueueMessage = {

export type DOTphinElement = 'air' | 'earth' | 'water';

export type DOTphinLevel = 'orbo' | 'nix';
export type DOTphinLevel = 'orbo' | 'nix' | 'naia';

0 comments on commit 2ad2345

Please sign in to comment.