#[macro_export]
macro_rules! impl_from_into {
($outer:ident($inner:ident)) => {
impl From<$inner> for $outer {
fn from(v: $inner) -> $outer {
$outer(v)
}
}
impl From<$outer> for $inner {
fn from($outer(v): $outer) -> $inner {
v
}
}
}
}
#[macro_export]
macro_rules! newtype {
($outer:ident($inner:ident)) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct $outer(pub $inner);
$crate::impl_from_into!($outer($inner));
};
($outer:ident($inner:ident), $fmt:literal) => {
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct $outer(pub $inner);
$crate::impl_from_into!($outer($inner));
impl ::core::fmt::Debug for $outer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple(stringify!($outer))
.field(&format_args!($fmt, &self.0))
.finish()
}
}
};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FuncId(pub u16, pub u16);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Pos2 {
pub x: i32,
pub z: i32,
}
pub type Pos3 = glam::IVec3;
newtype!(NameId(u16));
newtype!(BgmId(u16));
newtype!(SoundId(u32));
newtype!(ItemId(u16));
newtype!(RecipeId(u16));
newtype!(TownId(u16));
newtype!(ShopId(u8));
newtype!(MagicId(u16));
newtype!(FileId(u32), "0x{:08X}");
impl FileId {
pub const NONE: FileId = FileId(0);
}
newtype!(Color(u32), "0x{:08X}");
newtype!(Flag(u16));
newtype!(Angle(i16));
newtype!(Length(i32));
newtype!(Time(u32));
newtype!(Speed(u32));
newtype!(AngularSpeed(u16));
newtype!(Angle32(i32));
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CharId {
FieldParty(u16),
Local(LocalCharId),
Party(u16),
Custom(u16),
Null,
Self_,
Name(NameId),
}
newtype!(LocalCharId(u16));
newtype!(ChipId(u16));
newtype!(LookPointId(u16));
newtype!(ObjectId(u16));
newtype!(EntranceId(u8));
newtype!(TriggerId(u16));
newtype!(LabelId(u16));
newtype!(AnimId(u16));
newtype!(BattleId(u32));
newtype!(SepithId(u16));
newtype!(PlacementId(u16));
newtype!(AtRollId(u16));
newtype!(SystemFlags(u32));
newtype!(QuestId(u16));
newtype!(QuestFlags(u8));
newtype!(QuestTask(u16));
newtype!(CharFlags(u16));
newtype!(ObjectFlags(u32));
newtype!(LookPointFlags(u16));
newtype!(EntryFlags(u16));
newtype!(TriggerFlags(u16));
newtype!(TcMembers(u32));
newtype!(Var(u16)); newtype!(Global(u8));
newtype!(Attr(u8));
newtype!(EffId(u8));
newtype!(EffInstanceId(u8));
newtype!(MenuId(u16));
newtype!(VisId(u8));
newtype!(ForkId(u16));
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct CharAttr(pub CharId, pub u8);
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
#[repr(transparent)]
pub struct TString(pub String);
impl_from_into!(TString(String));
impl std::ops::Deref for TString {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::DerefMut for TString {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'a> From<&'a String> for &'a TString {
fn from(value: &'a String) -> Self {
unsafe { std::mem::transmute(value) }
}
}
impl<'a> From<&'a TString> for &'a String {
fn from(value: &'a TString) -> Self {
&value.0
}
}
impl From<&str> for TString {
fn from(value: &str) -> Self {
String::from(value).into()
}
}
impl std::fmt::Debug for TString {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "t{:?}", &self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BaseGame {
Fc, Sc, Tc,
Zero, Ao,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Game {
Fc, FcEvo, FcKai,
Sc, ScEvo, ScKai,
Tc, TcEvo, TcKai,
Zero, ZeroEvo, ZeroKai,
Ao, AoEvo, AoKai,
}
impl Game {
pub fn base(self) -> BaseGame {
use Game::*;
match self {
Fc|FcEvo|FcKai => BaseGame::Fc,
Sc|ScEvo|ScKai => BaseGame::Sc,
Tc|TcEvo|TcKai => BaseGame::Tc,
Zero|ZeroEvo|ZeroKai => BaseGame::Zero,
Ao|AoEvo|AoKai => BaseGame::Ao,
}
}
}
impl Game {
pub fn is_ed7(self) -> bool {
matches!(self.base(), BaseGame::Zero|BaseGame::Ao)
}
}