use horizon_world::{ component_patch::{Patch, Prototype}, item_stack_refs::{ItemStacks, StackRef}, item_stack_storage::ItemStackData, item_template::{self, ItemTemplate, ValidationRules}, }; use serde_json::Value; use std::{ fs, io::{self, Write}, path::Path, }; type Stack = StackRef; type Template = ItemTemplate; struct Rules; impl ValidationRules for Rules { type ContentsError = std::convert::Infallible; fn has_max_damage(&self, s: &ItemStackData) -> bool { s.component(&1).is_some() } fn max_stack_size(&self, s: &ItemStackData) -> i32 { s.component(&0).copied().unwrap_or(1) } fn validate_contents( &self, _: &ItemStackData, ) -> Result<(), Self::ContentsError> { Ok(()) } } fn opt(v: Option) -> String { v.map_or("none".into(), |v| v.to_string()) } fn patch(v: &Value) -> Patch { Patch::new(v.as_array().unwrap().iter().map(|v| { ( v[0].as_u64().unwrap() as usize, v[1].as_i64().map(|n| n as i32), ) })) } fn proto(v: &Value) -> Prototype { Prototype::new(v.as_array().unwrap().iter().map(|v| { ( v[0].as_u64().unwrap() as usize, v[1].as_i64().unwrap() as i32, ) })) } fn patch_text(p: &Patch) -> String { p.entries() .iter() .map(|(k, v)| format!("{k}={}", opt(*v))) .collect::>() .join(",") } fn all( out: &mut dyn Write, stacks: &[Stack], templates: &[Option