hmm?
This commit is contained in:
parent
9ef1b8dbb1
commit
d875df8600
22 changed files with 625 additions and 496 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const SCALABLE_TOOLS = new Set(scalableToolIds());
|
||||
const EMOJI_ICON_TOOLS = new Set(["poke", "pinch", "water_hose"]);
|
||||
|
||||
const SIZE_ORDER = typeof TOOL_SIZE_ORDER !== "undefined" ? TOOL_SIZE_ORDER : ["small", "medium", "large"];
|
||||
|
||||
|
|
@ -26,8 +27,13 @@ function renderToolPalette() {
|
|||
if (!def || def.simulationOnly) continue;
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "tool";
|
||||
if (EMOJI_ICON_TOOLS.has(toolId)) btn.classList.add("tool-emoji-icon");
|
||||
btn.dataset.tool = toolId;
|
||||
btn.textContent = def.label || toolId;
|
||||
const label = document.createElement("span");
|
||||
label.className = "tool-label";
|
||||
label.textContent = def.label || toolId;
|
||||
btn.title = label.textContent;
|
||||
btn.appendChild(label);
|
||||
attachToolSpritePreview(btn, def, toolId);
|
||||
if (toolId === world?.tool) btn.classList.add("selected");
|
||||
body.appendChild(btn);
|
||||
|
|
@ -38,32 +44,47 @@ function renderToolPalette() {
|
|||
ui.toolPalette.appendChild(frag);
|
||||
}
|
||||
|
||||
function drawToolPreviewCanvas(canvas, itemType, { watermark = false } = {}) {
|
||||
if (!canvas || !itemType) return false;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return false;
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
if (typeof window.drawToolItemPreview === "function") {
|
||||
return window.drawToolItemPreview(ctx, itemType, { width: canvas.width, height: canvas.height, compact: true, watermark }) !== false;
|
||||
}
|
||||
if (typeof window.isConsumableSpriteType === "function" && window.isConsumableSpriteType(itemType) && typeof window.drawConsumableFieldSprite === "function") {
|
||||
ctx.save();
|
||||
ctx.translate(canvas.width / 2, canvas.height / 2);
|
||||
const baseScale = itemType === "protein" || itemType === "niteropu" ? 0.9 : 1.0;
|
||||
ctx.scale(baseScale, baseScale);
|
||||
window.drawConsumableFieldSprite(ctx, itemType, 17.5, 112.4, { compact: true });
|
||||
ctx.restore();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function createToolPreviewCanvas(className, size = 96) {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.className = className;
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
canvas.setAttribute("aria-hidden", "true");
|
||||
return canvas;
|
||||
}
|
||||
|
||||
function attachToolSpritePreview(btn, def, toolId) {
|
||||
const itemType = def?.itemType || toolId;
|
||||
if (!btn || !itemType || !def?.placeable) return;
|
||||
if (toolId === "ball" || itemType === "ball") return;
|
||||
const drawPreview = window.drawToolItemPreview || window.drawConsumableFieldSprite;
|
||||
if (typeof drawPreview !== "function") return;
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.className = "tool-sprite-preview";
|
||||
canvas.width = 72;
|
||||
canvas.height = 72;
|
||||
canvas.setAttribute("aria-hidden", "true");
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
let drawn = false;
|
||||
if (typeof window.drawToolItemPreview === "function") {
|
||||
drawn = window.drawToolItemPreview(ctx, itemType, { width: canvas.width, height: canvas.height, compact: true }) !== false;
|
||||
} else if (typeof window.isConsumableSpriteType === "function" && window.isConsumableSpriteType(itemType)) {
|
||||
ctx.translate(canvas.width / 2, canvas.height / 2);
|
||||
const scale = itemType === "protein" || itemType === "niteropu" ? 0.82 : 0.92;
|
||||
ctx.scale(scale, scale);
|
||||
window.drawConsumableFieldSprite(ctx, itemType, 13.5, 112.4, { compact: true });
|
||||
drawn = true;
|
||||
}
|
||||
if (!drawn) return;
|
||||
if (typeof window.drawToolItemPreview !== "function" && typeof window.drawConsumableFieldSprite !== "function") return;
|
||||
|
||||
const iconCanvas = createToolPreviewCanvas("tool-sprite-preview", 160);
|
||||
const iconDrawn = drawToolPreviewCanvas(iconCanvas, itemType);
|
||||
if (!iconDrawn) return;
|
||||
|
||||
btn.classList.add("tool-has-canvas-icon");
|
||||
btn.prepend(canvas);
|
||||
btn.prepend(iconCanvas);
|
||||
}
|
||||
|
||||
function toolSizeFor(tool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue