package com.dunerealms.menus; import java.nio.file.*;import java.util.*;import java.awt.geom.*;import javax.imageio.ImageIO;import ai.resourcepack.ui.html.*;import ai.resourcepack.ui.html.css.Selector; public class RendererVerification { public static void main(String[]args)throws Exception{ Path dir=Path.of(args[0]);Files.createDirectories(dir);var loader=new Page.Loader(false,dir.resolve("engine-cache"));int checked=0; Files.createDirectories(dir.resolve("art"));Files.copy(Path.of("src/main/resources/menu-art/art/logo.png"),dir.resolve("art/logo.png"),StandardCopyOption.REPLACE_EXISTING); Files.copy(Path.of("src/main/resources/menu-art/art/rihla.png"),dir.resolve("art/rihla.png"),StandardCopyOption.REPLACE_EXISTING); for(String operation:List.of("withdraw","deposit","redeem","receipt")){ List cash=new ArrayList<>();Map cashArt=new HashMap<>(); if(operation.equals("withdraw")||operation.equals("deposit")){ String[] names={"note_10","note_20","note_50","note_100","note_500","coin_050","coin_1dm","coin_2dm"};String[] amounts={"10.00","20.00","50.00","100.00","500.00","0.50","1.00","2.00"}; for(int n=0;n cards=new ArrayList<>();int count=id.equals("exchange")?28:id.equals("travel")?5:8; for(int n=0;n",marker); String baseline=html.substring(0,marker)+html.substring(styleEnd); var oldPage=Page.of(baseline,dir.resolve(id+"-before.html"),loader); var oldFrame=HtmlRenderer.render(oldPage,1536,896,1.5,0,Selector.State.NONE); var oldBox=oldFrame.boundsOf(oldPage.document.selectFirst("main .card")); var newBox=frame.boundsOf(page.document.selectFirst("main .card")); if(Math.abs(newBox.getWidth()/oldBox.getWidth()-.75)>.002 || Math.abs(newBox.getHeight()/oldBox.getHeight()-.75)>.002) throw new AssertionError(id+" card size must be 75%: "+oldBox+" -> "+newBox); ImageIO.write(frame.image(),"png",dir.resolve(id+"-matrix-engine.png").toFile()); for(Card card:cards){ var element=page.document.selectFirst("[data-slot='"+card.slot()+"']");var bounds=frame.boundsOf(element); if(bounds==null||bounds.getWidth()<=0||bounds.getHeight()<=0)throw new AssertionError(id+" invisible slot "+card.slot()); var emblem=element.selectFirst(".emblem");if(emblem!=null&&!id.equals("travel")&&!card.material().equals("arrow")){var box=frame.boundsOf(emblem);if(box!=null&&Math.abs(box.getCenterX()-bounds.getCenterX())>1)throw new AssertionError(id+" icon not centered "+card.slot()+" "+box+" vs "+bounds);} for(var text:element.select("h2,p")){var box=frame.boundsOf(text);if(box!=null&&(box.getMinX()bounds.getMaxX()+1||box.getMinY()bounds.getMaxY()+1))throw new AssertionError(id+" text outside card "+card.slot()+" text="+box+" card="+bounds);} double scroll=Math.max(0,Math.min(frame.maxScroll(),bounds.getCenterY()-260));var visible=HtmlRenderer.render(page,1536,896,1.5,scroll,Selector.State.NONE); var at=visible.elementAt(bounds.getCenterX(),bounds.getCenterY()-scroll);var button=at==null?null:at.closest("[data-slot]"); if(button==null||!button.attr("data-slot").equals(""+card.slot()))throw new AssertionError(id+" hit slot "+card.slot()+" at "+bounds+" scroll="+scroll+" got="+button); checked++; } System.out.println(id+": parser clean; "+cards.size()+" action hitboxes; maxScroll="+frame.maxScroll()+"; render-and-hitbox-ms="+((System.nanoTime()-started)/1_000_000)); } verifyNavigators(dir,loader); verifyHouseChoices(dir,loader); var actualIcon=Path.of("../network/resource-pack/central/overlay/assets/dunerealms/textures/item/equipment/legendary_mk14_axe.png");Path iconTarget=dir.resolve("pack/assets/dunerealms/textures/item/equipment/legendary_mk14_axe.png");Files.createDirectories(iconTarget.getParent());Files.copy(actualIcon,iconTarget,StandardCopyOption.REPLACE_EXISTING); for(String name:List.of("item/iron_sword","block/cobblestone")){Path target=dir.resolve("pack/assets/minecraft/textures/"+name+".png");Files.createDirectories(target.getParent());Files.copy(Path.of("../network/resource-pack/vanilla-art/overlay/assets/minecraft/textures/"+name+".png"),target,StandardCopyOption.REPLACE_EXISTING);} var listing=new Card(13,"\uE400§6Paul's chopper",List.of("LEGENDARY | MK XIV","Used by Paul himself.","Efficiency VIII","Fortune IV","Mending I","Unbreaking IV","Seller: J.A.R.V.I.S. HQ","1 available · 500.00 DM each"),"netherite_axe"); String listingHtml=SuppliedDocument.html("exchange","Exchange · Buy","Authoritative item artwork",List.of(new Card(1,"Buy",List.of("Browse available items"),"emerald"),new Card(4,"Kits",List.of(),"netherite_chestplate"),new Card(7,"My listings",List.of(),"chest"),new Card(49,"Sell item",List.of(),"hopper"),new Card(50,"Collect purchases",List.of(),"chest_minecart"),listing,new Card(14,"Cobblestone",List.of("64 available · 1.00 DM each"),"cobblestone"),new Card(15,"Iron sword",List.of("1 available · 10.00 DM each"),"iron_sword")),List.of(),Map.of(13,"pack/assets/dunerealms/textures/item/equipment/legendary_mk14_axe.png",14,"pack/assets/minecraft/textures/block/cobblestone.png",15,"pack/assets/minecraft/textures/item/iron_sword.png"),13); var listingPage=Page.of(listingHtml,dir.resolve("exchange-item.html"),loader);var listingFrame=HtmlRenderer.render(listingPage,1536,896,1.5,0,Selector.State.NONE);if(!listingPage.problems.isEmpty())throw new AssertionError(listingPage.problems.toString());ImageIO.write(listingFrame.image(),"png",dir.resolve("exchange-item-engine.png").toFile()); for(var element:listingPage.document.select(".market-tool,[data-slot='1013']")){var bounds=listingFrame.boundsOf(element);var at=listingFrame.elementAt(bounds.getCenterX(),bounds.getCenterY());if(at==null||!at.closest("[data-slot]").attr("data-slot").equals(element.attr("data-slot")))throw new AssertionError("Detail control hitbox");} System.out.println("PASS: "+checked+" direct action hitboxes across15 menu families."); } private static void verifyHouseChoices(Path dir,Page.Loader loader)throws Exception{ List cards=List.of(new Card(10,"Aerdrecht",List.of("Click to select this House"),"paper"), new Card(13,"Harkveen",List.of("Click to select this House"),"paper"), new Card(16,"Korenholt",List.of("Click to select this House"),"paper"), new Card(29,"Vlierdam",List.of("Click to select this House"),"paper"), new Card(33,"Imperial House with a longer name",List.of("Selected · confirm below"),"paper")); String html=SuppliedDocument.html("house","Choose your House","",cards,List.of()); var page=Page.of(html,dir.resolve("house-choices.html"),loader); var frame=HtmlRenderer.render(page,1536,896,1.5,0,Selector.State.NONE); if(!page.problems.isEmpty())throw new AssertionError(page.problems.toString()); var rendered=page.document.select("main > button"); if(rendered.size()!=5)throw new AssertionError("Expected five House actions"); double firstRow=frame.boundsOf(rendered.first()).getMinY(); int onFirstRow=0; for(var element:rendered){ var box=frame.boundsOf(element); if(box==null||box.isEmpty())throw new AssertionError("Missing House card"); if(Math.abs(box.getMinY()-firstRow)<1)onFirstRow++; var hit=frame.elementAt(box.getCenterX(),box.getCenterY()); if(hit==null||hit.closest("[data-slot]")!=element)throw new AssertionError("House action not reachable"); for(var text:element.select("h2,p")){ var bounds=frame.boundsOf(text); if(bounds!=null&&(bounds.getMinX()box.getMaxX()+1 ||bounds.getMinY()box.getMaxY()+1)) throw new AssertionError("House text outside card: "+bounds+" vs "+box); } } int expectedColumns=page.document.selectFirst("main").hasClass("house-choices")?4:3; if(onFirstRow!=expectedColumns)throw new AssertionError("Expected "+expectedColumns+" compact House cards across, got "+onFirstRow); ImageIO.write(frame.image(),"png",dir.resolve("house-choices-engine.png").toFile()); System.out.println("House selector: five original actions, variant-preserving compact columns, contained text"); } private static void verifyNavigators(Path dir,Page.Loader loader)throws Exception{ List guild=List.of( new Card(4,"Arrakduin",List.of("Fare: 125.00 DM"),"compass"), new Card(19,"Kaladam",List.of("Your House has no Imperial passage for this destination."),"gray_dye",false), new Card(25,"Giedermark",List.of("Current Guild embargo"),"gray_dye",false), new Card(37,"Kaiterhof",List.of("Fare: 125.00 DM"),"compass"), new Card(43,"Sigmadraken IV",List.of("World currently offline"),"gray_dye",false), new Card(45,"Back",List.of(),"arrow")); var owned=new ArrayList(); for(int i=0;i<28;i++){ int slot=10+i/7*9+i%7; owned.add(new Card(slot,"Company Home Block "+(i+1), List.of(i%2==0?"Kaladam · View fare":"No registered Home Block"), i%2==0?"cyan_banner":"gray_dye",i%2==0)); } owned.add(new Card(45,"Back",List.of(),"arrow")); owned.add(new Card(51,"Next page",List.of(),"arrow")); var confirm=List.of(new Card(22,"Company Home Block",List.of("Smuggler fare: 125.07 DM"),"compass"), new Card(31,"Confirm paid passage",List.of("Payment settles after arrival"),"lime_dye"), new Card(45,"Back",List.of(),"arrow")); for(var family:Map.of("guild",guild,"esmar",guild,"owned-home",owned,"confirm",confirm).entrySet()){ String name=family.getKey(); var cards=family.getValue(); String html=SuppliedDocument.html(name.equals("guild")?"travel":"smuggler","Smuggler Navigator","Choose a destination",cards,List.of()); var page=Page.of(html,dir.resolve(name+"-navigator.html"),loader); var frame=HtmlRenderer.render(page,1536,896,1.5,0,Selector.State.NONE); if(!page.problems.isEmpty())throw new AssertionError(name+" parser problems "+page.problems); var rendered=page.document.select("main > *"); if(rendered.size()!=cards.size())throw new AssertionError(name+" duplicate or missing rows: "+rendered.size()); for(int index=0;indexbounds.getMaxX()+1 ||box.getMinY()bounds.getMaxY()+1)) throw new AssertionError(name+" text outside card "+card.title()+": "+box+" vs "+bounds); } if(card.enabled()){ double scroll=Math.max(0,Math.min(frame.maxScroll(),bounds.getCenterY()-260)); var visible=HtmlRenderer.render(page,1536,896,1.5,scroll,Selector.State.NONE); var hit=visible.elementAt(bounds.getCenterX(),bounds.getCenterY()-scroll); if(hit==null||hit.closest("[data-slot]")==null||!hit.closest("[data-slot]").attr("data-slot").equals(""+card.slot())) throw new AssertionError(name+" unreachable action "+card.title()); } } ImageIO.write(frame.image(),"png",dir.resolve(name+"-navigator-engine.png").toFile()); System.out.println(name+" navigator: "+cards.size()+" distinct rows, contained text, disabled routes have no actions"); } } }