diff --git a/251 - CELEBI - B434BCEB935C.pk3 b/251 - CELEBI - B434BCEB935C.pk3 new file mode 100644 index 0000000..11a22b3 Binary files /dev/null and b/251 - CELEBI - B434BCEB935C.pk3 differ diff --git a/lib/GEmeTool/Save/Pokemon.pm b/lib/GEmeTool/Save/Pokemon.pm index aa25c8b..db32040 100644 --- a/lib/GEmeTool/Save/Pokemon.pm +++ b/lib/GEmeTool/Save/Pokemon.pm @@ -9,8 +9,9 @@ use Moo; use Rsaves; use Rsaves::Constants::Emerald::Species; use Rsaves::Constants::Emerald::SpeciesData; +use Path::Tiny; -has _pokemon => ( is => 'rw', ); +has _pokemon => ( is => 'rw', required => 1); sub species { my $self = shift; @@ -23,6 +24,26 @@ sub species { return $substruct_0->{species}; } +sub load_from_file { + my $class = shift; + my $file = shift; + $file = path($file); + die 'No such plain file' if !-f $file; + return $class->new(_pokemon => Rsaves::read_pk3_file($file)); +} + +sub empty { + my $class = shift; + return $class->new(_pokemon => Rsaves::read_pk3_raw("\0" x 0x80)); +} + +sub copy { + my $self = shift; + my $object_to_copy_from = shift; + %{$self->_pokemon} = %{$object_to_copy_from->_pokemon}; + return $self; +} + sub ivs { my $self = shift; my $arg = shift; @@ -111,6 +132,7 @@ sub level { my $self = shift; my $arg = shift; my $pokemon = $self->_pokemon; + return 0 if $self->species == 0; my $growth_func = sub { my $n = shift; if ( $n == 1 ) { diff --git a/lib/GEmeTool/View/PokemonEditorWindow.pm b/lib/GEmeTool/View/PokemonEditorWindow.pm index e4f23ef..7dcf620 100644 --- a/lib/GEmeTool/View/PokemonEditorWindow.pm +++ b/lib/GEmeTool/View/PokemonEditorWindow.pm @@ -15,6 +15,8 @@ use Path::Tiny; use Rsaves; use Rsaves::Constants::Emerald::Species; use Rsaves::Constants::Emerald::Natures; +use GEmeTool::Save::Pokemon; +use GEmeTool::Options; Glib::Object::Introspection->setup( basename => 'Gtk', @@ -99,6 +101,8 @@ sub draw { my @species = (@Rsaves::Constants::Emerald::Species::SPECIES); my $string_list = Gtk4::StringList->new( [@species] ); my $save_button = Gtk4::Button->new_with_label('Save changes'); + my $delete_button = Gtk4::Button->new_with_label('Delete pokemon'); + my $import_button = Gtk4::Button->new_with_label('Import .pk3'); $self->_selected_species( $pokemon->species ); my $box_right_image = Gtk4::Box->new( 'vertical', 1 ); $box_right_image->set_margin_top(30); @@ -123,14 +127,58 @@ sub draw { $self->draw; } ); + $delete_button->signal_connect(clicked => sub { + $self->delete; + }); + $import_button->signal_connect(clicked => sub { + $self->activate_import_pk3; + }); $self->draw_dropdown_pokemon_list($box_right_image); - $box_right_image->append(Gtk4::Label->new('Select IV')); + my $box_label_iv = Gtk4::Box->new('horizontal', 10); + $box_label_iv->append(Gtk4::Label->new('Select IV')); + $box_right_image->append($box_label_iv); $self->create_select_ivs($box_right_image); $self->create_modify_personality($grid); $grid->attach( $save_button, 4, 7, 1, 1 ); + $grid->attach( $delete_button, 2, 7, 1, 1 ); + $grid->attach( $import_button, 1, 7, 1, 1 ); $window->set_child($grid); } +sub delete { + my $self = shift; + $self->pokemon->copy(GEmeTool::Save::Pokemon->empty); + $self->draw; +} + +sub activate_import_pk3 { + my $self = shift; + my $cancellable = Glib::IO::Cancellable->new; + my $dialog = Gtk4::FileDialog->new; + my $win = $self->_win; + 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->open( + $win, + $cancellable, + sub { + my ( $self_dialog, $res ) = @_; + if ( $res->had_error ) { + return; + } + my $file = $dialog->open_finish($res); + return if !defined $file; + $file = path( $file->get_path ); + $options->set_last_dir_open( $file->parent . '' ); + $self->pokemon->copy(GEmeTool::Save::Pokemon->load_from_file($file)); + $self->draw; + } + ); +} sub create_select_level { my $self = shift; my $box = shift; diff --git a/save.sav b/save.sav new file mode 100644 index 0000000..ab04843 Binary files /dev/null and b/save.sav differ