explorata/src/stores/index.js

115 lines
2.8 KiB
JavaScript

import { defineStore } from "pinia";
import { Board } from "../modules/board.js";
import { Renderer } from "../modules/renderer.js";
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",
},
initial1dState: "onecell",
drawingDirection: "y",
board: new Board(),
draw1d: false,
draw2d: false,
draw2dLast: false,
draw2dpicture: false,
reset: false,
canDraw: true,
picture: new Image(),
mainMenu: false,
activeSubMenu: "",
loop: false,
lastAction: "drawfromlast",
renderer: new Renderer(),
};
},
actions: {
setBoardWidth() {
this.board.width = Math.floor(
this.renderer.width / this.board.cellProperties.size
);
},
setBoardHeight() {
this.board.height = Math.floor(
this.renderer.height / this.board.cellProperties.size
);
},
setCellProperties(name, value) {
this.board.cellProperties[name] = value;
},
switchColor() {
[
this.board.cellProperties["liveColor"],
this.board.cellProperties["deadColor"],
] = [
this.board.cellProperties["deadColor"],
this.board.cellProperties["liveColor"],
];
},
toggleDraw1d() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.draw1d = !this.draw1d;
},
toggleDraw2d() {
this.setActiveSubMenu("");
this.lastAction = "draw2d";
this.setMainMenu(false);
this.toggleStop();
this.canDraw = !this.canDraw;
this.draw2d = !this.draw2d;
},
toggleDraw2dLast() {
this.setActiveSubMenu("");
this.lastAction = "drawfromlast";
this.setMainMenu(false);
this.toggleStop();
this.canDraw = !this.canDraw;
this.draw2dLast = !this.draw2dLast;
},
toggle2dDrawFromPicture() {
this.toggleStop();
this.canDraw = !this.canDraw;
this.draw2dpicture = !this.draw2dpicture;
},
toggleReset() {
this.toggleStop();
this.reset = !this.reset;
},
toggleStop() {
this.draw1d = false;
this.draw2d = false;
this.draw2dLast = false;
this.draw2dpicture = false;
this.canDraw = false;
},
toggleLoop() {
this.loop = !this.loop;
},
setActiveSubMenu(data) {
if (this.activeSubMenu == data) this.activeSubMenu = "";
else this.activeSubMenu = data;
},
setMainMenu(data) {
this.mainMenu = data;
},
},
});