2025-03-15 19:34:29 -04:00
|
|
|
use physis::{
|
2025-03-15 21:41:39 -04:00
|
|
|
common::{Language, Platform},
|
2025-03-15 19:34:29 -04:00
|
|
|
gamedata::GameData,
|
|
|
|
layer::{
|
|
|
|
ExitRangeInstanceObject, InstanceObject, LayerEntryData, LayerGroup, PopRangeInstanceObject,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2025-03-15 20:36:39 -04:00
|
|
|
use crate::config::get_config;
|
2025-03-15 19:34:29 -04:00
|
|
|
|
|
|
|
/// Represents a loaded zone
|
2025-03-28 22:34:34 -04:00
|
|
|
#[derive(Default)]
|
2025-03-15 19:34:29 -04:00
|
|
|
pub struct Zone {
|
2025-03-15 20:49:07 -04:00
|
|
|
pub id: u16,
|
2025-03-28 22:34:34 -04:00
|
|
|
planevent: Option<LayerGroup>,
|
|
|
|
vfx: Option<LayerGroup>,
|
|
|
|
planmap: Option<LayerGroup>,
|
|
|
|
planner: Option<LayerGroup>,
|
|
|
|
bg: Option<LayerGroup>,
|
|
|
|
sound: Option<LayerGroup>,
|
|
|
|
planlive: Option<LayerGroup>,
|
2025-03-15 19:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Zone {
|
|
|
|
pub fn load(id: u16) -> Self {
|
|
|
|
let config = get_config();
|
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let mut zone = Self {
|
|
|
|
id,
|
2025-03-28 22:34:34 -04:00
|
|
|
..Default::default()
|
2025-03-23 16:31:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let Some(mut game_data) = GameData::from_existing(Platform::Win32, &config.game_location)
|
|
|
|
else {
|
|
|
|
return zone;
|
|
|
|
};
|
2025-03-15 21:41:39 -04:00
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
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;
|
|
|
|
};
|
2025-03-15 21:41:39 -04:00
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let Some(territory_type_row) = &exd.read_row(&exh, id as u32) else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
let territory_type_row = &territory_type_row[0];
|
2025-03-15 21:41:39 -04:00
|
|
|
|
|
|
|
// e.g. ffxiv/fst_f1/fld/f1f3/level/f1f3
|
|
|
|
let physis::exd::ColumnData::String(bg_path) = &territory_type_row.data[1] else {
|
|
|
|
panic!("Unexpected type!");
|
|
|
|
};
|
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let Some(level_index) = bg_path.find("/level/") else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
|
2025-03-28 22:34:34 -04:00
|
|
|
let mut load_lgb = |name: &str| -> Option<LayerGroup> {
|
|
|
|
let path = format!("bg/{}/level/{}.lgb", &bg_path[..level_index], name);
|
|
|
|
tracing::info!("Loading {path}");
|
|
|
|
let Some(lgb) = game_data.extract(&path) else {
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
LayerGroup::from_existing(&lgb)
|
2025-03-23 16:31:30 -04:00
|
|
|
};
|
2025-03-28 22:34:34 -04:00
|
|
|
|
|
|
|
zone.planevent = load_lgb("planevent");
|
|
|
|
zone.vfx = load_lgb("vfx");
|
|
|
|
zone.planmap = load_lgb("planmap");
|
|
|
|
zone.planner = load_lgb("planner");
|
|
|
|
zone.bg = load_lgb("bg");
|
|
|
|
zone.sound = load_lgb("sound");
|
|
|
|
zone.planlive = load_lgb("planlive");
|
2025-03-23 16:31:30 -04:00
|
|
|
|
|
|
|
zone
|
2025-03-15 19:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Search for an exit box matching an id.
|
|
|
|
pub fn find_exit_box(
|
|
|
|
&self,
|
|
|
|
instance_id: u32,
|
|
|
|
) -> Option<(&InstanceObject, &ExitRangeInstanceObject)> {
|
|
|
|
// TODO: also check position!
|
2025-03-28 22:34:34 -04:00
|
|
|
for group in &self.planmap.as_ref().unwrap().layers {
|
2025-03-15 19:34:29 -04:00
|
|
|
for object in &group.objects {
|
|
|
|
if let LayerEntryData::ExitRange(exit_range) = &object.data {
|
|
|
|
if object.instance_id == instance_id {
|
|
|
|
return Some((object, exit_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn find_pop_range(
|
|
|
|
&self,
|
|
|
|
instance_id: u32,
|
|
|
|
) -> Option<(&InstanceObject, &PopRangeInstanceObject)> {
|
|
|
|
// TODO: also check position!
|
2025-03-28 22:34:34 -04:00
|
|
|
for group in &self.planmap.as_ref().unwrap().layers {
|
|
|
|
for object in &group.objects {
|
|
|
|
if let LayerEntryData::PopRange(pop_range) = &object.data {
|
|
|
|
if object.instance_id == instance_id {
|
|
|
|
return Some((object, pop_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For certain PopRanges (e.g. the starting position in the opening zones)
|
|
|
|
for group in &self.planevent.as_ref().unwrap().layers {
|
2025-03-15 19:34:29 -04:00
|
|
|
for object in &group.objects {
|
|
|
|
if let LayerEntryData::PopRange(pop_range) = &object.data {
|
|
|
|
if object.instance_id == instance_id {
|
|
|
|
return Some((object, pop_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|