Skip to content

banonly and banonly shaded view added #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ for (const { cookie, id, installation, overrideConfig, post } of FIELDS) {
const totalSize = config.challengeConfig.size;
const partitionSize = config.challengeConfig.partitionSize;

const canvas = await renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name);
const canvas = await renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name,false,false);

const writeStream = createWriteStream(`${OUTPUT_DIR}/${id}.png`);
canvas.createPNGStream().pipe(writeStream);

const bancanvas = await renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name,true,false);

const banWriteStream = createWriteStream(`${OUTPUT_DIR}/${id}_b.png`);
bancanvas.createPNGStream().pipe(banWriteStream);

const shadecanvas = await renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name,true,true);

const shadeWriteStream = createWriteStream(`${OUTPUT_DIR}/${id}_s.png`);
shadecanvas.createPNGStream().pipe(shadeWriteStream);
} catch (error) {
log("failed to capture screenshot for %s", installation, error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { decodePartition } from "./utils/decode.js";
import { fetchPartition } from "./partition.js";
import { getCellColor } from "./utils/color.js";

export async function renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name) {
export async function renderPartition(totalSize, partitionSize, subreddit, challenge, sequence, name, banOnly, shade) {
log("capturing screenshot for %s", name);

const partitionCount = Math.floor(totalSize / partitionSize);
Expand All @@ -28,7 +28,7 @@ export async function renderPartition(totalSize, partitionSize, subreddit, chall
let index = 0;

for (const cell of cells) {
const color = getCellColor(cell);
const color = getCellColor(cell, banOnly, shade);

imageData.data[index * 4] = (color >> 16) & 0xFF;
imageData.data[index * 4 + 1] = (color >> 8) & 0xFF;
Expand Down
14 changes: 11 additions & 3 deletions src/utils/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ const TEAM_COLORS = [

const BAN_COLOR = 0x7DFF00;
const UNCLAIMED_COLOR = 0x000000;

const CLAIMED_SHADE = 0x202020;
/**
* Gets an RGB color representing a given cell.
* @param {import("./decode").Cell | null} cell the cell to get the color for
* @returns {number} the color
*/
export function getCellColor(cell) {
export function getCellColor(cell,banOnly,shade) {
if (cell?.ban) {
return BAN_COLOR;
} else if (cell?.team !== undefined) {
return TEAM_COLORS[cell.team];
if(banOnly) {
if(shade) {
return CLAIMED_SHADE;
}
else return UNCLAIMED_COLOR;
}
else {
return TEAM_COLORS[cell.team];
}
}

return UNCLAIMED_COLOR;
Expand Down