add addon tooltip to block picker
This commit is contained in:
parent
cfa5cea524
commit
3e2a17f5cd
|
|
@ -39,18 +39,21 @@ export async function buildAtlas(data) {
|
||||||
...Object.entries(data.configuration),
|
...Object.entries(data.configuration),
|
||||||
...data.addons.flatMap(a => Object.entries(a.configuration)),
|
...data.addons.flatMap(a => Object.entries(a.configuration)),
|
||||||
]
|
]
|
||||||
.flatMap(([config, data]) => Object.entries(data)
|
.map(([t, d]) => [t, d.modules["plannerator:configuration_metadata"], d])
|
||||||
.map(([type, entries]) => [config, type, entries]))
|
// .map(v => {console.log(v); return v})
|
||||||
.flatMap(([c, t, e]) => Array.isArray(e)
|
.flatMap(([config, addon, data]) => Object.entries(data)
|
||||||
? [[c, t, e]]
|
.map(([type, entries]) => [config, type, addon, entries]))
|
||||||
|
.flatMap(([c, t, a, e]) => Array.isArray(e)
|
||||||
|
? [[c, t, a, e]]
|
||||||
: t === "modules" && e["plannerator:global_elements"]
|
: t === "modules" && e["plannerator:global_elements"]
|
||||||
? [[c, "plannerator:global_elements", e["plannerator:global_elements"].elements]]
|
? [[c, "plannerator:global_elements", a, e["plannerator:global_elements"].elements]]
|
||||||
: [])
|
: [])
|
||||||
.flatMap(([c, t, l]) => l.map((v) => [c, t, v]))
|
.flatMap(([c, t, a, l]) => l.map((v) => [c, t, a, v]))
|
||||||
.filter(([,, b]) => b && b.modules && b.modules["plannerator:texture"])
|
.filter(([,,, b]) => b && b.modules && b.modules["plannerator:texture"])
|
||||||
.map(([c, t, b]) => ({
|
.map(([c, t, a, b]) => ({
|
||||||
configuration: c,
|
configuration: c,
|
||||||
configurationList: t,
|
configurationList: t,
|
||||||
|
configurationAddon: a,
|
||||||
texture: b.modules["plannerator:texture"].texture,
|
texture: b.modules["plannerator:texture"].texture,
|
||||||
...(Object.fromEntries(Object.entries(b).filter(([k]) => k !== "modules")))
|
...(Object.fromEntries(Object.entries(b).filter(([k]) => k !== "modules")))
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export class Filter {
|
||||||
test(...data) {
|
test(...data) {
|
||||||
for (const datum of data) {
|
for (const datum of data) {
|
||||||
if (typeof datum !== "string") {
|
if (typeof datum !== "string") {
|
||||||
console.log("cannot test %o", datum);
|
console.trace("cannot test %o", datum);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ window.addEventListener("load", () => {
|
||||||
|
|
||||||
emitEvent("setup-end");
|
emitEvent("setup-end");
|
||||||
|
|
||||||
void loadConfiguration("catastrophe");
|
void loadConfiguration("addons");
|
||||||
|
|
||||||
awaitEvent("config:end").then(() => loadExampleFile("tiny reactor"));
|
awaitEvent("config:end").then(() => loadExampleFile("tiny reactor"));
|
||||||
// awaitEvent("config:end").then(() => loadExampleFile("multi-reactor"));
|
// awaitEvent("config:end").then(() => loadExampleFile("multi-reactor"));
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { atlases, makeAtlasImage } from "./atlas.js";
|
||||||
import { DomList } from "./dom-list.js";
|
import { DomList } from "./dom-list.js";
|
||||||
import { emitEvent, listenTo } from "./events.js";
|
import { emitEvent, listenTo } from "./events.js";
|
||||||
import { Filter } from "./filter.js";
|
import { Filter } from "./filter.js";
|
||||||
import { createTooltip } from "./tooltip.js";
|
import { createTooltip, tooltipDataToPlain } from "./tooltip.js";
|
||||||
import { lookupFromMetadata, resolveBlockName } from "./ncpf-utils.js";
|
import { lookupFromMetadata, resolveBlockName } from "./ncpf-utils.js";
|
||||||
import { addEventToButton } from "./dom-utils.js";
|
import { addEventToButton } from "./dom-utils.js";
|
||||||
|
|
||||||
|
|
@ -134,15 +134,14 @@ function buildBlockPicker() {
|
||||||
const grid = new DomList(document.querySelector("#block-list"));
|
const grid = new DomList(document.querySelector("#block-list"));
|
||||||
grid.clear();
|
grid.clear();
|
||||||
|
|
||||||
const blocks = atlases.flatMap(a => a.metadata)
|
atlases.flatMap(a => a.metadata)
|
||||||
.filter(m => m.configuration === multiblockType && m.configurationList === "blocks");
|
.filter(m => m.configuration === multiblockType && m.configurationList === "blocks")
|
||||||
console.log(blocks);
|
.forEach(m => {
|
||||||
blocks.forEach(m => {
|
|
||||||
const item = grid.makeItem();
|
const item = grid.makeItem();
|
||||||
item.dataset.index = m.index.toString(10);
|
item.dataset.index = m.index.toString(10);
|
||||||
const tooltipData = [...getBlockTooltip(m)];
|
const tooltipData = [...getBlockTooltip(m)];
|
||||||
item.dataset.tooltip = createTooltip(tooltipData).toString(10);
|
item.dataset.tooltip = createTooltip(tooltipData).toString(10);
|
||||||
if (!filter.test(...tooltipData)) {
|
if (!filter.test(...tooltipDataToPlain(tooltipData))) {
|
||||||
item.classList.add("hidden");
|
item.classList.add("hidden");
|
||||||
}
|
}
|
||||||
item.appendChild(makeAtlasImage(m.index));
|
item.appendChild(makeAtlasImage(m.index));
|
||||||
|
|
@ -297,6 +296,11 @@ function* getBlockTooltip(metadata) {
|
||||||
if (!hasAdditionalData) {
|
if (!hasAdditionalData) {
|
||||||
console.log("unknown block", data);
|
console.log("unknown block", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yield {
|
||||||
|
type: "italics",
|
||||||
|
text: metadata.configurationAddon.name,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseRuleAsTooltip(rule, props) {
|
function parseRuleAsTooltip(rule, props) {
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,31 @@ function createTooltipDom(id) {
|
||||||
if (typeof row === "string") {
|
if (typeof row === "string") {
|
||||||
rowElem.innerText = row;
|
rowElem.innerText = row;
|
||||||
} else {
|
} else {
|
||||||
// TODO: support rich tooltips
|
if (!row.type) {
|
||||||
throw row;
|
throw row;
|
||||||
}
|
}
|
||||||
|
// TODO: support richer tooltips
|
||||||
|
if (row.type === "italics") {
|
||||||
|
rowElem.innerText = row.text;
|
||||||
|
rowElem.classList.add("italics");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
div.appendChild(rowElem);
|
div.appendChild(rowElem);
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function tooltipDataToPlain(data) {
|
||||||
|
if (!Array.isArray(data)) {
|
||||||
|
console.warn("tooltip data is not an array: %o", data);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.flatMap(row => {
|
||||||
|
if (typeof row === "string") return row;
|
||||||
|
if (!row.type) return [];
|
||||||
|
if (row.text) return row.text;
|
||||||
|
return [];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue