Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use utf8;
- use strict;
- use warnings;
- use JSON;
- open IN, "<:utf8", "portals.txt" or die "Are you sure that portals.txt exists? Internal error: ".$!;
- open OUT, ">:utf8", "portalsJSON.txt" or die $!;
- my @portals;
- while (<IN>) {
- next if $_ =~ /^#/;
- $_ =~ s/\cM|\cJ//g;
- $_ =~ s/\s+/ /g;
- $_ =~ s/^\s+|\s+$//g;
- $_ =~ s/(.*)[\s\t]+#.*$/$1/;
- if ($_ =~ /^([\w|@|-]+)\s(\d{1,3})\s(\d{1,3})\s([\w|@|-]+)\s(\d{1,3})\s(\d{1,3})\s?(.*)/) {
- my %portal;
- my ($source_map, $source_x, $source_y, $dest_map, $dest_x, $dest_y, $misc) = ($1, $2, $3, $4, $5, $6, $7);
- $portal{'source'}{'map'} = $source_map;
- $portal{'source'}{'x'} = $source_x;
- $portal{'source'}{'y'} = $source_y;
- $portal{'destination'}{'map'} = $dest_map;
- $portal{'destination'}{'x'} = $dest_x;
- $portal{'destination'}{'y'} = $dest_y;
- if ($misc) {
- if ($misc =~ /^(\d+)\s(\d)\s(.*)$/) { # [cost] [allow_ticket] [talk sequence]
- $portal{'cost'} = $1;
- $portal{'allow_ticket'} = $2;
- $portal{'steps'} = $3;
- } elsif ($misc =~ /^(\d+)\s(.*)$/) { # [cost] [talk sequence]
- $portal{'cost'} = $1;
- $portal{'steps'} = $2;
- } else { # [talk sequence]
- $portal{'steps'} = $misc;
- }
- }
- push @portals, \%portal;
- }
- }
- print OUT to_json(\@portals, {utf8 => 1, pretty => 1, canonical => 1});
- close(IN);
- close(OUT);
- print "Finished !\n";
- system("pause");
Advertisement
Add Comment
Please, Sign In to add comment