explorata/src/stores/index.js

102 lines
2.3 KiB
JavaScript

import { defineStore } from "pinia";
export const globalStore = defineStore("globalStore", {
state: () => {
return {
ruleset1d: {
name: "rule 73",
rules: {
111: 0,
110: 1,
101: 0,
100: 0,
"011": 1,
"010": 0,
"001": 0,
"000": 1,
},
},
selected2dRules: {
id: "conway",
name: "Conway's Game of Life",
description: "The most popular 2d automata",
},
cellProperties: {
size: 3,
liveColor: "#000000",
deadColor: "#F5F5F5",
},
canvasWidth: 0,
canvasHeight: 0,
boardWidth: 0,
boardHeight: 0,
refreshRate: 300,
initial1dState: "onecell",
drawingDirection: "y",
lastBoard: null,
draw1d: false,
draw2d: false,
draw2dLast: false,
draw2dpicture: false,
reset: false,
canDraw: true,
picture: null,
mainMenu: false,
activeSubMenu: "",
loop: true,
};
},
actions: {
setBoardWidth() {
this.boardWidth = Math.floor(this.canvasWidth / this.cellProperties.size);
},
setBoardHeight() {
this.boardHeight = Math.floor(
this.canvasHeight / this.cellProperties.size
);
},
toggleDraw1d() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.draw1d = true;
},
toggleDraw2d() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.toggleStop();
this.canDraw = true;
this.draw2d = true;
},
toggleDraw2dLast() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.toggleStop();
this.canDraw = true;
this.draw2dLast = true;
},
toggle2dDrawFromPicture() {
this.toggleStop();
this.canDraw = true;
this.draw2dpicture = true;
},
toggleReset() {
this.toggleStop();
this.reset = true;
},
toggleStop() {
this.draw1d = false;
this.draw2d = false;
this.draw2dLast = false;
this.draw2dpicture = false;
this.canDraw = false;
},
setActiveSubMenu(data) {
if (this.activeSubMenu == data) this.activeSubMenu = "";
else this.activeSubMenu = data;
},
setMainMenu(data) {
this.mainMenu = data;
},
},
});