flatland-client-ui 0.2.7

Engine-agnostic play client UI state (world grid, input, presentation)
Documentation
//! Play-client keybindings — shared by in-game help overlay and `flatland3 keys`.

use crate::map_presentation::format_map_legend_plain;

pub struct KeyBinding {
    pub keys: &'static str,
    pub description: &'static str,
}

pub struct KeyBindingCategory {
    pub name: &'static str,
    pub bindings: &'static [KeyBinding],
}

pub const CATEGORIES: &[KeyBindingCategory] = &[
    KeyBindingCategory {
        name: "Movement",
        bindings: &[
            KeyBinding {
                keys: "WASD / arrows",
                description: "Move (cardinals; hold two for diagonal)",
            },
            KeyBinding {
                keys: "Click map",
                description: "Auto-walk to clicked cell (A* path); right-click cancels",
            },
            KeyBinding {
                keys: "Shift (hold)",
                description: "Sprint while moving",
            },
            KeyBinding {
                keys: "x",
                description: "Toggle sprint mode (faster move, stamina drain)",
            },
            KeyBinding {
                keys: "Shift+Space",
                description: "Lunge forward (~8.5 m, high stamina)",
            },
            KeyBinding {
                keys: "m",
                description: "Map target mode — mouse/WASD place X, Enter to auto-walk",
            },
            KeyBinding {
                keys: "u / j",
                description: "Climb / descend",
            },
            KeyBinding {
                keys: "Alt + WASD / arrows",
                description: "Directional jump — leap one cell over a medium cliff (~2 m rise)",
            },
            KeyBinding {
                keys: "Space",
                description: "Stop movement / cancel auto-walk",
            },
        ],
    },
    KeyBindingCategory {
        name: "Combat",
        bindings: &[
            KeyBinding {
                keys: "Tab",
                description: "Cycle T1 target (hostile)",
            },
            KeyBinding {
                keys: "Shift+Tab",
                description: "Cycle T2 target (allies, then monsters)",
            },
            KeyBinding {
                keys: "0 / Shift+0",
                description: "Clear T1 / T2 target",
            },
            KeyBinding {
                keys: "1–9",
                description: "Hotbar — cast bound ability (see client-settings.yaml)",
            },
            KeyBinding {
                keys: "r / Shift+r",
                description: "Toggle auto rotation for T1 / T2",
            },
            KeyBinding {
                keys: "c",
                description: "Dodge (i-frames, stamina)",
            },
            KeyBinding {
                keys: "q",
                description: "Toggle block (melee damage reduction)",
            },
            KeyBinding {
                keys: "l",
                description: "Loadout — assign rotation preset to T1/T2",
            },
            KeyBinding {
                keys: "o",
                description: "Rotation editor — create/edit/delete presets",
            },
            KeyBinding {
                keys: "(auto)",
                description: "T1 auto pursues into weapon range when idle",
            },
        ],
    },
    KeyBindingCategory {
        name: "World",
        bindings: &[
            KeyBinding {
                keys: "f",
                description: "Use nearest — interact, then pickup loot/chest, then harvest/butcher",
            },
            KeyBinding {
                keys: "v",
                description: "Quest log / withdraw menu",
            },
        ],
    },
    KeyBindingCategory {
        name: "Inventory & crafting",
        bindings: &[
            KeyBinding {
                keys: "b",
                description: "Inventory (worn items by body slot, on-you items, nearby open chests)",
            },
            KeyBinding {
                keys: "n",
                description: "Craft menu (Enter to craft, Esc to close)",
            },
            KeyBinding {
                keys: ",",
                description: "Keychain — stow/retrieve chest keys (zero carry mass when stowed)",
            },
            KeyBinding {
                keys: "i",
                description: "Character stats overlay",
            },
            KeyBinding {
                keys: "↑↓ / jk",
                description: "Move selection in craft or inventory menus",
            },
            KeyBinding {
                keys: "Enter",
                description: "Inventory: equip/wear/use selected item, or move it",
            },
            KeyBinding {
                keys: "m / d / x / l",
                description: "Inventory: move to… picker / drop on ground / destroy permanently / lock nearby chest",
            },
        ],
    },
    KeyBindingCategory {
        name: "Chat",
        bindings: &[
            KeyBinding {
                keys: "t",
                description: "Say to nearby players",
            },
            KeyBinding {
                keys: "g",
                description: "Whisper (requires whisper_stone)",
            },
            KeyBinding {
                keys: "Enter",
                description: "Send chat line",
            },
            KeyBinding {
                keys: "Esc",
                description: "Cancel chat or close overlay",
            },
        ],
    },
    KeyBindingCategory {
        name: "Session",
        bindings: &[
            KeyBinding {
                keys: "? or /",
                description: "Toggle this keybindings help",
            },
            KeyBinding {
                keys: ".",
                description: "Cycle HUD view — normal → compact → map",
            },
            KeyBinding {
                keys: "Ctrl+Q",
                description: "Quit client",
            },
            KeyBinding {
                keys: "Ctrl+C",
                description: "Interrupt / force quit",
            },
        ],
    },
    KeyBindingCategory {
        name: "Dev / debug",
        bindings: &[
            KeyBinding {
                keys: "-",
                description: "Test damage (25 HP) — dev only",
            },
        ],
    },
];

/// Plain-text reference for `flatland3 keys` and similar CLIs.
pub fn format_keybindings_plain() -> String {
    let mut out = String::from("Flatland3 play — keybindings\n\n");
    for cat in CATEGORIES {
        out.push_str(cat.name);
        out.push_str("\n");
        for b in cat.bindings {
            out.push_str(&format!("  {:<16} {}\n", b.keys, b.description));
        }
        out.push('\n');
    }
    out.push_str(&format_map_legend_plain());
    out.push_str("Wildlife: rabbits north meadow (~95,195); wolves bog (~118,122).\n");
    out
}