﻿if (!$gbl) {
	require "../xlsdiff/xls.pm";

	$gbl->{xls_info} = {
		"src/communication.gmm" => {
			name => "xls/communication_comment.xls", col => "L"
		}, "src/contest.gmm"       => {
			name => "xls/contest_comment.xls",       col => "L"
		}, "src/fight_msg.gmm"     => {
			name => "xls/fight_comment.xls",         col => "H"
		}, "src/menu_msg1.gmm"     => {
			name => "xls/menu1comment.xls",          col => "F"
		}, "src/menu_msg2.gmm"     => {
			name => "xls/menu2comment.xls",          col => "F"
		}, "src/mystery.gmm"       => {
			name => "xls/mystery_comment.xls",       col => "L"
		}, "src/pokefood.gmm"      => {
			name => "xls/pokefood_comment.xls",      col => "L"
		}, "src/poketch.gmm"       => {
			name => "xls/poketch_comment.xls",       col => "L"
		}, "src/scenario1.gmm"     => {
			name => "xls/scenario1_comment.xls",     col => "E"
		}, "src/scenario2.gmm"     => {
			name => "xls/scenario2_comment.gmm.xls", col => "E"
		}, "src/scenario3.gmm"     => {
			name => "xls/scenario3_comment.xls",     col => "E"
		}, "src/townmap.gmm"       => {
			name => "xls/townmap_comment.xls",       col => "M"
		}, "src/trainer_msg.gmm"   => {
			name => "xls/trainer_comment.xls",       col => "F"
		}, "src/underground.gmm"   => {
			name => "xls/undergroud_comment.xls",    col => "L"
		}, "src/wifi.gmm"          => {
			name => "xls/wifi_comment.xls",          col => "L"
		}
	};
	{
		my ($ltr, $idx) = ( 'A', 0 );

		for my $i (1 .. 100) {
			$gbl->{col_num}{$ltr} = $idx;
			$ltr++;
			$idx++;
		}
	}
	$gbl->{fname} = "";
}

if ($gbl->{fname} ne $i) {
	$gbl->{fname} = $i;
	if ($gbl->{xls_info}{$i}) {
		my %col = (
			msg_id => $gbl->{col_num}{"A"},
			cmmt => $gbl->{col_num}{$gbl->{xls_info}{$i}{col}}
		);
		my ($xls, $data);

		$xls = new xls($gbl->{xls_info}{$i}{name});
		$data = $xls->getData('Z');
		for my $j (@{$data}[1 .. $#{$data}]) {
			if ($j->[$col{cmmt}]) {
				$gbl->{cmt}{$j->[$col{msg_id}]} = $j->[$col{cmmt}];
			}
		}
	}
}

if ($gbl->{cmt}{$data{msg_id}}) {
	$iter->setCommentEnglish($gbl->{cmt}{$data{msg_id}});

	delete $gbl->{cmt}{$data{msg_id}};
	if (scalar(keys %{$gbl->{cmt}}) == 0) {
		print "$i が終了。\n";
	}
}
