Skip to content
Rich Lane edited this page Nov 8, 2024 · 10 revisions

You can use any editor with Oort. After creating a Rust file in Vim/VSCode/etc, right click in the Oort editor and hit "Link to file(s) on disk". On Chrome, this will pop up an open dialog where you can select the file. On Firefox, it will create a target for you to drag-and-drop the file onto (ripdrag is useful for this). After this the game will re-read the file from disk every second. You can end this by clicking "unlink".

Optional: Create a Rust crate

To get optimal rust-analyzer diagnostics you can create a real crate. Example:

cargo new --lib myai
cd myai
cargo add oort_api

Then replace the code in src/lib.rs with the starter code for the scenario you're working on.

Optional: Multiple files

As your AIs get larger it's useful to split libraries into separate files and share them between different AIs. You can add additional files following the Rust crate structure. Example:

lib.rs:

pub mod guidance;
pub mod fighter_duel;

guidance.rs:

pub fn seek_to_target(...) {}

fighter_duel.rs:

use crate::guidance;

When linking to a file you'd then select all three files instead of just lib.rs. Or, you can use "Link to directory" which watches an entire directory. The UI will show a select box to pick the file with the Ship implementation you want to use. It defaults to SCENARIO_NAME.rs.

Subdirectories are not yet supported.

Optional: Using a bundler (deprecated)

There are other tools that can be used to combine multiple files together.

Using oort-bundler

After cloning the repo, run:

cargo oort-bundler --watch -o bundled.rs path/to/a.rs path/to/b.rs

This will watch the given files for changes and write to bundled.rs. You can then use the "Link to file on disk" option in Oort on bundled.rs.

Using rust-sourcebundler

Using rust-sourcebundler you can bundle all files in a crate into a single rust file.

  1. Add rust-sourcebundler as a build dependency to your Cargo.toml:
[build-dependencies]
rustsourcebundler = { git = "https://github.com/lpenz/rust-sourcebundler", rev = "fbc017eeb3aa5c53ee5f6d15aff4d7f9d567430b" }
  1. Add an input file for rust-sourcebundler to read, e.g. src/bundle_input.rs:
extern crate myai; // this must match the package name in Cargo.toml
pub use myai::Ship;
  1. Add a build.rs file and add it to Cargo.toml to run rust-sourcebundler and output a bundled file:

build.rs:

use std::path::Path;
extern crate rustsourcebundler;
use rustsourcebundler::Bundler;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut bundler: Bundler =
        Bundler::new(Path::new("src/bundle_input.rs"), Path::new("target/bundle_output.rs"));
    bundler.crate_name("myai"); // again this must match the name in Cargo.toml
    bundler.run();
    Ok(())
}

Cargo.toml:

[package]
name = "myai"
build = "build.rs"
# ...
  1. run cargo build

  2. Load target/bundle_output.rs into the Oort editor.