Mirror von
https://github.com/Chaoscaot/schemsearch
synchronisiert 2024-12-17 23:40:06 +01:00
Fixes and more Tests
Dieser Commit ist enthalten in:
Ursprung
ca249c8900
Commit
74df144d05
@ -8,13 +8,6 @@ members = [
|
|||||||
"schemsearch-java"
|
"schemsearch-java"
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.test]
|
|
||||||
inherits = "release"
|
|
||||||
lto = true
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
|
|
||||||
[profile.small]
|
[profile.small]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
lto = true
|
lto = true
|
||||||
|
@ -29,14 +29,14 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("ignore-block-entities")
|
Arg::new("ignore-block-entities")
|
||||||
.help("Ignores block entities when searching")
|
.help("Ignores block entities when searching [Not Implemented]")
|
||||||
.short('b')
|
.short('b')
|
||||||
.long("ignore-block-entities")
|
.long("ignore-block-entities")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("ignore-entities")
|
Arg::new("ignore-entities")
|
||||||
.help("Ignores entities when searching")
|
.help("Ignores entities when searching [Not Implemented]")
|
||||||
.short('e')
|
.short('e')
|
||||||
.long("ignore-entities")
|
.long("ignore-entities")
|
||||||
.action(ArgAction::SetTrue),
|
.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();
|
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 {
|
for x in matches {
|
||||||
if *output_std {
|
if *output_std {
|
||||||
|
@ -34,7 +34,7 @@ fn read_blockdata<'de, D>(deserializer: D) -> Result<Vec<i32>, D::Error>
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let s: Vec<u8> = Deserialize::deserialize(deserializer)?;
|
let s: Vec<i8> = Deserialize::deserialize(deserializer)?;
|
||||||
Ok(read_varint_array(&s))
|
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 data = Vec::new();
|
||||||
let mut value: i32 = 0;
|
let mut value: i32 = 0;
|
||||||
let mut position = 0;
|
let mut position = 0;
|
||||||
@ -76,7 +76,7 @@ pub fn read_varint_array(read: &Vec<u8>) -> Vec<i32> {
|
|||||||
let mut cursor = 0;
|
let mut cursor = 0;
|
||||||
loop {
|
loop {
|
||||||
match read.get(cursor) {
|
match read.get(cursor) {
|
||||||
Some(byte) => { current_byte = *byte; cursor += 1; },
|
Some(byte) => { current_byte = *byte as u8; cursor += 1; },
|
||||||
None => break,
|
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 schematic = Schematic::load(Path::new(&schematic_path)).unwrap();
|
||||||
let pattern = Schematic::load(Path::new(&pattern_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_data: true,
|
||||||
ignore_block_entities: true,
|
ignore_block_entities: true,
|
||||||
ignore_entities: true,
|
ignore_entities: true,
|
||||||
|
@ -2,6 +2,7 @@ pub mod pattern_mapper;
|
|||||||
|
|
||||||
use pattern_mapper::match_palette;
|
use pattern_mapper::match_palette;
|
||||||
use schemsearch_files::Schematic;
|
use schemsearch_files::Schematic;
|
||||||
|
use crate::pattern_mapper::match_palette_adapt;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct SearchBehavior {
|
pub struct SearchBehavior {
|
||||||
@ -14,7 +15,7 @@ pub struct SearchBehavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn search(
|
pub fn search(
|
||||||
schem: &Schematic,
|
schem: Schematic,
|
||||||
pattern_schem: &Schematic,
|
pattern_schem: &Schematic,
|
||||||
search_behavior: SearchBehavior,
|
search_behavior: SearchBehavior,
|
||||||
) -> Vec<(u16, u16, u16, f64)> {
|
) -> Vec<(u16, u16, u16, f64)> {
|
||||||
@ -26,15 +27,18 @@ pub fn search(
|
|||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern_schem = match match_palette(&schem, &pattern_schem, search_behavior.ignore_block_data) {
|
let pattern_schem = match_palette(&schem, &pattern_schem, search_behavior.ignore_block_data);
|
||||||
Some(x) => x,
|
|
||||||
None => return vec![],
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut matches: Vec<(u16, u16, u16, f64)> = Vec::new();
|
let mut matches: Vec<(u16, u16, u16, f64)> = Vec::new();
|
||||||
|
|
||||||
let pattern_data = pattern_schem.block_data;
|
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 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;
|
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 i in 0..pattern_schem.width as usize {
|
||||||
for j in 0..pattern_schem.height as usize {
|
for j in 0..pattern_schem.height as usize {
|
||||||
for k in 0..pattern_schem.length 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 index = (x + i) + (z + k) * (schem.width as usize) + (y + j) * (schem.width as usize) * (schem.length as usize);
|
||||||
let pattern_index = i + j * pattern_schem.width as usize + k * pattern_schem.width as usize * pattern_schem.height 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 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");
|
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;
|
matching += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +140,7 @@ mod tests {
|
|||||||
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap();
|
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap();
|
||||||
let endstone = Schematic::load(Path::new("../tests/endstone.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_data: true,
|
||||||
ignore_block_entities: true,
|
ignore_block_entities: true,
|
||||||
ignore_entities: true,
|
ignore_entities: true,
|
||||||
@ -151,7 +155,7 @@ mod tests {
|
|||||||
let schematic = Schematic::load(Path::new("../tests/Random.schem")).unwrap();
|
let schematic = Schematic::load(Path::new("../tests/Random.schem")).unwrap();
|
||||||
let pattern = Schematic::load(Path::new("../tests/Pattern.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_data: true,
|
||||||
ignore_block_entities: true,
|
ignore_block_entities: true,
|
||||||
ignore_entities: true,
|
ignore_entities: true,
|
||||||
@ -164,4 +168,22 @@ mod tests {
|
|||||||
assert_eq!(matches.len(), 1);
|
assert_eq!(matches.len(), 1);
|
||||||
assert_eq!(matches[0], (1, 0, 3, 1.0));
|
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: Map<String, i32> = Map::new();
|
||||||
let mut palette_max: i32 = 0;
|
let mut palette_max: i32 = 0;
|
||||||
let reverse_palette = create_reverse_palette(schem);
|
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 = reverse_palette[*block as usize].clone();
|
||||||
let block_name = block_name.split('[').next().unwrap().to_string();
|
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 mut data: Vec<i32> = Vec::new();
|
||||||
|
let reverse_palette = create_reverse_palette(schem);
|
||||||
|
|
||||||
for x in schem.block_data.iter() {
|
for x in &schem.block_data {
|
||||||
let blockname = schem.palette.iter().find(|(_, &v)| v == *x).expect("Invalid Schematic").0;
|
let blockname = &reverse_palette[*x as usize];
|
||||||
let blockname = if ignore_data { normalize_data(&blockname, ignore_data) } else { blockname.clone() };
|
let blockname = if ignore_data { normalize_data(&blockname, ignore_data) } else { blockname.clone() };
|
||||||
let block_id = match matching_palette.get(&blockname) {
|
let block_id = match matching_palette.get(&blockname) {
|
||||||
None => return None,
|
None => -1,
|
||||||
Some(x) => x
|
Some(x) => *x
|
||||||
};
|
};
|
||||||
data.push(*block_id);
|
data.push(block_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(data)
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn match_palette(
|
pub fn match_palette(
|
||||||
schem: &Schematic,
|
schem: &Schematic,
|
||||||
pattern: &Schematic,
|
pattern: &Schematic,
|
||||||
ignore_data: bool,
|
ignore_data: bool,
|
||||||
) -> Option<Schematic> {
|
) -> Schematic {
|
||||||
if ignore_data {
|
if ignore_data {
|
||||||
match_palette_internal(&strip_data(schem), &strip_data(pattern), ignore_data)
|
match_palette_internal(&strip_data(schem), &strip_data(pattern), ignore_data)
|
||||||
} else {
|
} else {
|
||||||
@ -79,16 +79,10 @@ fn match_palette_internal(
|
|||||||
schem: &Schematic,
|
schem: &Schematic,
|
||||||
pattern: &Schematic,
|
pattern: &Schematic,
|
||||||
ignore_data: bool,
|
ignore_data: bool,
|
||||||
) -> Option<Schematic> {
|
) -> Schematic {
|
||||||
if pattern.palette.iter().any(|(k, _)| schem.palette.get(k).is_none()) {
|
let data_pattern: Vec<i32> = match_palette_adapt(&pattern, &schem.palette, ignore_data);
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let data_pattern: Vec<i32> = match match_palette_adapt(&pattern, &schem.palette, ignore_data) {
|
Schematic {
|
||||||
None => return None,
|
|
||||||
Some(x) => x
|
|
||||||
};
|
|
||||||
Some(Schematic {
|
|
||||||
version: pattern.version.clone(),
|
version: pattern.version.clone(),
|
||||||
data_version: pattern.data_version.clone(),
|
data_version: pattern.data_version.clone(),
|
||||||
palette: schem.palette.clone(),
|
palette: schem.palette.clone(),
|
||||||
@ -101,5 +95,5 @@ fn match_palette_internal(
|
|||||||
metadata: pattern.metadata.clone(),
|
metadata: pattern.metadata.clone(),
|
||||||
offset: pattern.offset.clone(),
|
offset: pattern.offset.clone(),
|
||||||
entities: None,
|
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.
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren