From 99c92d1b678014c1f1e0e8c1a780af597d6e6407 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 9 May 2025 18:03:25 -0400 Subject: [PATCH] Update and use the nice, new Physis ColumnData API Now the GameData::get_warp function looks much closer to how I want it to! --- Cargo.lock | 2 +- src/common/gamedata.rs | 13 ++++--------- src/world/connection.rs | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27328ea..3080d69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1017,7 +1017,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "physis" version = "0.4.0" -source = "git+https://github.com/redstrate/physis#70343e12125c70cffa1998e68ff28a8d2dc4f3df" +source = "git+https://github.com/redstrate/physis#309726163a0d76f26831236f43740a2c8bd1b01d" dependencies = [ "binrw", "bitflags", diff --git a/src/common/gamedata.rs b/src/common/gamedata.rs index fc154b3..307aa0e 100644 --- a/src/common/gamedata.rs +++ b/src/common/gamedata.rs @@ -132,19 +132,14 @@ impl GameData { } /// Returns the pop range object id that's associated with the warp id - pub fn get_warp(&mut self, warp_id: u32) -> (u32, u16) { + pub fn get_warp(&mut self, warp_id: u32) -> Option<(u32, u16)> { let warp_sheet = Warp::read_from(&mut self.game_data, Language::English); let row = warp_sheet.get_row(warp_id); - let physis::exd::ColumnData::UInt32(pop_range_id) = row.PopRange() else { - panic!("Unexpected type!"); - }; + let pop_range_id = row.PopRange().into_u32()?; + let zone_id = row.TerritoryType().into_u16()?; - let physis::exd::ColumnData::UInt16(zone_id) = row.TerritoryType() else { - panic!("Unexpected type!"); - }; - - (*pop_range_id, *zone_id) + Some((*pop_range_id, *zone_id)) } } diff --git a/src/world/connection.rs b/src/world/connection.rs index 88888bb..53c1d86 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -434,7 +434,9 @@ impl ZoneConnection { // find the pop range on the other side { let mut game_data = self.gamedata.lock().unwrap(); - let (pop_range_id, zone_id) = game_data.get_warp(warp_id); + let (pop_range_id, zone_id) = game_data + .get_warp(warp_id) + .expect("Failed to find the warp!"); let new_zone = Zone::load(&mut game_data.game_data, zone_id);