mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
remove build from gitignore
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -44,7 +44,6 @@ Temporary Items
|
||||
|
||||
## Java/Gradle Stuff
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
.kotlin
|
||||
|
||||
|
||||
37
pumpkin-data/build/build.rs
Normal file
37
pumpkin-data/build/build.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use std::{env, fs, path::Path, process::Command};
|
||||
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use syn::Ident;
|
||||
|
||||
mod packet;
|
||||
mod particle;
|
||||
mod screen;
|
||||
mod sound;
|
||||
|
||||
pub fn main() {
|
||||
write_generated_file(packet::build(), "packet.rs");
|
||||
write_generated_file(screen::build(), "screen.rs");
|
||||
write_generated_file(particle::build(), "particle.rs");
|
||||
write_generated_file(sound::build(), "sound.rs");
|
||||
}
|
||||
|
||||
pub fn write_generated_file(content: TokenStream, out_file: &str) {
|
||||
let out_dir = env::var_os("OUT_DIR").expect("failed to get OUT_DIR env var");
|
||||
let path = Path::new(&out_dir).join(out_file);
|
||||
let code = content.to_string();
|
||||
|
||||
fs::write(&path, code).expect("Faile to write to fs");
|
||||
|
||||
// Try to format the output for debugging purposes.
|
||||
// Doesn't matter if rustfmt is unavailable.
|
||||
let _ = Command::new("rustfmt").arg(path).output();
|
||||
}
|
||||
|
||||
pub fn ident<I: AsRef<str>>(s: I) -> Ident {
|
||||
let s = s.as_ref().trim();
|
||||
|
||||
// Parse the ident from a str. If the string is a Rust keyword, stick an
|
||||
// underscore in front.
|
||||
syn::parse_str::<Ident>(s)
|
||||
.unwrap_or_else(|_| Ident::new(format!("_{s}").as_str(), Span::call_site()))
|
||||
}
|
||||
50
pumpkin-data/build/packet.rs
Normal file
50
pumpkin-data/build/packet.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::ident;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Packets {
|
||||
serverbound: HashMap<String, Vec<String>>,
|
||||
clientbound: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/packets.json");
|
||||
|
||||
let packets: Packets = serde_json::from_str(include_str!("../../assets/packets.json"))
|
||||
.expect("Failed to parse packets.json");
|
||||
let serverbound_consts = parse_packets(packets.serverbound);
|
||||
let clientbound_consts = parse_packets(packets.clientbound);
|
||||
|
||||
quote!(
|
||||
pub mod serverbound {
|
||||
#serverbound_consts
|
||||
}
|
||||
|
||||
pub mod clientbound {
|
||||
#clientbound_consts
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_packets(packets: HashMap<String, Vec<String>>) -> proc_macro2::TokenStream {
|
||||
let mut consts = TokenStream::new();
|
||||
|
||||
for packet in packets {
|
||||
let phase = packet.0;
|
||||
|
||||
for (id, packet_name) in packet.1.iter().enumerate() {
|
||||
let packet_id = id as i32;
|
||||
let name = format!("{phase}_{packet_name}").to_uppercase();
|
||||
let name = ident(name);
|
||||
consts.extend([quote! {
|
||||
pub const #name: i32 = #packet_id;
|
||||
}]);
|
||||
}
|
||||
}
|
||||
consts
|
||||
}
|
||||
29
pumpkin-data/build/particle.rs
Normal file
29
pumpkin-data/build/particle.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use heck::ToPascalCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::ident;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/particles.json");
|
||||
|
||||
let screens: Vec<String> = serde_json::from_str(include_str!("../../assets/particles.json"))
|
||||
.expect("Failed to parse particles.json");
|
||||
let mut variants = TokenStream::new();
|
||||
|
||||
for (id, screen) in screens.iter().enumerate() {
|
||||
let id = id as u8;
|
||||
let name = ident(screen.to_pascal_case());
|
||||
|
||||
variants.extend([quote! {
|
||||
#name = #id,
|
||||
}]);
|
||||
}
|
||||
quote! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[repr(u8)]
|
||||
pub enum Particle {
|
||||
#variants
|
||||
}
|
||||
}
|
||||
}
|
||||
29
pumpkin-data/build/screen.rs
Normal file
29
pumpkin-data/build/screen.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use heck::ToPascalCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::ident;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/screens.json");
|
||||
|
||||
let screens: Vec<String> = serde_json::from_str(include_str!("../../assets/screens.json"))
|
||||
.expect("Failed to parse screens.json");
|
||||
let mut variants = TokenStream::new();
|
||||
|
||||
for (id, screen) in screens.iter().enumerate() {
|
||||
let id = id as u8;
|
||||
let name = ident(screen.to_pascal_case());
|
||||
|
||||
variants.extend([quote! {
|
||||
#name = #id,
|
||||
}]);
|
||||
}
|
||||
quote! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[repr(u8)]
|
||||
pub enum WindowType {
|
||||
#variants
|
||||
}
|
||||
}
|
||||
}
|
||||
29
pumpkin-data/build/sound.rs
Normal file
29
pumpkin-data/build/sound.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use heck::ToPascalCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::ident;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/sounds.json");
|
||||
|
||||
let screens: Vec<String> = serde_json::from_str(include_str!("../../assets/sounds.json"))
|
||||
.expect("Failed to parse sounds.json");
|
||||
let mut variants = TokenStream::new();
|
||||
|
||||
for (id, screen) in screens.iter().enumerate() {
|
||||
let id = id as u16;
|
||||
let name = ident(screen.to_pascal_case());
|
||||
|
||||
variants.extend([quote! {
|
||||
#name = #id,
|
||||
}]);
|
||||
}
|
||||
quote! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[repr(u16)]
|
||||
pub enum Sound {
|
||||
#variants
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user