Workers P2: Engine-Sprites (Raster, Figuren mit Posen, Text, Blasen)
Raster je Kontext in einem WeakMap (setGrid/px/tint), Figuren mit den Posen stand, type, coffee und sleep, Graustufe für nicht angeschlossene Worker, Warnzeichen, Text und Sprechblasen mit Klemmung in die Canvas-Breite. Aufzeichnender Test-Kontext in tests/unit/helpers/fakeCtx.mjs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
67df2fd902
commit
d44b28368d
3 files changed
+466
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// Aufzeichnender Canvas-Kontext für die Engine-Tests (Muster: Proxy aus entwuerfe/smoke.js).
|
||||
// fillRect/fillText werden mit dem aktuellen fillStyle/font notiert, alles Übrige ist ein No-op.
|
||||
|
||||
/**
|
||||
* makeCtx({ width, height }) → { ctx, rects, texts, counts, alphas }
|
||||
* rects: [{ x, y, w, h, fill }] jedes fillRect
|
||||
* texts: [{ text, x, y, font }] jedes fillText (Nicht-String wirft wie im Smoke-Test)
|
||||
* counts: { save, restore } Aufrufe von ctx.save()/ctx.restore()
|
||||
* alphas: [] jede Zuweisung an ctx.globalAlpha
|
||||
*/
|
||||
export function makeCtx({ width = 960, height = 768 } = {}) {
|
||||
const rects = []
|
||||
const texts = []
|
||||
const counts = { save: 0, restore: 0 }
|
||||
const alphas = []
|
||||
const target = { canvas: { width, height }, fillStyle: '#000000', font: '10px sans-serif', globalAlpha: 1 }
|
||||
const ctx = new Proxy(target, {
|
||||
get(t, prop) {
|
||||
if (typeof prop === 'symbol') return undefined
|
||||
if (prop === 'save') return () => { counts.save++ }
|
||||
if (prop === 'restore') return () => { counts.restore++ }
|
||||
if (prop === 'measureText') return (text) => ({ width: String(text).length * 7 })
|
||||
if (prop === 'fillRect') return (x, y, w, h) => { rects.push({ x, y, w, h, fill: t.fillStyle }) }
|
||||
if (prop === 'fillText') {
|
||||
return (text, x, y) => {
|
||||
if (typeof text !== 'string') throw new Error('fillText mit Nicht-String: ' + text)
|
||||
texts.push({ text, x, y, font: t.font })
|
||||
}
|
||||
}
|
||||
if (prop === 'createLinearGradient' || prop === 'createRadialGradient') return () => ({ addColorStop() {} })
|
||||
if (prop === 'getImageData') return () => ({ data: new Uint8ClampedArray(4) })
|
||||
if (prop in t) return t[prop]
|
||||
return () => {}
|
||||
},
|
||||
set(t, prop, value) {
|
||||
if (prop === 'globalAlpha') alphas.push(value)
|
||||
t[prop] = value
|
||||
return true
|
||||
},
|
||||
})
|
||||
return { ctx, rects, texts, counts, alphas }
|
||||
}
|
||||
Reference in new issue
Block a user