Skip to content

Commit 7f9fbe5

Browse files
authored
Merge pull request #1 from LeagueToolkit/copilot/add-godot-rust-extension
[WIP] Add Godot 4 Rust extension for custom file formats
2 parents 7746a65 + 5bd2f59 commit 7f9fbe5

File tree

13 files changed

+603
-1
lines changed

13 files changed

+603
-1
lines changed

.github/workflows/ci.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
name: Build
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest, windows-latest, macos-latest]
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install Rust
24+
uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
override: true
28+
components: rustfmt, clippy
29+
30+
- name: Cache cargo registry
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cargo/registry
34+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
35+
36+
- name: Cache cargo index
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.cargo/git
40+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
41+
42+
- name: Cache cargo build
43+
uses: actions/cache@v4
44+
with:
45+
path: target
46+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
47+
48+
- name: Check formatting
49+
run: cargo fmt -- --check
50+
51+
- name: Run clippy
52+
run: cargo clippy -- -D warnings
53+
54+
- name: Build
55+
run: cargo build --verbose
56+
57+
- name: Build release
58+
run: cargo build --release --verbose
59+
60+
- name: Run tests
61+
run: cargo test --verbose
62+
63+
check:
64+
name: Security Check
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Install Rust
70+
uses: actions-rs/toolchain@v1
71+
with:
72+
toolchain: stable
73+
override: true
74+
75+
- name: Run cargo audit
76+
run: |
77+
cargo install cargo-audit
78+
cargo audit

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Rust build artifacts
2+
/target
3+
Cargo.lock
4+
5+
# Godot files
6+
.godot/
7+
*.import
8+
9+
# IDE files
10+
.vscode/
11+
.idea/
12+
*.swp
13+
*.swo
14+
*~
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+

CONTRIBUTING.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Contributing to ltk-godot
2+
3+
Thank you for your interest in contributing to ltk-godot!
4+
5+
## Development Setup
6+
7+
1. **Install Rust**: Make sure you have Rust 1.70+ installed
8+
```bash
9+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
10+
```
11+
12+
2. **Clone the repository**:
13+
```bash
14+
git clone https://github.com/LeagueToolkit/ltk-godot.git
15+
cd ltk-godot
16+
```
17+
18+
3. **Build the project**:
19+
```bash
20+
cargo build
21+
```
22+
23+
## Project Structure
24+
25+
```
26+
ltk-godot/
27+
├── src/
28+
│ ├── lib.rs # Main library entry point
29+
│ └── loaders/ # File format loaders
30+
│ ├── mod.rs
31+
│ ├── wad_loader.rs
32+
│ ├── mesh_loader.rs
33+
│ └── texture_loader.rs
34+
├── ltk_godot.gdextension # Godot extension configuration
35+
├── Cargo.toml # Rust dependencies
36+
└── README.md
37+
```
38+
39+
## Adding New Features
40+
41+
### Adding a New Loader
42+
43+
1. Create a new file in `src/loaders/` (e.g., `animation_loader.rs`)
44+
2. Implement the loader using `godot::prelude::*` and the `#[derive(GodotClass)]` macro
45+
3. Add the module to `src/loaders/mod.rs`
46+
4. Export the loader from `src/lib.rs`
47+
5. Update documentation
48+
49+
### Example Loader Template
50+
51+
```rust
52+
use godot::prelude::*;
53+
54+
#[derive(GodotClass)]
55+
#[class(base=RefCounted)]
56+
pub struct MyLoader {
57+
base: Base<RefCounted>,
58+
}
59+
60+
#[godot_api]
61+
impl IRefCounted for MyLoader {
62+
fn init(base: Base<RefCounted>) -> Self {
63+
MyLoader { base }
64+
}
65+
}
66+
67+
#[godot_api]
68+
impl MyLoader {
69+
#[func]
70+
pub fn load(&mut self, path: GString) -> bool {
71+
// Implementation
72+
true
73+
}
74+
}
75+
```
76+
77+
## Testing
78+
79+
Run tests with:
80+
```bash
81+
cargo test
82+
```
83+
84+
## Code Style
85+
86+
- Follow Rust conventions and use `cargo fmt` to format code
87+
- Run `cargo clippy` to check for common mistakes
88+
- Write clear documentation comments for public APIs
89+
90+
## Pull Requests
91+
92+
1. Fork the repository
93+
2. Create a feature branch (`git checkout -b feature/my-feature`)
94+
3. Make your changes
95+
4. Run tests and ensure code compiles
96+
5. Commit your changes (`git commit -am 'Add new feature'`)
97+
6. Push to the branch (`git push origin feature/my-feature`)
98+
7. Open a Pull Request
99+
100+
## License
101+
102+
By contributing, you agree that your contributions will be licensed under the AGPL-3.0 license.

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "ltk_godot"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["LeagueToolkit Contributors"]
6+
description = "Godot 4 extension for importing League of Legends file formats"
7+
license = "AGPL-3.0"
8+
repository = "https://github.com/LeagueToolkit/ltk-godot"
9+
10+
[lib]
11+
crate-type = ["cdylib"]
12+
13+
[dependencies]
14+
godot = { git = "https://github.com/godot-rust/gdext", branch = "master" }
15+
league-toolkit = { git = "https://github.com/LeagueToolkit/league-toolkit", features = ["wad", "mesh", "texture", "anim", "meta"] }

EXAMPLES.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Examples
2+
3+
This directory would contain example Godot projects demonstrating how to use ltk-godot.
4+
5+
## Basic Usage Example
6+
7+
Here's a simple example of using the extension in GDScript:
8+
9+
```gdscript
10+
extends Node
11+
12+
func _ready():
13+
# Load a WAD archive
14+
var wad = WadLoader.new()
15+
if wad.load("res://assets/league/Data.wad"):
16+
print("WAD loaded successfully!")
17+
print("Entry count: ", wad.get_entry_count())
18+
19+
# Load a mesh
20+
var mesh = MeshLoader.new()
21+
if mesh.load("res://assets/league/model.skn"):
22+
print("Mesh loaded successfully!")
23+
print("Vertices: ", mesh.get_vertex_count())
24+
var bounds = mesh.get_bounds()
25+
print("Bounds min: ", bounds["min"])
26+
print("Bounds max: ", bounds["max"])
27+
28+
# Load a texture
29+
var texture = TextureLoader.new()
30+
if texture.load("res://assets/league/texture.dds"):
31+
print("Texture loaded successfully!")
32+
print("Dimensions: ", texture.get_dimensions())
33+
```
34+
35+
## Integration Example
36+
37+
Project structure when using ltk-godot:
38+
39+
```
40+
my_godot_project/
41+
├── addons/
42+
│ └── ltk-godot/
43+
│ ├── ltk_godot.gdextension
44+
│ ├── target/
45+
│ │ ├── debug/
46+
│ │ │ └── libltk_godot.so
47+
│ │ └── release/
48+
│ │ └── libltk_godot.so
49+
│ └── ...
50+
├── assets/
51+
│ └── league/
52+
│ ├── Data.wad
53+
│ ├── model.skn
54+
│ └── texture.dds
55+
├── scenes/
56+
│ └── main.tscn
57+
└── project.godot
58+
```
59+
60+
## Advanced Usage
61+
62+
### Custom Resource Loader
63+
64+
You can create custom resource loaders that use ltk-godot to automatically import League of Legends assets:
65+
66+
```gdscript
67+
@tool
68+
extends EditorImportPlugin
69+
70+
func _get_importer_name():
71+
return "league.mesh"
72+
73+
func _get_visible_name():
74+
return "League Mesh"
75+
76+
func _get_recognized_extensions():
77+
return ["skn", "scb", "sco"]
78+
79+
func _get_resource_type():
80+
return "Mesh"
81+
82+
func _import(source_file, save_path, options, r_platform_variants, r_gen_files):
83+
var loader = MeshLoader.new()
84+
if loader.load(source_file):
85+
# Convert to Godot mesh format
86+
# Save as .res or .tres
87+
return OK
88+
return FAILED
89+
```
90+
91+
This allows you to drag-and-drop League of Legends files directly into your Godot project!

LICENSE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GNU AFFERO GENERAL PUBLIC LICENSE
2+
Version 3, 19 November 2007
3+
4+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
Preamble
9+
10+
The GNU Affero General Public License is a free, copyleft license for
11+
software and other kinds of works, specifically designed to ensure
12+
cooperation with the community in the case of network server software.
13+
14+
(For the complete license text, please visit: https://www.gnu.org/licenses/agpl-3.0.txt)
15+
16+
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-only).

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# ltk-godot
1+
# ltk-godot
2+
3+
Godot 4 extension for importing League of Legends file formats using [league-toolkit](https://github.com/LeagueToolkit/league-toolkit).
4+
5+
## Overview
6+
7+
`ltk-godot` is a GDExtension written in Rust that brings League of Legends asset importing capabilities to Godot 4. It leverages the powerful `league-toolkit` library to parse and load various LoL file formats.
8+
9+
## Supported Formats
10+
11+
- **WAD Archives** - Container format for League of Legends assets
12+
- **Meshes** - 3D model formats (SKN, SCB, SCO)
13+
- **Textures** - Texture formats (DDS, TEX)
14+
- **Animations** - Animation data (ANM)
15+
- **Metadata** - Game metadata (BIN)
16+
17+
## Building
18+
19+
### Prerequisites
20+
21+
- Rust 1.70 or later
22+
- Cargo
23+
- Godot 4.1 or later (for testing)
24+
25+
### Build Steps
26+
27+
```bash
28+
# Clone the repository
29+
git clone https://github.com/LeagueToolkit/ltk-godot.git
30+
cd ltk-godot
31+
32+
# Build the extension (debug)
33+
cargo build
34+
35+
# Build the extension (release)
36+
cargo build --release
37+
```
38+
39+
The compiled library will be placed in `target/debug/` or `target/release/` depending on your build configuration.
40+
41+
## Usage in Godot
42+
43+
1. Copy the entire `ltk-godot` directory into your Godot project
44+
2. The `ltk_godot.gdextension` file tells Godot where to find the native library
45+
3. The extension classes will be available in GDScript:
46+
47+
```gdscript
48+
# Example: Loading a WAD archive
49+
var wad_loader = WadLoader.new()
50+
wad_loader.load("res://path/to/archive.wad")
51+
var entry_count = wad_loader.get_entry_count()
52+
print("WAD contains ", entry_count, " entries")
53+
```
54+
55+
## Development
56+
57+
This project uses:
58+
- [godot-rust (gdext)](https://github.com/godot-rust/gdext) - Rust bindings for Godot 4
59+
- [league-toolkit](https://github.com/LeagueToolkit/league-toolkit) - Rust library for League of Legends file formats
60+
61+
## License
62+
63+
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.
64+
65+
## Contributing
66+
67+
Contributions are welcome! Please feel free to submit issues or pull requests.

0 commit comments

Comments
 (0)