Skip to main content
Verticopolis engineGitHub

import_tdt

Function import_tdt 

Source
pub fn import_tdt(
    bytes: &[u8],
    filename: &str,
) -> Result<(String, Vec<String>), String>
Expand description

Reads a 1994 SimTower .TDT save into this engine’s save JSON, plus warnings about anything it could not carry over. Load the JSON with deserialize_tdt after parsing it. The error is a sentence a player can read.

use verticopolis_engine::clock::GameMode;
use verticopolis_engine::sim::Simulation;
use verticopolis_engine::{export_tdt, import_tdt};

let sim = Simulation::new_game(1, GameMode::Classic);
let bytes = export_tdt(&sim.serialize().to_string()).unwrap();
let (json, _warnings) = import_tdt(&bytes, "TOWER.TDT").unwrap();
let save: serde_json::Value = serde_json::from_str(&json).unwrap();
let tower = verticopolis_engine::load::deserialize_tdt(&save).unwrap();
assert_eq!(tower.mode, GameMode::Classic);