2021-03-27 00:47:22 +00:00
|
|
|
import React, { useContext, useState } from "react";
|
|
|
|
import { AutoSizingSvg } from "../auto-sizing-svg";
|
|
|
|
import { CreatureContext, CreatureContextType } from "../creature-symbol";
|
|
|
|
import { createCreatureSymbolFactory } from "../creature-symbol-factory";
|
|
|
|
import { HoverDebugHelper } from "../hover-debug-helper";
|
Improve layout (#74)
This improves the layout of all our pages to look more like the mandala page.
Additionally, some form widgets now have better layout, and the header takes up less vertical space.
At an implementation level, the component hierarchy of pages has been inverted to make this kind of layout easier. Now fully laid-out pages are contained within `<Page>` components that are at the top of the component hierarchy, and which are defined by each specific page (mandala, creature, vocabulary, etc).
I had to do a few architectural things to avoid circular imports, though; most notably, this involved the creation of a new React context called a `PageContext`.
It uses CSS grid, which should be pretty well-supported amongst recent browsers.
2021-04-02 23:00:29 +00:00
|
|
|
import { Page } from "../page";
|
2021-04-17 11:33:27 +00:00
|
|
|
import { PaletteAlgorithmWidget } from "../palette-algorithm-widget";
|
2021-04-08 00:08:55 +00:00
|
|
|
import { Random } from "../random";
|
2021-04-17 11:33:27 +00:00
|
|
|
import {
|
|
|
|
createRandomColorPalette,
|
|
|
|
DEFAULT_RANDOM_PALETTE_ALGORITHM,
|
|
|
|
RandomPaletteAlgorithm,
|
|
|
|
} from "../random-colors";
|
2021-03-27 00:47:22 +00:00
|
|
|
import { createSvgSymbolContext } from "../svg-symbol";
|
2021-03-28 10:39:06 +00:00
|
|
|
import { svgScale, SvgTransform } from "../svg-transform";
|
2021-03-27 12:29:42 +00:00
|
|
|
import { SvgVocabulary } from "../svg-vocabulary";
|
2021-03-27 00:47:22 +00:00
|
|
|
import { SymbolContextWidget } from "../symbol-context-widget";
|
2021-04-08 00:08:55 +00:00
|
|
|
import { range } from "../util";
|
2021-03-27 00:47:22 +00:00
|
|
|
|
2021-03-27 12:29:42 +00:00
|
|
|
const symbol = createCreatureSymbolFactory(SvgVocabulary);
|
2021-03-27 00:47:22 +00:00
|
|
|
|
|
|
|
const Eye = symbol("eye");
|
|
|
|
|
|
|
|
const Hand = symbol("hand");
|
|
|
|
|
|
|
|
const Arm = symbol("arm");
|
|
|
|
|
|
|
|
const Antler = symbol("antler");
|
|
|
|
|
|
|
|
const Crown = symbol("crown");
|
|
|
|
|
|
|
|
const Wing = symbol("wing");
|
|
|
|
|
|
|
|
const MuscleArm = symbol("muscle_arm");
|
|
|
|
|
|
|
|
const Leg = symbol("leg");
|
|
|
|
|
|
|
|
const Tail = symbol("tail");
|
|
|
|
|
|
|
|
const Lightning = symbol("lightning");
|
|
|
|
|
|
|
|
const EYE_CREATURE = (
|
|
|
|
<Eye>
|
|
|
|
<Lightning nestInside />
|
|
|
|
<Arm attachTo="arm" left>
|
|
|
|
<Wing attachTo="arm" left right />
|
|
|
|
</Arm>
|
|
|
|
<Arm attachTo="arm" right>
|
|
|
|
<MuscleArm attachTo="arm" left right />
|
|
|
|
</Arm>
|
|
|
|
<Antler attachTo="horn" left right />
|
|
|
|
<Crown attachTo="crown">
|
|
|
|
<Hand attachTo="horn" left right>
|
|
|
|
<Arm attachTo="arm" left />
|
|
|
|
</Hand>
|
|
|
|
</Crown>
|
|
|
|
<Leg attachTo="leg" left right />
|
|
|
|
<Tail attachTo="tail" invert />
|
|
|
|
</Eye>
|
|
|
|
);
|
|
|
|
|
2021-04-08 00:08:55 +00:00
|
|
|
const RandomColorSampling: React.FC<{}> = () => {
|
2021-04-17 11:33:27 +00:00
|
|
|
const [paletteAlg, setPaletteAlg] = useState<RandomPaletteAlgorithm>(
|
|
|
|
DEFAULT_RANDOM_PALETTE_ALGORITHM
|
|
|
|
);
|
2021-04-08 00:08:55 +00:00
|
|
|
const [seed, setSeed] = useState(Date.now());
|
|
|
|
const NUM_COLORS = 100;
|
|
|
|
const rng = new Random(seed);
|
2021-04-17 11:33:27 +00:00
|
|
|
const palette = createRandomColorPalette(NUM_COLORS, rng, paletteAlg);
|
2021-04-08 00:08:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-04-17 11:33:27 +00:00
|
|
|
<PaletteAlgorithmWidget value={paletteAlg} onChange={setPaletteAlg} />
|
2021-04-08 00:08:55 +00:00
|
|
|
<div className="thingy">
|
|
|
|
<div style={{ fontSize: 0 }}>
|
|
|
|
{range(NUM_COLORS).map((i) => (
|
|
|
|
<div
|
2021-04-17 11:33:27 +00:00
|
|
|
key={i}
|
2021-04-08 00:08:55 +00:00
|
|
|
style={{
|
|
|
|
backgroundColor: palette[i],
|
|
|
|
width: "1rem",
|
|
|
|
height: "1rem",
|
|
|
|
display: "inline-block",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="thingy">
|
|
|
|
<button onClick={() => setSeed(Date.now())}>Regenerate colors</button>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-03-27 00:47:22 +00:00
|
|
|
export const DebugPage: React.FC<{}> = () => {
|
|
|
|
const [symbolCtx, setSymbolCtx] = useState(createSvgSymbolContext());
|
|
|
|
const defaultCtx = useContext(CreatureContext);
|
|
|
|
const ctx: CreatureContextType = {
|
|
|
|
...defaultCtx,
|
|
|
|
...symbolCtx,
|
|
|
|
fill: symbolCtx.showSpecs ? "none" : symbolCtx.fill,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
Improve layout (#74)
This improves the layout of all our pages to look more like the mandala page.
Additionally, some form widgets now have better layout, and the header takes up less vertical space.
At an implementation level, the component hierarchy of pages has been inverted to make this kind of layout easier. Now fully laid-out pages are contained within `<Page>` components that are at the top of the component hierarchy, and which are defined by each specific page (mandala, creature, vocabulary, etc).
I had to do a few architectural things to avoid circular imports, though; most notably, this involved the creation of a new React context called a `PageContext`.
It uses CSS grid, which should be pretty well-supported amongst recent browsers.
2021-04-02 23:00:29 +00:00
|
|
|
<Page title="Debug!">
|
|
|
|
<div className="sidebar">
|
|
|
|
<SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx} />
|
2021-04-08 00:08:55 +00:00
|
|
|
<h2>Random color sampling</h2>
|
|
|
|
<RandomColorSampling />
|
Improve layout (#74)
This improves the layout of all our pages to look more like the mandala page.
Additionally, some form widgets now have better layout, and the header takes up less vertical space.
At an implementation level, the component hierarchy of pages has been inverted to make this kind of layout easier. Now fully laid-out pages are contained within `<Page>` components that are at the top of the component hierarchy, and which are defined by each specific page (mandala, creature, vocabulary, etc).
I had to do a few architectural things to avoid circular imports, though; most notably, this involved the creation of a new React context called a `PageContext`.
It uses CSS grid, which should be pretty well-supported amongst recent browsers.
2021-04-02 23:00:29 +00:00
|
|
|
</div>
|
|
|
|
<div className="canvas">
|
|
|
|
<CreatureContext.Provider value={ctx}>
|
|
|
|
<HoverDebugHelper>
|
|
|
|
<AutoSizingSvg padding={20}>
|
|
|
|
<SvgTransform transform={svgScale(0.5)}>
|
|
|
|
{EYE_CREATURE}
|
|
|
|
</SvgTransform>
|
|
|
|
</AutoSizingSvg>
|
|
|
|
</HoverDebugHelper>
|
|
|
|
</CreatureContext.Provider>
|
|
|
|
</div>
|
|
|
|
</Page>
|
2021-03-27 00:47:22 +00:00
|
|
|
);
|
|
|
|
};
|