1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-25 08:27:44 +00:00

Allow loading territories without a planmap

This commit is contained in:
Joshua Goins 2025-03-23 16:31:30 -04:00
parent 90a78fcaa8
commit 8659623eda

View file

@ -11,35 +11,51 @@ use crate::config::get_config;
/// Represents a loaded zone /// Represents a loaded zone
pub struct Zone { pub struct Zone {
pub id: u16, pub id: u16,
layer_group: LayerGroup, layer_group: Option<LayerGroup>,
} }
impl Zone { impl Zone {
pub fn load(id: u16) -> Self { pub fn load(id: u16) -> Self {
let config = get_config(); let config = get_config();
let mut game_data = let mut zone = Self {
GameData::from_existing(Platform::Win32, &config.game_location).unwrap(); id,
layer_group: None,
};
let exh = game_data.read_excel_sheet_header("TerritoryType").unwrap(); let Some(mut game_data) = GameData::from_existing(Platform::Win32, &config.game_location)
let exd = game_data else {
.read_excel_sheet("TerritoryType", &exh, Language::None, 0) return zone;
.unwrap(); };
let territory_type_row = &exd.read_row(&exh, id as u32).unwrap()[0]; let Some(exh) = game_data.read_excel_sheet_header("TerritoryType") else {
return zone;
};
let Some(exd) = game_data.read_excel_sheet("TerritoryType", &exh, Language::None, 0) else {
return zone;
};
let Some(territory_type_row) = &exd.read_row(&exh, id as u32) else {
return zone;
};
let territory_type_row = &territory_type_row[0];
// e.g. ffxiv/fst_f1/fld/f1f3/level/f1f3 // e.g. ffxiv/fst_f1/fld/f1f3/level/f1f3
let physis::exd::ColumnData::String(bg_path) = &territory_type_row.data[1] else { let physis::exd::ColumnData::String(bg_path) = &territory_type_row.data[1] else {
panic!("Unexpected type!"); panic!("Unexpected type!");
}; };
let path = format!( let Some(level_index) = bg_path.find("/level/") else {
"bg/{}/level/planmap.lgb", return zone;
&bg_path[..bg_path.find("/level/").unwrap()] };
);
let lgb = game_data.extract(&path).unwrap(); let path = format!("bg/{}/level/planmap.lgb", &bg_path[..level_index]);
let layer_group = LayerGroup::from_existing(&lgb).unwrap(); let Some(lgb) = game_data.extract(&path) else {
Self { id, layer_group } return zone;
};
zone.layer_group = LayerGroup::from_existing(&lgb);
zone
} }
/// Search for an exit box matching an id. /// Search for an exit box matching an id.
@ -48,7 +64,7 @@ impl Zone {
instance_id: u32, instance_id: u32,
) -> Option<(&InstanceObject, &ExitRangeInstanceObject)> { ) -> Option<(&InstanceObject, &ExitRangeInstanceObject)> {
// TODO: also check position! // TODO: also check position!
for group in &self.layer_group.layers { for group in &self.layer_group.as_ref().unwrap().layers {
for object in &group.objects { for object in &group.objects {
if let LayerEntryData::ExitRange(exit_range) = &object.data { if let LayerEntryData::ExitRange(exit_range) = &object.data {
if object.instance_id == instance_id { if object.instance_id == instance_id {
@ -66,7 +82,7 @@ impl Zone {
instance_id: u32, instance_id: u32,
) -> Option<(&InstanceObject, &PopRangeInstanceObject)> { ) -> Option<(&InstanceObject, &PopRangeInstanceObject)> {
// TODO: also check position! // TODO: also check position!
for group in &self.layer_group.layers { for group in &self.layer_group.as_ref().unwrap().layers {
for object in &group.objects { for object in &group.objects {
if let LayerEntryData::PopRange(pop_range) = &object.data { if let LayerEntryData::PopRange(pop_range) = &object.data {
if object.instance_id == instance_id { if object.instance_id == instance_id {