Adding export to .pk3 file option.
This commit is contained in:
parent
e26e807e8b
commit
7ebbc18eaa
|
@ -32,6 +32,12 @@ sub load_from_file {
|
||||||
return $class->new(_pokemon => Rsaves::read_pk3_file($file));
|
return $class->new(_pokemon => Rsaves::read_pk3_file($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub export_file {
|
||||||
|
my $self = shift;
|
||||||
|
my $file = shift;
|
||||||
|
Rsaves::write_pk3_file($self->_pokemon, $file);
|
||||||
|
}
|
||||||
|
|
||||||
sub empty {
|
sub empty {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
return $class->new(_pokemon => Rsaves::read_pk3_raw("\0" x 0x80));
|
return $class->new(_pokemon => Rsaves::read_pk3_raw("\0" x 0x80));
|
||||||
|
|
|
@ -103,6 +103,7 @@ sub draw {
|
||||||
my $save_button = Gtk4::Button->new_with_label('Save changes');
|
my $save_button = Gtk4::Button->new_with_label('Save changes');
|
||||||
my $delete_button = Gtk4::Button->new_with_label('Delete pokemon');
|
my $delete_button = Gtk4::Button->new_with_label('Delete pokemon');
|
||||||
my $import_button = Gtk4::Button->new_with_label('Import .pk3');
|
my $import_button = Gtk4::Button->new_with_label('Import .pk3');
|
||||||
|
my $export_button = Gtk4::Button->new_with_label('Export .pk3');
|
||||||
$self->_selected_species( $pokemon->species );
|
$self->_selected_species( $pokemon->species );
|
||||||
my $box_right_image = Gtk4::Box->new( 'vertical', 1 );
|
my $box_right_image = Gtk4::Box->new( 'vertical', 1 );
|
||||||
$box_right_image->set_margin_top(30);
|
$box_right_image->set_margin_top(30);
|
||||||
|
@ -133,6 +134,9 @@ sub draw {
|
||||||
$import_button->signal_connect(clicked => sub {
|
$import_button->signal_connect(clicked => sub {
|
||||||
$self->activate_import_pk3;
|
$self->activate_import_pk3;
|
||||||
});
|
});
|
||||||
|
$export_button->signal_connect(clicked => sub {
|
||||||
|
$self->activate_export_pk3;
|
||||||
|
});
|
||||||
$self->draw_dropdown_pokemon_list($box_right_image);
|
$self->draw_dropdown_pokemon_list($box_right_image);
|
||||||
my $box_label_iv = Gtk4::Box->new('horizontal', 10);
|
my $box_label_iv = Gtk4::Box->new('horizontal', 10);
|
||||||
$box_label_iv->append(Gtk4::Label->new('Select IV'));
|
$box_label_iv->append(Gtk4::Label->new('Select IV'));
|
||||||
|
@ -140,11 +144,38 @@ sub draw {
|
||||||
$self->create_select_ivs($box_right_image);
|
$self->create_select_ivs($box_right_image);
|
||||||
$self->create_modify_personality($grid);
|
$self->create_modify_personality($grid);
|
||||||
$grid->attach( $save_button, 4, 7, 1, 1 );
|
$grid->attach( $save_button, 4, 7, 1, 1 );
|
||||||
|
$grid->attach( $export_button, 3, 7, 1, 1 );
|
||||||
$grid->attach( $delete_button, 2, 7, 1, 1 );
|
$grid->attach( $delete_button, 2, 7, 1, 1 );
|
||||||
$grid->attach( $import_button, 1, 7, 1, 1 );
|
$grid->attach( $import_button, 1, 7, 1, 1 );
|
||||||
$window->set_child($grid);
|
$window->set_child($grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub activate_export_pk3 {
|
||||||
|
my $self = shift;
|
||||||
|
my $win = $self->_win;
|
||||||
|
my $dialog = Gtk4::FileDialog->new;
|
||||||
|
my $options = GEmeTool::Options->new;
|
||||||
|
my $last_dir = $options->get_last_dir_open;
|
||||||
|
if ( defined $last_dir && -d $last_dir ) {
|
||||||
|
my $curdir = Glib::IO::File::new_for_path($last_dir);
|
||||||
|
$dialog->set_initial_folder($curdir);
|
||||||
|
$dialog->set_initial_name( Rsaves::translate_3rd_encoding($self->pokemon->nickname) . '-' . $self->pokemon->pokemon_name . '.pk3');
|
||||||
|
}
|
||||||
|
$dialog->save(
|
||||||
|
$win, undef,
|
||||||
|
sub {
|
||||||
|
my ( $self_dialog, $res ) = @_;
|
||||||
|
if ( $res->had_error ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
my $file = $dialog->save_finish($res);
|
||||||
|
return if !defined $file;
|
||||||
|
$file = path( $file->get_path );
|
||||||
|
$self->pokemon->export_file($file);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->pokemon->copy(GEmeTool::Save::Pokemon->empty);
|
$self->pokemon->copy(GEmeTool::Save::Pokemon->empty);
|
||||||
|
|
|
@ -295,6 +295,14 @@ sub get_pk3_raw {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub write_pk3_file {
|
||||||
|
my $pokemon = shift;
|
||||||
|
my $file = shift;
|
||||||
|
my $content = get_pk3_raw($pokemon);
|
||||||
|
open my $fh, '>', $file or return;
|
||||||
|
print $fh $content;
|
||||||
|
}
|
||||||
|
|
||||||
sub _write_pokemon_fh {
|
sub _write_pokemon_fh {
|
||||||
my $fh = shift;
|
my $fh = shift;
|
||||||
my $pokemon = shift;
|
my $pokemon = shift;
|
||||||
|
|
Loading…
Reference in New Issue