pub fn load_image<'a>(path: String) -> Result<VM<'a>, Box<dyn Error>> {
    let mut image_data = png_to_image_data(path)?;

    let mut vm = VM::new_redshift();

    let _unknown_1 = image_data.read_int();
    let _level_id = image_data.read_string();

    let game_name = image_data.read_string();
    vm.redshift.as_mut().unwrap().game_name = game_name;

    let _unknown_2 = image_data.read_int();

    let _solution_length = image_data.read_int();
    let _unknown_3 = image_data.read_int();

    let exa_count = image_data.read_int();

    let start_host = vm.hosts.get("core").unwrap().clone();
    let mut seen_names: HashSet<String> = HashSet::new();

    for _ in 0..exa_count {
        let _unknown_4 = image_data.read_byte();
        let mut exa_name = image_data.read_string();

        while seen_names.contains(&exa_name) {
            exa_name.push_str("x");
        }
        seen_names.insert(exa_name.clone());

        let mut exa_script = image_data.read_string();
        // hack to help out our parser
        if !exa_script.ends_with("\n") {
            exa_script.push_str("\n");
        }

        let _view_mode = image_data.read_byte();
        let message_bus_mode = image_data.read_byte();

        let mut raw_sprite = [false; 100];
        for idx in 0..100 {
            raw_sprite[idx] = image_data.read_bool();
        }
        let sprite = Sprite::from_pixels(raw_sprite);

        let exa = Exa::spawn(
            &mut vm,
            start_host.clone(),
            exa_name,
            true,
            exa_script.as_str(),
        )
        .expect("failed to initialize exa");
        exa.borrow_mut().sprite = sprite;
        if message_bus_mode == 1 {
            exa.borrow_mut().mode = Mode::Local;
        }
    }

    Ok(vm)
}
/// Load a Redshift image from the specified file and return
/// an initialized Redshift VM implementing the program.
Load a Redshift image from the specified file and return
an initialized Redshift VM implementing the program.
Load a Redshift image from the specified file and return an initialized Redshift VM implementing the program .
pub fn load_image<'a>(path: String) -> Result<VM<'a>, Box<dyn Error>> {
    let mut image_data = png_to_image_data(path)?;
    let mut vm = VM::new_redshift();
    let _unknown_1 = image_data.read_int();
    let _level_id = image_data.read_string();
    let game_name = image_data.read_string();
    vm.redshift.as_mut().unwrap().game_name = game_name;
    let _unknown_2 = image_data.read_int();
    let _solution_length = image_data.read_int();
    let _unknown_3 = image_data.read_int();
    let exa_count = image_data.read_int();
    let start_host = vm.hosts.get("core").unwrap().clone();
    let mut seen_names: HashSet<String> = HashSet::new();
    for _ in 0..exa_count {
        let _unknown_4 = image_data.read_byte();
        let mut exa_name = image_data.read_string();
        while seen_names.contains(&exa_name) {
            exa_name.push_str("x");
        }
        seen_names.insert(exa_name.clone());
        let mut exa_script = image_data.read_string();
        // hack to help out our parser
        if !exa_script.ends_with("\n") {
            exa_script.push_str("\n");
        }
        let _view_mode = image_data.read_byte();
        let message_bus_mode = image_data.read_byte();
        let mut raw_sprite = [false; 100];
        for idx in 0..100 {
            raw_sprite[idx] = image_data.read_bool();
        }
        let sprite = Sprite::from_pixels(raw_sprite);
        let exa = Exa::spawn(
            &mut vm,
            start_host.clone(),
            exa_name,
            true,
            exa_script.as_str(),
        )
        .expect("failed to initialize exa");
        exa.borrow_mut().sprite = sprite;
        if message_bus_mode == 1 {
            exa.borrow_mut().mode = Mode::Local;
        }
    }
    Ok(vm)
}
pub fn load_image < ' a > ( path : String ) -> Result < VM < ' a > , Box < dyn Error > > { let mut image_data = png_to_image_data ( path ) ? ; let mut vm = VM :: new_redshift ( ) ; let _unknown_1 = image_data . read_int ( ) ; let _level_id = image_data . read_string ( ) ; let game_name = image_data . read_string ( ) ; vm . redshift . as_mut ( ) . unwrap ( ) . game_name = game_name ; let _unknown_2 = image_data . read_int ( ) ; let _solution_length = image_data . read_int ( ) ; let _unknown_3 = image_data . read_int ( ) ; let exa_count = image_data . read_int ( ) ; let start_host = vm . hosts . get ( " " ) . unwrap ( ) . clone ( ) ; let mut seen_names : HashSet < String > = HashSet :: new ( ) ; for _ in 0 .. exa_count { let _unknown_4 = image_data . read_byte ( ) ; let mut exa_name = image_data . read_string ( ) ; while seen_names . contains ( & exa_name ) { exa_name . push_str ( " " ) ; } seen_names . insert ( exa_name . clone ( ) ) ; let mut exa_script = image_data . read_string ( ) ; // hack to help out our parser if ! exa_script . ends_with ( " \n " ) { exa_script . push_str ( " \n " ) ; } let _view_mode = image_data . read_byte ( ) ; let message_bus_mode = image_data . read_byte ( ) ; let mut raw_sprite = [ false ; 100 ] ; for idx in 0 .. 100 { raw_sprite [ idx ] = image_data . read_bool ( ) ; } let sprite = Sprite :: from_pixels ( raw_sprite ) ; let exa = Exa :: spawn ( & mut vm , start_host . clone ( ) , exa_name , true , exa_script . as_str ( ) , ) . expect ( " " ) ; exa . borrow_mut ( ) . sprite = sprite ; if message_bus_mode == 1 { exa . borrow_mut ( ) . mode = Mode :: Local ; } } Ok ( vm ) }
Load a Redshift image from the specified file and return
an initialized Redshift VM implementing the program.
Load a Redshift image from the specified file and return an initialized Redshift VM implementing the program .
path
String
path
String