web/website/tests/reward-art.test.mjs

6 lines
1.7 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import{readFileSync}from'node:fs';import{inflateSync}from'node:zlib';
test('reward ingot has real transparent alpha, not a painted background',()=>{
const p=readFileSync(new URL('../web/assets/reward-gold-ingot-transparent-v1.png',import.meta.url));assert.equal(p.subarray(1,4).toString(),'PNG');const w=p.readUInt32BE(16),h=p.readUInt32BE(20);assert.equal(p[24],8);assert.equal(p[25],6);let parts=[];for(let i=8;i<p.length;){let n=p.readUInt32BE(i);if(p.toString('ascii',i+4,i+8)==='IDAT')parts.push(p.subarray(i+8,i+8+n));i+=n+12;}const raw=inflateSync(Buffer.concat(parts)),stride=w*4;let prior=Buffer.alloc(stride),pos=0,transparent=0,solid=0;const corners=[];for(let y=0;y<h;y++){let f=raw[pos++],row=Buffer.alloc(stride);for(let x=0;x<stride;x++){let a=x>=4?row[x-4]:0,b=prior[x],c=x>=4?prior[x-4]:0,v=0;if(f===1)v=a;else if(f===2)v=b;else if(f===3)v=Math.floor((a+b)/2);else if(f===4){let q=a+b-c,pa=Math.abs(q-a),pb=Math.abs(q-b),pc=Math.abs(q-c);v=pa<=pb&&pa<=pc?a:pb<=pc?b:c;}else assert.equal(f,0);row[x]=(raw[pos++]+v)&255;}for(let x=3;x<stride;x+=4){if(row[x]===0)transparent++;if(row[x]>=240)solid++;}if(y===0||y===h-1)corners.push(row[3],row[stride-1]);prior=row;}assert(corners.every(a=>a===0));assert(transparent>w*h*.3);assert(solid>w*h*.1);
});
test('reward heading uses transparent sibling asset served by CP',()=>{const ui=readFileSync(new URL('../control-panel/public/quest-rewards.mjs',import.meta.url),'utf8'),server=readFileSync(new URL('../control-panel/server.mjs',import.meta.url),'utf8');assert(ui.includes("art.src='/assets/reward-gold-ingot-transparent-v1.png'"));assert(server.includes("'reward-gold-ingot-transparent-v1.png'"));});