parent
51468398fa
commit
2b02298ae0
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,126 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fuzzy-matcher"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94"
|
||||||
|
dependencies = [
|
||||||
|
"thread_local",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "multi-map"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bba551d6d795f74a01767577ea8339560bf0a65354e0417b7e915ed608443d46"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "poe_data"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"fuzzy-matcher",
|
||||||
|
"multi-map",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.66"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.175"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d25439cd7397d044e2748a6fe2432b5e85db703d6d097bd014b3c0ad1ebff0b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.175"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b23f7ade6f110613c0d63858ddb8b94c1041f550eab58a16b371bdf2c9c80ab4"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.103"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thread_local"
|
||||||
|
version = "1.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "poe_data"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde_derive = "1.0.175"
|
||||||
|
multi-map = "1.3.0"
|
||||||
|
fuzzy-matcher = "0.3.7"
|
||||||
|
serde_json = "1.0.103"
|
||||||
|
serde = "1.0.175"
|
@ -0,0 +1 @@
|
|||||||
|
pub mod world_area;
|
@ -0,0 +1,261 @@
|
|||||||
|
use std::collections::BinaryHeap;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
|
use fuzzy_matcher::skim::SkimMatcherV2;
|
||||||
|
use multi_map::MultiMap;
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
type UnprocessedAreas = Vec<UnprocessedArea>;
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct UnprocessedArea {
|
||||||
|
#[serde(rename = "Id")]
|
||||||
|
pub named_id: String,
|
||||||
|
|
||||||
|
#[serde(rename = "_rid")]
|
||||||
|
pub key_id: usize,
|
||||||
|
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Act")]
|
||||||
|
pub act: i64,
|
||||||
|
|
||||||
|
#[serde(rename = "IsTown")]
|
||||||
|
pub is_town: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "HasWaypoint")]
|
||||||
|
pub has_waypoint: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Connections_WorldAreasKeys")]
|
||||||
|
pub connections_world_areas_keys: Vec<i64>,
|
||||||
|
|
||||||
|
#[serde(rename = "IsVaalArea")]
|
||||||
|
pub is_vaal_area: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Unknown64")]
|
||||||
|
pub unknown64: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Unknown9")]
|
||||||
|
pub unknown9: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type AreaName = String;
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
|
||||||
|
pub struct WorldArea {
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Act")]
|
||||||
|
pub act: i64,
|
||||||
|
|
||||||
|
#[serde(rename = "_rid")]
|
||||||
|
pub key_id: usize,
|
||||||
|
|
||||||
|
#[serde(rename = "IsTown")]
|
||||||
|
pub is_town: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "HasWaypoint")]
|
||||||
|
pub has_waypoint: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Connections_WorldAreasKeys")]
|
||||||
|
pub connections_world_areas_keys: Vec<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type AreaId = usize;
|
||||||
|
pub type WorldAreasMap = MultiMap<AreaName, AreaId, WorldArea>;
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn load_world_areas_map(content: &'static str) -> WorldAreasMap {
|
||||||
|
let mut world_area_map = WorldAreasMap::new();
|
||||||
|
|
||||||
|
serde_json::from_str::<HashMap<AreaName, WorldArea>>(content)
|
||||||
|
.expect("Could not load world areas json")
|
||||||
|
.into_iter()
|
||||||
|
.for_each(|(area_name, world_area)|
|
||||||
|
{
|
||||||
|
world_area_map.insert(area_name, world_area.key_id, world_area);
|
||||||
|
});
|
||||||
|
|
||||||
|
world_area_map
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! load_world_areas {
|
||||||
|
($e:expr) => {
|
||||||
|
crate::world_area::load_world_areas_map(&include_str!($e))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct WorldAreas {
|
||||||
|
pub areas_map: WorldAreasMap,
|
||||||
|
matcher: Matcher,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WorldAreas {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new(areas: WorldAreasMap, matcher: Matcher) -> Self {
|
||||||
|
Self {
|
||||||
|
areas_map: areas,
|
||||||
|
matcher,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn fuzzy_area(&self, count: usize, area: &str) -> Vec<WorldArea> {
|
||||||
|
let mut matches = Vec::new();
|
||||||
|
|
||||||
|
for (_k, (_key_id, v)) in &self.areas_map {
|
||||||
|
if let Some(mut score) = self.matcher.fuzzy_match(&v.name, area) {
|
||||||
|
if v.name.contains(area) {
|
||||||
|
score = i64::MAX;
|
||||||
|
}
|
||||||
|
let f_entry = FEntry{area: v.clone(), score};
|
||||||
|
matches.push(f_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matches.sort_by(|entry1, entry2| {
|
||||||
|
entry1.score.cmp(&entry2.score).reverse()
|
||||||
|
.then(entry1.area.key_id.cmp(&entry2.area.key_id))
|
||||||
|
});
|
||||||
|
|
||||||
|
let matches_areas = matches
|
||||||
|
.into_iter()
|
||||||
|
.map(|entry| entry.area)
|
||||||
|
.take(count)
|
||||||
|
.collect::<Vec<WorldArea>>();
|
||||||
|
|
||||||
|
matches_areas
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn by_area_id(&self, key: AreaId) -> Option<&WorldArea> {
|
||||||
|
self.areas_map.get_alt(&key)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn by_area_name(&self, key: AreaName) -> Option<&WorldArea> {
|
||||||
|
self.areas_map.get(&key)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
struct FEntry {
|
||||||
|
area: WorldArea,
|
||||||
|
score: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for FEntry {
|
||||||
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
|
self.partial_cmp(other).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for FEntry {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
Some(self.score.cmp(&other.score))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Matcher(SkimMatcherV2);
|
||||||
|
|
||||||
|
impl Matcher {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let matcher = SkimMatcherV2::default()
|
||||||
|
.ignore_case()
|
||||||
|
.use_cache(true);
|
||||||
|
|
||||||
|
Matcher(matcher)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for Matcher {
|
||||||
|
type Target = SkimMatcherV2;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Matcher {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn fuzzy_area(&self, areas: &WorldAreasMap, area: &str) -> Vec<WorldArea> {
|
||||||
|
|
||||||
|
let mut matches: BinaryHeap<FEntry> = BinaryHeap::new();
|
||||||
|
|
||||||
|
for (_k, (_key_id, v)) in areas {
|
||||||
|
//println!("k: {:?}\nv: {:?}\n\n", k, v);
|
||||||
|
if let Some(score) = self.fuzzy_match(&v.name, area) {
|
||||||
|
let f_entry = FEntry{area: v.clone(), score};
|
||||||
|
matches.push(f_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut values = matches.into_iter();
|
||||||
|
|
||||||
|
let mut return_vec = Vec::new();
|
||||||
|
|
||||||
|
for _i in 0..30 {
|
||||||
|
if let Some(value) = values.next() {
|
||||||
|
return_vec.push(value.area.clone());
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return_vec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Multimap
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn repack(content: &str, out_path: &str) {
|
||||||
|
let areas_json = serde_json::from_str::<UnprocessedAreas>(content);
|
||||||
|
|
||||||
|
let area_map = areas_json.expect("Could not read world areas").into_iter().filter_map(|w_a| {
|
||||||
|
if
|
||||||
|
w_a.act < 11 &&
|
||||||
|
!w_a.is_vaal_area &&
|
||||||
|
!w_a.connections_world_areas_keys.is_empty() &&
|
||||||
|
!w_a.unknown64 &&
|
||||||
|
!w_a.named_id.starts_with("Map") &&
|
||||||
|
!w_a.named_id.starts_with("Descent") &&
|
||||||
|
!w_a.named_id.starts_with("EndlessLedge") &&
|
||||||
|
w_a.unknown9 != 20
|
||||||
|
{
|
||||||
|
Some((
|
||||||
|
w_a.named_id,
|
||||||
|
WorldArea{
|
||||||
|
name: w_a.name,
|
||||||
|
act: w_a.act,
|
||||||
|
is_town: w_a.is_town,
|
||||||
|
has_waypoint: w_a.has_waypoint,
|
||||||
|
connections_world_areas_keys: w_a.connections_world_areas_keys,
|
||||||
|
key_id: w_a.key_id,
|
||||||
|
}
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}).collect::<HashMap<AreaName, WorldArea>>();
|
||||||
|
|
||||||
|
let new_json = serde_json::to_string(&area_map).unwrap();
|
||||||
|
|
||||||
|
std::fs::write(out_path, &new_json).expect("Could not write to file");
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
fn main() {
|
||||||
|
const unprocessed: &str = "data/unprocessed_world_areas.json";
|
||||||
|
const out_processed: &str = "data/world_areas.json";
|
||||||
|
println!("cargo:rerun-if-changed={unprocessed}");
|
||||||
|
poe_data::world_area::repack(&include_str!(unprocessed), out_processed);
|
||||||
|
}
|
Loading…
Reference in new issue