feat: integrate brighter A3 soft ribbon hints with cached target glow

This commit is contained in:
toshiocn
2026-10-23 17:18:09 +08:00
parent 6abbc37399
commit 8f2263b5d3
23 changed files with 683 additions and 186 deletions
@@ -12,7 +12,7 @@ export function applyBrightClassroom(source) {
if(canvas.width!==Math.round(width*dpr))canvas.width=Math.round(width*dpr);
if(canvas.height!==Math.round(height*dpr))canvas.height=Math.round(height*dpr);
ctx.setTransform(dpr,0,0,dpr,0,0);
brightScene=renderBrightBoard(ctx,level,path,width,height,{preview:previewOnly});
brightScene=renderBrightBoard(ctx,level,path,width,height,{preview:previewOnly,...brightHintOptions(Date.now()),pixelRatio:dpr});
({polygons,centers,unit}=brightScene);channelViews=brightScene.channels;cellViews=brightScene.views;
const bad=violations(level,path);
${tail}`;
@@ -28,13 +28,15 @@ ${tail}`;
// Preview rendering must restore every reference used by the live hint layer.
source=source.replace('const saved={canvas,ctx,level,solution,path,polygons,centers,unit,focus,cleared,channelViews,cellViews};','const saved={canvas,ctx,level,solution,path,polygons,centers,unit,focus,cleared,channelViews,cellViews,brightScene};');
source=source.replace('({canvas,ctx,level,solution,path,polygons,centers,unit,focus,cleared,channelViews,cellViews}=saved)','({canvas,ctx,level,solution,path,polygons,centers,unit,focus,cleared,channelViews,cellViews,brightScene}=saved)');
source=`import {renderBrightBoard,hintGeometry,drawBarriers} from '../bright-classroom/board-renderer.mjs';\nlet brightScene=null;\n`+source;
source=`import {renderBrightBoard,hintGeometry,drawBarriers} from '../bright-classroom/board-renderer.mjs';\nlet brightScene=null,brightHintKey='',brightHintStarted=0;\n`+source;
source+=`
export function refreshBrightBoard(now){
if(!brightScene?.animating)return;
const options=brightHintOptions(now);if(!brightScene?.animating&&!options.hintTarget&&!brightScene?.hintLayers)return;
const dpr=window.devicePixelRatio||1;ctx.setTransform(dpr,0,0,dpr,0,0);
brightScene=renderBrightBoard(ctx,level,path,canvas.clientWidth,canvas.clientHeight,{now});
brightScene=renderBrightBoard(ctx,level,path,canvas.clientWidth,canvas.clientHeight,{now,...options,pixelRatio:dpr});
}
function brightHintOptions(now){const h=previewOnly?null:segmentHints.view(level,solution,path),key=h?level.id+':'+h.start+':'+h.end:'';if(key!==brightHintKey){brightHintKey=key;brightHintStarted=now;}return {hintTarget:h?.route.at(-1)||null,hintElapsed:now-brightHintStarted};}
export function resetBrightHint(){brightHintKey='';if(brightScene)brightScene.hintLayers=null;}
export function brightOverlay(target){if(brightScene)drawBarriers(target,brightScene,path);}
export function brightAnimating(){return Boolean(brightScene?.animating);}
`;