Skip to content

Commit

Permalink
feat: switch rules on web implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
acifani committed Nov 13, 2023
1 parent 5876061 commit c5acea4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ func main() {
return nil
})

addEventListener("conway", "click", func(this js.Value, args []js.Value) interface{} {
universe.Rules = universe.ConwayRules
return nil
})

addEventListener("seeds", "click", func(this js.Value, args []js.Value) interface{} {
universe.Rules = universe.SeedsRules
return nil
})

addEventListener("daynight", "click", func(this js.Value, args []js.Value) interface{} {
universe.Rules = universe.DayAndNightRules
return nil
})

playPauseButton := document.Call("getElementById", "play-pause")
addEventListener("play-pause", "click", func(this js.Value, args []js.Value) interface{} {
if animationID != -1 {
Expand Down
19 changes: 18 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
border: 1px solid var(--border-color);
display: inline-block;
border-radius: 0.25rem;
margin-top: 1rem;
margin: 1rem 0;
}

label,
Expand Down Expand Up @@ -196,6 +196,23 @@ <h1>Vita</h1>
</div>

<p>Generations per second: <span id="gps"></span></p>

<details>
<summary>Advanced</summary>
<fieldset>
<legend>Game rules</legend>
<input type="radio" id="conway" name="action" checked="true" />
<label for="conway">Conway (standard)</label>

<input type="radio" id="seeds" name="action" />
<label for="seeds"><a href="https://conwaylife.com/wiki/OCA:Seeds" target="_blank"
rel="noopener noreferrer">Seeds</a></label>

<input type="radio" id="daynight" name="action" />
<label for="daynight"><a href="https://conwaylife.com/wiki/OCA:Day_&_Night" target="_blank"
rel="noopener noreferrer">Day & Night</a></label>
</fieldset>
</details>
</main>
<aside>
<noscript>This page is powered by WebAssembly, you need JavaScript to run the game.</noscript>
Expand Down

0 comments on commit c5acea4

Please sign in to comment.