master
rascul 3 years ago
parent 4f0b3e2d65
commit 73b2f1421f

@ -5,122 +5,122 @@ use serde_derive::Deserialize;
/// Type of environment for the room /// Type of environment for the room
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub enum Environment { pub enum Environment {
/// Inside a building /// Inside a building
Inside, Inside,
/// Out in the wild /// Out in the wild
Wilderness, Wilderness,
/// On a road /// On a road
Road, Road,
/// Horse load /// Horse load
Horse, Horse,
/// In a swamp /// In a swamp
Swamp, Swamp,
/// In the water /// In the water
Water, Water,
/// A drinking source /// A drinking source
Drink, Drink,
/// Weapon shop /// Weapon shop
Weaponsmith, Weaponsmith,
/// Armor shop /// Armor shop
Armorer, Armorer,
/// Master blacksmith /// Master blacksmith
Blacksmith, Blacksmith,
/// Bank /// Bank
Bank, Bank,
/// Stables /// Stables
Stables, Stables,
/// Place to rent /// Place to rent
Rent, Rent,
/// Grocer /// Grocer
Grocer, Grocer,
/// Warrior practice /// Warrior practice
Warrior, Warrior,
/// Rogue practice /// Rogue practice
Rogue, Rogue,
/// Hunter practice /// Hunter practice
Hunter, Hunter,
/// Possible PK objective /// Possible PK objective
Pk, Pk,
/// Other /// Other
Other, Other,
} }
impl From<i64> for Environment { impl From<i64> for Environment {
fn from(num: i64) -> Self { fn from(num: i64) -> Self {
match num { match num {
20 => Self::Inside, 20 => Self::Inside,
21 => Self::Wilderness, 21 => Self::Wilderness,
22 => Self::Road, 22 => Self::Road,
23 => Self::Horse, 23 => Self::Horse,
24 => Self::Swamp, 24 => Self::Swamp,
25 => Self::Water, 25 => Self::Water,
26 => Self::Drink, 26 => Self::Drink,
27 => Self::Weaponsmith, 27 => Self::Weaponsmith,
28 => Self::Armorer, 28 => Self::Armorer,
29 => Self::Blacksmith, 29 => Self::Blacksmith,
30 => Self::Bank, 30 => Self::Bank,
31 => Self::Stables, 31 => Self::Stables,
32 => Self::Rent, 32 => Self::Rent,
33 => Self::Grocer, 33 => Self::Grocer,
34 => Self::Warrior, 34 => Self::Warrior,
35 => Self::Rogue, 35 => Self::Rogue,
36 => Self::Hunter, 36 => Self::Hunter,
37 => Self::Pk, 37 => Self::Pk,
_ => Self::Other, _ => Self::Other,
} }
} }
} }
impl Environment { impl Environment {
/// Some room environments have a symbol to put in the room on the map /// Some room environments have a symbol to put in the room on the map
pub fn symbol(&self) -> String { pub fn symbol(&self) -> String {
match self { match self {
Self::Horse => "<bba>H", Self::Horse => "<bba>H",
Self::Drink => "<abf>D", Self::Drink => "<abf>D",
Self::Weaponsmith => "<eac>W", Self::Weaponsmith => "<eac>W",
Self::Armorer => "<eac>A", Self::Armorer => "<eac>A",
Self::Blacksmith => "<cbf>B", Self::Blacksmith => "<cbf>B",
Self::Bank => "<afa>$", Self::Bank => "<afa>$",
Self::Stables => "<bba>S", Self::Stables => "<bba>S",
Self::Rent => "<efd>R", Self::Rent => "<efd>R",
Self::Grocer => "<eac>G", Self::Grocer => "<eac>G",
Self::Warrior => "<fdc>W", Self::Warrior => "<fdc>W",
Self::Rogue => "<fdc>R", Self::Rogue => "<fdc>R",
Self::Hunter => "<fdc>H", Self::Hunter => "<fdc>H",
Self::Pk => "<ffd>P", Self::Pk => "<ffd>P",
_ => "", _ => "",
} }
.to_string() .to_string()
} }
/// Color of the room /// Color of the room
pub fn color(&self) -> String { pub fn color(&self) -> String {
match self { match self {
Self::Inside => "<g12>", Self::Inside => "<g12>",
Self::Wilderness => "<bca>", Self::Wilderness => "<bca>",
Self::Road => "<cba>", Self::Road => "<cba>",
Self::Swamp => "<adb>", Self::Swamp => "<adb>",
Self::Water => "<abf>", Self::Water => "<abf>",
_ => "", _ => "",
} }
.to_string() .to_string()
} }
} }

@ -12,118 +12,118 @@ use serde_json::Value;
use environment::Environment; use environment::Environment;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let mut buffer = String::new(); let mut buffer = String::new();
let mut stdin = io::stdin(); let mut stdin = io::stdin();
stdin.read_to_string(&mut buffer)?; stdin.read_to_string(&mut buffer)?;
let mudlet_map: Value = serde_json::from_str(&buffer)?; let mudlet_map: Value = serde_json::from_str(&buffer)?;
let areas = match mudlet_map.get("areas") { let areas = match mudlet_map.get("areas") {
Some(areas) => match areas.as_array() { Some(areas) => match areas.as_array() {
Some(areas) => areas, Some(areas) => areas,
None => panic!("Areas not an array"), None => panic!("Areas not an array"),
}, },
None => panic!("No areas found"), None => panic!("No areas found"),
}; };
for area in areas { for area in areas {
let id: i64 = match area.get("id") { let id: i64 = match area.get("id") {
Some(id) => match id.as_i64() { Some(id) => match id.as_i64() {
Some(id) => id, Some(id) => id,
None => continue, None => continue,
}, },
None => continue, None => continue,
}; };
if id < 0 { if id < 0 {
continue; continue;
} }
let mudlet_area: mudlet::Area = serde_json::from_value(area.to_owned())?; let mudlet_area: mudlet::Area = serde_json::from_value(area.to_owned())?;
// hold the tintin version of the rooms // hold the tintin version of the rooms
let mut tintin_rooms: BTreeMap<i64, tintin::Room> = BTreeMap::new(); let mut tintin_rooms: BTreeMap<i64, tintin::Room> = BTreeMap::new();
for mudlet_room in mudlet_area.rooms { for mudlet_room in mudlet_area.rooms {
// hold the tintin version of room exits // hold the tintin version of room exits
let mut tintin_exits: Vec<tintin::Exit> = Vec::new(); let mut tintin_exits: Vec<tintin::Exit> = Vec::new();
for mudlet_exit in mudlet_room.exits { for mudlet_exit in mudlet_room.exits {
// map the exit direction // map the exit direction
let (dir_num, dir_short) = match mudlet_exit.name.as_str() { let (dir_num, dir_short) = match mudlet_exit.name.as_str() {
"north" => (1, 'n'), "north" => (1, 'n'),
"east" => (2, 'e'), "east" => (2, 'e'),
"south" => (4, 's'), "south" => (4, 's'),
"west" => (8, 'w'), "west" => (8, 'w'),
"up" => (16, 'u'), "up" => (16, 'u'),
"down" => (32, 'd'), "down" => (32, 'd'),
_ => panic!("Unknown exit: {}", mudlet_exit.name), _ => panic!("Unknown exit: {}", mudlet_exit.name),
}; };
// create a tintin exit from the mudlet exit // create a tintin exit from the mudlet exit
let tintin_exit = tintin::Exit { let tintin_exit = tintin::Exit {
vnum: mudlet_exit.exitId, vnum: mudlet_exit.exitId,
name: dir_short.into(), name: dir_short.into(),
cmd: dir_short.into(), cmd: dir_short.into(),
dir: dir_num, dir: dir_num,
flags: 0, flags: 0,
data: String::new(), data: String::new(),
weight: 1.0, weight: 1.0,
color: String::new(), color: String::new(),
decay: 0.0, decay: 0.0,
}; };
// add tintin exit to list of tintin exits for the room // add tintin exit to list of tintin exits for the room
tintin_exits.push(tintin_exit); tintin_exits.push(tintin_exit);
} }
let userdata = match mudlet_room.userData { let userdata = match mudlet_room.userData {
Some(userdata) => userdata, Some(userdata) => userdata,
None => continue, None => continue,
}; };
let environment = Environment::from(mudlet_room.environment); let environment = Environment::from(mudlet_room.environment);
let tintin_room = tintin::Room { let tintin_room = tintin::Room {
vnum: mudlet_room.id, vnum: mudlet_room.id,
flags: 0, flags: 0,
color: environment.color(), color: environment.color(),
name: mudlet_room.name, name: mudlet_room.name,
symbol: environment.symbol(), symbol: environment.symbol(),
desc: userdata.description.replace("\n", " ").replace(" ", " "), desc: userdata.description.replace("\n", " ").replace(" ", " "),
area: userdata.zone, area: userdata.zone,
note: String::new(), note: String::new(),
terrain: String::new(), terrain: String::new(),
data: String::new(), data: String::new(),
weight: 1.0, weight: 1.0,
id: String::new(), id: String::new(),
exits: tintin_exits, exits: tintin_exits,
}; };
tintin_rooms.insert(tintin_room.vnum, tintin_room); tintin_rooms.insert(tintin_room.vnum, tintin_room);
} }
for (vnum, room) in tintin_rooms { for (vnum, room) in tintin_rooms {
println!("R {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}", vnum, room.flags, room.color, room.name, room.symbol, room.desc, room.area, room.note, room.terrain, room.data, room.weight, room.id); println!("{}", room);
for exit in room.exits { for exit in room.exits {
println!( println!(
"E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}", "E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}",
exit.vnum, exit.vnum,
exit.name, exit.name,
exit.cmd, exit.cmd,
exit.dir, exit.dir,
exit.flags, exit.flags,
exit.data, exit.data,
exit.weight, exit.weight,
exit.color, exit.color,
exit.decay exit.decay
); );
} }
println!(); println!();
} }
} }
Ok(()) Ok(())
} }

@ -7,15 +7,15 @@ use crate::mudlet;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Area { pub struct Area {
/// area id /// area id
//id: i64, //id: i64,
/// area name /// area name
//name: String, //name: String,
/// rooms /// rooms
pub rooms: Vec<mudlet::Room>, pub rooms: Vec<mudlet::Room>,
#[serde(flatten)] #[serde(flatten)]
_extra: HashMap<String, Value>, _extra: HashMap<String, Value>,
} }

@ -5,12 +5,12 @@ use serde_json::Value;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Exit { pub struct Exit {
/// connected room /// connected room
pub exitId: i64, pub exitId: i64,
/// direction /// direction
pub name: String, pub name: String,
#[serde(flatten)] #[serde(flatten)]
_extra: HashMap<String, Value>, _extra: HashMap<String, Value>,
} }

@ -4,19 +4,19 @@ use crate::mudlet;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Room { pub struct Room {
/// environment /// environment
pub environment: i64, pub environment: i64,
/// exits /// exits
pub exits: Vec<mudlet::Exit>, pub exits: Vec<mudlet::Exit>,
/// room number /// room number
pub id: i64, pub id: i64,
/// room name /// room name
#[serde(default)] #[serde(default)]
pub name: String, pub name: String,
/// user data /// user data
pub userData: Option<mudlet::UserData>, pub userData: Option<mudlet::UserData>,
} }

@ -5,13 +5,13 @@ use serde_json::Value;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct UserData { pub struct UserData {
/// room description /// room description
pub description: String, pub description: String,
/// zone name /// zone name
#[serde(default)] #[serde(default)]
pub zone: String, pub zone: String,
#[serde(flatten)] #[serde(flatten)]
_extra: HashMap<String, Value>, _extra: HashMap<String, Value>,
} }

@ -1,29 +1,29 @@
#[derive(Debug)] #[derive(Debug)]
pub struct Exit { pub struct Exit {
/// vnum /// vnum
pub vnum: i64, pub vnum: i64,
/// exit name /// exit name
pub name: String, pub name: String,
/// command to use the exit /// command to use the exit
pub cmd: String, pub cmd: String,
/// exit direction /// exit direction
pub dir: i8, pub dir: i8,
/// exit flags /// exit flags
pub flags: i64, pub flags: i64,
/// extra data /// extra data
pub data: String, pub data: String,
/// movement cost? /// movement cost?
pub weight: f64, pub weight: f64,
/// exit color /// exit color
pub color: String, pub color: String,
/// decay? /// decay?
pub decay: f64, pub decay: f64,
} }

@ -1,43 +1,66 @@
use std::fmt;
use crate::tintin; use crate::tintin;
#[derive(Debug)] #[derive(Debug)]
pub struct Room { pub struct Room {
/// room number /// room number
pub vnum: i64, pub vnum: i64,
/// flags
pub flags: i64,
/// flags /// color
pub flags: i64, pub color: String,
/// color /// room name
pub color: String, pub name: String,
/// room name /// room symbol
pub name: String, pub symbol: String,
/// room symbol /// room description
pub symbol: String, pub desc: String,
/// room description /// area that room is in
pub desc: String, pub area: String,
/// area that room is in /// notes
pub area: String, pub note: String,
/// notes /// type of terrain
pub note: String, pub terrain: String,
/// type of terrain /// extra data
pub terrain: String, pub data: String,
/// extra data /// movement cost
pub data: String, pub weight: f64,
/// movement cost /// room id
pub weight: f64, pub id: String,
/// room id /// exits
pub id: String, pub exits: Vec<tintin::Exit>,
}
/// exits impl fmt::Display for Room {
pub exits: Vec<tintin::Exit>, fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"R {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}",
&self.vnum,
&self.flags,
&self.color,
&self.name,
&self.symbol,
&self.desc,
&self.area,
&self.note,
&self.terrain,
&self.data,
&self.weight,
&self.id
)
}
} }

Loading…
Cancel
Save