Skip to content

levilamina::client

Client-only capabilities.

On a server host this whole family is empty slots

Not a compile error but a runtime Err. Contract Β§2.1: the layout is identical on every target and an absent capability is a NULL slot, so the same mod source compiles for both targets and loading onto the wrong one is refused explicitly by the host during the handshake, from mod_flags.

Decide with is_available and not with a cfg.

A callback runs on the client thread

Not the server thread. A hotkey callback must not touch server state.

Functions

client::is_available

Rust
pub fn is_available() -> bool

Whether this host was built for the client target, meaning whether the client_* slots are filled.

client::is_in_level

Rust
pub fn is_in_level() -> Result<bool>

Whether the client is currently in a world.

client::local_player_name

Rust
pub fn local_player_name() -> Result<String>

The name of the local player. Not being in a world is an Err.

client::screen_name

Rust
pub fn screen_name() -> Result<String>

The current screen name, such as "hud_screen" or "pause_screen".

client::register_key

Rust
1
2
3
4
5
6
pub fn register_key(
    name: &str,
    key_codes: &[i32],
    allow_remap: bool,
    handler: impl FnMut(KeyAction, i32) + Send + 'static,
) -> Result<KeyBinding>

Registers a hotkey.

key_codes is the default binding and allow_remap decides whether the player may change it in the settings. The callback receives (action, focus impact) and both run on the client thread.

  • Parameters:
    • name : &str
    • key_codes : &[i32]
    • allow_remap : bool
    • handler : impl FnMut(KeyAction, i32) + Send + 'static
  • Return type: Result<KeyBinding>
  • Slots: client_register_key

KeyBinding

Rust
1
2
3
pub struct KeyBinding {
    // private fields
}

One registered hotkey. Dropping it deregisters.

  • Implements: Drop

KeyBinding::name

Rust
pub fn name(&self) -> &str
  • Return type: &str

KeyBinding::key_codes

Rust
pub fn key_codes(&self) -> Result<Vec<i32>>

The key codes currently bound. They differ from the defaults once the player has rebound them.

KeyBinding::forget

Rust
pub fn forget(mut self)

Keeps it alive until the mod unloads, when the host clears it.

KeyAction

Rust
1
2
3
4
5
6
pub enum KeyAction {
        Up,
        Down,
        /// The host reported an action code this side does not recognize.
        Unknown(i32),
}

A key action.

  • Implements: Debug, Clone, Copy, PartialEq, Eq

KeyAction::from_i32

Rust
pub fn from_i32(v: i32) -> KeyAction
  • Parameters:
    • v : i32
  • Return type: KeyAction

KeyAction::is_down

Rust
pub fn is_down(self) -> bool
  • Return type: bool