File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 1+ const on = { } ;
2+
3+ window . addEventListener ( "message" , ( event ) => {
4+ const handler = on [ event . data . type ] ;
5+ if ( handler ) {
6+ handler ( event . data . data ) ;
7+ }
8+ } ) ;
Original file line number Diff line number Diff line change 11"use strict" ;
22
33let timer = "stop" ;
4+ let timerId = 0 ;
45let generationFigure = 0 ;
56
67//定数
@@ -159,6 +160,26 @@ function progressBoard() {
159160 renderBoard ( ) ;
160161}
161162
163+ //イベント
164+
165+ on . play = ( ) => {
166+ timer = "start" ;
167+ timerId = setInterval ( progressBoard , 1000 ) ;
168+ } ;
169+
170+ on . pause = ( ) => {
171+ timer = "stop" ;
172+ clearInterval ( timerId ) ;
173+ } ;
174+
175+ on . load_board = ( boardTemplate ) => {
176+ board = boardTemplate ;
177+ } ;
178+
179+ on . resize = ( newBoardSize ) => {
180+ boardSize = newBoardSize ;
181+ } ;
182+
162183//以下パターンデータ
163184//(注)minBoardSizeは、パターンが余裕をもって変形できるために必要なボードのサイズを表し、パターン自体より大きい。
164185
Original file line number Diff line number Diff line change 22 import * as icons from " $lib/icons/index.ts" ;
33 import lghtml from " ../life-game/life-game.html?raw" ;
44 import lgjs from " ../life-game/life-game.js?raw" ;
5- import PlayandPause from " ../life-game/play-pause .js?raw" ;
5+ import event from " ../life-game/event .js?raw" ;
66
77 let code = $state (lgjs );
88
99 let previewDoc = $derived (
1010 lghtml .replace (
1111 / <script src="\.\/ life-game\. js"><\/ script>/ ,
1212 ` <script>
13+ \n ${event }\n
1314 \n ${lgjs }\n
14- \n ${PlayandPause }\n
1515 <\/ script> ` ,
1616 ),
1717 );
1818
1919 let showEditor = $state (true );
2020 let preview_iframe: HTMLIFrameElement | undefined = $state ();
2121 let isProgress = $state (false );
22+
23+ function sendEvent(event : string , message ? : unknown ) {
24+ preview_iframe ?.contentWindow ?.postMessage ({ type: event , date: message }, " *" );
25+ }
2226 </script >
2327
2428<div class =" navbar bg-[#E0E0E0] shadow-sm" >
3539 <button
3640 class =" btn btn-ghost btn-circle hover:bg-[rgb(220,220,220)] swap ml-5"
3741 onclick ={() => {
38- preview_iframe ?.contentWindow ?.postMessage ({ type: isProgress ? " pause" : " play" }, " *" );
42+ const eventName = isProgress ? " pause" : " play" ;
43+ sendEvent (eventName );
3944 isProgress = ! isProgress ;
4045 }}
4146 >
You can’t perform that action at this time.
0 commit comments