← All Workshops
MudEngine Part 3: File-Based World Loading
Step 5 / 9
Update the World model
Replace the hardcoded World::new() with a World::from_file(path) method that deserializes the TOML file.
We define serde-compatible structs for the TOML format — TomlRoom includes a numeric id field, and each exit's destination is a room id. The loader copies the data straight through; no name-to-index resolution is needed.
mud-engine-repl/src/main.rs
use std::io::{self, Write}; use serde::Deserialize; #[derive(Deserialize)] struct TomlRoom { id: usize, name: String, description: String, exits: Vec<TomlExit>, } #[derive(Deserialize)] struct TomlExit { direction: String, destination: usize, } #[derive(Deserialize)] struct TomlWorld { rooms: Vec<TomlRoom>, }
Step 5 / 9