#!/usr/bin/perl
# requires imagemagick binary 'convert'
use strict;
use warnings;

my $irpg_db = '/home/superkuh/app_installs/idlerpg/irpg.db';
my $file_path = "/home/superkuh/app_installs/idlerpg/questinfo.txt";
my $basemapfilepath = '/home/superkuh/www/newmap.png'; # input idlerpg map without text
my $worldmapfilepath = '/home/superkuh/www/worldmap.png'; #output with text markers

# copy map anew then write names on top of it
print "copying $basemapfilepath to $worldmapfilepath\n";
`cp $basemapfilepath $worldmapfilepath`;

open(my $file, "<", $irpg_db) or die "Cannot open file: $!";
<$file>; # Skip the first line

while (my $line = <$file>) {
    chomp $line;
    my @fields = split(/\t/, $line);
    
    #print "-------------\n\n";
    #print "$_ ," foreach @fields;
    #print "-------------\n\n";
    
    #my ($online, $x, $y) = @fields[7, 9, 10];
    #my ($online, $x, $y) = @fields[8, 10, 11];
    my ($nick, $online, $x, $y) = @fields[0, 8, 10, 11];
    
    if ($online == 1) {
        print "nick: $nick - online:$online, x:$x, y:$y\n";
        `convert $worldmapfilepath -gravity NorthWest -pointsize 18 -fill red -stroke red -draw "text $x,$y '$nick'" $worldmapfilepath`;
    } else {
        print "nick: $nick - offline:$online, x:$x, y:$y\n";
        `convert $worldmapfilepath -gravity NorthWest -pointsize 10 -fill black -stroke black -draw "text $x,$y '$nick'" $worldmapfilepath`;
    }
}

close($file);
    
