diff --git a/prisma/migrations/20251115084446_add_is_edited_and_code_data_column/migration.sql b/prisma/migrations/20251115084446_add_is_edited_and_code_data_column/migration.sql new file mode 100644 index 0000000..64be531 --- /dev/null +++ b/prisma/migrations/20251115084446_add_is_edited_and_code_data_column/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - Added the required column `codeData` to the `Board` table without a default value. This is not possible if the table is not empty. + - Added the required column `isEdited` to the `Board` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "Board" ADD COLUMN "codeData" JSONB NOT NULL, +ADD COLUMN "isEdited" BOOLEAN NOT NULL; diff --git a/prisma/migrations/20251115104313_delete_is_edited_column/migration.sql b/prisma/migrations/20251115104313_delete_is_edited_column/migration.sql new file mode 100644 index 0000000..c2c8d3d --- /dev/null +++ b/prisma/migrations/20251115104313_delete_is_edited_column/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `isEdited` on the `Board` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "Board" DROP COLUMN "isEdited"; diff --git a/prisma/migrations/20251115105024_rename_columns/migration.sql b/prisma/migrations/20251115105024_rename_columns/migration.sql new file mode 100644 index 0000000..ca9bf31 --- /dev/null +++ b/prisma/migrations/20251115105024_rename_columns/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - You are about to drop the column `codeData` on the `Board` table. All the data in the column will be lost. + - You are about to drop the column `data` on the `Board` table. All the data in the column will be lost. + - Added the required column `board` to the `Board` table without a default value. This is not possible if the table is not empty. + - Added the required column `code` to the `Board` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "Board" DROP COLUMN "codeData", +DROP COLUMN "data", +ADD COLUMN "board" JSONB NOT NULL, +ADD COLUMN "code" JSONB NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fc26eee..e93858e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -18,9 +18,10 @@ datasource db { model Board { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) - data Json + board Json name String preview Json + code Json } model Code { diff --git a/src/iframe/life-game.js b/src/iframe/life-game.js index ba97e7d..71a8b5c 100644 --- a/src/iframe/life-game.js +++ b/src/iframe/life-game.js @@ -3,7 +3,7 @@ let timer = "stop"; let generationFigure = 0; let isDragging = false; -let dragMode = false; // true: 黒にする, false: 白にする +let dragMode = 0; // 1: 黒にする, 0: 白にする let isPlacingTemplate = false; let patternShape = []; let patternHeight = 0; @@ -70,7 +70,7 @@ function renderBoard() { for (let c = 0; c < patternWidth; c++) { const boardRow = i + r; const boardCol = j + c; - board[boardRow][boardCol] = patternShape[r][c] === 1; + board[boardRow][boardCol] = patternShape[r][c]; } } rerender(); @@ -239,7 +239,7 @@ on.pause = () => { on.board_reset = () => { //すべて白にBoardを変更 - board = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); + board = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => 0)); renderBoard(); generationChange(0); }; @@ -247,7 +247,7 @@ on.board_reset = () => { on.board_randomize = () => { //白黒ランダムにBoardを変更 board = Array.from({ length: boardSize }, () => - Array.from({ length: boardSize }, () => Math.random() > 0.5), + Array.from({ length: boardSize }, () => (Math.random() > 0.5 ? 1 : 0)), ); renderBoard(); generationChange(0); diff --git a/src/lib/api/board.ts b/src/lib/api/board.ts index bf474eb..bbe477c 100644 --- a/src/lib/api/board.ts +++ b/src/lib/api/board.ts @@ -1,6 +1,9 @@ import { toast } from "$lib/models/ToastStore.svelte"; -export async function saveBoard(data: { board: number[][]; name: string }, isJapanese: boolean) { +export async function saveBoard( + data: { board: number[][]; name: string; code: string }, + isJapanese: boolean, +) { try { const response = await fetch("/api/board", { method: "POST", @@ -61,10 +64,15 @@ export async function fetchBoardList(isJapanese: boolean): Promise { +): Promise { try { const response = await fetch(`/api/board?id=${id}`); @@ -78,7 +86,7 @@ export async function loadBoardById( const loadedBoard = await response.json(); - return loadedBoard as number[][]; + return loadedBoard as LoadedBoardData; } catch (err) { console.error("Load error", err); if (isJapanese) { diff --git a/src/lib/components/BoardModals.svelte b/src/lib/components/BoardModals.svelte index 17841a8..791271e 100644 --- a/src/lib/components/BoardModals.svelte +++ b/src/lib/components/BoardModals.svelte @@ -10,6 +10,22 @@ isJapanese: boolean; onSelect: (id: number) => void; } = $props(); + + let showConfirmation = $state(false); + let selectedBoardId = $state(null); + + function handleLoadClick(id: number) { + selectedBoardId = id; + showConfirmation = true; + } + + function handleConfirmLoad() { + if (selectedBoardId !== null) { + onSelect(selectedBoardId); + } + showConfirmation = false; + selectedBoardId = null; + } @@ -105,7 +121,7 @@ @@ -125,6 +141,27 @@ + + + +