Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | import React, { useCallback, useContext, useEffect, useRef, useState, } from "react"; import { getSettings } from "store/features/settings/settingsState"; import settingsActions from "store/features/settings/settingsActions"; import { useAppDispatch, useAppSelector } from "store/hooks"; import styled, { ThemeContext } from "styled-components"; import { SplitPaneHeader } from "ui/splitpane/SplitPaneHeader"; import { decHexVal } from "shared/lib/helpers/8bit"; import l10n from "shared/lib/lang/l10n"; import { DataLabel, DataRow } from "components/debugger/DebuggerState"; const Content = styled.div` background: ${(props) => props.theme.colors.scripting.form.background}; padding: 10px; max-width: 256px; `; const VramPreview = styled.div` position: relative; max-height: 240px; `; const Canvas = styled.canvas` position: absolute; top: 0px; left: 0px; width: 256px; height: 256px; border-radius: 4px; image-rendering: pixelated; `; const TileAddr = styled.span` font-family: monospace; `; const VramAreaLabel = styled.span` opacity: 0.5; text-overflow: ellipsis; overflow: hidden; `; const DebuggerVRAMPane = () => { const dispatch = useAppDispatch(); const vramPreview = useAppSelector((state) => state.debug.vramPreview); const isCollapsed = useAppSelector((state) => getSettings(state).debuggerCollapsedPanes.includes("vram") ); const themeContext = useContext(ThemeContext); const onToggleCollapsed = useCallback(() => { dispatch(settingsActions.toggleDebuggerPaneCollapsed("vram")); }, [dispatch]); const [position, setPosition] = useState([-1, -1]); const [index, setIndex] = useState(0); const [bank, setBank] = useState(0); const [vramArea, setVramArea] = useState(l10n("NAV_SPRITES")); const canvasRef = useRef<HTMLCanvasElement>(null); useEffect(() => { const canvas = canvasRef.current; Iif (!canvas) { return; } Iif (!themeContext) { return; } const drawWidth = canvas.width; const rect = canvas.getBoundingClientRect(); const scaleX = canvas.width / rect.width; const scaleY = canvas.height / rect.height; const ctx = canvas.getContext("2d"); const tileSize = drawWidth / 32; // eslint-disable-next-line no-self-assign canvas.width = canvas.width; // eslint-disable-next-line no-self-assign canvas.height = canvas.height; const highlightColor = themeContext.colors.highlight; const drawGrid = () => { Iif (ctx) { // Draw grid ctx.beginPath(); ctx.strokeStyle = "rgba(0, 0, 0, .1)"; ctx.lineWidth = scaleX; ctx.moveTo(tileSize * 16 - 1, 0); ctx.lineTo(tileSize * 16 - 1, 24 * tileSize); ctx.moveTo(0, tileSize * 8 - 1); ctx.lineTo(canvas.width, tileSize * 8 - 1); ctx.moveTo(0, tileSize * 12 - 1); ctx.lineTo(canvas.width, tileSize * 12 - 1); ctx.moveTo(0, tileSize * 16 - 1); ctx.lineTo(canvas.width, tileSize * 16 - 1); ctx.stroke(); ctx.beginPath(); ctx.strokeStyle = highlightColor; ctx.strokeRect( position[0] * tileSize - 1, position[1] * tileSize - 1, tileSize, tileSize ); ctx.stroke(); } }; drawGrid(); const handleMouseMove = (e: MouseEvent) => { Iif (e.target !== canvasRef.current) { return; } Iif (ctx) { const x = (e.clientX - rect.left) * scaleX; const y = (e.clientY - rect.top) * scaleY; const i = Math.floor(x / 16); const j = Math.floor(y / 16); Iif (i >= 0 && j >= 0) { let index = j * 16 + (i % 16); const bank = i < 16 ? 0 : 1; let vramArea = ""; if (j < 8) { vramArea = l10n("NAV_SPRITES"); } else if (j < 12) { vramArea = l10n("FIELD_SHARED"); } else if (j < 16) { vramArea = l10n("MENU_UI_ELEMENTS"); } else Iif (j < 24) { vramArea = l10n("FIELD_BACKGROUND"); index = index - 256; } Iif (j < 24) { setPosition([i, j]); setIndex(index); setBank(bank); setVramArea(vramArea); } } } }; window.addEventListener("mousemove", handleMouseMove); return () => { window.removeEventListener("mousemove", handleMouseMove); }; }); return ( <> <SplitPaneHeader onToggle={onToggleCollapsed} collapsed={isCollapsed} variant="secondary" > VRAM </SplitPaneHeader> {!isCollapsed && ( <> <Content> <VramPreview> <img src={vramPreview} alt=""></img> <Canvas ref={canvasRef} width={512} height={512} /> </VramPreview> <DataRow> <DataLabel>{l10n("FIELD_TILE_INDEX")}:</DataLabel> <TileAddr> {String(index).padStart(3, "0")} (${decHexVal(index)}) </TileAddr> </DataRow> <DataRow> <DataLabel>{l10n("FIELD_MEMORY_BANK")}:</DataLabel> <TileAddr>{bank}</TileAddr> </DataRow> <DataRow> <VramAreaLabel>{vramArea}</VramAreaLabel> </DataRow> </Content> </> )} </> ); }; export default DebuggerVRAMPane; |