use serde::{Deserialize, Serialize};
macro_rules! newtype_id {
($($(#[$meta:meta])* $name:ident),* $(,)?) => {
$(
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize)]
pub struct $name(pub String);
impl $name {
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(&self.0)
}
}
impl From<&str> for $name {
fn from(value: &str) -> Self {
Self(value.to_string())
}
}
impl From<String> for $name {
fn from(value: String) -> Self {
Self(value)
}
}
)*
};
}
newtype_id! {
RoomId,
ItemId,
EntityId,
DialogueId,
NodeId,
RuleId,
QuestId,
EndingId,
TextId,
ConditionId,
FlagKey,
StatKey,
TimerId,
EventName,
}