explorata/src/components/MenuElementaryCA.vue

108 lines
2.7 KiB
Vue
Raw Normal View History

2022-12-21 23:45:22 +01:00
<script setup>
import { presetRuleset, initialStates } from "../modules/preset.js";
import { globalStore } from "../stores/index.js";
import MenuRow from "./MenuRow.vue";
const store = globalStore();
const copyRuleset = () => {
const newRuleset = JSON.stringify(store.ruleset1d);
navigator.clipboard.writeText(newRuleset);
};
const updateSingleRule = (event) => {
const elem = event.target;
const value = elem.checked ? 1 : 0;
store.ruleset1d.rules[elem.name] = value;
};
const updateRuleset = (event) => {
const elem = event.target;
const name = elem.value;
const newRuleset = presetRuleset.find((ruleset) => {
return ruleset.name === name;
});
store.ruleset1d = newRuleset;
};
const updateInitialState = (event) => {
const elem = event.target;
store.initial1dState = elem.value;
};
</script>
<template>
2022-12-04 18:38:50 +01:00
<MenuRow row-title="Elementary Automaton">
<form>
2022-12-06 17:41:32 +01:00
<div class="form-field">
<input
type="button"
name="start"
2024-04-27 14:55:33 +02:00
value="▶"
2022-12-21 23:45:22 +01:00
@click="store.toggleDraw1d()"
2022-12-06 17:41:32 +01:00
/>
</div>
2022-01-11 13:16:42 +01:00
<div class="form-field">
<label>
Initial state presets
<br />
2022-01-11 13:16:42 +01:00
<select
name="initialStates"
2022-12-21 23:45:22 +01:00
:value="store.initial1dState"
@input="updateInitialState"
2022-01-11 13:16:42 +01:00
>
<option
2022-12-01 20:37:03 +01:00
v-for="(state, index) in initialStates"
:key="'initial-state-elementary' + index"
2022-01-11 13:16:42 +01:00
:value="state.id"
>
{{ state.name }}
2022-01-11 13:16:42 +01:00
</option>
</select>
</label>
</div>
<div class="form-field">
<label>Rules</label>
</div>
<div class="form-field">
<label
2022-12-02 17:11:34 +01:00
>Rules presets
<br />
<select
name="ruleset-elementary"
2022-12-21 23:45:22 +01:00
:value="store.ruleset1d.name"
2022-12-04 18:38:50 +01:00
@input="updateRuleset"
>
<option
2022-12-04 18:38:50 +01:00
v-for="(ruleset, index) in presetRuleset"
2022-12-01 20:37:03 +01:00
:key="'ruleset-preset-elementary-' + index"
:value="ruleset.name"
>
{{ ruleset.name }}
</option>
</select>
</label>
</div>
<div class="form-field">
2022-12-04 18:38:50 +01:00
<a style="cursor: pointer" @click="copyRuleset">copy rules</a>
</div>
2022-01-10 11:13:44 +01:00
<div
2022-12-21 23:45:22 +01:00
v-for="(rule, name, index) in store.ruleset1d.rules"
2022-12-01 20:37:03 +01:00
:key="'rule-' + index"
2022-01-10 11:13:44 +01:00
class="form-field"
>
<label
2022-12-02 17:11:34 +01:00
>{{ name }}
<input
:value="rule"
type="checkbox"
:name="name"
:checked="rule"
@input="updateSingleRule"
/>
</label>
</div>
</form>
</MenuRow>
</template>