2023-07-09 13:22:38 -04:00
|
|
|
import { Html, debug_render } from "./html.ts";
|
2023-07-09 13:21:24 -04:00
|
|
|
import { Component } from "./jsx/jsx-runtime.ts";
|
|
|
|
|
|
|
|
type DOption = [Html, Dialogue];
|
|
|
|
type Dialogue = Html | [Html, ...DOption[]];
|
|
|
|
|
|
|
|
function not_empty<T>(arr: T[]): arr is [T, ...T[]] {
|
|
|
|
return arr.length > 0;
|
|
|
|
}
|
|
|
|
|
2023-07-10 05:51:25 -04:00
|
|
|
export function reify_dialogue(d: Dialogue): Html {
|
2023-07-09 13:21:24 -04:00
|
|
|
if (!Array.isArray(d)) return d;
|
|
|
|
|
|
|
|
const [r, ...rest] = d;
|
|
|
|
if (rest.length == 0) {
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div class="dialogue">
|
|
|
|
{r}
|
|
|
|
{...rest.map(([r, d]) => {
|
|
|
|
return (
|
|
|
|
<details>
|
|
|
|
<summary class="option">{r}</summary>
|
|
|
|
<div class="response">{reify_dialogue(d)}</div>
|
|
|
|
</details>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|