Skip to content

Commit b881fd2

Browse files
committed
refactor: Move rulesExplanation to lib
1 parent f72f657 commit b881fd2

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/lib/rules-explanation.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import lifespan from "$lib/assets/life-game-rules/lifespan.js?raw";
2+
import probabilistics from "$lib/assets/life-game-rules/probabilistics.js?raw";
3+
4+
export type RuleExplanation = {
5+
code: string;
6+
ja: string;
7+
en: string;
8+
};
9+
10+
export const rulesExplanation = {
11+
lifespan: {
12+
code: lifespan,
13+
ja: "それぞれのいのちに寿命を設定できます",
14+
en: "Set lifespan for each cell",
15+
},
16+
probabilistics: {
17+
code: probabilistics,
18+
ja: "生死に確率を導入できます",
19+
en: "Introduce probability to life and death",
20+
},
21+
};

src/routes/+page.svelte

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import event from "@/iframe/event.js?raw";
44
import lifeGameHTML from "@/iframe/life-game.html?raw";
55
import lifeGameJS from "@/iframe/life-game.js?raw";
6-
import lifespan from "$lib/assets/life-game-rules/lifespan.js?raw";
7-
import probabilistics from "$lib/assets/life-game-rules/probabilistics.js?raw";
6+
import { rulesExplanation, type RuleExplanation } from "$lib/rules-explanation";
87
import patterns from "$lib/board-templates";
98
import * as icons from "$lib/icons/index.ts";
109
import { BoardManager } from "$lib/models/BoardManager.svelte";
@@ -142,28 +141,7 @@
142141
},
143142
});
144143
145-
const rulesExplanation = {
146-
lifespan: {
147-
code: lifespan,
148-
ja: "それぞれのいのちに寿命を設定できます",
149-
en: "Set lifespan for each cell",
150-
},
151-
probabilistics: {
152-
code: probabilistics,
153-
ja: "生死に確率を導入できます",
154-
en: "Introduce probability to life and death",
155-
},
156-
};
157-
158-
type RuleExplanation = {
159-
code: string;
160-
ja: string;
161-
en: string;
162-
};
163-
164-
function selectRule(ruleName: keyof typeof rulesExplanation) {
165-
console.log(`Selected rule: ${ruleName}`);
166-
const rule = rulesExplanation[ruleName] as RuleExplanation;
144+
function selectRule(rule: RuleExplanation) {
167145
editingCode = rule.code;
168146
appliedCode = rule.code;
169147
}
@@ -258,7 +236,7 @@
258236
<button
259237
class="card bg-base-100 shadow-md hover:shadow-lg transition-shadow cursor-pointer text-left flex-shrink-0 w-64"
260238
onclick={() => {
261-
selectRule(ruleName as keyof typeof rulesExplanation);
239+
selectRule(description as RuleExplanation);
262240
ruleDrawerOpen = false;
263241
}}
264242
>
@@ -522,9 +500,9 @@
522500
{#if ruleDrawerOpen}
523501
524502
{:else if isJapanese}
525-
追加ルール
503+
ルール選択
526504
{:else}
527-
Additional Rules
505+
Select Rule
528506
{/if}
529507
</button>
530508
</div>

0 commit comments

Comments
 (0)