eb9bee05bd
LoomMenu (selectable patterns, clickMenuButton, the six-layer limit, quick moves, the result's onTake) and the server's CrafterMenu over the block entity (the result following the grid, slot state packets, filled disabled slots enabling) join the menu click harness, now 8,000 click sequences over 19 menus with pattern button and slot state ops. Slot clicks end with setChanged and container slots are limited to their stack size as SimpleContainer does. The game's loom and crafter screens now click through Game::menu_session on the same engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.5 KiB
Rust
92 lines
3.5 KiB
Rust
//! Menu clicks for tools/test_menu_click_parity.py: reads one JSON case per
|
|
//! line (menu, creative, slots, carried, data, ops) and prints the oracle's
|
|
//! state lines after every click.
|
|
//!
|
|
//! usage: menu_fixture RESOURCES INPUT OUTPUT
|
|
use horizon_client::{
|
|
crafting::Recipes,
|
|
item_data::{canon_stack, parse_stack},
|
|
items::Items,
|
|
menu::{Env, Input, Kind, Menu},
|
|
};
|
|
use serde_json::Value;
|
|
use std::{fs, path::Path};
|
|
|
|
fn state(menu: &Menu) -> String {
|
|
let slots: Vec<String> = (0..menu.slot_count())
|
|
.map(|i| canon_stack(menu.slot(i)))
|
|
.collect();
|
|
let data: String = menu.data.iter().map(|d| format!(" {d}")).collect();
|
|
format!(
|
|
"{} | {} |{data} | {}",
|
|
slots.join(" "),
|
|
canon_stack(menu.carried.as_ref()),
|
|
menu.drops.join(";")
|
|
)
|
|
}
|
|
|
|
fn main() -> horizon_client::Result<()> {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let root = Path::new(
|
|
args.get(1)
|
|
.ok_or("usage: menu_fixture RESOURCES INPUT OUTPUT")?,
|
|
);
|
|
let input = fs::read_to_string(args.get(2).ok_or("missing INPUT")?)?;
|
|
let items = Items::catalog(root)?;
|
|
let recipes = Recipes::load(root, &items)?;
|
|
let brewing = horizon_client::brewing::Brewing::load(root, &items);
|
|
let banners = horizon_client::banner::Banners::load(root);
|
|
let env = Env {
|
|
items: &items,
|
|
recipes: &recipes,
|
|
brewing: &brewing,
|
|
banners: &banners,
|
|
};
|
|
let mut out = String::new();
|
|
for line in input.lines() {
|
|
let case: Value = serde_json::from_str(line)?;
|
|
let kind = Kind::parse(case["menu"].as_str().unwrap_or_default()).ok_or("menu kind")?;
|
|
let mut menu = Menu::new(kind);
|
|
menu.creative = case["creative"].as_bool().unwrap_or(false);
|
|
for (i, slot) in case["slots"].as_array().ok_or("slots")?.iter().enumerate() {
|
|
menu.set_slot(&env, i, parse_stack(slot.as_str().unwrap_or("-"))?);
|
|
}
|
|
menu.carried = parse_stack(case["carried"].as_str().unwrap_or("-"))?;
|
|
menu.settle(&env);
|
|
for (i, v) in case["data"].as_array().ok_or("data")?.iter().enumerate() {
|
|
menu.data[i] = v.as_i64().unwrap_or(0) as i32;
|
|
}
|
|
menu.drops.clear();
|
|
out += &format!("init {}\n", state(&menu));
|
|
for op in case["ops"].as_array().ok_or("ops")? {
|
|
let slot = op[0].as_i64().unwrap_or(0) as i32;
|
|
let button = op[1].as_i64().unwrap_or(0) as i32;
|
|
match op[2].as_str().unwrap_or_default() {
|
|
// ServerboundContainerButtonClickPacket: clickMenuButton.
|
|
"BUTTON" => {
|
|
menu.button(&env, slot);
|
|
out += &format!("{}\n", state(&menu));
|
|
continue;
|
|
}
|
|
// ServerboundContainerSlotStateChangedPacket.
|
|
"SLOT_STATE" => {
|
|
if (0..9).contains(&slot) {
|
|
menu.set_slot_state(slot as usize, button == 1);
|
|
}
|
|
out += &format!("{}\n", state(&menu));
|
|
continue;
|
|
}
|
|
_ => {}
|
|
}
|
|
let kind = Input::parse(op[2].as_str().unwrap_or_default()).ok_or("input")?;
|
|
match menu.click(&env, slot, button, kind) {
|
|
Ok(()) => out += &format!("{}\n", state(&menu)),
|
|
Err(name) => out += &format!("error {name}\n"),
|
|
}
|
|
}
|
|
out += "end\n";
|
|
}
|
|
fs::write(args.get(3).ok_or("missing OUTPUT")?, out)?;
|
|
Ok(())
|
|
}
|