should have been committing more oops
This commit is contained in:
parent
0a7571115e
commit
028fdda858
2 changed files with 94 additions and 4 deletions
90
html/chessboard.tsx
Normal file
90
html/chessboard.tsx
Normal file
|
@ -0,0 +1,90 @@
|
|||
import { Main, mk_class_wrapper, render_and_copy } from "./common.tsx";
|
||||
|
||||
// const Movable
|
||||
|
||||
const Row = ({ n }: { n: number }) => (
|
||||
<div class={`row ${n % 2 == 0 ? "light" : "dark"}-first`}></div>
|
||||
);
|
||||
|
||||
const piece_names = {
|
||||
bb: "black bishop",
|
||||
bk: "black king",
|
||||
bn: "black knight",
|
||||
bp: "black pawn",
|
||||
bq: "black queen",
|
||||
br: "black rook",
|
||||
wb: "white bishop",
|
||||
wk: "white king",
|
||||
wn: "white knight",
|
||||
wp: "white pawn",
|
||||
wq: "white queen",
|
||||
wr: "white rook",
|
||||
} as const;
|
||||
|
||||
// there's some dedup that could be done but eh
|
||||
const start_pos: Record<keyof typeof piece_names, [number, number][]> = {
|
||||
br: [
|
||||
[0, 0],
|
||||
[7, 0],
|
||||
],
|
||||
bn: [
|
||||
[1, 0],
|
||||
[6, 0],
|
||||
],
|
||||
bb: [
|
||||
[2, 0],
|
||||
[5, 0],
|
||||
],
|
||||
bq: [[3, 0]],
|
||||
bk: [[4, 0]],
|
||||
bp: new Array(8).fill(null).map((_, i) => [i, 1]),
|
||||
wr: [
|
||||
[0, 7],
|
||||
[7, 7],
|
||||
],
|
||||
wn: [
|
||||
[1, 7],
|
||||
[6, 7],
|
||||
],
|
||||
wb: [
|
||||
[2, 7],
|
||||
[5, 7],
|
||||
],
|
||||
wq: [[3, 7]],
|
||||
wk: [[4, 7]],
|
||||
wp: new Array(8).fill(null).map((_, i) => [i, 6]),
|
||||
};
|
||||
|
||||
const get_src = (piece: keyof typeof piece_names): string =>
|
||||
`https://elo-worldle.pyrope.net/piece-${piece}.png`;
|
||||
|
||||
const get_alt = (piece: keyof typeof piece_names): string =>
|
||||
`the ${piece_names[piece]}, lovinly pixeled by tom7`;
|
||||
|
||||
const Piece = ({
|
||||
piece,
|
||||
width,
|
||||
height,
|
||||
}: {
|
||||
piece: keyof typeof piece_names;
|
||||
width: string;
|
||||
height: string;
|
||||
}) => (
|
||||
<div class="piece-container" style={{ width, height }}>
|
||||
<img class="piece" src={get_src(piece)} alt={get_alt(piece)} />
|
||||
</div>
|
||||
);
|
||||
|
||||
render_and_copy(
|
||||
<Main>
|
||||
<Row n={0} />
|
||||
<Row n={1} />
|
||||
<Row n={2} />
|
||||
<Row n={3} />
|
||||
<Row n={4} />
|
||||
<Row n={5} />
|
||||
<Row n={6} />
|
||||
<Row n={7} />
|
||||
</Main>,
|
||||
true
|
||||
);
|
|
@ -13,7 +13,7 @@ export function Main({
|
|||
children,
|
||||
...attributes
|
||||
}: {
|
||||
children: ComponentChildren;
|
||||
children?: ComponentChildren;
|
||||
attributes?: Attributes;
|
||||
}) {
|
||||
return (
|
||||
|
@ -52,15 +52,15 @@ export const eggbug_emotions = {
|
|||
export const EggbugImg = ({ type }: { type: keyof typeof eggbug_emotions }) =>
|
||||
eggbug_emotions[type];
|
||||
|
||||
export const render_and_copy = (elem: VNode) => {
|
||||
const rendered = render(elem);
|
||||
export const render_and_copy = (elem: VNode, pretty = false) => {
|
||||
const rendered = render(elem, null, { pretty });
|
||||
writeText(rendered);
|
||||
console.log(rendered);
|
||||
};
|
||||
|
||||
export const mk_class_wrapper =
|
||||
(klass: string) =>
|
||||
({ children }: { children: ComponentChildren }) =>
|
||||
({ children }: { children?: ComponentChildren }) =>
|
||||
<div class={klass}>{...toChildArray(children)}</div>;
|
||||
|
||||
export const slidify = (
|
||||
|
|
Loading…
Reference in a new issue