diff --git a/editor-solidjs/src/Editor.jsx b/editor-solidjs/src/Editor.jsx
index bf53039..1bcdeb2 100644
--- a/editor-solidjs/src/Editor.jsx
+++ b/editor-solidjs/src/Editor.jsx
@@ -16,10 +16,27 @@ import Controls from "./Controls.jsx";
import {World, Pane} from "../stackline-wasm/stackline_wasm.js";
-let json = await (await fetch("/prime.json")).json();
+// let json = await (await fetch("/prime.json")).json();
+
+let new_world = window.localStorage.getItem("world");
export default function Editor() {
- let [world, setWorld] = createSignal(World.deserialize(json), {equals: false});
+ let start_world = window.localStorage.getItem("world");
+
+ try {
+ if (start_world) {
+ start_world = JSON.parse(start_world);
+ start_world = World.deserialize(start_world);
+ } else {
+ start_world = new World();
+ }
+ } catch (err) {
+ console.error(err);
+ start_world = new World();
+ }
+
+ let [world, setWorld] = createSignal(start_world, {equals: false});
+ start_world = null;
world.init = () => setWorld((world) => {
world.init();
@@ -39,13 +56,13 @@ export default function Editor() {
});
setWorld((world) => {
- let tile = world.get(4, 0);
- tile.signal = {direction: "Up", stack: []};
- tile.state = "Active";
- world.set(4, 0, tile);
- world.init();
+ // let tile = world.get(4, 0);
+ // tile.signal = {direction: "Up", stack: []};
+ // tile.state = "Active";
+ // world.set(4, 0, tile);
+ // world.init();
- console.log(world.toString());
+ // console.log(world.toString());
return world;
});
@@ -108,7 +125,7 @@ export default function Editor() {
}
});
- let [left_pane, presets] = LeftPane({settings, setSettings});
+ let [left_pane, presets] = LeftPane({settings, setSettings, world, setWorld});
let last_click = 0, last_selected = null;
const DOUBLE_CLICK_DURATION = 250;
diff --git a/editor-solidjs/src/LeftPane.jsx b/editor-solidjs/src/LeftPane.jsx
index 7d8d9f6..b706f53 100644
--- a/editor-solidjs/src/LeftPane.jsx
+++ b/editor-solidjs/src/LeftPane.jsx
@@ -1,42 +1,16 @@
-import {createSignal} from "solid-js";
-import {createStore} from "solid-js/store";
+import {onMount, onCleanup} from "solid-js";
+import Tabbed from "./Tabbed.jsx";
-import styles from "./LeftPane.module.css";
-
-import {available_tiles, Pane, FullTile} from "../stackline-wasm/stackline_wasm.js";
-import TilePreset from "./TilePreset.jsx";
-
-export const BASE_TILES = [];
-
-export class Tile {
- constructor(serialized, name) {
- this.serialized = serialized;
- this.name = name;
- }
-}
-
-export function init() {
- let pane = new Pane(1, 1);
- BASE_TILES.push(new Tile(pane.serialize(), "Empty"));
- pane.free();
+import Presets, {init} from "./Presets.jsx";
+import Panes from "./Panes.jsx";
- for (let name of available_tiles().sort()) {
- let pane = new Pane(1, 1);
-
- let tile = new FullTile(name);
- pane.set(0, 0, tile);
+import styles from "./LeftPane.module.css";
- let serialized = pane.serialize();
-
- pane.free();
- BASE_TILES.push(new Tile(serialized, name));
- }
-}
+export {init};
export default function LeftPane(props) {
- let [preset, setPresets] = createStore(BASE_TILES);
- let {settings, setSettings} = props;
- let left_pane;
+ let [preset_picker, presets] = Presets(props);
+ let container;
function resize() {
let width = document.body.clientWidth / 4;
@@ -48,30 +22,29 @@ export default function LeftPane(props) {
width = 125;
}
- left_pane.style.width = `${Math.round(width)}px`;
+ container.style.width = `calc(${Math.round(width)}px + 2em)`;
}
- function set_resize() {
+ onMount(() => {
setTimeout(() => {
window.addEventListener("resize", resize);
resize();
}, 0);
- }
+ });
- function remove_resize() {
+ onCleanup(() => {
window.removeEventListener("resize", resize);
- }
+ });
return [
-
- {(item, index) => {
- return item.serialized} name={() => item.name} settings={settings} setSettings={setSettings} index={index} />;
- }}
-
-
, preset];
+
+ {preset_picker}
+
+
+ , presets];
}
diff --git a/editor-solidjs/src/LeftPane.module.css b/editor-solidjs/src/LeftPane.module.css
index 2e50180..fd36735 100644
--- a/editor-solidjs/src/LeftPane.module.css
+++ b/editor-solidjs/src/LeftPane.module.css
@@ -1,7 +1,7 @@
.LeftPane_container {
background: #18181b;
color: white;
- padding: 1.5em 1em;
+ /* padding: 1.5em 1em; */
font-family: monospace;
font-size: 15px;
flex-shrink: 0;
@@ -11,6 +11,9 @@
.LeftPane {
width: 25vw;
+}
+
+.Presets {
display: grid;
grid-template-columns: repeat(auto-fill, calc(8em));
grid-gap: 1em;
@@ -48,3 +51,7 @@
.TilePreset.picked:hover {
border: 4px solid white;
}
+
+.indent {
+ padding-left: 1em;
+}
diff --git a/editor-solidjs/src/Panes.jsx b/editor-solidjs/src/Panes.jsx
new file mode 100644
index 0000000..f2def71
--- /dev/null
+++ b/editor-solidjs/src/Panes.jsx
@@ -0,0 +1,73 @@
+import {createMemo} from "solid-js";
+import Number from "./input/Number.jsx";
+import styles from "./LeftPane.module.css";
+import input_styles from "./input/input.module.css";
+import {Pane} from "../stackline-wasm/stackline_wasm.js";
+
+export default function Panes(props) {
+ let {world, setWorld} = props;
+
+ let panes = createMemo(() => {
+ let world = props.world();
+
+ let res = [];
+
+ for (let pane_name of world.panes()) {
+ let pane = world.get_pane(pane_name);
+
+ res.push({
+ x: pane.x,
+ y: pane.y,
+ width: pane.width,
+ height: pane.height,
+ name: pane_name,
+ });
+
+ pane.free();
+ }
+
+ return res;
+ });
+
+ return (
+
+
+ {(item, _index) => {
+ function setProp(name) {
+ return function(value) {
+ setWorld((world) => {
+ let pane = world.get_pane(item.name);
+ pane[name] = value;
+ world.set_pane(item.name, pane);
+ return world;
+ });
+ }
+ }
+
+ return -
+ {item.name}:
+
+
X: item.x} setValue={setProp("x")} />
+
Y: item.y} setValue={setProp("y")} />
+
Width: item.width} setValue={setProp("width")} />
+
Height: item.height} setValue={setProp("height")} />
+
+ ;
+ }}
+
+
+
+
);
+}
diff --git a/editor-solidjs/src/Presets.jsx b/editor-solidjs/src/Presets.jsx
new file mode 100644
index 0000000..e06f181
--- /dev/null
+++ b/editor-solidjs/src/Presets.jsx
@@ -0,0 +1,47 @@
+import {createSignal} from "solid-js";
+import {createStore} from "solid-js/store";
+
+import styles from "./LeftPane.module.css";
+
+import {available_tiles, Pane, FullTile} from "../stackline-wasm/stackline_wasm.js";
+import TilePreset from "./TilePreset.jsx";
+
+export const BASE_TILES = [];
+
+export class Tile {
+ constructor(serialized, name) {
+ this.serialized = serialized;
+ this.name = name;
+ }
+}
+
+export function init() {
+ let pane = new Pane(1, 1);
+ BASE_TILES.push(new Tile(pane.serialize(), "Empty"));
+ pane.free();
+
+ for (let name of available_tiles().sort()) {
+ let pane = new Pane(1, 1);
+
+ let tile = new FullTile(name);
+ pane.set(0, 0, tile);
+
+ let serialized = pane.serialize();
+
+ pane.free();
+ BASE_TILES.push(new Tile(serialized, name));
+ }
+}
+
+export default function Presets(props) {
+ let [presets, setPresets] = createStore(BASE_TILES);
+ let {settings, setSettings} = props;
+
+ return [
+
+ {(item, index) => {
+ return item.serialized} name={() => item.name} settings={settings} setSettings={setSettings} index={index} />;
+ }}
+
+
, presets];
+}
diff --git a/editor-solidjs/src/Signal.jsx b/editor-solidjs/src/Signal.jsx
index aa8d5df..f74d569 100644
--- a/editor-solidjs/src/Signal.jsx
+++ b/editor-solidjs/src/Signal.jsx
@@ -43,47 +43,6 @@ export default function Signal(props) {
} : null;
return item} setValue={setValue} />;
-
- // if (setSignal) {
- // if ("Number" in item) {
- // // Return number input for the `index()`-th element
- // return
- // {
- // console.log("input");
- // setSignal((signal) => {
- // signal.stack[index()] = {"Number": +evt.currentTarget.value};
- // return signal;
- // });
- // }}
- // />
- // ;
- // } else if ("String" in item) {
- // // Return string input for the `index()`-th element
- // return "
- // {
- // setSignal((signal) => {
- // signal.stack[index()] = {"String": evt.currentTarget.value};
- // return signal;
- // });
- // }}
- // />
- // ";
- // }
- // } else {
- // if (item?.["Number"]) {
- // return {item["Number"]};
- // } else if (item?.["String"]) {
- // return "{item["String"]}";
- // }
- // }
}}
diff --git a/editor-solidjs/src/Tabbed.jsx b/editor-solidjs/src/Tabbed.jsx
index c280aa6..82b520e 100644
--- a/editor-solidjs/src/Tabbed.jsx
+++ b/editor-solidjs/src/Tabbed.jsx
@@ -6,6 +6,8 @@ export default function Tabbed(props) {
let children = props.children;
+ if (!Array.isArray(children)) children = [children];
+
return