Skip to content

Commit

Permalink
Release (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
instructr13 authored Oct 23, 2024
2 parents 9829d1d + a9aac2c commit 060fc18
Show file tree
Hide file tree
Showing 23 changed files with 915 additions and 55 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.rs]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[*.json]
insert_final_newline = false

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: Build solver (standalone)
working-directory: apps/solver
run: bun build --minify --sourcemap --compile --bytecode --target=bun-${{ matrix.target }} --outfile=dist/solver-${{ matrix.outfile }} dist/index.js $(find dist -name '*.js' -not -name 'index.js')
run: bun build --minify --sourcemap --compile --bytecode --target=bun-${{ matrix.target }} --outfile=dist/solver-${{ matrix.outfile }} dist/index.js $(find dist -name '*.js' -not -name 'index.js') $(find dist -name '*.wasm')

- name: Build mock server
working-directory: apps/mock-server
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"editor.rulers": [120],
"npm.packageManager": "bun",
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"rust-analyzer.linkedProjects": ["${workspaceFolder}/packages/algorithm/src/v3/Cargo.toml"],
"rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}
52 changes: 38 additions & 14 deletions apps/frontend/src/app/components/pattern/Pattern.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import type { Pattern as PatternSchema } from "@data-maki/schemas";
import { Grid } from "@yamada-ui/react";
import type { CSSProperties } from "react";
import { BoardCell, isCell } from "../board/Cell";
import { type CSSProperties, useEffect, useRef } from "react";
import { isCell } from "../board/Cell";

type Props = Readonly<{
pattern: PatternSchema;
size?: number;
style?: CSSProperties;
}>;

export const Pattern = ({ pattern, style }: Props) => (
<Grid templateColumns={`repeat(${pattern.width}, 1fr)`} style={style}>
{pattern.cells.map((row, rowIndex) =>
row.split("").map((cell, colIndex) => {
if (!isCell(cell)) throw new Error(`Invalid cell: ${cell}`);

return <BoardCell key={`${rowIndex}-${colIndex}-${cell}`} cell={cell} size="2rem" />;
}),
)}
</Grid>
);
export const Pattern = ({ pattern, size = 192, style }: Props) => {
const canvasRef = useRef<HTMLCanvasElement>(null);

useEffect(() => {
if (!canvasRef.current) return;

const canvas = canvasRef.current;
const ctx = canvas.getContext("2d");

if (!ctx) return;

const { width, height, cells } = pattern;

const cellHeight = size / height;
const cellWidth = size / width;

for (let i = 0; i < height; i++) {
for (let j = 0; j < width; j++) {
const cell = cells[i][j];

if (isCell(cell)) {
if (cell === "1") {
ctx.fillStyle = "#000";
} else {
ctx.fillStyle = "#fff";
}

ctx.fillRect(j * cellWidth, i * cellHeight, cellWidth, cellHeight);
}
}
}
}, [pattern, size]);

return <canvas ref={canvasRef} width={size} height={size} style={style} />;
};
30 changes: 12 additions & 18 deletions apps/frontend/src/app/components/pattern/PatternList.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import { type Pattern as PatternSchema, fixedPatterns } from "@data-maki/schemas";
import { useVirtualizer } from "@tanstack/react-virtual";
import { Box, Card, CardBody, FormControl, HStack, Option, ScrollArea, Select } from "@yamada-ui/react";
import { Box, Card, CardBody, FormControl, HStack, Option, ScrollArea, Select, Textarea } from "@yamada-ui/react";
import { Fragment, useRef, useState } from "react";
import { Pattern } from "./Pattern";

type PatternType = "general" | "fixed";

type Props = Readonly<{
patterns: PatternSchema[];
}>;

export const PatternListInner = ({ patterns }) => {
export const PatternListInner = ({ patterns }: Props) => {
const scrollRef = useRef<HTMLDivElement>(null);

const virtualizer = useVirtualizer({
horizontal: true,
gap: 12,
count: patterns.length,
getScrollElement: () => scrollRef.current,
estimateSize: (i) => patterns[i].width * 32,
estimateSize: (i) => 192,
paddingEnd: 12,
overscan: 2,
});

return (
<ScrollArea ref={scrollRef} innerProps={{ as: CardBody }} minH="200px">
<ScrollArea ref={scrollRef} innerProps={{ as: CardBody }} minH="256px">
<Box width={`${virtualizer.getTotalSize()}px`} h="100%" position="relative">
{virtualizer.getVirtualItems().map((virtualItem) => {
const pattern = patterns[virtualItem.index];
Expand All @@ -33,6 +31,7 @@ export const PatternListInner = ({ patterns }) => {
<Fragment key={virtualItem.key}>
<Pattern
pattern={pattern}
size={192}
style={{
position: "absolute",
top: 0,
Expand All @@ -49,19 +48,14 @@ export const PatternListInner = ({ patterns }) => {
};

export const PatternList = ({ patterns }: Props) => {
const [patternType, setPatternType] = useState<PatternType>("general");

return (
<HStack w="100vw">
<FormControl label="Type" w="15vw">
<Select value={patternType} onChange={(value) => setPatternType(value as PatternType)}>
<Option value={"general" satisfies PatternType}>General</Option>
<Option value={"fixed" satisfies PatternType}>Fixed</Option>
</Select>
</FormControl>
<Card variant="outline" w="75vw">
<PatternListInner patterns={patternType === "general" ? patterns : fixedPatterns.slice(0, 7)} />
<>
<Card variant="outline" w="100%">
<PatternListInner patterns={patterns} />
</Card>
</HStack>
<FormControl mt={8} label="Memo">
<Textarea autosize />
</FormControl>
</>
);
};
17 changes: 15 additions & 2 deletions apps/frontend/src/app/routes/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ import { useState } from "react";
import { MockServerConnectionCard } from "../components/mock-server/MockServerConnectionCard";

// Code from apps/frontend/src/app/routes/mock.tsx
type GenerationKindStart = "all-random" | "gen-random" | "column-seq" | "column-seq-reverse" | "column-group-shuffle";
type GenerationKindStart =
| "all-random"
| "gen-random"
| "column-seq"
| "column-seq-reverse"
| "column-group-shuffle"
| "random-rectangle-area"
| "random-eclipse-area";

const generationKindStarts: GenerationKindStart[] = [
"all-random",
"gen-random",
"column-seq",
"column-seq-reverse",
"column-group-shuffle",
"random-rectangle-area",
"random-eclipse-area",
] as const;

type GenerationKindGoal =
Expand All @@ -38,7 +47,9 @@ type GenerationKindGoal =
| "column-seq"
| "column-seq-reverse"
| "partial-single-swap"
| "partial-block-swap";
| "partial-block-swap"
| "random-area-reverse"
| "block-swap";

const generationKindGoals: GenerationKindGoal[] = [
"all-random",
Expand All @@ -49,6 +60,8 @@ const generationKindGoals: GenerationKindGoal[] = [
"column-seq-reverse",
"partial-single-swap",
"partial-block-swap",
"random-area-reverse",
"block-swap",
] as const;

export default function Page() {
Expand Down
Loading

0 comments on commit 060fc18

Please sign in to comment.