|
|
|
@ -1,153 +1,55 @@
|
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
|
|
mod environment;
|
|
|
|
|
mod mudlet;
|
|
|
|
|
mod tintin;
|
|
|
|
|
|
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
use std::io;
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
|
|
use serde_derive::Deserialize;
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct MudletMap {
|
|
|
|
|
/// area id
|
|
|
|
|
id: i64,
|
|
|
|
|
|
|
|
|
|
/// area name
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
|
|
/// rooms
|
|
|
|
|
rooms: Vec<MudletRoom>,
|
|
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
_extra: HashMap<String, Value>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct MudletRoom {
|
|
|
|
|
/// exits
|
|
|
|
|
exits: Vec<MudletExit>,
|
|
|
|
|
|
|
|
|
|
/// room number
|
|
|
|
|
id: i64,
|
|
|
|
|
|
|
|
|
|
/// room name
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
|
|
/// user data
|
|
|
|
|
userData: MudletUserData,
|
|
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
_extra: HashMap<String, Value>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct MudletExit {
|
|
|
|
|
/// connected room
|
|
|
|
|
exitId: i64,
|
|
|
|
|
|
|
|
|
|
/// direction
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
_extra: HashMap<String, Value>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct MudletUserData {
|
|
|
|
|
/// room description
|
|
|
|
|
description: String,
|
|
|
|
|
|
|
|
|
|
/// zone name
|
|
|
|
|
zone: String,
|
|
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
_extra: HashMap<String, Value>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct TinTinRoom {
|
|
|
|
|
/// room number
|
|
|
|
|
vnum: i64,
|
|
|
|
|
|
|
|
|
|
/// flags
|
|
|
|
|
flags: i64,
|
|
|
|
|
|
|
|
|
|
/// color
|
|
|
|
|
color: String,
|
|
|
|
|
|
|
|
|
|
/// room name
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
|
|
/// room symbol
|
|
|
|
|
symbol: char,
|
|
|
|
|
|
|
|
|
|
/// room description
|
|
|
|
|
desc: String,
|
|
|
|
|
|
|
|
|
|
/// area that room is in
|
|
|
|
|
area: String,
|
|
|
|
|
|
|
|
|
|
/// notes
|
|
|
|
|
note: String,
|
|
|
|
|
use environment::Environment;
|
|
|
|
|
|
|
|
|
|
/// type of terrain
|
|
|
|
|
terrain: String,
|
|
|
|
|
|
|
|
|
|
/// extra data
|
|
|
|
|
data: String,
|
|
|
|
|
|
|
|
|
|
/// movement cost
|
|
|
|
|
weight: f64,
|
|
|
|
|
|
|
|
|
|
/// room id
|
|
|
|
|
id: String,
|
|
|
|
|
|
|
|
|
|
/// exits
|
|
|
|
|
exits: Vec<TinTinExit>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct TinTinExit {
|
|
|
|
|
/// vnum
|
|
|
|
|
vnum: i64,
|
|
|
|
|
|
|
|
|
|
/// exit name
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
|
|
/// command to use the exit
|
|
|
|
|
cmd: String,
|
|
|
|
|
|
|
|
|
|
/// exit direction
|
|
|
|
|
dir: i8,
|
|
|
|
|
|
|
|
|
|
/// exit flags
|
|
|
|
|
flags: i64,
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let mut buffer = String::new();
|
|
|
|
|
let mut stdin = io::stdin();
|
|
|
|
|
stdin.read_to_string(&mut buffer)?;
|
|
|
|
|
|
|
|
|
|
/// extra data
|
|
|
|
|
data: String,
|
|
|
|
|
let mudlet_map: Value = serde_json::from_str(&buffer)?;
|
|
|
|
|
|
|
|
|
|
/// movement cost?
|
|
|
|
|
weight: f64,
|
|
|
|
|
let areas = match mudlet_map.get("areas") {
|
|
|
|
|
Some(areas) => match areas.as_array() {
|
|
|
|
|
Some(areas) => areas,
|
|
|
|
|
None => panic!("Areas not an array"),
|
|
|
|
|
},
|
|
|
|
|
None => panic!("No areas found"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// exit color
|
|
|
|
|
color: String,
|
|
|
|
|
for area in areas {
|
|
|
|
|
let id: i64 = match area.get("id") {
|
|
|
|
|
Some(id) => match id.as_i64() {
|
|
|
|
|
Some(id) => id,
|
|
|
|
|
None => continue,
|
|
|
|
|
},
|
|
|
|
|
None => continue,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// decay?
|
|
|
|
|
decay: f64,
|
|
|
|
|
if id < 0 {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let mut buffer = String::new();
|
|
|
|
|
let mut stdin = io::stdin();
|
|
|
|
|
stdin.read_to_string(&mut buffer)?;
|
|
|
|
|
|
|
|
|
|
let mudlet_map: MudletMap = serde_json::from_str(&buffer)?;
|
|
|
|
|
let mudlet_area: mudlet::Area = serde_json::from_value(area.to_owned())?;
|
|
|
|
|
|
|
|
|
|
let mut tintin_rooms: BTreeMap<i64, TinTinRoom> = BTreeMap::new();
|
|
|
|
|
// hold the tintin version of the rooms
|
|
|
|
|
let mut tintin_rooms: BTreeMap<i64, tintin::Room> = BTreeMap::new();
|
|
|
|
|
|
|
|
|
|
for mudlet_room in mudlet_map.rooms {
|
|
|
|
|
let mut tintin_exits: Vec<TinTinExit> = Vec::new();
|
|
|
|
|
for mudlet_room in mudlet_area.rooms {
|
|
|
|
|
// hold the tintin version of room exits
|
|
|
|
|
let mut tintin_exits: Vec<tintin::Exit> = Vec::new();
|
|
|
|
|
|
|
|
|
|
for mudlet_exit in mudlet_room.exits {
|
|
|
|
|
// map the exit direction
|
|
|
|
|
let (dir_num, dir_short) = match mudlet_exit.name.as_str() {
|
|
|
|
|
"north" => (1, 'n'),
|
|
|
|
|
"east" => (2, 'e'),
|
|
|
|
@ -158,7 +60,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
_ => panic!("Unknown exit: {}", mudlet_exit.name),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let tintin_exit = TinTinExit {
|
|
|
|
|
// create a tintin exit from the mudlet exit
|
|
|
|
|
let tintin_exit = tintin::Exit {
|
|
|
|
|
vnum: mudlet_exit.exitId,
|
|
|
|
|
name: dir_short.into(),
|
|
|
|
|
cmd: dir_short.into(),
|
|
|
|
@ -170,17 +73,25 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
decay: 0.0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// add tintin exit to list of tintin exits for the room
|
|
|
|
|
tintin_exits.push(tintin_exit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let tintin_room = TinTinRoom {
|
|
|
|
|
let userdata = match mudlet_room.userData {
|
|
|
|
|
Some(userdata) => userdata,
|
|
|
|
|
None => continue,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let environment = Environment::from(mudlet_room.environment);
|
|
|
|
|
|
|
|
|
|
let tintin_room = tintin::Room {
|
|
|
|
|
vnum: mudlet_room.id,
|
|
|
|
|
flags: 0,
|
|
|
|
|
color: String::new(),
|
|
|
|
|
color: environment.color(),
|
|
|
|
|
name: mudlet_room.name,
|
|
|
|
|
symbol: ' ',
|
|
|
|
|
desc: mudlet_room.userData.description.replace("\n", " ").replace (" ", " "),
|
|
|
|
|
area: mudlet_room.userData.zone,
|
|
|
|
|
symbol: environment.symbol(),
|
|
|
|
|
desc: userdata.description.replace("\n", " ").replace(" ", " "),
|
|
|
|
|
area: userdata.zone,
|
|
|
|
|
note: String::new(),
|
|
|
|
|
terrain: String::new(),
|
|
|
|
|
data: String::new(),
|
|
|
|
@ -196,12 +107,23 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
for exit in room.exits {
|
|
|
|
|
println!("E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}", exit.vnum, exit.name, exit.cmd, exit.dir, exit.flags, exit.data, exit.weight, exit.color, exit.decay);
|
|
|
|
|
println!(
|
|
|
|
|
"E {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}} {{{}}}",
|
|
|
|
|
exit.vnum,
|
|
|
|
|
exit.name,
|
|
|
|
|
exit.cmd,
|
|
|
|
|
exit.dir,
|
|
|
|
|
exit.flags,
|
|
|
|
|
exit.data,
|
|
|
|
|
exit.weight,
|
|
|
|
|
exit.color,
|
|
|
|
|
exit.decay
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println!();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|