#social #binding #open-ttd #integration #api-bindings #openttd #plugin-api

openttd_social_integration_api

Unofficial Rust binding for OpenTTD Social Integration API

3 releases

0.1.3 Feb 7, 2024
0.1.2 Feb 7, 2024
0.1.1 Feb 7, 2024
0.1.0 Feb 7, 2024

#19 in #social

MIT license

12KB
128 lines

Rust bindings for OpenTTD Social Integration API

This is an unofficial Rust binding for OpenTTD Social Integration API.


lib.rs:

Unofficial Rust binding for OpenTTD Social Integration API.

Use init for entrypoint.

Examples

use openttd_social_integration_api::{OpenTTDInfo, PluginApi};

fn shutdown() {
    println!("Shutting down!");
}

fn run_callbacks() -> bool {
    // This println will make log full of garbage.
    return true;
}

fn event_enter_main_menu() {
    println!("Entering main menu!");
}

fn event_enter_scenario_editor(map_width: u32, map_height: u32) {
    println!("Entering scenario editor ({}x{})!", map_width, map_height);
}

fn event_enter_singleplayer(map_width: u32, map_height: u32) {
    println!("Entering singleplayer ({}x{})!", map_width, map_height);
}

fn event_enter_multiplayer(map_width: u32, map_height: u32) {
    println!("Entering multiplayer ({}x{})!", map_width, map_height);
}

fn event_joining_multiplayer() {
    println!("Joining multiplayer!");
}

#[openttd_social_integration_api::init(platform = "test", name = "Test Plugin", version = "0.1")]
pub fn init(info: OpenTTDInfo) -> Result<Option<PluginApi>, ()> {
    println!("Init for OpenTTD {}", info.openttd_version);
    Ok(Some(PluginApi {
        shutdown: Some(shutdown),
        run_callbacks: Some(run_callbacks),
        event_enter_main_menu: Some(event_enter_main_menu),
        event_enter_scenario_editor: Some(event_enter_scenario_editor),
        event_enter_singleplayer: Some(event_enter_singleplayer),
        event_enter_multiplayer: Some(event_enter_multiplayer),
        event_joining_multiplayer: Some(event_joining_multiplayer)
    }))
}

Dependencies

~0.2–2.5MB
~51K SLoC