Created
July 20, 2017 19:21
-
-
Save Juerd/b26ab3fbb704aa9812f4fc1b9ba429ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person is Entity does Location { } | |
class Place is Entity does Location { } | |
class Thing is Entity does Lendable { } | |
class Container is Entity does Lendable does Location { } | |
... | |
class Command::info is Command::Unary { | |
sub show-contents(Entity $entity where Location) { | |
my Entity @items = Entity.all-entities.grep(Lendable) | |
.grep({ .location && .location.id.lc eq $entity.id.lc }); | |
put "$entity has { +@items } { | |
@items == 0 ?? 'items.' !! @items == 1 ?? 'item:' !! 'items:' }"; | |
put yellow("* "), $_ for @items; | |
} | |
sub show-location(Entity $entity where Lendable) { | |
my $location = $entity.location; | |
without $location { | |
put "I don't know where $entity is."; | |
return; | |
} | |
put "$entity is currently at $location."; | |
Command::info.execute: $location if $location ~~ Lendable; | |
} | |
method execute(Entity $entity) { | |
show-contents $entity if $entity ~~ Location; | |
show-location $entity if $entity ~~ Lendable; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment