Skip to content
strout edited this page Oct 17, 2023 · 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 a file 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. After this the game will re-read the file from disk every second and the built-in editor will be read-only. You can end this by selecting "Unlink from a file on disk".

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: Bundle multiple files

While the web UI only supports a single file in the editor, there are tools that can be used to combine multiple files together. This can let you work with smaller, more manageable files, and share code between AIs.

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 my_oort_ai; // this must match the package name in Cargo.toml
pub use my_oort_ai::Ship;
  1. Add a build.rs file to run rust-sourcebundler and output a bundled file:
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("my_oort_ai"); // again this must match the name in Cargo.toml
    bundler.run();
    Ok(())
}
  1. Load bundle_output.rs into the Oort editor.