mod attempt;
pub mod classify;
mod export;
mod kept;
pub mod keys;
mod plan;
#[cfg(feature = "gltf")]
mod prefab;
#[cfg(feature = "gltf")]
pub use prefab::failure::export as classify_gltf;
#[cfg(feature = "gltf")]
pub use prefab::{Prefabs, Selection, cut_prefabs};
pub mod read;
pub mod recognize;
pub mod register;
mod resource;
pub mod seam;
mod select;
mod sprites;
mod table;
pub mod winners;
use unityrs_core::limits::Charge;
use unityrs_core::{Bytes, RawStr};
pub use classify::{Class, Reason};
pub use keys::{KeyRule, KeyTable, Template, TemplateError, TemplateKind};
pub use register::{
Admit, Bits, Data, PeekBits, Registration, Staged, peek, register, register_bytes, same_open,
};
pub use seam::{Context, Hooks, MemberTemplate, NoHooks, Registered};
pub use select::select_own;
pub use unityrs_texture::{Format, Formats, TEXTURE_FORMATS};
pub use winners::{Candidate, Decision, Prefer, Rule, decide};
#[derive(Clone, Debug)]
pub struct Options {
pub sprite_key: Template,
pub json_key: Template,
pub texture_key: Option<Template>,
pub sprites_key: Option<Template>,
pub script_classes: Vec<Vec<u8>>,
pub skip_name_suffixes: Vec<Vec<u8>>,
pub atlases: bool,
pub formats: Formats,
pub image: ImageEncoding,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ImageEncoding {
#[default]
Png,
PngFast,
Webp { quality: u8 },
}
impl ImageEncoding {
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Png => "png",
Self::PngFast => "png_fast",
Self::Webp { .. } => "webp",
}
}
}
#[derive(Clone, Debug)]
pub struct Member {
pub id: String,
pub data: Bytes,
}
#[derive(Clone, Copy, Debug)]
pub struct View<'a> {
pub input: &'a Member,
pub members: &'a [Member],
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum OutputKind {
Texture,
Sprite,
AtlasJson,
AtlasSprite,
Glb,
}
impl OutputKind {
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Texture => "texture",
Self::Sprite => "sprite",
Self::AtlasJson => "atlas_json",
Self::AtlasSprite => "atlas_sprite",
Self::Glb => "glb",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum SkipOutput {
Texture,
Sprite,
AtlasJson,
AtlasSprite,
Atlas,
Glb,
}
impl SkipOutput {
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Texture => "texture",
Self::Sprite => "sprite",
Self::AtlasJson => "atlas_json",
Self::AtlasSprite => "atlas_sprite",
Self::Atlas => "atlas",
Self::Glb => "glb",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Picture {
pub mode: &'static str,
pub width: u32,
pub height: u32,
pub visible_hash: [u8; 32],
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MemberPath {
pub archive: usize,
pub path: Result<String, Rejected>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Rejected {
pub rule: KeyRule,
pub path: String,
pub cut: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PrefabRow {
pub file_index: u32,
pub ordinal: u32,
pub serialized_file: RawStr,
pub path: Option<RawStr>,
pub root: Option<(RawStr, i64)>,
}
#[derive(Debug)]
pub struct GlbDiagnostic {
#[cfg(feature = "gltf")]
pub resource: Option<unityrs_gltf::RendererResource>,
pub key: String,
pub node: usize,
pub reason: &'static str,
}
#[derive(Debug)]
pub struct Output {
pub prefab: Option<PrefabRow>,
pub plan_index: u64,
pub key: String,
pub kind: OutputKind,
pub unit: Option<String>,
pub serialized_file: RawStr,
pub path_id: i64,
pub sprite: Option<usize>,
pub bytes: Vec<u8>,
pub md5: [u8; 16],
pub picture: Option<Picture>,
pub members: Vec<MemberPath>,
_charge: Option<Charge>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Skip {
pub serialized_file: RawStr,
pub path_id: i64,
pub class: String,
pub output: SkipOutput,
pub sprite: Option<usize>,
pub reason: Reason,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PrefabSkip {
pub skip: Skip,
pub row: PrefabRow,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SheetBy {
MaterialName,
AtlasName,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SheetRow {
pub atlas_file: RawStr,
pub atlas_path_id: i64,
pub by: SheetBy,
pub texture_file: RawStr,
pub texture_path_id: i64,
}
#[derive(Debug, Default)]
pub struct Cut {
pub glb_diagnostics: Vec<GlbDiagnostic>,
pub prefab_plan_skips: Vec<PrefabSkip>,
pub prefab_export_skips: Vec<PrefabSkip>,
pub plan_skips: Vec<Skip>,
pub export_skips: Vec<Skip>,
pub unresolved_scripts: u64,
pub sheets: Vec<SheetRow>,
pub nested_containers: Vec<RawStr>,
_charge: Option<Charge>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Failure {
Input(Reason),
Run(Reason),
Stopped,
}
impl From<Class> for Failure {
fn from(c: Class) -> Self {
match c {
Class::Skip(r) | Class::Input(r) => Self::Input(r),
Class::Run(r) => Self::Run(r),
}
}
}
pub fn cut(ctx: Context<'_>, options: &Options) -> Result<Cut, Failure> {
cut_inner(
ctx,
options,
#[cfg(feature = "gltf")]
None,
)
}
fn cut_inner(
ctx: Context<'_>,
options: &Options,
#[cfg(feature = "gltf")] mut prefabs: Option<Prefabs<'_, '_>>,
) -> Result<Cut, Failure> {
let Context {
registered,
meter,
input,
hooks,
max_evictions,
prefix,
members,
keys,
sink,
} = ctx;
let seam = seam::Seam {
registered,
meter,
hooks,
max_evictions,
prefix,
members,
};
seam.stop()?;
let mut attempt = attempt::Attempt::new(seam, options, input, keys, sink)?;
let files = attempt.select()?;
let planned = attempt.plan(files.as_slice())?;
#[cfg(feature = "gltf")]
let prefab_plan = prefabs
.as_mut()
.map(|prefabs| attempt.plan_prefabs(files.as_slice(), planned.next_ordinal, prefabs))
.transpose()?;
attempt.export(&planned)?;
#[cfg(feature = "gltf")]
if let Some((prefabs, plan)) = prefabs.as_ref().zip(prefab_plan) {
attempt.export_prefabs(prefabs, plan)?;
}
drop(planned);
drop(files);
Ok(attempt.finish())
}