Skip to content

Commit c9ed0ae

Browse files
committed
🔨
1 parent 645f554 commit c9ed0ae

3 files changed

Lines changed: 67 additions & 67 deletions

File tree

‎packages/demo/interactive/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getCanvasWorldSize,
55
} from "@snk/draw/drawWorld";
66
import type { Res } from "@snk/github-user-contribution";
7-
import { cellsToGrid } from "generate-snake-animation/generateSnakeAnimation";
7+
import { cellsToGrid } from "generate-snake-animation/cellsToGrid";
88
import { parseEntry } from "generate-snake-animation/outputsOptions";
99
import { basePalettes } from "generate-snake-animation/palettes";
1010
import { step } from "@snk/solver/step";
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {
2-
type Color,
3-
createEmptyGrid,
4-
setColor,
5-
setColorEmpty,
2+
type Color,
3+
createEmptyGrid,
4+
setColor,
5+
setColorEmpty,
66
} from "@snk/types/grid";
77

88
export const cellsToGrid = (
9-
cells: { x: number; y: number; level: number }[],
9+
cells: { x: number; y: number; level: number }[],
1010
) => {
11-
const width = Math.max(0, ...cells.map((c) => c.x)) + 1;
12-
const height = Math.max(0, ...cells.map((c) => c.y)) + 1;
11+
const width = Math.max(0, ...cells.map((c) => c.x)) + 1;
12+
const height = Math.max(0, ...cells.map((c) => c.y)) + 1;
1313

14-
const grid = createEmptyGrid(width, height);
15-
for (const c of cells) {
16-
if (c.level > 0) setColor(grid, c.x, c.y, c.level as Color);
17-
else setColorEmpty(grid, c.x, c.y);
18-
}
14+
const grid = createEmptyGrid(width, height);
15+
for (const c of cells) {
16+
if (c.level > 0) setColor(grid, c.x, c.y, c.level as Color);
17+
else setColorEmpty(grid, c.x, c.y);
18+
}
1919

20-
return grid;
20+
return grid;
2121
};

‎packages/generate-snake-animation/generateSnakeAnimation.ts‎

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,68 @@ import { snake4 } from "@snk/types/__fixtures__/snake";
99
import { cellsToGrid } from "./cellsToGrid";
1010

1111
export type Source =
12-
| {
13-
platform: "github";
14-
username: string;
15-
githubToken: string;
16-
baseUrl?: string;
17-
}
18-
| { platform: "gitlab"; username: string; baseUrl?: string }
19-
| { platform: "forgejo"; username: string; baseUrl: string };
12+
| {
13+
platform: "github";
14+
username: string;
15+
githubToken: string;
16+
baseUrl?: string;
17+
}
18+
| { platform: "gitlab"; username: string; baseUrl?: string }
19+
| { platform: "forgejo"; username: string; baseUrl: string };
2020

2121
export type Output = {
22-
format: "svg" | "gif";
23-
drawOptions: DrawOptions;
24-
animationOptions: AnimationOptions;
22+
format: "svg" | "gif";
23+
drawOptions: DrawOptions;
24+
animationOptions: AnimationOptions;
2525
};
2626

2727
export const getUserContribution = async (source: Source) => {
28-
switch (source.platform) {
29-
case "github":
30-
return getGithubUserContribution(source.username, {
31-
githubToken: source.githubToken,
32-
baseUrl: source.baseUrl,
33-
});
34-
case "gitlab":
35-
return getGitlabUserContribution(source.username, {
36-
baseUrl: source.baseUrl,
37-
});
38-
case "forgejo":
39-
return getForgejoUserContribution(source.username, {
40-
baseUrl: source.baseUrl,
41-
});
42-
}
28+
switch (source.platform) {
29+
case "github":
30+
return getGithubUserContribution(source.username, {
31+
githubToken: source.githubToken,
32+
baseUrl: source.baseUrl,
33+
});
34+
case "gitlab":
35+
return getGitlabUserContribution(source.username, {
36+
baseUrl: source.baseUrl,
37+
});
38+
case "forgejo":
39+
return getForgejoUserContribution(source.username, {
40+
baseUrl: source.baseUrl,
41+
});
42+
}
4343
};
4444

4545
export const generateSnakeAnimation = async (
46-
source: Source,
47-
outputs: (Output | null)[],
46+
source: Source,
47+
outputs: (Output | null)[],
4848
) => {
49-
console.log(`🎣 fetching user contribution from ${source.platform}`);
50-
const cells = await getUserContribution(source);
51-
const grid = cellsToGrid(cells);
52-
const snake = snake4;
49+
console.log(`🎣 fetching user contribution from ${source.platform}`);
50+
const cells = await getUserContribution(source);
51+
const grid = cellsToGrid(cells);
52+
const snake = snake4;
5353

54-
console.log("📡 computing best route");
55-
const chain = getBestRoute(grid, snake)!;
56-
chain.push(...getPathToPose(chain.slice(-1)[0], snake)!);
54+
console.log("📡 computing best route");
55+
const chain = getBestRoute(grid, snake)!;
56+
chain.push(...getPathToPose(chain.slice(-1)[0], snake)!);
5757

58-
return Promise.all(
59-
outputs.map(async (out, i) => {
60-
if (!out) return;
61-
const { format, drawOptions, animationOptions } = out;
62-
switch (format) {
63-
case "svg": {
64-
console.log(`🖌 creating svg (outputs[${i}])`);
65-
const { createSvg } = await import("@snk/svg-creator");
66-
return createSvg(grid, cells, chain, drawOptions, animationOptions);
67-
}
68-
case "gif": {
69-
console.log(`📹 creating gif (outputs[${i}])`);
70-
const { createGif } = await import("@snk/gif-creator");
71-
return createGif(grid, cells, chain, drawOptions, animationOptions);
72-
}
73-
}
74-
}),
75-
);
58+
return Promise.all(
59+
outputs.map(async (out, i) => {
60+
if (!out) return;
61+
const { format, drawOptions, animationOptions } = out;
62+
switch (format) {
63+
case "svg": {
64+
console.log(`🖌 creating svg (outputs[${i}])`);
65+
const { createSvg } = await import("@snk/svg-creator");
66+
return createSvg(grid, cells, chain, drawOptions, animationOptions);
67+
}
68+
case "gif": {
69+
console.log(`📹 creating gif (outputs[${i}])`);
70+
const { createGif } = await import("@snk/gif-creator");
71+
return createGif(grid, cells, chain, drawOptions, animationOptions);
72+
}
73+
}
74+
}),
75+
);
7676
};

0 commit comments

Comments
 (0)