Skip to content

Loading…

More change #54

Merged
merged 1 commit into from

2 participants

@lemming552
Collaborator

Interface in server code, so blackhole.pl needed to reflect that.

@fireartist fireartist merged commit f49f25a into tsee:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 28 additions and 34 deletions.
  1. +28 −34 examples/blackhole.pl
View
62 examples/blackhole.pl
@@ -17,18 +17,17 @@
v => 0,
config => "lacuna.yml",
datafile => "data/data_blackhole.js",
- probefile => "data/probe_data_cmb.js",
- starfile => "data/stars.csv",
maxdist => 450,
);
my $ok = GetOptions(\%opts,
'planet=s',
+ 'x=i',
+ 'y=i',
+ 'id=i',
'target=s',
'help|h',
'datafile=s',
- 'probefile=s',
- 'starfile=s',
'make_asteroid',
'make_planet',
'increase_size',
@@ -52,7 +51,7 @@
}
usage() if ($opts{h});
if (!$opts{planet}) {
- print "Need both BHG planet and target body!\n";
+ print "Need BHG planet set with --planet!\n";
usage();
}
my $json = JSON->new->utf8(1);
@@ -70,31 +69,10 @@
print "Changing to type $params->{newtype}\n";
}
}
+ usage() if !$opts{target} && !defined $opts{x} && !defined $opts{y} && !defined $opts{id};
- my $bod;
- my $bodies;
- if (-e $opts{probefile}) {
- my $pf;
- open($pf, "$opts{probefile}") || die "Could not open $opts{probefile}\n";
- my $lines = join("", <$pf>);
- $bodies = $json->decode($lines);
- close($pf);
- }
- else {
- print STDERR "$opts{probefile} not found!\n";
- die;
- }
-
- for my $bod (@$bodies) {
- if ($bod->{name} eq $opts{target}) {
- $target_id = $bod->{id};
- last;
- }
- }
-
- unless ($target_id) {
- die "$opts{target} not found in probe file\n";
- }
+ usage() if defined $opts{x} && !defined $opts{y};
+ usage() if defined $opts{y} && !defined $opts{x};
}
my $ofh;
@@ -129,14 +107,30 @@
die "No BHG on this planet\n"
if !$bhg_id;
+ my $target; my $target_name;
my $bhg = $glc->building( id => $bhg_id, type => 'BlackHoleGenerator' );
+ if ( defined $opts{x} && defined $opts{y} ) {
+ $target = { x => $opts{x}, y => $opts{y} };
+ $target_name = "$opts{x},$opts{y}";
+ }
+ elsif ( defined $opts{target} ) {
+ $target = { body_name => $opts{target} };
+ $target_name = $opts{target};
+ }
+ elsif ( defined $opts{id} ) {
+ $target = { body_id => $opts{id} };
+ $target_name = $opts{id};
+ }
+ else {
+ die "target arguments missing\n";
+ }
if ($bhg) {
if ($opts{view}) {
print "Viewing BHG: $bhg_id\n";
}
else {
- print "Targetting $target_id with $bhg_id\n";
+ print "Targetting $target_name with $bhg_id\n";
}
}
else {
@@ -148,16 +142,16 @@
$bhg_out = $bhg->view();
}
elsif ($opts{make_planet}) {
- $bhg_out = $bhg->generate_singularity($target_id, "Make Planet");
+ $bhg_out = $bhg->generate_singularity($target, "Make Planet");
}
elsif ($opts{make_asteroid}) {
- $bhg_out = $bhg->generate_singularity($target_id, "Make Asteroid");
+ $bhg_out = $bhg->generate_singularity($target, "Make Asteroid");
}
elsif ($opts{increase_size}) {
- $bhg_out = $bhg->generate_singularity($target_id, "Increase Size");
+ $bhg_out = $bhg->generate_singularity($target, "Increase Size");
}
elsif ($opts{change_type}) {
- $bhg_out = $bhg->generate_singularity($target_id, "Change Type", $params);
+ $bhg_out = $bhg->generate_singularity($target, "Change Type", $params);
}
else {
die "Nothing to do!\n";
Something went wrong with that request. Please try again.