parent
0ed5df3fcc
commit
aa495b8747
@ -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 (<div>
|
||||
<ol>
|
||||
<For each={panes()}>
|
||||
{(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 <li>
|
||||
<span>{item.name}</span>:
|
||||
<div class={styles.indent}>
|
||||
<div>X: <Number value={() => item.x} setValue={setProp("x")} /></div>
|
||||
<div>Y: <Number value={() => item.y} setValue={setProp("y")} /></div>
|
||||
<div>Width: <Number value={() => item.width} setValue={setProp("width")} /></div>
|
||||
<div>Height: <Number value={() => item.height} setValue={setProp("height")} /></div>
|
||||
</div>
|
||||
</li>;
|
||||
}}
|
||||
</For>
|
||||
</ol>
|
||||
<button
|
||||
class={input_styles.button}
|
||||
aria-label="Add a new Pane to the World"
|
||||
title="Add Pane"
|
||||
onClick={() => {
|
||||
setWorld((world) => {
|
||||
let name = `pane-${world.panes().length + 1}`;
|
||||
let pane = new Pane(1, 1);
|
||||
world.set_pane(name, pane);
|
||||
return world;
|
||||
});
|
||||
}}
|
||||
>+</button>
|
||||
</div>);
|
||||
}
|
@ -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 [<div class={styles.Presets}>
|
||||
<For each={BASE_TILES}>
|
||||
{(item, index) => {
|
||||
return <TilePreset pane={() => item.serialized} name={() => item.name} settings={settings} setSettings={setSettings} index={index} />;
|
||||
}}
|
||||
</For>
|
||||
</div>, presets];
|
||||
}
|
Loading…
Reference in new issue