Fixed palettes
This commit is contained in:
parent
9fe261610f
commit
93bc6e7a07
6 changed files with 328 additions and 100 deletions
|
|
@ -13,6 +13,18 @@ const GLYPHS = {
|
|||
'7': ['111', '001', '001', '001', '001'],
|
||||
'8': ['111', '101', '111', '101', '111'],
|
||||
'9': ['111', '101', '111', '001', '111'],
|
||||
'a': ['010', '101', '111', '101', '101'],
|
||||
'b': ['110', '101', '110', '101', '110'],
|
||||
'c': ['111', '100', '100', '100', '111'],
|
||||
'd': ['110', '101', '101', '101', '110'],
|
||||
'e': ['111', '100', '110', '100', '111'],
|
||||
'f': ['111', '100', '110', '100', '100'],
|
||||
'p': ['110', '101', '110', '100', '100'],
|
||||
't': ['111', '010', '010', '010', '010'],
|
||||
'#': ['101', '111', '101', '111', '101'],
|
||||
':': ['000', '010', '000', '010', '000'],
|
||||
'/': ['001', '001', '010', '100', '100'],
|
||||
'-': ['000', '000', '111', '000', '000'],
|
||||
};
|
||||
|
||||
function clearCanvas(width, height, background = null) {
|
||||
|
|
@ -87,6 +99,18 @@ function drawLabel(canvas, canvasWidth, canvasHeight, text, x, y) {
|
|||
}
|
||||
}
|
||||
|
||||
function drawBoundingBox(canvas, canvasWidth, canvasHeight, x, y, width, height, alpha = 220) {
|
||||
if (width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
// Top + bottom edges
|
||||
fillRect(canvas, canvasWidth, canvasHeight, x, y, width, 1, 255, 255, 255, alpha);
|
||||
fillRect(canvas, canvasWidth, canvasHeight, x, y + height - 1, width, 1, 255, 255, 255, alpha);
|
||||
// Left + right edges
|
||||
fillRect(canvas, canvasWidth, canvasHeight, x, y, 1, height, 255, 255, 255, alpha);
|
||||
fillRect(canvas, canvasWidth, canvasHeight, x + width - 1, y, 1, height, 255, 255, 255, alpha);
|
||||
}
|
||||
|
||||
function blitRgba(canvas, canvasWidth, canvasHeight, sprite, dstX, dstY, flipped = false) {
|
||||
for (let y = 0; y < sprite.height; y += 1) {
|
||||
const canvasY = dstY + y;
|
||||
|
|
@ -148,15 +172,37 @@ export function renderMap(items, options = {}) {
|
|||
}
|
||||
|
||||
if (options.drawLabels) {
|
||||
// Cap labels at 10 instances per (typeWord, bundleAbsoluteOffset) pair so
|
||||
// dense root layers (e.g. floor tiles) do not bury the labels we actually
|
||||
// need to read. The bounding box is also suppressed once the label budget
|
||||
// is exhausted so duplicate-instance clusters do not redraw white outlines
|
||||
// on every tile and obscure surrounding art.
|
||||
const labelBudgetPerBundle = 10;
|
||||
const labelTally = new Map();
|
||||
for (const item of items) {
|
||||
drawLabel(
|
||||
canvas,
|
||||
width,
|
||||
height,
|
||||
item.labelId ?? item.id,
|
||||
item.drawX - bounds.minX + padding,
|
||||
item.drawY - bounds.minY + padding
|
||||
);
|
||||
const tallyKey = `${item.typeWord ?? '?'}|${item.bundleAbsoluteOffset ?? '?'}`;
|
||||
const used = labelTally.get(tallyKey) ?? 0;
|
||||
if (used >= labelBudgetPerBundle) {
|
||||
continue;
|
||||
}
|
||||
labelTally.set(tallyKey, used + 1);
|
||||
const boxX = item.drawX - bounds.minX + padding;
|
||||
const boxY = item.drawY - bounds.minY + padding;
|
||||
const boxW = item.width ?? item.sprite?.width ?? 0;
|
||||
const boxH = item.height ?? item.sprite?.height ?? 0;
|
||||
drawBoundingBox(canvas, width, height, boxX, boxY, boxW, boxH);
|
||||
// Compose a useful label: typeWord (hex) + bundle absolute offset (last 4 hex)
|
||||
const labelParts = [];
|
||||
if (Number.isInteger(item.typeWord)) {
|
||||
labelParts.push('t' + item.typeWord.toString(16));
|
||||
}
|
||||
if (Number.isInteger(item.bundleAbsoluteOffset)) {
|
||||
labelParts.push('b' + (item.bundleAbsoluteOffset & 0xffff).toString(16).padStart(4, '0'));
|
||||
}
|
||||
if (labelParts.length === 0 && (item.labelId ?? item.id) !== undefined) {
|
||||
labelParts.push('#' + (item.labelId ?? item.id));
|
||||
}
|
||||
drawLabel(canvas, width, height, labelParts.join(':'), boxX, boxY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue