|
9 | 9 | import type { IRenderOptions } from "@abstractplay/renderer"; |
10 | 10 | import { onMount } from "svelte"; |
11 | 11 | import ColorPicker from "svelte-awesome-color-picker"; |
| 12 | + import { generateField as genField } from "@/lib/modular"; |
12 | 13 |
|
13 | 14 | const boardTypes = new Map<SupportedBoards, string>([ |
14 | 15 | [ |
|
128 | 129 | let whichWidth: "abs" | "minmax" | undefined; |
129 | 130 | let canBlock = false; |
130 | 131 | let canAlternate = false; |
| 132 | + let canHalf = false; |
131 | 133 | let symmetryLocked = true; |
132 | 134 | let invertOrientation = false; |
133 | 135 | let canInvertOrientation = false; |
134 | 136 | let startDiamonds = false; |
135 | 137 | let selectedOptions: ValidOption[] = []; |
| 138 | + let selectedHalf: "full"|"top"|"bottom" = "full"; |
| 139 | + let numModules = 7; |
136 | 140 | const initVars = () => { |
137 | 141 | canBlock = false; |
138 | 142 | canAlternate = false; |
| 143 | + canHalf = false; |
| 144 | + selectedHalf = "full"; |
139 | 145 | if ($state.board.style === undefined) { |
140 | 146 | whichWidth = undefined; |
141 | 147 | } else if ( |
|
185 | 191 | if ($state.board.style.startsWith("hex-of")) { |
186 | 192 | canBlock = true; |
187 | 193 | canAlternate = true; |
| 194 | + canHalf = true; |
188 | 195 | } |
189 | 196 | } else { |
190 | 197 | // go board here |
|
202 | 209 | $state = $state; |
203 | 210 | } |
204 | 211 |
|
| 212 | + $: if (selectedHalf !== undefined) { |
| 213 | + if (selectedHalf === "full") { |
| 214 | + delete $state.board.half; |
| 215 | + } else { |
| 216 | + $state.board.alternatingSymmetry = false; |
| 217 | + $state.board.half = selectedHalf; |
| 218 | + } |
| 219 | + $state = $state; |
| 220 | + } |
| 221 | +
|
205 | 222 | const handleInvertClick = () => { |
206 | 223 | if ($state.board.style === "cairo-collinear") { |
207 | 224 | if (invertOrientation) { |
|
361 | 378 | return false; |
362 | 379 | }; |
363 | 380 |
|
| 381 | + const generateField = () => { |
| 382 | + $state.board = genField(numModules) as (BoardBasic & { style: SupportedBoards | "modular-hex"; }); |
| 383 | + $state = $state; |
| 384 | + } |
| 385 | +
|
364 | 386 | let previewDiv: HTMLDivElement; |
365 | 387 | onMount(() => { |
366 | 388 | const updatePreview = (state: RenderRepModified) => { |
|
544 | 566 | </label> |
545 | 567 | </div> |
546 | 568 | {/if} |
| 569 | + {#if canHalf} |
| 570 | + <div class="control"> |
| 571 | + <label class="radio"> |
| 572 | + <input type="radio" name="half" value="full" bind:group="{selectedHalf}" /> |
| 573 | + Full |
| 574 | + </label> |
| 575 | + <label class="radio"> |
| 576 | + <input type="radio" name="half" value="top" bind:group="{selectedHalf}" /> |
| 577 | + Top half |
| 578 | + </label> |
| 579 | + <label class="radio"> |
| 580 | + <input type="radio" name="half" value="bottom" bind:group="{selectedHalf}" /> |
| 581 | + Bottom half |
| 582 | + </label> |
| 583 | + </div> |
| 584 | + {/if} |
547 | 585 | {#if canInvertOrientation} |
548 | 586 | <div class="control"> |
549 | 587 | <label class="checkbox"> |
|
606 | 644 | > |
607 | 645 | {/if} |
608 | 646 | <hr /> |
| 647 | + <div class="content"> |
| 648 | + <p>You can generate a randomized hex field composed of modules (hexhex 2s) arranged to always touch another at two points. Select the number of modules and then the `Generate field` button.</p> |
| 649 | + </div> |
| 650 | + <div class="field padTop"> |
| 651 | + <label class="label" for="numModules">Number of modules</label> |
| 652 | + <div class="control"> |
| 653 | + <input class="input" name="numModules" type="number" min="1" max="30" bind:value="{numModules}" /> |
| 654 | + </div> |
| 655 | + <div class="control"> |
| 656 | + <button class="button apButton" on:click="{generateField}">Generate field</button> |
| 657 | + </div> |
| 658 | + </div> |
| 659 | + <hr /> |
609 | 660 | <div class="content"> |
610 | 661 | <p> |
611 | 662 | The renderer supports a number of other options that might be |
|
0 commit comments