1use proc_macro::TokenStream;
2use quote::quote;
3use syn::DeriveInput;
4
5#[proc_macro_derive(DestinyRiftArcaneScript)]
6pub fn destiny_rift_derive(input: TokenStream) -> TokenStream {
7 let ast = syn::parse(input).unwrap();
8 impl_destiny_rift(&ast)
9}
10
11fn impl_destiny_rift(ast: &syn::DeriveInput) -> TokenStream {
12 let name = &ast.ident;
13 let gen = quote! {
14 impl forged_in_lost_lands::destiny_rift::DestinyRift for #name {}
15 };
16 gen.into()
17}
18
19#[proc_macro_derive(EtherealFlowArcaneScript)]
20pub fn ethereal_flow_derive(input: TokenStream) -> TokenStream {
21 let ast = syn::parse(input).unwrap();
22 impl_ethereal_flow(&ast)
23}
24
25fn impl_ethereal_flow(ast: &syn::DeriveInput) -> TokenStream {
26 let name = &ast.ident;
27 let gen = quote! {
28 impl forged_in_lost_lands::EtherealFlow for #name {
29 fn as_any(&self) -> &dyn std::any::Any {
30 self
31 }
32
33 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
34 self
35 }
36 }
37 };
38 gen.into()
39}
40
41#[proc_macro_attribute]
42pub fn hierarchy_ethereal_flow(_attr: TokenStream, item: TokenStream) -> TokenStream {
43 let struct_pos = item.to_string().find("struct").unwrap();
44 let first_parenthesis_pos = item.to_string().find("{").unwrap();
45 let str_item = item.to_string();
46 let struct_name = str_item[struct_pos + 6..first_parenthesis_pos].trim();
47
48 let item = add_ethereal_flow_derive(item);
50
51 let father_str = "pub father: Option<String>}
52 impl ::forged_in_lost_lands::forged_trait::ForgedHierarchy for #### {
53 fn get_father(&self) -> Option<String> {
54 if let Some(father) = &self.father {
55 return Some(father.clone());
56 }
57 None
58 }
59 fn set_father(&mut self, father_id:String) {
60 self.father = Some(father_id);
61 }
62 }";
63 let father_str = father_str.replace("####", struct_name);
64 let item = item.to_string().replace("}", &father_str).parse().unwrap();
65 item
66}
67
68fn add_ethereal_flow_derive(item: TokenStream) -> TokenStream {
69 let ast: DeriveInput = syn::parse(item).unwrap();
70 let gen = quote! {
71 #[derive(EtherealFlowArcaneScript)]
72 #ast
73 };
74 gen.into()
75}