Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Mar 19, 2015
0 parents commit 92d0e1c
Show file tree
Hide file tree
Showing 6 changed files with 3,834 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
@@ -0,0 +1,2 @@
spells.json: parse-spells.pl spelllist.txt spelldescs.txt
perl6 parse-spells.pl | json_pp -json_opt pretty,utf8,canonical > spells.json
15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
This is a hopefully complete and mostly correct database of D&D 5e spells in a computer
readable format.

It may be a bit off in some places, as it was created by copypasting the list from the
Basic Rules PDF, cleaning it up a bit manually and lazily parsing it line-by-line.
The result is in spells.json, if you wish to generate it yourself you'll need a Perl 6
compiler with JSON::Tiny installed.

Please report any issues and discrepancies with the original list (I know that tables either
aren't there at all or are completely wrong), and I'll try to fix them.

I'm not sure if Basic Rules license allows that (not too good at lawyerspeak), but if you
Wizards are reading this, I'll happily comply to any DMCA takedown or whatever.

Enjoy!
48 changes: 48 additions & 0 deletions parse-spells.pl
@@ -0,0 +1,48 @@
use v6;
use JSON::Tiny;

my @list = 'spelllist.txt'.IO.lines;

my @buf;
my %spells;

my @descs = 'spelldescs.txt'.IO.lines;

sub parse-type($line) {
my @words = $line.words;
if @words[0] ~~ /^(\d)/ {
return [+~$0, @words[1].tc]
} else {
return [0, @words[0].tc]
}
}

sub parse(@buf) {
my %props;
my $type = parse-type(@buf.shift);
%props<level> = $type[0];
%props<school> = $type[1];
%props<casting_time> = @buf.shift.subst(/^'Casting Time: '/, '');
%props<range> = @buf.shift.subst(/^'Range: '/, '');
%props<components> = @buf.shift.subst(/^'Components: '/, '');
%props<duration> = @buf.shift.subst(/^'Duration: '/, '');
%props<description> = @buf.join(" ");
return %props;
}

my $current = @list.shift;
for @descs -> $descline {
if $descline eq (@list[0] // '') {
if not %spells {
@buf.shift; # fix for Acid Splash
}
%spells{$current} = parse(@buf);
$current = @list.shift;
@buf = ();
} else {
@buf.push: $descline
}
}
%spells{$current} = parse(@buf);

say to-json(%spells);

0 comments on commit 92d0e1c

Please sign in to comment.