use super::super::{
BuildError, PropName, atlas, file, format, material, mono_script, sheet, texture,
texture_streamed,
};
use super::{Built, CutOptions, NULL, SCRIPT, SceneBundle, by_name, one, plain, rgba, scene};
use crate::env::{bundle, res_bytes, web_file};
use crate::ngui::V;
use crate::web::unsupported_name_length;
pub fn sheet_skips() -> Built {
let one_sprite = || vec![plain("a", (0, 0, 1, 1))];
let cab = file(
&[],
&[
mono_script(1, "NGUIAtlas"),
texture(2, b"alpha", format::ALPHA8, (2, 2), vec![1, 2, 3, 4]),
texture(3, b"short", format::RGBA32, (4, 4), vec![7; 10]),
texture(4, b"flat", format::RGBA32, (2, 0), Vec::new()),
by_name(5, "alpha", one_sprite()),
by_name(6, "short", one_sprite()),
by_name(7, "flat", one_sprite()),
texture(8, b"huge", format::DXT1, (16_385, 16_381), vec![0; 8]),
texture(9, b"wide", format::RGBA32, (67_108_857, 1), vec![0; 4]),
texture(10, b"neg", format::RGBA32, (-2, 2), vec![0; 16]),
texture(11, b"nodata", format::RGBA32, (2, 2), Vec::new()),
by_name(12, "huge", one_sprite()),
by_name(13, "wide", one_sprite()),
by_name(14, "neg", one_sprite()),
by_name(15, "nodata", one_sprite()),
],
true,
)?;
Ok(scene(
vec![one("x.bundle", &[("CAB-x12", cab)], &[])],
&["x.bundle"],
CutOptions::textures("{name}.png"),
))
}
pub fn streamed_sheets() -> Built {
let streamed = |id, name: &str, size, path: &str, offset, len| {
texture_streamed(id, name.as_bytes(), format::RGBA32, size, path, offset, len)
};
let mut own_res = res_bytes(5, 0x70);
own_res.extend(sheet(0x17, 2, 2, false));
let rows: [(i64, &str, &str); 6] = [
(14, "res", "archive:/CAB-x16/res.dat"),
(15, "as", "archive:/CAB-x16/as.dat"),
(16, "st", "archive:/CAB-x16/st.dat"),
(17, "bb", "archive:/CAB-x16/CAB-b.resS"),
(18, "cc", "archive:/CAB-x16/CAB-c.resS"),
(19, "self", "archive:/CAB-x16/CAB-x16"),
];
let mut objects = vec![
mono_script(1, "NGUIAtlas"),
streamed(2, "own", (2, 2), "archive:/CAB-x16/CAB-x16.resS", 5, 16),
streamed(3, "dep", (1, 2), "archive:/CAB-d16/CAB-d16.resS", 0, 8),
streamed(4, "gone", (1, 1), "archive:/CAB-x16/CAB-missing.resS", 0, 4),
streamed(5, "twin", (2, 1), "archive:/CAB-x16/CAB-twin.resS", 0, 8),
streamed(6, "empty", (2, 2), "", 0, 0),
streamed(7, "negs", (-1, 1), "archive:/CAB-x16/CAB-x16.resS", 5, 4),
by_name(8, "own", vec![plain("s", (0, 0, 2, 2))]),
by_name(9, "dep", vec![plain("s", (0, 0, 1, 2))]),
by_name(10, "gone", vec![plain("s", (0, 0, 1, 1))]),
by_name(11, "twin", vec![plain("s", (0, 0, 2, 1))]),
by_name(12, "empty", vec![plain("s", (0, 0, 1, 1))]),
by_name(13, "negs", vec![plain("s", (0, 0, 1, 1))]),
];
for (id, name, path) in rows {
objects.push(streamed(id, name, (1, 1), path, 0, 4));
objects.push(by_name(id + 10, name, vec![plain("s", (0, 0, 1, 1))]));
}
let cab = file(&[], &objects, true)?;
let pointing = file(
&["archive:/inner/inner"],
&[
mono_script(1, "NGUIAtlas"),
atlas(
2,
b"pp",
SCRIPT,
(1, 1),
vec![plain("s", (0, 0, 1, 1))],
Vec::new(),
),
rgba(3, "pp", 0x49, 1, 1),
],
true,
)?;
let inner = bundle(&[("CAB-twin.resS", sheet(0x19, 2, 1, false))]);
let nested_b = bundle(&[("CAB-b.resS", sheet(0x46, 1, 1, false))]);
let dep = file(&[], &[], true)?;
let x16 = |base| sheet(base, 1, 1, false);
Ok(scene(
vec![
one(
"d.bundle",
&[("CAB-d16", dep), ("CAB-d16.resS", sheet(0x1A, 1, 2, false))],
&[],
),
one(
"x.bundle",
&[
("CAB-x16", cab),
("CAB-x16p", pointing),
("CAB-x16.resS", own_res),
("CAB-twin.resS", sheet(0x18, 2, 1, false)),
("inner", inner),
("res.resource", x16(0x41)),
("res.resS", x16(0x44)),
("as.assets.resS", x16(0x42)),
("st.resS", x16(0x43)),
("sub/CAB-b.resS", x16(0x45)),
("CAB-b.resS", nested_b),
("CAB-c.resS", x16(0x47)),
("dir/CAB-c.resS", x16(0x48)),
],
&["d.bundle"],
),
],
&["x.bundle"],
CutOptions::textures("{name}.png"),
))
}
pub fn repeated_rows() -> Built {
let x16 = |base| sheet(base, 1, 1, false);
let streamed = |id, name: &[u8], path: &str| {
texture_streamed(id, name, format::RGBA32, (1, 1), path, 0, 4)
};
let cab = file(
&[],
&[
mono_script(1, "NGUIAtlas"),
streamed(2, b"rep", "archive:/CAB-x20/sheet.resS"),
streamed(3, b"nest", "archive:/CAB-x20/CAB-n.resS"),
by_name(4, "rep", vec![plain("s", (0, 0, 1, 1))]),
by_name(5, "nest", vec![plain("s", (0, 0, 1, 1))]),
],
true,
)?;
let nested = bundle(&[("CAB-n.resS", x16(0x55))]);
Ok(scene(
vec![one(
"x.bundle",
&[
("CAB-x20", cab),
("sheet.resS", x16(0x51)),
("SHEET.resS", x16(0x52)),
("sheet.resS", x16(0x53)),
("CAB-n.resS", x16(0x54)),
("CAB-n.resS", nested),
],
&[],
)],
&["x.bundle"],
CutOptions::textures("{name}.png"),
))
}
pub fn fallback_rows() -> Built {
let x22 = |base| sheet(base, 1, 1, false);
let streamed = |id, name: &[u8], path: &str| {
texture_streamed(id, name, format::RGBA32, (1, 1), path, 0, 4)
};
let one_sprite = || vec![plain("s", (0, 0, 1, 1))];
let cab = file(
&[
"archive:/CAB-dm/CAB-dm",
"archive:/CAB-dn/CAB-dn",
"archive:/CAB-dw/CAB-dw",
"archive:/CAB-dz/CAB-dz",
"archive:/CAB-d22/w.resS",
],
&[
mono_script(1, "NGUIAtlas"),
streamed(2, b"dr", "archive:/CAB-x22/r.resS"),
streamed(3, b"nn", "archive:/CAB-x22/n.resS"),
by_name(4, "dr", one_sprite()),
by_name(5, "nn", one_sprite()),
atlas(6, b"am", SCRIPT, (1, 1), one_sprite(), Vec::new()),
atlas(7, b"ms", (1, 2), NULL, one_sprite(), Vec::new()),
atlas(8, b"an", SCRIPT, (2, 1), one_sprite(), Vec::new()),
atlas(9, b"ns", (2, 2), NULL, one_sprite(), Vec::new()),
rgba(10, "mx", 0x84, 1, 1),
rgba(11, "am", 0x85, 1, 1),
rgba(12, "nx", 0x86, 1, 1),
rgba(13, "an", 0x87, 1, 1),
streamed(14, b"wq", "archive:/CAB-x22/w.resS"),
by_name(15, "wq", one_sprite()),
streamed(16, b"qq", "archive:/CAB-x22/q.resS"),
by_name(17, "qq", one_sprite()),
streamed(18, b"sd", "archive:/CAB-d22/CAB-d22"),
by_name(19, "sd", one_sprite()),
streamed(20, b"wv", "archive:/CAB-x22/w2.resS"),
by_name(21, "wv", one_sprite()),
streamed(22, b"wt", "archive:/CAB-x22/w4.resS"),
by_name(23, "wt", one_sprite()),
atlas(24, b"aw", SCRIPT, (3, 1), one_sprite(), Vec::new()),
atlas(25, b"az", SCRIPT, (4, 1), one_sprite(), Vec::new()),
rgba(26, "wx", 0x94, 1, 1),
rgba(27, "aw", 0x95, 1, 1),
rgba(28, "zx", 0x96, 1, 1),
rgba(29, "az", 0x97, 1, 1),
streamed(30, b"wi", "archive:/CAB-x22/in2.resS"),
by_name(31, "wi", one_sprite()),
],
true,
)?;
let holder = bundle(&[
("n.resS", x22(0x83)),
(
"pad5.resS",
unsupported_name_length(&[("in5.resS", x22(0x99))]),
),
]);
Ok(scene(
vec![
fallback_dependency()?,
one(
"e.bundle",
&[
("CAB-e22", file(&[], &[mono_script(1, "Dependency")], true)?),
("CAB-dn", bundle(&[("pad.resS", x22(0x8D))])),
],
&[],
),
one(
"x.bundle",
&[
("CAB-x22", cab),
("n.resS", holder),
("q.resS", bundle(&[("q.resS", x22(0x89))])),
],
&["d.bundle", "e.bundle"],
),
],
&["x.bundle"],
CutOptions::textures("{name}.png"),
))
}
fn fallback_dependency() -> Result<SceneBundle, BuildError> {
let x22 = |base| sheet(base, 1, 1, false);
let wrap = bundle(&[("w.resS", bundle(&[("inner.resS", x22(0x8A))]))]);
let dep = file(
&["archive:/CAB-d22/w4.resS"],
&[mono_script(1, "Dependency")],
true,
)?;
let held = |x: &str| {
file(
&[],
&[
material(1, "held", PropName::Plain, &[("_MainTex", (0, 3))]),
mono_script(2, "NGUIAtlas"),
rgba(3, x, 0x8F, 1, 1),
],
true,
)
};
let shadow = bundle(&[("other.resS", x22(0x82))]);
Ok(one(
"d.bundle",
&[
("CAB-d22", dep),
("r.resS", x22(0x81)),
("r.resS", shadow),
("CAB-dm", held("mx")?),
("sub/CAB-dm", bundle(&[("pad.resS", x22(0x8B))])),
("CAB-dn", held("nx")?),
("w.resS", x22(0x88)),
("wrap", wrap),
("q.resource", x22(0x8C)),
("w2.resS", x22(0x90)),
(
"wrap2",
bundle(&[(
"w2.resS",
unsupported_name_length(&[("in2.resS", x22(0x91))]),
)]),
),
(
"w4.resS",
unsupported_name_length(&[("in4.resS", x22(0x92))]),
),
("CAB-dw", held("wx")?),
(
"sub/CAB-dw",
unsupported_name_length(&[("pad3.resS", x22(0x93))]),
),
("CAB-dz", held("zx")?),
(
"wrap3",
bundle(&[(
"CAB-dz",
unsupported_name_length(&[("pad4.resS", x22(0x98))]),
)]),
),
],
&[],
))
}
pub fn crop_bounds() -> Built {
super::alone(
"CAB-x17",
&[
mono_script(1, "NGUIAtlas"),
rgba(2, "cb", 0x1B, 1, 1),
by_name(
3,
"cb",
vec![
plain("ok", (0, 0, 1, 1)),
plain("bomb", (0, 0, 20_000, 10_000)),
plain("far", (i32::MAX, 0, 1, 1)),
plain("low", (0, i32::MAX, 1, 1)),
],
),
rgba(4, "big", 0x1F, 1, 1),
by_name(5, "big", vec![wide_sprite()]),
],
)
}
fn wide_sprite() -> V {
let int64 = |name: &str, v: i64| (name.to_owned(), V::Int64(v));
V::Struct(
"UISpriteData".to_owned(),
vec![
("name".to_owned(), V::Str(b"wide".to_vec())),
int64("x", 0),
int64("y", 0),
int64("width", 1 << 33),
int64("height", 1 << 31),
],
)
}
pub fn failed_sheet_rows() -> Built {
let cab = file(
&[],
&[
mono_script(1, "NGUIAtlas"),
rgba(2, "decoy", 0x61, 1, 1),
texture(3, b"bad", format::RGBA32, (4, 4), vec![7; 10]),
material(4, "bmat", PropName::Plain, &[("_MainTex", (0, 3))]),
atlas(
5,
b"a1",
SCRIPT,
(0, 4),
vec![plain("s", (0, 0, 1, 1))],
Vec::new(),
),
atlas(
6,
b"a2",
SCRIPT,
(0, 4),
vec![plain("s", (0, 0, 1, 1))],
Vec::new(),
),
],
true,
)?;
let options = CutOptions {
sprite_key: "{sprite}.png".to_owned(),
json_key: "atlas.json".to_owned(),
..CutOptions::textures("sheet.png")
};
Ok(scene(
vec![one("x.bundle", &[("CAB-x21", cab)], &[])],
&["x.bundle"],
options,
))
}
pub fn webfile_sibling() -> Built {
let dep = file(
&["archive:/CAB-dv/wv.resS"],
&[material(1, "mv", PropName::Plain, &[("_MainTex", (1, 5))])],
true,
)?;
let decoy = file(&[], &[rgba(5, "decoy", 0xA1, 1, 1)], true)?;
let cab = file(
&["archive:/CAB-dv/CAB-dv"],
&[
mono_script(1, "NGUIAtlas"),
atlas(
2,
b"hop",
SCRIPT,
(1, 1),
vec![plain("s", (0, 0, 1, 1))],
Vec::new(),
),
rgba(3, "decoy", 0xA2, 1, 1),
rgba(4, "hop", 0xA3, 1, 1),
],
true,
)?;
let web = web_file(&[("CAB-wv", decoy)]);
Ok(scene(
vec![
one("d.bundle", &[("CAB-dv", dep), ("wv.resS", web)], &[]),
one("x.bundle", &[("CAB-xv", cab)], &["d.bundle"]),
],
&["x.bundle"],
CutOptions::default(),
))
}