Fixes and more Tests
Dieser Commit ist enthalten in:
Ursprung
ca249c8900
Commit
74df144d05
@ -8,13 +8,6 @@ members = [
|
||||
"schemsearch-java"
|
||||
]
|
||||
|
||||
[profile.test]
|
||||
inherits = "release"
|
||||
lto = true
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[profile.small]
|
||||
inherits = "release"
|
||||
lto = true
|
||||
|
@ -29,14 +29,14 @@ fn main() {
|
||||
)
|
||||
.arg(
|
||||
Arg::new("ignore-block-entities")
|
||||
.help("Ignores block entities when searching")
|
||||
.help("Ignores block entities when searching [Not Implemented]")
|
||||
.short('b')
|
||||
.long("ignore-block-entities")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("ignore-entities")
|
||||
.help("Ignores entities when searching")
|
||||
.help("Ignores entities when searching [Not Implemented]")
|
||||
.short('e')
|
||||
.long("ignore-entities")
|
||||
.action(ArgAction::SetTrue),
|
||||
@ -184,7 +184,7 @@ fn search_schempath(cmd: &mut Command, search_behavior: SearchBehavior, pattern:
|
||||
writeln!(file_out.as_mut().unwrap(), "Searching in schematic: {}", schem_path.file_name().unwrap().to_str().unwrap()).unwrap();
|
||||
}
|
||||
|
||||
let matches = search(&schematic, &pattern, search_behavior);
|
||||
let matches = search(schematic, pattern, search_behavior);
|
||||
|
||||
for x in matches {
|
||||
if *output_std {
|
||||
|
@ -34,7 +34,7 @@ fn read_blockdata<'de, D>(deserializer: D) -> Result<Vec<i32>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s: Vec<u8> = Deserialize::deserialize(deserializer)?;
|
||||
let s: Vec<i8> = Deserialize::deserialize(deserializer)?;
|
||||
Ok(read_varint_array(&s))
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ impl Schematic {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_varint_array(read: &Vec<u8>) -> Vec<i32> {
|
||||
pub fn read_varint_array(read: &Vec<i8>) -> Vec<i32> {
|
||||
let mut data = Vec::new();
|
||||
let mut value: i32 = 0;
|
||||
let mut position = 0;
|
||||
@ -76,7 +76,7 @@ pub fn read_varint_array(read: &Vec<u8>) -> Vec<i32> {
|
||||
let mut cursor = 0;
|
||||
loop {
|
||||
match read.get(cursor) {
|
||||
Some(byte) => { current_byte = *byte; cursor += 1; },
|
||||
Some(byte) => { current_byte = *byte as u8; cursor += 1; },
|
||||
None => break,
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub extern "system" fn Java_SchemSearch_search<'local>(mut env: JNIEnv<'local>,
|
||||
let schematic = Schematic::load(Path::new(&schematic_path)).unwrap();
|
||||
let pattern = Schematic::load(Path::new(&pattern_path)).unwrap();
|
||||
|
||||
let matches = search(&schematic, &pattern, SearchBehavior {
|
||||
let matches = search(schematic, &pattern, SearchBehavior {
|
||||
ignore_block_data: true,
|
||||
ignore_block_entities: true,
|
||||
ignore_entities: true,
|
||||
|
@ -2,6 +2,7 @@ pub mod pattern_mapper;
|
||||
|
||||
use pattern_mapper::match_palette;
|
||||
use schemsearch_files::Schematic;
|
||||
use crate::pattern_mapper::match_palette_adapt;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SearchBehavior {
|
||||
@ -14,7 +15,7 @@ pub struct SearchBehavior {
|
||||
}
|
||||
|
||||
pub fn search(
|
||||
schem: &Schematic,
|
||||
schem: Schematic,
|
||||
pattern_schem: &Schematic,
|
||||
search_behavior: SearchBehavior,
|
||||
) -> Vec<(u16, u16, u16, f64)> {
|
||||
@ -26,15 +27,18 @@ pub fn search(
|
||||
return vec![];
|
||||
}
|
||||
|
||||
let pattern_schem = match match_palette(&schem, &pattern_schem, search_behavior.ignore_block_data) {
|
||||
Some(x) => x,
|
||||
None => return vec![],
|
||||
};
|
||||
let pattern_schem = match_palette(&schem, &pattern_schem, search_behavior.ignore_block_data);
|
||||
|
||||
let mut matches: Vec<(u16, u16, u16, f64)> = Vec::new();
|
||||
|
||||
let pattern_data = pattern_schem.block_data;
|
||||
let schem_data = &schem.block_data;
|
||||
|
||||
let schem_data = if search_behavior.ignore_block_data {
|
||||
match_palette_adapt(&schem, &pattern_schem.palette, search_behavior.ignore_block_data)
|
||||
} else {
|
||||
schem.block_data
|
||||
};
|
||||
|
||||
let air_id = if search_behavior.ignore_air || search_behavior.air_as_any { pattern_schem.palette.get("minecraft:air").unwrap_or(&-1) } else { &-1};
|
||||
|
||||
let pattern_blocks = (pattern_schem.width * pattern_schem.height * pattern_schem.length) as f64;
|
||||
@ -46,11 +50,11 @@ pub fn search(
|
||||
for i in 0..pattern_schem.width as usize {
|
||||
for j in 0..pattern_schem.height as usize {
|
||||
for k in 0..pattern_schem.length as usize {
|
||||
let index = (x + i) + (y + j) * (schem.width as usize) + (z + k) * (schem.width as usize) * (schem.height as usize);
|
||||
let pattern_index = i + j * pattern_schem.width as usize + k * pattern_schem.width as usize * pattern_schem.height as usize;
|
||||
let index = (x + i) + (z + k) * (schem.width as usize) + (y + j) * (schem.width as usize) * (schem.length as usize);
|
||||
let pattern_index = i + k * pattern_schem.width as usize + j * pattern_schem.width as usize * pattern_schem.length as usize;
|
||||
let data = schem_data.get(index as usize).expect("Index out of bounds");
|
||||
let pattern_data = pattern_data.get(pattern_index as usize).expect("Index out of bounds");
|
||||
if data == pattern_data || (search_behavior.ignore_air && *data == *air_id) || (search_behavior.air_as_any && *pattern_data == *air_id) {
|
||||
if *data == *pattern_data || (search_behavior.ignore_air && *data == *air_id) || (search_behavior.air_as_any && *pattern_data == *air_id) {
|
||||
matching += 1;
|
||||
}
|
||||
}
|
||||
@ -136,7 +140,7 @@ mod tests {
|
||||
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap();
|
||||
let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap();
|
||||
|
||||
let _ = search(&schematic, &endstone, SearchBehavior {
|
||||
let _ = search(schematic, &endstone, SearchBehavior {
|
||||
ignore_block_data: true,
|
||||
ignore_block_entities: true,
|
||||
ignore_entities: true,
|
||||
@ -151,7 +155,7 @@ mod tests {
|
||||
let schematic = Schematic::load(Path::new("../tests/Random.schem")).unwrap();
|
||||
let pattern = Schematic::load(Path::new("../tests/Pattern.schem")).unwrap();
|
||||
|
||||
let matches = search(&schematic, &pattern, SearchBehavior {
|
||||
let matches = search(schematic, &pattern, SearchBehavior {
|
||||
ignore_block_data: true,
|
||||
ignore_block_entities: true,
|
||||
ignore_entities: true,
|
||||
@ -164,4 +168,22 @@ mod tests {
|
||||
assert_eq!(matches.len(), 1);
|
||||
assert_eq!(matches[0], (1, 0, 3, 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_search_ws() {
|
||||
let schematic = Schematic::load(Path::new("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap();
|
||||
let pattern = Schematic::load(Path::new("../tests/gray_castle_complex.schem")).unwrap();
|
||||
|
||||
let matches = search(schematic, &pattern, SearchBehavior {
|
||||
ignore_block_data: false,
|
||||
ignore_block_entities: false,
|
||||
ignore_entities: false,
|
||||
ignore_air: false,
|
||||
air_as_any: false,
|
||||
threshold: 0.9
|
||||
});
|
||||
|
||||
println!("{:?}", matches);
|
||||
assert_eq!(matches.len(), 1);
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,8 @@ pub fn strip_data(schem: &Schematic) -> Schematic {
|
||||
let mut palette: Map<String, i32> = Map::new();
|
||||
let mut palette_max: i32 = 0;
|
||||
let reverse_palette = create_reverse_palette(schem);
|
||||
let dat = &schem.block_data;
|
||||
|
||||
for block in dat.iter() {
|
||||
for block in schem.block_data.iter() {
|
||||
let block_name = reverse_palette[*block as usize].clone();
|
||||
let block_name = block_name.split('[').next().unwrap().to_string();
|
||||
|
||||
@ -47,27 +46,28 @@ pub fn strip_data(schem: &Schematic) -> Schematic {
|
||||
}
|
||||
}
|
||||
|
||||
fn match_palette_adapt(schem: &Schematic, matching_palette: &Map<String, i32>, ignore_data: bool) -> Option<Vec<i32>> {
|
||||
pub fn match_palette_adapt(schem: &Schematic, matching_palette: &Map<String, i32>, ignore_data: bool) -> Vec<i32> {
|
||||
let mut data: Vec<i32> = Vec::new();
|
||||
let reverse_palette = create_reverse_palette(schem);
|
||||
|
||||
for x in schem.block_data.iter() {
|
||||
let blockname = schem.palette.iter().find(|(_, &v)| v == *x).expect("Invalid Schematic").0;
|
||||
for x in &schem.block_data {
|
||||
let blockname = &reverse_palette[*x as usize];
|
||||
let blockname = if ignore_data { normalize_data(&blockname, ignore_data) } else { blockname.clone() };
|
||||
let block_id = match matching_palette.get(&blockname) {
|
||||
None => return None,
|
||||
Some(x) => x
|
||||
None => -1,
|
||||
Some(x) => *x
|
||||
};
|
||||
data.push(*block_id);
|
||||
data.push(block_id);
|
||||
}
|
||||
|
||||
Some(data)
|
||||
data
|
||||
}
|
||||
|
||||
pub fn match_palette(
|
||||
schem: &Schematic,
|
||||
pattern: &Schematic,
|
||||
ignore_data: bool,
|
||||
) -> Option<Schematic> {
|
||||
) -> Schematic {
|
||||
if ignore_data {
|
||||
match_palette_internal(&strip_data(schem), &strip_data(pattern), ignore_data)
|
||||
} else {
|
||||
@ -79,16 +79,10 @@ fn match_palette_internal(
|
||||
schem: &Schematic,
|
||||
pattern: &Schematic,
|
||||
ignore_data: bool,
|
||||
) -> Option<Schematic> {
|
||||
if pattern.palette.iter().any(|(k, _)| schem.palette.get(k).is_none()) {
|
||||
return None;
|
||||
}
|
||||
) -> Schematic {
|
||||
let data_pattern: Vec<i32> = match_palette_adapt(&pattern, &schem.palette, ignore_data);
|
||||
|
||||
let data_pattern: Vec<i32> = match match_palette_adapt(&pattern, &schem.palette, ignore_data) {
|
||||
None => return None,
|
||||
Some(x) => x
|
||||
};
|
||||
Some(Schematic {
|
||||
Schematic {
|
||||
version: pattern.version.clone(),
|
||||
data_version: pattern.data_version.clone(),
|
||||
palette: schem.palette.clone(),
|
||||
@ -101,5 +95,5 @@ fn match_palette_internal(
|
||||
metadata: pattern.metadata.clone(),
|
||||
offset: pattern.offset.clone(),
|
||||
entities: None,
|
||||
})
|
||||
}
|
||||
}
|
BIN
tests/endstone_large.schem
Normale Datei
BIN
tests/endstone_large.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/gray_castle_complex.schem
Normale Datei
BIN
tests/gray_castle_complex.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/iron_block.schem
Normale Datei
BIN
tests/iron_block.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/Blue_Fortress.schem
Normale Datei
BIN
tests/wargears/Blue_Fortress.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/Dear-God.schem
Normale Datei
BIN
tests/wargears/Dear-God.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/GrayCastle.schem
Normale Datei
BIN
tests/wargears/GrayCastle.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/PXSuperStarVI.schem
Normale Datei
BIN
tests/wargears/PXSuperStarVI.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/Predator_X.schem
Normale Datei
BIN
tests/wargears/Predator_X.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/wargears/WarpedOwl.schem
Normale Datei
BIN
tests/wargears/WarpedOwl.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/AaZ_Buttercreme.schem
Normale Datei
BIN
tests/warships/AaZ_Buttercreme.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/Donauwelle.schem
Normale Datei
BIN
tests/warships/Donauwelle.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/GreyFly-by-Bosslar.schem
Normale Datei
BIN
tests/warships/GreyFly-by-Bosslar.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/HMS-Invincible_by_aaZ.schem
Normale Datei
BIN
tests/warships/HMS-Invincible_by_aaZ.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/HRMS_Rotterdam.schem
Normale Datei
BIN
tests/warships/HRMS_Rotterdam.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/SMS_Helgoland.schem
Normale Datei
BIN
tests/warships/SMS_Helgoland.schem
Normale Datei
Binäre Datei nicht angezeigt.
BIN
tests/warships/USS_Oklahoma.schem
Normale Datei
BIN
tests/warships/USS_Oklahoma.schem
Normale Datei
Binäre Datei nicht angezeigt.
In neuem Issue referenzieren
Einen Benutzer sperren