Skip to content

Commit

Permalink
fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanfrans committed Apr 12, 2024
1 parent f1d17ec commit 2fe3b36
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 15 deletions.
Binary file modified src/assets/backgrounds/bandidas_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/bandidos_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/barons_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/bullets_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/bulls_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/bulls_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/bulls_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/backgrounds/bulls_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/glove_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/u10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/backgrounds/u12_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/backgrounds/u14_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/backgrounds/u16_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/bull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export function toTimeString(date: Date): string {
export function isDateBeforeToday(date: Date) {
return new Date(date.toDateString()) < new Date(new Date().toDateString());
}

export function isPastDate(date: Date) {
return date < new Date();
}
4 changes: 2 additions & 2 deletions src/games-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Game } from "./model/game.ts";
import { isDateBeforeToday, toDateString, toTimeString } from "./date.ts";
import { isPastDate, toDateString, toTimeString } from "./date.ts";

type ApiGame = {
venue: string;
Expand Down Expand Up @@ -87,7 +87,7 @@ export abstract class GamesRepository {

const gameDate = toDateString(gameDateTime);
const gameIdentifier = `${apiGame.home}_${apiGame.away}_${apiGame.venue}_${gameDate}`;
const isFutureGame = !isDateBeforeToday(gameDateTime);
const isFutureGame = !isPastDate(gameDateTime);

if (apiGame.status === "scheduled" && isHomeGame && isFutureGame) {
const existingGame = result[gameIdentifier] || undefined;
Expand Down
5 changes: 5 additions & 0 deletions src/image-to-blob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function imageToBlob(url: string) {
const response = await fetch(url);

return await response.blob();
}
17 changes: 15 additions & 2 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ body {
width: 100%;
font-family: sans-serif;
background-color: rgb(196, 196, 196);
display: flex;
}

#controls {
Expand All @@ -15,7 +16,7 @@ body {
justify-content: center;
justify-items: center;
gap: 16px;
width: 100%;
margin-inline: 12px;
}

.file-input {
Expand Down Expand Up @@ -67,11 +68,24 @@ body {
#download button {
width: 100%;
font-size: 2em;
margin-inline: 12px;
}

.app {
margin: 0 auto;
display: flex;
justify-content: center;

@media (min-width: 981px) {
max-width: 900px;
}

width: 100%;
}

#output-image {
width: 100%;
height: auto;
}

.container {
Expand All @@ -80,6 +94,5 @@ body {
display: flex;
flex-direction: column;
width: 100%;
max-width: 900px;
gap: 16px;
}
53 changes: 42 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GamesRepository } from "./games-repository.ts";
import { Game } from "./model/game.ts";
import { convertFileToBase64 } from "./file-to-base64.ts";
import { drawRoundedLeftSquare, drawRoundedRightSquare } from "./draw.ts";
import { imageToBlob } from "./image-to-blob.ts";

const BULLS_COLOR = "#e20613";

Expand Down Expand Up @@ -51,6 +52,10 @@ async function controls(
name: "Bulls Battery",
url: "bulls_2.png",
},
{
name: "Bulls Pitcher",
url: "bulls_4.png",
},
{
name: "Bulls Win",
url: "bulls_3.png",
Expand All @@ -75,6 +80,14 @@ async function controls(
name: "U10 Win",
url: "u10_1.png",
},
{
name: "U12 Huddle",
url: "u12_1.png",
},
{
name: "U14 Batter",
url: "u14_1.png",
},
{
name: "U16 Team",
url: "u16_1.png",
Expand Down Expand Up @@ -165,14 +178,15 @@ async function renderCanvas(
canvas.width = 900;
canvas.height = 1600;

ctx.reset();
ctx.fillStyle = "#000000";
ctx.fillRect(0, 0, canvas.width, canvas.height);

if (options.background) {
await drawImage(ctx, options.background, 0, 0, 900, 450);

ctx.shadowColor = "#000000";
ctx.shadowBlur = 50;
ctx.shadowBlur = 30;
ctx.fillStyle = "#000000";
ctx.fillRect(0, 450, canvas.width, canvas.height - 450);

Expand Down Expand Up @@ -241,34 +255,51 @@ async function renderCanvas(

ctx.fill();

ctx.font = "60px Steelfish";
const gameFontSize = 60;

ctx.font = `${gameFontSize}px Steelfish`;
ctx.fillStyle = "#ffffff";
ctx.textAlign = "right";

const date = new Date(game.date);

ctx.fillText(
`${date.getDate().toString().padStart(2, "0")}.${(date.getMonth() + 1)
.toString()
.padStart(2, "0")}`,
90 + offsetX,
gamesOffset + 60 + offsetY,
.padStart(2, "0")}.`,
96 + offsetX,
gamesOffset + gameFontSize + offsetY,
);

ctx.fillStyle = "#000000";
ctx.textAlign = "left";

ctx.fillText(
`${game.times.join(" | ")}`,
`${game.times[0]}`,
114 + offsetX,
gamesOffset + 60 + offsetY,
gamesOffset + gameFontSize + offsetY,
);

if (game.times.length > 1) {
ctx.fillText(
`|`,
114 + offsetX + 82,
gamesOffset + gameFontSize + offsetY,
);

ctx.fillText(
`${game.times[1]}`,
114 + offsetX + 100,
gamesOffset + gameFontSize + offsetY,
);
}

ctx.textAlign = "right";

const teamsDisplay = `${game.home} vs. ${game.away}${
game.league ? ` (${game.league.toUpperCase()})` : ""
}`;
ctx.fillText(teamsDisplay, 770, gamesOffset + 60 + offsetY);
ctx.fillText(teamsDisplay, 770, gamesOffset + gameFontSize + offsetY);
}

outputImage.src = canvas.toDataURL("image/png");
Expand Down Expand Up @@ -336,6 +367,8 @@ function uploadBackground(
const canvas = document.createElement("canvas");
const outputImage = document.createElement("img");

outputImage.id = "output-image";

const uploadField = uploadBackground(async (file) => {
await renderCanvas(outputImage, canvas, {
background: await convertFileToBase64(file),
Expand All @@ -344,10 +377,8 @@ function uploadBackground(
});

const backgroundSelect = await controls(async (background) => {
canvas.getContext("2d")?.reset();

await renderCanvas(outputImage, canvas, {
background,
background: await convertFileToBase64(await imageToBlob(background)),
games,
});
});
Expand Down

0 comments on commit 2fe3b36

Please sign in to comment.