use assembly_core::types::{ObjectID, ObjectTemplate, Quaternion, Vector3f, WorldID};
use std::{collections::HashMap, fmt};
#[cfg(feature = "serde-derives")]
use serde::Serialize;
enum ErrorKind {
ArgumentError,
}
pub struct Error {
kind: ErrorKind,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
ErrorKind::ArgumentError => write!(f, "Argument Error"),
}
}
}
impl Error {
fn argument_error() -> Self {
Self {
kind: ErrorKind::ArgumentError,
}
}
}
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
#[derive(Clone, Debug)]
pub struct ZonePathsVersion(u32);
impl ZonePathsVersion {
pub fn id(&self) -> u32 {
self.0
}
}
impl From<u32> for ZonePathsVersion {
fn from(v: u32) -> Self {
Self(v)
}
}
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
#[derive(Clone, Copy, Debug)]
pub struct PathVersion(u32);
impl From<u32> for PathVersion {
fn from(v: u32) -> Self {
Self(v)
}
}
impl PathVersion {
pub fn min(self, val: u32) -> bool {
self.0 >= val
}
pub fn id(&self) -> u32 {
self.0
}
}
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
#[derive(Debug, Copy, Clone)]
pub enum PathType {
Movement,
MovingPlatform,
Property,
Camera,
Spawner,
Showcase,
Race,
Rail,
}
impl PathType {
const VALUES: [PathType; 8] = [
Self::Movement,
Self::MovingPlatform,
Self::Property,
Self::Camera,
Self::Spawner,
Self::Showcase,
Self::Race,
Self::Rail,
];
pub fn from_u32(v: u32) -> Option<Self> {
Self::VALUES.get(v as usize).copied()
}
}
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
#[derive(Debug)]
pub enum PathComposition {
Polygon,
Points,
Line,
}
impl PathComposition {
pub fn from_u32(v: u32) -> Result<Self, Error> {
match v {
0 => Ok(Self::Polygon),
1 => Ok(Self::Points),
2 => Ok(Self::Line),
_ => Err(Error {
kind: ErrorKind::ArgumentError,
}),
}
}
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataMovement {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub enum PathDataMovingPlatform {
PreV13,
V13ToV17 {
platform_travel_sound: String,
},
PostV18 {
something: u8,
},
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub enum PropertyRentalTimeUnit {
Forever,
Seconds,
Minutes,
Hours,
Days,
Weeks,
Months,
Years,
}
impl PropertyRentalTimeUnit {
pub fn from_u32(v: u32) -> Option<Self> {
match v {
0 => Some(Self::Forever),
1 => Some(Self::Seconds),
2 => Some(Self::Minutes),
3 => Some(Self::Hours),
4 => Some(Self::Days),
5 => Some(Self::Weeks),
6 => Some(Self::Months),
7 => Some(Self::Years),
_ => None,
}
}
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub enum PropertyAchievementRequired {
None,
Builder,
Craftsman,
SeniorBuilder,
Journeyman,
MasterBuilder,
Architect,
SeniorArchitect,
MasterArchitect,
Visionary,
Exemplar,
}
impl PropertyAchievementRequired {
pub fn from_u32(v: u32) -> Result<Option<PropertyAchievementRequired>, Error> {
match v {
0 => Ok(None),
1 => Ok(Some(Self::Builder)),
2 => Ok(Some(Self::Craftsman)),
3 => Ok(Some(Self::SeniorBuilder)),
4 => Ok(Some(Self::Journeyman)),
5 => Ok(Some(Self::MasterBuilder)),
6 => Ok(Some(Self::Architect)),
7 => Ok(Some(Self::SeniorArchitect)),
8 => Ok(Some(Self::MasterArchitect)),
9 => Ok(Some(Self::Visionary)),
10 => Ok(Some(Self::Exemplar)),
_ => Err(Error::argument_error()),
}
}
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataProperty {
pub value_1: u32,
pub price: u32,
pub rental_time: u32,
pub associated_map: WorldID,
pub value_2: u32,
pub display_name: String,
pub display_description: String,
pub value_3: u32,
pub clone_limit: u32,
pub reputation_multiplier: f32,
pub rental_time_unit: PropertyRentalTimeUnit,
pub achievement_required: Option<PropertyAchievementRequired>,
pub player_zone_coordinate: Vector3f,
pub max_build_height: f32,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataCamera {
pub next_path: String,
pub value_1: Option<u8>,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataSpawner {
pub spawned_lot: ObjectTemplate,
pub respawn_time: u32,
pub max_to_spawn: u32,
pub min_to_spawn: u32,
pub spawner_obj_id: ObjectID,
pub activate_network_on_load: bool,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataShowcase {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataRace {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathDataRail {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataMovement {
pub config: WaypointConfig,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataMovingPlatformSounds {
pub arrive_sound: String,
pub depart_sound: String,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataMovingPlatform {
pub rotation: Quaternion,
pub lock_player: bool,
pub speed: f32,
pub wait: f32,
pub sounds: Option<PathWaypointDataMovingPlatformSounds>,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataProperty {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataCamera {
pub rotation: Quaternion,
pub time: f32,
pub value_5: f32,
pub tension: f32,
pub continuity: f32,
pub bias: f32,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataSpawner {
pub rotation: Quaternion,
pub config: WaypointConfig,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataShowcase {}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataRace {
pub rotation: Quaternion,
pub value_1: u8,
pub value_2: u8,
pub value_3: f32,
pub value_4: f32,
pub value_5: f32,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointDataRail {
pub rotation: Quaternion,
pub speed: Option<f32>,
pub config: WaypointConfig,
}
pub type WaypointConfig = HashMap<String, String>;
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathWaypointVariant<WaypointType> {
pub position: Vector3f,
#[cfg_attr(feature = "serde-derives", serde(flatten))]
pub data: WaypointType,
}
pub type PathWaypointVariantMovement = PathWaypointVariant<PathWaypointDataMovement>;
pub type PathWaypointVariantMovingPlatform = PathWaypointVariant<PathWaypointDataMovingPlatform>;
pub type PathWaypointVariantProperty = PathWaypointVariant<PathWaypointDataProperty>;
pub type PathWaypointVariantCamera = PathWaypointVariant<PathWaypointDataCamera>;
pub type PathWaypointVariantSpawner = PathWaypointVariant<PathWaypointDataSpawner>;
pub type PathWaypointVariantShowcase = PathWaypointVariant<PathWaypointDataShowcase>;
pub type PathWaypointVariantRace = PathWaypointVariant<PathWaypointDataRace>;
pub type PathWaypointVariantRail = PathWaypointVariant<PathWaypointDataRail>;
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathHeader {
pub version: PathVersion,
pub path_name: String,
pub value_1: u32,
pub path_composition: PathComposition,
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct PathVariant<DataType, WaypointDataType> {
pub header: PathHeader,
pub path_data: DataType,
pub waypoints: Vec<PathWaypointVariant<WaypointDataType>>,
}
pub type PathVariantMovement = PathVariant<PathDataMovement, PathWaypointDataMovement>;
pub type PathVariantMovingPlatform =
PathVariant<PathDataMovingPlatform, PathWaypointDataMovingPlatform>;
pub type PathVariantProperty = PathVariant<PathDataProperty, PathWaypointDataProperty>;
pub type PathVariantCamera = PathVariant<PathDataCamera, PathWaypointDataCamera>;
pub type PathVariantSpawner = PathVariant<PathDataSpawner, PathWaypointDataSpawner>;
pub type PathVariantShowcase = PathVariant<PathDataShowcase, PathWaypointDataShowcase>;
pub type PathVariantRace = PathVariant<PathDataRace, PathWaypointDataRace>;
pub type PathVariantRail = PathVariant<PathDataRail, PathWaypointDataRail>;
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
#[cfg_attr(feature = "serde-derives", serde(tag = "type"))]
pub enum Path {
Movement(PathVariantMovement),
MovingPlatform(PathVariantMovingPlatform),
Property(PathVariantProperty),
Camera(PathVariantCamera),
Spawner(PathVariantSpawner),
Showcase(PathVariantShowcase),
Race(PathVariantRace),
Rail(PathVariantRail),
}
#[derive(Debug)]
#[cfg_attr(feature = "serde-derives", derive(Serialize))]
pub struct ZonePaths {
pub version: ZonePathsVersion,
pub paths: Vec<Path>,
}