Skip to content

Commit 2cb9bef

Browse files
authored
Merge pull request #9 from Big-Dungeons/packets
Packet macro and dungeon map
2 parents 6ba2f22 + 04718de commit 2cb9bef

File tree

167 files changed

+4701
-4664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+4701
-4664
lines changed

.github/workflows/build.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
upload_artifacts:
7+
required: false
8+
type: boolean
9+
default: true
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
include:
17+
- os: ubuntu-latest
18+
ext: ""
19+
- os: macos-latest
20+
ext: ""
21+
- os: windows-latest
22+
ext: ".exe"
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Get ClearData Room Data
28+
uses: actions/checkout@v4
29+
with:
30+
repository: Big-Dungeons/ClearData
31+
ref: main
32+
path: ClearData
33+
34+
- name: Copy room_data into project
35+
shell: bash
36+
run: |
37+
mkdir -p src/room_data
38+
cp -r ClearData/room_data/* src/room_data/
39+
40+
- name: Extract version from Cargo.toml
41+
id: get_version
42+
shell: bash
43+
run: |
44+
version=$(grep '^version =' Cargo.toml | head -n1 | cut -d '"' -f2)
45+
echo "version=$version" >> $GITHUB_OUTPUT
46+
47+
- name: Cargo Cache
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
~/.cargo/registry
52+
~/.cargo/git
53+
target
54+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
55+
restore-keys: |
56+
${{ runner.os }}-cargo-
57+
58+
- name: Build
59+
run: cargo build --release --verbose
60+
61+
- name: Run tests
62+
run: cargo test --verbose
63+
64+
- name: Prepare dist + OS-named binary
65+
shell: bash
66+
run: |
67+
version=$(grep '^version =' Cargo.toml | head -n1 | cut -d '"' -f2)
68+
mkdir -p dist
69+
cp target/release/RustClear${{ matrix.ext }} \
70+
"dist/RustClear-v${{ steps.get_version.outputs.version }}-${{ matrix.os }}${{ matrix.ext }}"
71+
72+
- name: Upload build artifact
73+
if: ${{ inputs.upload_artifacts }}
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: RustClear-v${{ steps.get_version.outputs.version }}-${{ matrix.os }}
77+
path: dist/*

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
uses: ./.github/workflows/build.yml
9+
10+
release:
11+
runs-on: ubuntu-latest
12+
needs: build
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v4
16+
17+
- name: Download Artifacts
18+
uses: actions/download-artifact@v4
19+
with:
20+
path: ./dist
21+
22+
- name: Extract version from Cargo.toml
23+
id: get_version
24+
shell: bash
25+
run: |
26+
version=$(grep '^version =' Cargo.toml | head -n1 | cut -d '"' -f2)
27+
echo "version=$version" >> $GITHUB_OUTPUT
28+
29+
- name: Generate Release
30+
uses: softprops/action-gh-release@v1
31+
with:
32+
tag_name: v${{ steps.get_version.outputs.version }}
33+
name: Release v${{ steps.get_version.outputs.version }}
34+
draft: true
35+
files: ./dist/**
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/rust.yml

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,15 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ "main", "packets", "bloom" ]
5+
branches:
6+
- "*"
67
pull_request:
7-
branches: [ "main", "packets", "bloom" ]
8+
branches:
9+
- "*"
810

911
env:
1012
CARGO_TERM_COLOR: always
1113

1214
jobs:
1315
build:
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
os: [ubuntu-latest, windows-latest, macos-latest]
18-
19-
steps:
20-
- uses: actions/checkout@v4
21-
22-
- name: Get ClearData Room Data
23-
uses: actions/checkout@v4
24-
with:
25-
repository: Big-Dungeons/ClearData
26-
ref: main
27-
path: ClearData
28-
29-
- name: copy room_data into project
30-
shell: bash
31-
run: |
32-
mkdir =p src/room_data
33-
cp -r ClearData/room_data/* src/room_data/
34-
35-
36-
- name: Cargo Cache
37-
uses: actions/cache@v4
38-
with:
39-
path: |
40-
~/.cargo/registry
41-
~/.cargo/git
42-
target
43-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
44-
restore-keys: |
45-
${{ runner.os }}-cargo-
46-
47-
- name: Build
48-
run: cargo build --release --verbose
49-
- name: Run tests
50-
run: cargo test --verbose
51-
52-
- name: Upload build artifact
53-
uses: actions/upload-artifact@v4
54-
with:
55-
name: RustClear-${{ matrix.os }}
56-
path: |
57-
target/release/RustClear${{ matrix.os == 'windows-latest' && '.exe' || '' }}
16+
uses: ./.github/workflows/build.yml

Cargo.lock

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2024"
77
bytes = "1.10.1"
88
tokio = { version = "1.45.1", features = ["rt", "rt-multi-thread", "macros", "net", "io-util", "sync", "time"] }
99
anyhow = "1.0.98"
10-
async-trait = "0.1.88"
1110
serde_json = "1.0.140"
1211
serde = { version = "1.0.219", features = ["derive"] }
1312
uuid = { version = "1.17.0", features = ["v4"] }
@@ -16,5 +15,13 @@ indoc = "2.0.6"
1615
include_dir = "0.7.4"
1716
blocks = { path = "crates/macros" }
1817
chrono = "0.4.41"
18+
rand_chacha = "0.9.0"
1919
base64 = "0.22.1"
2020
once_cell = "1.21.3"
21+
22+
[profile.dev.package."*"]
23+
opt-level = 3
24+
25+
[profile.release]
26+
codegen-units = 1
27+
lto = "thin"

crates/macros/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
mod packet_serializable;
2+
mod packet_deserializable;
3+
4+
use crate::packet_deserializable::packet_deserializable_macro;
5+
use crate::packet_serializable::packet_serializable_macro;
16
use proc_macro::TokenStream;
27
use quote::quote;
38
use syn::{parse_macro_input, DeriveInput, Fields, Ident, ItemEnum};
49

10+
#[proc_macro]
11+
pub fn packet_serializable(input: TokenStream) -> TokenStream {
12+
packet_serializable_macro(input)
13+
}
14+
15+
#[proc_macro]
16+
pub fn packet_deserializable(input: TokenStream) -> TokenStream {
17+
packet_deserializable_macro(input)
18+
}
19+
20+
21+
// todo: new file for block stuff
22+
// at that point im redoing the macro
23+
// because it is really annoying if a block has a niche metadata serializations
24+
// and i don't want to have a bunch of direction enum copies,
25+
// also want to be able to specify vanilla block toughness
26+
527
type TokenStream2 = proc_macro2::TokenStream;
628

729
///
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use proc_macro::TokenStream;
2+
use quote::quote;
3+
use syn::Fields::Unit;
4+
use syn::{parse_macro_input, Item};
5+
6+
pub fn packet_deserializable_macro(input: TokenStream) -> TokenStream {
7+
let input = parse_macro_input!(input as Item);
8+
match input {
9+
Item::Struct(ref item_struct) => {
10+
let name = &item_struct.ident;
11+
let fields = item_struct.fields.iter().map(|field| {
12+
let ident = &field.ident;
13+
quote! { #ident: crate::net::packets::packet_deserialize::PacketDeserializable::read(buffer)?, }
14+
});
15+
quote! {
16+
#input
17+
18+
impl crate::net::packets::packet_deserialize::PacketDeserializable for #name {
19+
fn read(buffer: &mut bytes::BytesMut) -> anyhow::Result<Self> {
20+
Ok(Self {
21+
#(#fields)*
22+
})
23+
}
24+
}
25+
}
26+
}
27+
Item::Enum(ref item_enum) => {
28+
let name = &item_enum.ident;
29+
let variants = item_enum.variants.iter().enumerate().map(|(index, variant)| {
30+
if let Unit = variant.fields {
31+
let index = index as i8;
32+
let indent = &variant.ident;
33+
quote! {
34+
#index => Ok(#name::#indent),
35+
}
36+
} else {
37+
return quote! {
38+
compile_error!("packet_deserializable doesn't support enums with fields");
39+
}.into()
40+
}
41+
});
42+
quote! {
43+
#input
44+
45+
impl crate::net::packets::packet_deserialize::PacketDeserializable for #name {
46+
fn read(buffer: &mut bytes::BytesMut) -> anyhow::Result<Self> {
47+
let id: i8 = crate::net::packets::packet_deserialize::PacketDeserializable::read(buffer)?;
48+
match id {
49+
#(#variants)*
50+
_ => Err(anyhow::anyhow!("Invalid id ({}) for enum {}", id, stringify!(#name)))
51+
}
52+
}
53+
}
54+
}
55+
}
56+
_ => {
57+
syn::Error::new_spanned(input, "packet_deserializable only supports structs and enums")
58+
.into_compile_error()
59+
}
60+
}.into()
61+
}

0 commit comments

Comments
 (0)