Skip to content

Commit

Permalink
make stars same color as card
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabnock01 committed Nov 4, 2023
1 parent 503e813 commit d4b95bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions script/PrintFlagToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ contract PrintFlagTokenScript is Script {
_tokenId: (31 << 128) | 21_563,
_author: address(0),
_solveTime: uint40(49 days + 23 minutes + 17 seconds),
_solveMetadata: uint56((0xABCDEF0 << 28) | 0x1234567),
_solveMetadata: uint56((0xABCDEF0 << 28) | 0x1122334),
_phase: 0,
_solves: 256,
_colors: 0xFFC0CB181E2827303DF0F6FC94A3B3
_colors: 0x181E287851A927303DF0F6FC94A3B3
})
);
}
Expand Down
35 changes: 17 additions & 18 deletions script/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ exec("forge script script/PrintFlagToken.s.sol:PrintFlagTokenScript --rpc-url ht
console.log(`stderr: ${stderr}`);
return;
}

const regex = /data:application\/json;base64,[a-zA-Z0-9+/]+=*/g;
const base64Jsons = stdout.match(regex);
const matches = [];

base64Jsons?.forEach(base64Json => {
base64Jsons?.forEach((base64Json, index) => {
const startIndex = base64Json.indexOf(',') + 1;
const encodedJson = base64Json.slice(startIndex);

try {
const decodedJson = atob(encodedJson);
const parsedJson = JSON.parse(decodedJson);
if(parsedJson.image_data !== undefined) {

if (parsedJson.image_data !== undefined) {
matches.push(parsedJson.image_data);
}
} catch(e) {
} catch (e) {
console.error('Error in decoding/parsing JSON:', e);
}
});
Expand All @@ -37,31 +37,30 @@ exec("forge script script/PrintFlagToken.s.sol:PrintFlagTokenScript --rpc-url ht
const dir = path.join(__dirname, 'preview');

// Create the directory if it doesn't exist
if (!fs.existsSync(dir)){
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}

fs.readdir(dir, (err, files) => {
if (err) throw err;

for (const file of files) {
fs.unlink(path.join(dir, file), err => {
if (err) throw err;
});
}

for (let i = 0; i < matches.length; i++) {
const base64Data = matches[i].replace('data:image/svg+xml;base64,', '');

const fileName = `${i + 1}.svg`;

fs.writeFile(path.join(dir, fileName), Buffer.from(base64Data, 'base64'), { flag: 'w' }, function(err) {
if(err) {
let fileName;
let counter = 0;
do {
counter++;
fileName = `${i + counter}.svg`;
} while (files.includes(fileName));

fs.writeFile(path.join(dir, fileName), Buffer.from(base64Data, 'base64'), { flag: 'w' }, function (err) {
if (err) {
console.log(err);
} else {
console.log(`saved ${fileName}`);
}
});
}
});
});
});
2 changes: 1 addition & 1 deletion src/FlagRenderer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ contract FlagRenderer {
'" y="97" width="',
width.toString(),
'" height="24" rx="12"/><path id="s" fill="#',
uint256((_colors >> 96) & 0xFFFFFF).toHexStringNoPrefix(3),
uint256((_colors >> 72) & 0xFFFFFF).toHexStringNoPrefix(3),
'" d="M366.192 103.14c.299-.718 1.317-.718 1.616 '
"0l1.388 3.338 3.603.289c.776.062 1.09 1.03.499 1.536l-2.745 2.352.838 3.515c.181.7"
"57-.642 1.355-1.306.95L367 113.236l-3.085 1.884c-.664.405-1.487-.193-1.306-.95l.83"
Expand Down

0 comments on commit d4b95bc

Please sign in to comment.