Emberveil source

tests/FirePartyhatCheck.java

import java.util.*;import java.io.*;import java.awt.image.BufferedImage;import javax.imageio.ImageIO;
public final class FirePartyhatCheck {
 static int checks;static void check(boolean b,String m){checks++;if(!b)throw new AssertionError(m);}
 static int[] render(int frame){int[] p=new int[80*60];Arrays.fill(p,0x252125);DrawingArea.initDrawingArea(60,80,p);FirePartyhat.draw(40,35,10,frame*85L);return p;}
 public static void main(String[]args)throws Exception {
  Player p=new Player();p.name="Bonds";p.equipment[0]=14999+512;check(FirePartyhat.wearing(p),"bonds unique partyhat enables flames");p.name="darren";check(!FirePartyhat.wearing(p),"darren unaffected");p.name="strelly";check(!FirePartyhat.wearing(p),"other players unaffected");p.name="bonds";p.equipment[0]=1038+512;check(!FirePartyhat.wearing(p),"ordinary red partyhat unaffected");p.equipment[0]=0;check(!FirePartyhat.wearing(p),"unequipping stops fire");check(!FirePartyhat.wearing(null),"null safe");
  BufferedImage frames=new BufferedImage(80*6,60,BufferedImage.TYPE_INT_RGB);Set<Integer> hashes=new HashSet<>();
  for(int i=0;i<6;i++){int[] px=render(i);hashes.add(Arrays.hashCode(px));frames.setRGB(i*80,0,80,60,px,0,80);int fire=0;for(int color:px)if((color>>16&255)>100&&(color>>16&255)>(color>>8&255))fire++;check(fire>20,"visible flames frame "+i);}
  check(hashes.size()==6,"six distinct animated frames");
  for(int x:new int[]{-1,0,79,80})for(int y:new int[]{-1,0,59,60}){DrawingArea.initDrawingArea(60,80,new int[4800]);FirePartyhat.draw(x,y,22,300);checks++;}
  int[] clipped=new int[4800];DrawingArea.initDrawingArea(60,80,clipped);DrawingArea.setDrawingArea(40,20,60,20);FirePartyhat.draw(20,20,22,0);for(int y=0;y<60;y++)for(int x=0;x<80;x++)if(x<20||x>=60||y<20||y>=40)check(clipped[x+y*80]==0,"clip respected");
  ImageIO.write(frames,"png",new File("runtime/fire-partyhat-animation-frames.png"));System.out.println("PASS "+checks+" owner isolation, animation and clipping checks");
 }
}