Docs.rs
  • controlmap-parser-0.3.0
    • controlmap-parser 0.3.0
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • SARDONYX-sard
    • Dependencies
      • nom ^7.1.3 normal
      • num-derive ^0.4 normal
      • num-traits ^0.2 normal
      • serde ^1.0 normal
      • serde_json ^1.0 normal
      • thiserror ^1.0.49 normal
      • anyhow ^1.0.75 dev
      • pretty_assertions ^1.4.0 dev
      • tracing ^0.1.40 dev
      • tracing-appender ^0.2.3 dev
      • tracing-subscriber ^0.3.18 dev
    • Versions
    • 8.97% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate controlmap_parser

controlmap_parser0.3.0

  • All Items

Sections

  • ControlMap Parser Library
    • features
  • Examples

Crate Items

  • Modules
  • Structs
  • Enums

Crates

  • controlmap_parser

Crate controlmap_parser

Source
Expand description

§ControlMap Parser Library

The controlmap.txt parser for Skyrim.

§features

  • controlmap.txt => json structure
  • json structure => controlmap.txt
  • Analysis using enum scanCodes.

§Examples

use controlmap_parser::ControlMap;

type Result<T, E = Box<dyn std::error::Error + 'static>> = core::result::Result<T, E>;
fn main() -> Result<()> {
    let input = r#"
// Lockpicking
RotatePick	0xff		0xa		0x000b	0	0	0	0x8
RotateLock	0x1e,0xff	0xff	0x000c	0	0	0	0x8
DebugMode	0x35		0xff	0x4000	0	0	0	0x8
Cancel		0x0f		0xff	0x1000	0	0	0	0x8

// Favor
Cancel	0x0f	0xff	0x1000	0	0	0	0x108"#;

    let control_map = ControlMap::from_txt(input)?;
    println!("txt => Struct:\n{:?}", &control_map);

    let json = serde_json::to_string_pretty(&control_map)?;
    let expected_json = r#"{
  "lines": [
    "BlankLine",
    {
      "Comment": " Lockpicking"
    },
    {
      "EventLine": {
        "event_name": "RotatePick",
        "keyboard_id": {
          "One": "0xff"
        },
        "mouse_id": {
          "One": "0xa"
        },
        "gamepad_id": {
          "One": "0x000b"
        },
        "remap_key": false,
        "remap_mouse": false,
        "remap_gamepad": false,
        "event_binary_flag": "0x8"
      }
    },
    {
      "EventLine": {
        "event_name": "RotateLock",
        "keyboard_id": {
          "Or": [
            {
              "One": "0x1e"
            },
            {
              "One": "0xff"
            }
          ]
        },
        "mouse_id": {
          "One": "0xff"
        },
        "gamepad_id": {
          "One": "0x000c"
        },
        "remap_key": false,
        "remap_mouse": false,
        "remap_gamepad": false,
        "event_binary_flag": "0x8"
      }
    },
    {
      "EventLine": {
        "event_name": "DebugMode",
        "keyboard_id": {
          "One": "0x35"
        },
        "mouse_id": {
          "One": "0xff"
        },
        "gamepad_id": {
          "One": "0x4000"
        },
        "remap_key": false,
        "remap_mouse": false,
        "remap_gamepad": false,
        "event_binary_flag": "0x8"
      }
    },
    {
      "EventLine": {
        "event_name": "Cancel",
        "keyboard_id": {
          "One": "0x0f"
        },
        "mouse_id": {
          "One": "0xff"
        },
        "gamepad_id": {
          "One": "0x1000"
        },
        "remap_key": false,
        "remap_mouse": false,
        "remap_gamepad": false,
        "event_binary_flag": "0x8"
      }
    },
    "BlankLine",
    {
      "Comment": " Favor"
    },
    {
      "EventLine": {
        "event_name": "Cancel",
        "keyboard_id": {
          "One": "0x0f"
        },
        "mouse_id": {
          "One": "0xff"
        },
        "gamepad_id": {
          "One": "0x1000"
        },
        "remap_key": false,
        "remap_mouse": false,
        "remap_gamepad": false,
        "event_binary_flag": "0x108"
      }
    }
  ]
}"#;
    assert_eq!(&json, expected_json);

    let control_map: ControlMap = serde_json::from_str(&json)?;
    // Yes, blank lines are not removed, they are applied as is.
    // There are places where it would be an error to do otherwise.
    let formatted_control_map = r#"
// Lockpicking
RotatePick	0xff	0xa	0x000b	0	0	0	0x8
RotateLock	0x1e+0xff	0xff	0x000c	0	0	0	0x8
DebugMode	0x35	0xff	0x4000	0	0	0	0x8
Cancel	0x0f	0xff	0x1000	0	0	0	0x8

// Favor
Cancel	0x0f	0xff	0x1000	0	0	0	0x108
"#;
    assert_eq!(control_map.to_string(), formatted_control_map);

    Ok(())
}

Modules§

parser
ControlMap Parser
scan_code
Input scan codes with unknown details defined at the following sites. Direct input enumerator for Skyrim

Structs§

ControlMap
Structure with an array containing controlmap.txt line by line.

Enums§

ControlMapError

Results

Settings
Help
    module
    controlmap_parser::parser
    ControlMap Parser
    enum variant
    controlmap_parser::ControlMapError::ParseError
    extern crate
    controlmap_parser
    ControlMap Parser Library
    function
    controlmap_parser::parser::control_map_parser
    parse controlmap.txt
    enum variant
    controlmap_parser::scan_code::KeyboardCode::Pause
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.