Skip to content

Commit

Permalink
add a little countdown helper
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Jul 12, 2019
1 parent 194831f commit e0a3bbd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
29 changes: 29 additions & 0 deletions countdown.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package countdown;

use Mu;
use strictures;
use Time::HiRes 'time';

ro "total";
ro _start_time => default => sub { time };
rw current => default => 0;
rw _last_time_left => default => 0;
lazy minimum_step => sub { 0.05 };

sub update_and_return { shift->update_count_and_return( undef, shift ) }

sub update_count_and_return { shift->update(shift); return shift; }

sub update {
my ( $self, $done_count ) = @_;
$self->current( $self->current + ( $done_count || 1 ) );
my $elapsed = time - $self->_start_time;
my $total_time = $self->total * $elapsed / $self->current;
my $left = $total_time - $elapsed;
return if $self->_last_time_left and abs( $self->_last_time_left - $left ) < $self->minimum_step;
printf "\r% 20s", sprintf "%.2f s", $left;
$self->_last_time_left($left);
return;
}

1;
6 changes: 5 additions & 1 deletion translate_utf8_binary.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use motionlist;
use presetdeck;
use presetship;
use countdown;

=head1 DESCRIPTION
Expand Down Expand Up @@ -273,7 +274,8 @@ sub utf8_asset_files {
my @list = $has_find ? split /\n/, `c:/cygwin/bin/find "$src_dir" -type f` #
: io($src_dir)->All_Files;
@list = grep !/\.(tex|dds(_\d)*|mat|gobj|shader|txt|ttf|amtc|ani|avatar|cbm|flr|fsb|mesh|obj|physmat2D|rtex|script|snd|[0-9]+)$/, @list;
@list = map +( ref $_ ? $_ : io($_) ), @list;
my $ctd = countdown->new( total => scalar @list );
@list = map $ctd->update_and_return( ref $_ ? $_ : io($_) ), @list;
@list = map +{ file => $_, filename => $_->filename, fileparts => [ split /\/|\\/, $_ ], enc => "UTF-8", ext => $_->ext }, @list;
$_->{fileid} = join "/", @{ $_->{fileparts} }[ 4 .. $#{ $_->{fileparts} } ] for @list;
return @list;
Expand Down Expand Up @@ -647,10 +649,12 @@ sub run {
my $font = $mw->fontCreate( "test", -family => $font_name, -size => 18 );
my %what = $font->actual;
die "didn't create right font, but: $what{-family}" if $what{-family} ne $font_name;
my $ctd = countdown->new( total => scalar @tr_keys );
for my $jp (@tr_keys) {
$tr{$jp}{width} = $font->measure($jp);
$tr{$jp}{width_tr} = $font->measure( $tr{$jp}{tr} );
$tr{$jp}{width_ratio} = sprintf "%.2f", $tr{$jp}{width_tr} / $tr{$jp}{width};
$ctd->update;
}
for my $jp ( reverse sort { $tr{$a}{width_ratio} <=> $tr{$b}{width_ratio} } sort keys %tr ) {
next if $tr{$jp}{width_ratio} <= 1;
Expand Down
13 changes: 4 additions & 9 deletions unpack_original_files.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sub run {
io($target)->mkpath;
chdir "../kc_original_unpack/repatch/PCSG00684/Media";
my @files = io("../../../../kc_original/repatch/PCSG00684/Media/")->all_files;
$_->copy("./" . $_->filename) for @files;
$_->copy( "./" . $_->filename ) for @files;
my $unity_ex = io("../../../../unity_tools/UnityEX.exe")->absolute->pathname;
for my $file ( grep !/resources\.resource/, io(".")->all_files ) {
say "unpacking file $file'";
Expand All @@ -30,18 +30,13 @@ sub run {
: io(".")->All_Files;
@list = grep /\.(gobj|4|dds|fsb|snd|[\d]+|script|txt|shader|ani|obj|cbm|mesh)$/, @list;
say "deleting";
my $start = time;
my $total = @list;

my $ctd = countdown->new( total => scalar @list );
$|++;
while (@list) {
my @sublist = splice @list, 0, ( @list >= 100 ) ? 100 : @list;
unlink $_ for @sublist;
last if !@list;
my $elapsed = time - $start;
my $diff = $total - @list;
my $total_time = $total * $elapsed / $diff;
my $left = $total_time - $elapsed;
print "\r$left s ";
$ctd->update( scalar @sublist );
}
return;
}

0 comments on commit e0a3bbd

Please sign in to comment.