From 6eb7252141e103fbb92f607b1a5529e01f3df25b Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Sat, 8 Nov 2025 00:25:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Save,Load=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=92svelt=E3=81=AB=E7=A7=BB=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iframe/life-game.html | 4 ---- src/iframe/life-game.js | 15 +++++---------- src/routes/+page.svelte | 27 ++++++++++++++++++++++----- src/routes/api.ts | 1 - 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/iframe/life-game.html b/src/iframe/life-game.html index 9608c87..f9c5624 100644 --- a/src/iframe/life-game.html +++ b/src/iframe/life-game.html @@ -13,10 +13,6 @@ " >
- - - - diff --git a/src/iframe/life-game.js b/src/iframe/life-game.js index 1250aec..2875fc6 100644 --- a/src/iframe/life-game.js +++ b/src/iframe/life-game.js @@ -131,10 +131,6 @@ on.pause = () => { clearInterval(timerId); }; -on.load_board = (boardTemplate) => { - board = boardTemplate; -}; - on.resize = (newBoardSize) => { boardSize = newBoardSize; }; @@ -191,18 +187,17 @@ on.stateupdate = () => { on.sizechange(boardSize); -saveButton.onclick = async () => { +on.save_board = async () => { window.parent.postMessage({ type: "save_board", data: board }, "*"); }; -loadButton.onclick = async () => { +on.load_board = async () => { window.parent.postMessage({ type: "request:load_board" }, "*"); }; -on.load_board = (loadedBoard) => { - console.log("on.load_board"); - board = loadedBoard; +on.apply_board = (newBoard) => { + board = newBoard; renderBoard(); generationChange(0); - stop(); + on.pause(); }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 574deed..e71e599 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -60,22 +60,19 @@ onMount(() => { const handler = async (event: MessageEvent) => { - console.log("handler call"); const data = event.data as | { type: "unknown event" } | { type: "save_board"; data: boolean[][] } | { type: "request:load_board" }; if (data.type === "save_board") { - console.log("board saved!"); await saveBoard(data.data); return; } if (data.type === "request:load_board") { - console.log("loaded board"); const board = await loadBoard(); if (board) { - sendEvent("load_board", board); + sendEvent("apply_board", board); } return; } @@ -255,7 +252,7 @@ + + + + + + + + +