changed rules to ruleset for clarity
This commit is contained in:
parent
cb3ddadfdf
commit
d602c83d3d
@ -30,7 +30,7 @@
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState(globalStore, {
|
...mapState(globalStore, {
|
||||||
cellProperties: "cellProperties",
|
cellProperties: "cellProperties",
|
||||||
rules: "rules1d",
|
ruleset: "ruleset1d",
|
||||||
refreshRate: "refreshRate",
|
refreshRate: "refreshRate",
|
||||||
initial1dState: "initial1dState",
|
initial1dState: "initial1dState",
|
||||||
drawingDirection: "drawingDirection",
|
drawingDirection: "drawingDirection",
|
||||||
@ -101,7 +101,7 @@
|
|||||||
const initialState = this.compute1dInitialState();
|
const initialState = this.compute1dInitialState();
|
||||||
const board = createBoard(
|
const board = createBoard(
|
||||||
initialState,
|
initialState,
|
||||||
this.rules.rules,
|
this.ruleset.rules,
|
||||||
this.boardWidth
|
this.boardWidth
|
||||||
);
|
);
|
||||||
this.lastBoard = Object.freeze(board);
|
this.lastBoard = Object.freeze(board);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<MenuRow row-title="Elementary Cellular Automata">
|
<MenuRow row-title="Elementary Automaton">
|
||||||
<form>
|
<form>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label>
|
<label>
|
||||||
@ -30,10 +30,10 @@
|
|||||||
<select
|
<select
|
||||||
name="ruleset-elementary"
|
name="ruleset-elementary"
|
||||||
:value="ruleset.name"
|
:value="ruleset.name"
|
||||||
@input="updateRules"
|
@input="updateRuleset"
|
||||||
>
|
>
|
||||||
<option
|
<option
|
||||||
v-for="(ruleset, index) in presetRules"
|
v-for="(ruleset, index) in presetRuleset"
|
||||||
:key="'ruleset-preset-elementary-' + index"
|
:key="'ruleset-preset-elementary-' + index"
|
||||||
:value="ruleset.name"
|
:value="ruleset.name"
|
||||||
>
|
>
|
||||||
@ -43,10 +43,10 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<a style="cursor: pointer" @click="copyRules">copy rules</a>
|
<a style="cursor: pointer" @click="copyRuleset">copy rules</a>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-for="(rule, name, index) in rules.rules"
|
v-for="(rule, name, index) in ruleset.rules"
|
||||||
:key="'rule-' + index"
|
:key="'rule-' + index"
|
||||||
class="form-field"
|
class="form-field"
|
||||||
>
|
>
|
||||||
@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapWritableState } from "pinia";
|
import { mapActions, mapWritableState } from "pinia";
|
||||||
import { presetRules, initialStates } from "./preset.js";
|
import { presetRuleset, initialStates } from "../modules/preset.js";
|
||||||
import { globalStore } from "../stores/index.js";
|
import { globalStore } from "../stores/index.js";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
export default {
|
export default {
|
||||||
@ -80,21 +80,21 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
presetRules: presetRules,
|
presetRuleset: presetRuleset,
|
||||||
initialStates: initialStates,
|
initialStates: initialStates,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapWritableState(globalStore, {
|
...mapWritableState(globalStore, {
|
||||||
initialState: "initial1dState",
|
initialState: "initial1dState",
|
||||||
rules: "rules1d",
|
ruleset: "ruleset1d",
|
||||||
}),
|
}),
|
||||||
rules1dFileName() {
|
rules1dFileName() {
|
||||||
// TODO: broken
|
// TODO: broken
|
||||||
return (
|
return (
|
||||||
Object.keys(this.rules)
|
Object.keys(this.ruleset)
|
||||||
.map((index) => {
|
.map((index) => {
|
||||||
return this.rules[index];
|
return this.ruleset[index];
|
||||||
})
|
})
|
||||||
.join("_") + ".json"
|
.join("_") + ".json"
|
||||||
);
|
);
|
||||||
@ -102,9 +102,9 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(globalStore, ["toggleDraw1d"]),
|
...mapActions(globalStore, ["toggleDraw1d"]),
|
||||||
copyRules() {
|
copyRuleset() {
|
||||||
const rules = JSON.stringify(this.rules);
|
const newRuleset = JSON.stringify(this.ruleset);
|
||||||
navigator.clipboard.writeText(rules);
|
navigator.clipboard.writeText(newRuleset);
|
||||||
},
|
},
|
||||||
isCurrentPreset(event) {
|
isCurrentPreset(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
@ -113,15 +113,15 @@
|
|||||||
updateSingleRule(event) {
|
updateSingleRule(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const value = elem.checked ? 1 : 0;
|
const value = elem.checked ? 1 : 0;
|
||||||
this.rules.rules[elem.name] = value;
|
this.ruleset.rules[elem.name] = value;
|
||||||
},
|
},
|
||||||
updateRules(event) {
|
updateRuleset(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const name = elem.value;
|
const name = elem.value;
|
||||||
const newRuleset = this.presetRules.find((ruleset) => {
|
const newRuleset = this.presetRuleset.find((ruleset) => {
|
||||||
return ruleset.name === name;
|
return ruleset.name === name;
|
||||||
});
|
});
|
||||||
this.rules.rules = newRuleset.rules;
|
this.ruleset = newRuleset;
|
||||||
},
|
},
|
||||||
updateInitialState(event) {
|
updateInitialState(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const presetRules = [
|
const presetRuleset = [
|
||||||
{
|
{
|
||||||
name: "rule 73",
|
name: "rule 73",
|
||||||
rules: {
|
rules: {
|
||||||
@ -92,4 +92,4 @@ const initialStates = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export { presetRules, initialStates };
|
export { presetRuleset, initialStates };
|
||||||
|
95
src/modules/preset.js
Normal file
95
src/modules/preset.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
const presetRuleset = [
|
||||||
|
{
|
||||||
|
name: "rule 73",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 1,
|
||||||
|
"010": 0,
|
||||||
|
"001": 0,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 86",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 0,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 1,
|
||||||
|
"001": 0,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 90",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 0,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 45?",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 1,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 54?",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 1,
|
||||||
|
"001": 1,
|
||||||
|
"000": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown rule",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 0,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const initialStates = [
|
||||||
|
{
|
||||||
|
id: "onecell",
|
||||||
|
name: "One cell at center",
|
||||||
|
description: "State with a single cell in the middle",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "random",
|
||||||
|
name: "Random cell",
|
||||||
|
description: "State populated with random cells",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export { presetRuleset, initialStates };
|
@ -3,7 +3,7 @@ import { defineStore } from "pinia";
|
|||||||
export const globalStore = defineStore("globalStore", {
|
export const globalStore = defineStore("globalStore", {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
rules1d: {
|
ruleset1d: {
|
||||||
name: "rule 73",
|
name: "rule 73",
|
||||||
rules: {
|
rules: {
|
||||||
111: 0,
|
111: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user