plugins/DuneMenus/src/rendererTest/java/com/dunerealms/menus/RendererVerification.java
unimatrixgit b4dd9e42c3
Some checks failed
Compact Dune Menu Overlay / compact-menu-links (push) Successful in 3m16s
DuneRealms Plugin CI / plugins (push) Has been cancelled
Compact Dune menu cards and repair service navigation
2026-12-05 09:42:29 +01:00

152 lines
14 KiB
Java

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<Card> cash=new ArrayList<>();Map<Integer,String> 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<names.length;n++){cash.add(new Card(10+n,amounts[n]+" DM",List.of("Select one bill or coin"),"paper"));String asset="pack/assets/dunerealms/textures/item/currency/"+names[n]+".png";Path target=dir.resolve(asset);Files.createDirectories(target.getParent());Files.copy(Path.of("../network/resource-pack/central/overlay/assets/dunerealms/textures/item/currency/"+names[n]+".png"),target,StandardCopyOption.REPLACE_EXISTING);cashArt.put(10+n,asset);}
cash.add(new Card(24,operation.equals("withdraw")?"Withdraw 50.00 DM":"Deposit 50.00 DM",List.of(),"gold_ingot"));
}else if(operation.equals("redeem"))cash.add(new Card(13,"Enter RIA ID",List.of("Type the reference in chat"),"writable_book"));
cash.add(new Card(36,"Back",List.of(),"arrow"));
String html=SuppliedDocument.html(operation,"Rihla · "+operation,"Choose your transaction",cash,operation.equals("receipt")?List.of("Cash deposit — Amount: 50.00 DM","RIA ID — RIA-0123456789ABCDEF0123456789ABCDEF"):List.of(),cashArt);
var page=Page.of(html,dir.resolve("rihla-"+operation+".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());
for(Card card:cash){var element=page.document.selectFirst("[data-slot='"+card.slot()+"']");var bounds=frame.boundsOf(element);if(bounds==null)throw new AssertionError("Missing Rihla action");var hit=frame.elementAt(bounds.getCenterX(),bounds.getCenterY());if(hit==null||hit.closest("[data-slot]")==null||!hit.closest("[data-slot]").attr("data-slot").equals(""+card.slot()))throw new AssertionError("Rihla action outside initial viewport "+operation+" "+card.slot());}
ImageIO.write(frame.image(),"png",dir.resolve("rihla-"+operation+"-engine.png").toFile());
}
for(String id:List.of("hub","travel","exchange","clan","company","missions","spice","war","politics","house","equipment","bank","atm","withdraw","transfer")){
long started=System.nanoTime();List<Card> cards=new ArrayList<>();int count=id.equals("exchange")?28:id.equals("travel")?5:8;
for(int n=0;n<count;n++)cards.add(new Card(n,(n==0?"Imperial Postbank · very long official account title":"Entry "+(n+1)),(n==0||id.equals("exchange"))?List.of("Personal level, Reputation and active quests","LEGENDARY | MK XIV","Efficiency VIII","Fortune IV","Mending I","Unbreaking IV","4 available · 100.00 DM each","Seller: Guild"):List.of("Verified service detail","Amount: 100.00 DM"),id.equals("travel")?"compass":"emerald"));
cards.add(new Card(45,"Back",List.of(),"arrow"));
String html=SuppliedDocument.html(id,"DuneRealms · "+id,"Service information",cards,List.of("Read-only account and permission details"));
Path file=dir.resolve(id+"-matrix.html");Files.writeString(file,html);var page=Page.of(html,file,loader);var frame=HtmlRenderer.render(page,1536,896,1.5,0,Selector.State.NONE);
if(!page.problems.isEmpty())throw new AssertionError(id+" parser problems "+page.problems);
int marker=html.indexOf("/* compact-dune-cards */"),styleEnd=html.indexOf("</style>",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.getMinX()-1||box.getMaxX()>bounds.getMaxX()+1||box.getMinY()<bounds.getMinY()-1||box.getMaxY()>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<Card> 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.getMinX()-1||bounds.getMaxX()>box.getMaxX()+1
||bounds.getMinY()<box.getMinY()-1||bounds.getMaxY()>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<Card> 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<Card>();
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;index<cards.size();index++){
Card card=cards.get(index);
var element=rendered.get(index);
var bounds=frame.boundsOf(element);
if(bounds==null||bounds.isEmpty())throw new AssertionError(name+" invisible "+card.title());
if(!card.enabled()&&(!element.hasClass("locked")||!element.select("[data-slot]").isEmpty()||element.hasAttr("data-slot")))
throw new AssertionError(name+" disabled destination has an action "+card.title());
if(!card.enabled()&&!element.text().contains(card.lore().get(0)))
throw new AssertionError(name+" missing unavailable reason "+card.title());
for(var text:element.select("h2,p")){
var box=frame.boundsOf(text);
if(box!=null&&(box.getMinX()<bounds.getMinX()-1||box.getMaxX()>bounds.getMaxX()+1
||box.getMinY()<bounds.getMinY()-1||box.getMaxY()>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");
}
}
}