|
|
@ -6,11 +6,30 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
|
|
|
|
|
|
|
|
debugCanvas.classList.add('debug-canvas') |
|
|
|
debugCanvas.classList.add('debug-canvas') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mouseHoverCell = null |
|
|
|
|
|
|
|
let updateToolbar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let onMouseMove = e => { |
|
|
|
|
|
|
|
mouseHoverCell = screen.screenToGrid(e.offsetX, e.offsetY) |
|
|
|
|
|
|
|
startDrawing() |
|
|
|
|
|
|
|
updateToolbar() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let onMouseOut = () => (mouseHoverCell = null) |
|
|
|
|
|
|
|
|
|
|
|
let addCanvas = function () { |
|
|
|
let addCanvas = function () { |
|
|
|
if (!debugCanvas.parentNode) screen.canvas.parentNode.appendChild(debugCanvas) |
|
|
|
if (!debugCanvas.parentNode) { |
|
|
|
|
|
|
|
screen.canvas.parentNode.appendChild(debugCanvas) |
|
|
|
|
|
|
|
screen.canvas.parentNode.addEventListener('mousemove', onMouseMove) |
|
|
|
|
|
|
|
screen.canvas.parentNode.addEventListener('mouseout', onMouseOut) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let removeCanvas = function () { |
|
|
|
let removeCanvas = function () { |
|
|
|
if (debugCanvas.parentNode) debugCanvas.parentNode.removeChild(debugCanvas) |
|
|
|
if (debugCanvas.parentNode) { |
|
|
|
|
|
|
|
debugCanvas.parentNode.removeChild(debugCanvas) |
|
|
|
|
|
|
|
screen.canvas.parentNode.removeEventListener('mousemove', onMouseMove) |
|
|
|
|
|
|
|
screen.canvas.parentNode.removeEventListener('mouseout', onMouseOut) |
|
|
|
|
|
|
|
onMouseOut() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let updateCanvasSize = function () { |
|
|
|
let updateCanvasSize = function () { |
|
|
|
let { width, height, devicePixelRatio } = screen.window |
|
|
|
let { width, height, devicePixelRatio } = screen.window |
|
|
@ -21,6 +40,9 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
debugCanvas.style.height = `${height * cellSize.height}px` |
|
|
|
debugCanvas.style.height = `${height * cellSize.height}px` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let drawInfo = mk('div') |
|
|
|
|
|
|
|
drawInfo.classList.add('draw-info') |
|
|
|
|
|
|
|
|
|
|
|
let startTime, endTime, lastReason |
|
|
|
let startTime, endTime, lastReason |
|
|
|
let cells = new Map() |
|
|
|
let cells = new Map() |
|
|
|
let clippedRects = [] |
|
|
|
let clippedRects = [] |
|
|
@ -35,7 +57,7 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
drawEnd () { |
|
|
|
drawEnd () { |
|
|
|
endTime = Date.now() |
|
|
|
endTime = Date.now() |
|
|
|
console.log(`Draw: ${lastReason} (${(endTime - startTime)} ms) with fancy graphics: ${screen.window.graphics}`) |
|
|
|
console.log(drawInfo.textContent = `Draw: ${lastReason} (${(endTime - startTime)} ms) with graphics=${screen.window.graphics}`) |
|
|
|
startDrawing() |
|
|
|
startDrawing() |
|
|
|
}, |
|
|
|
}, |
|
|
|
setCell (cell, flags) { |
|
|
|
setCell (cell, flags) { |
|
|
@ -69,10 +91,16 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let isDrawing = false |
|
|
|
let isDrawing = false |
|
|
|
|
|
|
|
let lastDrawTime = 0 |
|
|
|
|
|
|
|
let t = 0 |
|
|
|
|
|
|
|
|
|
|
|
let drawLoop = function () { |
|
|
|
let drawLoop = function () { |
|
|
|
if (isDrawing) window.requestAnimationFrame(drawLoop) |
|
|
|
if (isDrawing) window.requestAnimationFrame(drawLoop) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dt = (Date.now() - lastDrawTime) / 1000 |
|
|
|
|
|
|
|
lastDrawTime = Date.now() |
|
|
|
|
|
|
|
t += dt |
|
|
|
|
|
|
|
|
|
|
|
let { devicePixelRatio, width, height } = screen.window |
|
|
|
let { devicePixelRatio, width, height } = screen.window |
|
|
|
let { width: cellWidth, height: cellHeight } = screen.getCellSize() |
|
|
|
let { width: cellWidth, height: cellHeight } = screen.getCellSize() |
|
|
|
let screenLength = width * height |
|
|
|
let screenLength = width * height |
|
|
@ -127,7 +155,22 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
ctx.fill() |
|
|
|
ctx.fill() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (activeCells === 0) { |
|
|
|
if (mouseHoverCell) { |
|
|
|
|
|
|
|
ctx.save() |
|
|
|
|
|
|
|
ctx.globalAlpha = 1 |
|
|
|
|
|
|
|
ctx.lineWidth = 1 + 0.5 * Math.sin(t * 10) |
|
|
|
|
|
|
|
ctx.strokeStyle = '#fff' |
|
|
|
|
|
|
|
ctx.lineJoin = 'round' |
|
|
|
|
|
|
|
ctx.setLineDash([2, 2]) |
|
|
|
|
|
|
|
ctx.lineDashOffset = t * 10 |
|
|
|
|
|
|
|
ctx.strokeRect(mouseHoverCell[0] * cellWidth, mouseHoverCell[1] * cellHeight, cellWidth, cellHeight) |
|
|
|
|
|
|
|
ctx.lineDashOffset += 2 |
|
|
|
|
|
|
|
ctx.strokeStyle = '#000' |
|
|
|
|
|
|
|
ctx.strokeRect(mouseHoverCell[0] * cellWidth, mouseHoverCell[1] * cellHeight, cellWidth, cellHeight) |
|
|
|
|
|
|
|
ctx.restore() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activeCells === 0 && !mouseHoverCell) { |
|
|
|
isDrawing = false |
|
|
|
isDrawing = false |
|
|
|
removeCanvas() |
|
|
|
removeCanvas() |
|
|
|
} |
|
|
|
} |
|
|
@ -138,6 +181,7 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
addCanvas() |
|
|
|
addCanvas() |
|
|
|
updateCanvasSize() |
|
|
|
updateCanvasSize() |
|
|
|
isDrawing = true |
|
|
|
isDrawing = true |
|
|
|
|
|
|
|
lastDrawTime = Date.now() |
|
|
|
drawLoop() |
|
|
|
drawLoop() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -145,6 +189,30 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
const toolbar = mk('div') |
|
|
|
const toolbar = mk('div') |
|
|
|
toolbar.classList.add('debug-toolbar') |
|
|
|
toolbar.classList.add('debug-toolbar') |
|
|
|
let toolbarAttached = false |
|
|
|
let toolbarAttached = false |
|
|
|
|
|
|
|
const dataDisplay = mk('div') |
|
|
|
|
|
|
|
dataDisplay.classList.add('data-display') |
|
|
|
|
|
|
|
toolbar.appendChild(dataDisplay) |
|
|
|
|
|
|
|
toolbar.appendChild(drawInfo) |
|
|
|
|
|
|
|
const buttons = mk('div') |
|
|
|
|
|
|
|
buttons.classList.add('toolbar-buttons') |
|
|
|
|
|
|
|
toolbar.appendChild(buttons) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const redraw = mk('button') |
|
|
|
|
|
|
|
redraw.textContent = 'Redraw' |
|
|
|
|
|
|
|
redraw.addEventListener('click', e => { |
|
|
|
|
|
|
|
screen.renderer.resetDrawn() |
|
|
|
|
|
|
|
screen.renderer.draw('debug-redraw') |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
buttons.appendChild(redraw) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fancyGraphics = mk('button') |
|
|
|
|
|
|
|
fancyGraphics.textContent = 'Toggle Graphics' |
|
|
|
|
|
|
|
fancyGraphics.addEventListener('click', e => { |
|
|
|
|
|
|
|
screen.window.graphics = +!screen.window.graphics |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
buttons.appendChild(fancyGraphics) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const attachToolbar = function () { |
|
|
|
const attachToolbar = function () { |
|
|
|
screen.canvas.parentNode.appendChild(toolbar) |
|
|
|
screen.canvas.parentNode.appendChild(toolbar) |
|
|
@ -157,20 +225,36 @@ module.exports = function attachDebugScreen (screen) { |
|
|
|
if (debug !== toolbarAttached) { |
|
|
|
if (debug !== toolbarAttached) { |
|
|
|
toolbarAttached = debug |
|
|
|
toolbarAttached = debug |
|
|
|
if (debug) attachToolbar() |
|
|
|
if (debug) attachToolbar() |
|
|
|
else detachToolbar() |
|
|
|
else { |
|
|
|
|
|
|
|
detachToolbar() |
|
|
|
|
|
|
|
removeCanvas() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
screen.on('draw', () => { |
|
|
|
const formatColor = color => color < 256 ? color : `#${`000000${(color - 256).toString(16)}`.substr(-6)}` |
|
|
|
if (!toolbarAttached) return |
|
|
|
const getCellData = cell => { |
|
|
|
let cursorCell = screen.cursor.y * screen.window.width + screen.cursor.x |
|
|
|
if (cell < 0 || cell > screen.screen.length) return '(-)' |
|
|
|
let cellFG = screen.screenFG[cursorCell] |
|
|
|
let cellAttrs = screen.renderer.drawnScreenAttrs[cell] |
|
|
|
let cellBG = screen.screenBG[cursorCell] |
|
|
|
let cellFG = formatColor(screen.renderer.drawnScreenFG[cell]) |
|
|
|
let cellCode = (screen.screen[cursorCell] || '').codePointAt(0) |
|
|
|
let cellBG = formatColor(screen.renderer.drawnScreenBG[cell]) |
|
|
|
let cellAttrs = screen.screenAttrs[cursorCell] |
|
|
|
let cellCode = (screen.renderer.drawnScreen[cell] || '').codePointAt(0) |
|
|
|
let hexcode = cellCode.toString(16).toUpperCase() |
|
|
|
let hexcode = cellCode.toString(16).toUpperCase() |
|
|
|
if (hexcode.length < 4) hexcode = `0000${hexcode}`.substr(-4) |
|
|
|
if (hexcode.length < 4) hexcode = `0000${hexcode}`.substr(-4) |
|
|
|
hexcode = `U+${hexcode}` |
|
|
|
hexcode = `U+${hexcode}` |
|
|
|
toolbar.textContent = `Cursor cell (${cursorCell}): ${hexcode} FG: ${cellFG} BG: ${cellBG} Attrs: ${cellAttrs.toString(2)}` |
|
|
|
let x = cell % screen.window.width |
|
|
|
}) |
|
|
|
let y = Math.floor(cell / screen.window.width) |
|
|
|
|
|
|
|
return `((${y},${x})=${cell}:${hexcode}:F${cellFG}:B${cellBG}:A${cellAttrs.toString(2)})` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateToolbar = () => { |
|
|
|
|
|
|
|
if (!toolbarAttached) return |
|
|
|
|
|
|
|
let text = `C((${screen.cursor.y},${screen.cursor.x}),hang:${screen.cursor.hanging},vis:${screen.cursor.visible})` |
|
|
|
|
|
|
|
if (mouseHoverCell) { |
|
|
|
|
|
|
|
text += ' m' + getCellData(mouseHoverCell[1] * screen.window.width + mouseHoverCell[0]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dataDisplay.textContent = text |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screen.on('draw', updateToolbar) |
|
|
|
} |
|
|
|
} |
|
|
|