Skip to content

Commit

Permalink
feat: profile token_uris
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Dec 5, 2024
1 parent 31ce991 commit 0366d61
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 271 deletions.
4 changes: 3 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ allowed-libfuncs-list.name = "experimental"
[profile.dev.cairo]
unstable-add-statements-code-locations-debug-info = true
unstable-add-statements-functions-debug-info = true
inlining-strategy = "avoid"
inlining-strategy = "avoid"

[lib]
75 changes: 75 additions & 0 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,81 @@ pub struct Profile {
pub follow_nft: ContractAddress
}

// *************************************************************************
// TOKEN URIs
// *************************************************************************
#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum BackVariants {
BLUEFLAG,
BLUEGOLFSTICK,
FISHINGSTICK,
REDFLAG,
STYLIZEDBATON,
WHITEGOLFSTICK,
}

#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum BodyVariants {
Body1,
Body2,
Body3,
Body4,
Body5,
Body6,
Body7,
}

#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum BackgroundVariants {
BACKGROUND1,
BACKGROUND2,
BACKGROUND3,
BACKGROUND4,
BACKGROUND5,
}

#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum ClothVariants {
CLOTH1,
ClOTH2,
CLOTH3,
CLOTH4,
CLOTH5,
}

#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum FaceVariants {
FACE1,
FACE2,
FACE3,
FACE4,
FACE5,
FACE6,
FACE7,
FACE8,
}

#[derive(Copy, Drop, Serde, starknet::Store, Clone)]
pub enum AccessoryVariants {
BLACKVISOR,
BLUEMASK,
CAP,
ORANGEMASK,
PINKVISOR,
REDMASK,
VRHEADSET,
}

#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct ProfileVariants {
pub body: BodyVariants,
pub back: BackVariants,
pub background: BackgroundVariants,
pub cloth: ClothVariants,
pub face: FaceVariants,
pub accessory: AccessoryVariants
}

// *************************************************************************
// FOLLOW
// *************************************************************************
Expand Down
1 change: 0 additions & 1 deletion src/base/token_uris.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pub mod follow_token_uri;
pub mod handle_token_uri;
pub mod profile_token_uri;
pub mod community_token_uri;
pub mod channel_token_uri;
pub mod traits;
5 changes: 0 additions & 5 deletions src/base/token_uris/channel_token_uri.cairo

This file was deleted.

30 changes: 9 additions & 21 deletions src/base/token_uris/profile_token_uri.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
pub mod ProfileTokenUri {
use core::array::ArrayTrait;
use coloniz::base::constants::types::ProfileVariants;
use coloniz::base::token_uris::traits::profile::profile::gen_profile_svg;
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::utils::base64_extended::{get_base64_encode, convert_into_byteArray};

fn get_svg(token_id: u256, mint_timestamp: u64) -> Array<felt252> {
let mut svg = ArrayTrait::<felt252>::new();
svg.append('<svg width="200" height="200" x');
svg.append('mlns="http://www.w3.org/2000/sv');
svg.append('g"><circle cx="100" cy="100" r=');
svg.append('"80" fill="red"/></svg>');
svg
}

fn get_attributes(token_id: u256, mint_timestamp: u64) -> Array<felt252> {
fn get_attributes(token_id: u256, mint_timestamp: u64) -> Array<felt252> { // TODO: review necessary attributes
let token_id_felt: felt252 = token_id.try_into().unwrap();
let timestamp_felt: felt252 = mint_timestamp.try_into().unwrap();
let token_id_byte: ByteArray = token_id_felt.try_into().unwrap();
Expand All @@ -38,36 +31,31 @@ pub mod ProfileTokenUri {
attributes
}

fn get_json(token_id: u256, mint_timestamp: u64) -> Array<felt252> {
fn get_json(token_id: u256) -> Array<felt252> {
let token_id_felt: felt252 = token_id.try_into().unwrap();
let timestamp_felt: felt252 = mint_timestamp.try_into().unwrap();
let mut json = ArrayTrait::<felt252>::new();
json.append('{"name":"Profile #');
json.append(token_id_felt);
json.append('","description":"Profile #');
json.append(timestamp_felt);
json.append('","image":"data:image/svg');
json.append('+xml;base64,');
json
}


pub fn get_token_uri(token_id: u256, mint_timestamp: u64) -> ByteArray {
pub fn get_token_uri(token_id: u256, mint_timestamp: u64, profile_variant: ProfileVariants) -> ByteArray {
let baseuri = 'data:image/svg+xml;base64,';
let mut svg = get_svg(token_id, mint_timestamp);
let mut svg_byte_array: ByteArray = convert_into_byteArray(ref svg);
let svg_encoded: ByteArray = get_base64_encode(svg_byte_array);
let mut svg = gen_profile_svg(profile_variant);
let svg_encoded: ByteArray = get_base64_encode(svg);
// getting json byte array
// json - json + svg_base64_encoded
let mut json = get_json(token_id, mint_timestamp);
let mut json = get_json(token_id);
let mut json_byte_array: ByteArray = convert_into_byteArray(ref json);
json_byte_array.append(@svg_encoded);
// getting attributes
let mut attribute = get_attributes(token_id, mint_timestamp);
let mut attribute_byte_array: ByteArray = convert_into_byteArray(ref attribute);
// tokenuri_to_encode = json + attribute
let mut tokenuri_to_encode: ByteArray = Default::default();
// concat json ,
// concat json
tokenuri_to_encode.append(@json_byte_array);
// concat attribute
tokenuri_to_encode.append(@attribute_byte_array);
Expand Down
2 changes: 0 additions & 2 deletions src/base/token_uris/traits/color.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// SPDX-License-Identifier: MIT

pub mod colonizColors {
pub const baseGreen: felt252 = '#A0D170';
pub const basePink: felt252 = '#FFD2DD';
Expand Down
29 changes: 16 additions & 13 deletions src/base/token_uris/traits/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ pub mod background;
pub mod face;

pub mod profile {
use coloniz::base::token_uris::traits::profile::head::head::headSvgStart;
use coloniz::base::token_uris::traits::profile::back::back::backSvgStart;
use coloniz::base::token_uris::traits::profile::body::body::bodySvgStart;
use coloniz::base::token_uris::traits::profile::cloth::cloth::clothSvgStart;
use coloniz::base::token_uris::traits::profile::background::background::backgroundSvgStart;
use coloniz::base::token_uris::traits::profile::face::face::faceSvgStart;
pub fn gen_profile_svg() -> ByteArray {
use coloniz::base::constants::types::ProfileVariants;
use coloniz::base::token_uris::traits::profile::head::head::accessoryVariant;
use coloniz::base::token_uris::traits::profile::back::back::backVariant;
use coloniz::base::token_uris::traits::profile::body::body::bodyVariant;
use coloniz::base::token_uris::traits::profile::cloth::cloth::clothVariant;
use coloniz::base::token_uris::traits::profile::background::background::backgroundVariant;
use coloniz::base::token_uris::traits::profile::face::face::faceVariant;

pub fn gen_profile_svg(profile_variant: ProfileVariants) -> ByteArray {
let mut profilesvg: ByteArray =
"<svg width=\"200\" height=\"200\" viewBox=\"0 0 52.917 52.917\" xmlns=\"http://www.w3.org/2000/svg\">";
profilesvg.append(@backgroundSvgStart());
profilesvg.append(@bodySvgStart());
profilesvg.append(@clothSvgStart());
profilesvg.append(@headSvgStart());
profilesvg.append(@backSvgStart());
profilesvg.append(@faceSvgStart());

profilesvg.append(@backgroundVariant(profile_variant.background));
profilesvg.append(@bodyVariant(profile_variant.body));
profilesvg.append(@clothVariant(profile_variant.cloth));
profilesvg.append(@accessoryVariant(profile_variant.accessory));
profilesvg.append(@backVariant(profile_variant.back));
profilesvg.append(@faceVariant(profile_variant.face));
profilesvg.append(@"</svg>");
profilesvg
}
Expand Down
32 changes: 10 additions & 22 deletions src/base/token_uris/traits/profile/back.cairo

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions src/base/token_uris/traits/profile/background.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// let make the face of the profile svg

pub mod background {
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::constants::types::BackgroundVariants;

#[derive(Drop)]
enum BackgroundVariants {
BACKGROUND1, // 1
BACKGROUND2, // 2
BACKGROUND3, // 3
BACKGROUND4, // 4
BACKGROUND5, // 5
}

pub fn backgroundSvgStart() -> ByteArray {
getBackgroundVariant(BackgroundVariants::BACKGROUND2)
pub fn backgroundVariant(variant: BackgroundVariants) -> ByteArray {
getBackgroundVariant(variant)
}

pub fn getBackgroundVariant(backgroundVariant: BackgroundVariants) -> ByteArray {
Expand Down
20 changes: 4 additions & 16 deletions src/base/token_uris/traits/profile/body.cairo
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
// let make the face of the profile svg

pub mod body {
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;

#[derive(Drop)]
enum BodyVariants {
Body1, // 1
Body2, // 2
Body3, // 3
Body4, // 4
Body5, // 5
Body6,
Body7,
}

pub fn bodySvgStart() -> ByteArray {
getBodyvariant(BodyVariants::Body7)
use coloniz::base::constants::types::BodyVariants;

pub fn bodyVariant(variant: BodyVariants) -> ByteArray {
getBodyvariant(variant)
}

pub fn getBodyvariant(backVariant: BodyVariants) -> ByteArray {
Expand Down
18 changes: 4 additions & 14 deletions src/base/token_uris/traits/profile/cloth.cairo
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
// let make the face of the profile svg

pub mod cloth {
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::constants::types::ClothVariants;

#[derive(Drop)]
enum ClothVariants {
CLOTH1,
ClOTH2, // 1
CLOTH3, // 2
CLOTH4, // 3
CLOTH5, // 4
}

pub fn clothSvgStart() -> ByteArray {
getClothvariant(ClothVariants::ClOTH2)
pub fn clothVariant(variant: ClothVariants) -> ByteArray {
getClothVariant(variant)
}

pub fn getClothvariant(clothVariant: ClothVariants) -> ByteArray {
pub fn getClothVariant(clothVariant: ClothVariants) -> ByteArray {
let mut decidedCloth: ByteArray = Default::default();
match clothVariant {
ClothVariants::CLOTH1 => {
Expand Down
43 changes: 14 additions & 29 deletions src/base/token_uris/traits/profile/face.cairo
Original file line number Diff line number Diff line change
@@ -1,62 +1,47 @@
// let make the face of the profile svg

pub mod face {
use core::traits::TryInto;
use coloniz::base::token_uris::traits::color::colonizColors;
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray;
use coloniz::base::constants::types::FaceVariants;

#[derive(Drop)]
enum FaceVariants {
FACE1, // 1
FACE2, // 2
FACE3, // 3
FACE4, // 4
FACE5, // 5
FACE6, // 6
FACE7, // 7
FACE8, // 8
}

pub fn faceSvgStart() -> ByteArray {
getacessoryvariant(FaceVariants::FACE1)
pub fn faceVariant(variant: FaceVariants) -> ByteArray {
getFaceVariant(variant)
}

pub fn getacessoryvariant(faceVariant: FaceVariants) -> ByteArray {
let mut decidedAcessory: ByteArray = Default::default();
pub fn getFaceVariant(faceVariant: FaceVariants) -> ByteArray {
let mut decidedFace: ByteArray = Default::default();
match faceVariant {
FaceVariants::FACE1 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\" transform=\"matrix(.10019 0 0 .1008 .16 -.277)\"><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke-width:.264583\" width=\"22.288\" height=\"19.2\" x=\"202.878\" y=\"208.652\" ry=\"9.6\"/><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke-width:.264583\" width=\"22.288\" height=\"19.2\" x=\"309.241\" y=\"212.885\" ry=\"9.6\"/></g>"
},
FaceVariants::FACE2 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\" transform=\"matrix(.10019 0 0 .1008 .16 -.276)\"><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke-width:.264583\" width=\"31.521\" height=\"3.418\" x=\"198.238\" y=\"217.606\" ry=\"1.709\"/><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke-width:.264583\" width=\"31.521\" height=\"3.418\" x=\"303.013\" y=\"220.252\" ry=\"1.709\"/><path style=\"fill:none;fill-opacity:1;stroke:#fff;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" d=\"M242.224 269.072s22.964-20.783 52.503 1.774\"/></g>"
},
FaceVariants::FACE3 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:none\" transform=\"matrix(.10019 0 0 .1008 .159 -.277)\"><ellipse style=\"fill:none;fill-opacity:1;stroke:#b8e5eb;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" cx=\"214.472\" cy=\"219.857\" rx=\"11.963\" ry=\"10.823\"/><ellipse style=\"fill:none;fill-opacity:1;stroke:#b8e5eb;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" cx=\"318.718\" cy=\"222.503\" rx=\"11.963\" ry=\"10.823\"/><path style=\"fill:none;fill-opacity:1;stroke:#b8e5eb;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" d=\"M251 252.694s16.423 17.266 32.28 0\"/></g>"
},
FaceVariants::FACE4 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#0f0\" transform=\"matrix(.10019 0 0 .1008 .159 -.276)\"><rect style=\"fill:#0b0;fill-opacity:1;stroke:#0f0;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" width=\"21.267\" height=\"2.279\" x=\"204.246\" y=\"218.285\" ry=\"1.139\"/><path style=\"fill:#0f0;fill-opacity:1;stroke:none;stroke-width:2.15202;stroke-dasharray:none;stroke-opacity:1\" d=\"M317.01 222.957s-5.38-11.03-9.957-3.68c-4.802 7.711 9.957 14.868 9.957 14.868s15.173-8.235 9.58-15.898c-4.151-5.686-9.58 4.71-9.58 4.71\"/></g>"
},
FaceVariants::FACE5 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\" transform=\"matrix(.10019 0 0 .1008 .159 -.276)\"><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke:#fff;stroke-width:2.77929;stroke-dasharray:none;stroke-opacity:1\" width=\"3.639\" height=\"17.69\" x=\"213.318\" y=\"211.04\" ry=\".816\"/><rect style=\"fill:#f9f9f9;fill-opacity:1;stroke:#fff;stroke-width:2.77929;stroke-dasharray:none;stroke-opacity:1\" width=\"3.639\" height=\"17.69\" x=\"317.564\" y=\"214.215\" ry=\".816\"/><path style=\"fill:none;fill-opacity:1;stroke:#fff;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" d=\"M246.468 253.671s17.792 18.793 35.319.38\"/></g>"
},
FaceVariants::FACE6 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\" transform=\"matrix(.10019 0 0 .1008 .159 -.277)\"><rect style=\"display:inline;fill:#ff0;fill-opacity:1;stroke:none;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" width=\"11.278\" height=\"21.483\" x=\"209.434\" y=\"208.383\" ry=\"5.639\"/><rect style=\"display:inline;fill:#ff0;fill-opacity:1;stroke:none;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" width=\"11.278\" height=\"21.483\" x=\"313.68\" y=\"212.617\" ry=\"5.639\"/></g>"
},
FaceVariants::FACE7 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\"><text xml:space=\"preserve\" style=\"font-style:italic;font-weight:600;font-size:26.7955px;font-family:&quot;Bookman Old Style&quot;;-inkscape-font-specification:&quot;Bookman Old Style Semi-Bold Italic&quot;;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;fill:#0ff;fill-opacity:1;stroke:none;stroke-width:1.58241;stroke-dasharray:none;stroke-opacity:1\" x=\"219.558\" y=\"201.857\" transform=\"matrix(.0886 0 0 .11398 .16 -.276)\"><tspan style=\"fill:#0ff;stroke-width:1.58241\" x=\"219.558\" y=\"201.857\">HE</tspan></text><text xml:space=\"preserve\" style=\"font-style:italic;font-weight:600;font-size:24.6578px;font-family:&quot;Bookman Old Style&quot;;-inkscape-font-specification:&quot;Bookman Old Style Semi-Bold Italic&quot;;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;fill:#0ff;fill-opacity:1;stroke:none;stroke-width:1.45617;stroke-dasharray:none;stroke-opacity:1\" x=\"364.759\" y=\"190.059\" transform=\"matrix(.08153 0 0 .12386 .16 -.276)\"><tspan style=\"fill:#0ff;stroke-width:1.45617\" x=\"364.759\" y=\"190.059\">LLO</tspan></text></g>"
},
FaceVariants::FACE8 => {
decidedAcessory =
decidedFace =
"<g style=\"display:inline;fill:#f9f9f9\"><path style=\"fill:none;fill-opacity:1;stroke:#fff;stroke-width:3;stroke-dasharray:none;stroke-opacity:1\" d=\"M203.013 226.644s-1.991-14.398 13.047-14.398 11.12 15.472 11.12 15.472m79.55 1.042s-1.991-14.397 13.047-14.397 11.121 15.472 11.121 15.472\" transform=\"matrix(.10019 0 0 .1008 .16 -.277)\"/></g>"
},
}
decidedAcessory
decidedFace
}
}
Loading

0 comments on commit 0366d61

Please sign in to comment.