1 package App
::Web
::VPKBuilder
;
6 use parent qw
/Plack::Component/;
7 our $VERSION = '0.000_001';
9 use File
::Basename qw
/fileparse/;
10 use File
::Find qw
/find/;
11 use File
::Path qw
/remove_tree/;
12 use File
::Spec
::Functions qw
/catfile rel2abs/;
13 use File
::Temp qw
/tempdir/;
14 use IO
::Compress
::Zip qw
/zip ZIP_CM_LZMA/;
15 use sigtrap qw
/die normal-signals/;
17 use Data
::Diver qw
/DiveRef/;
18 use File
::Slurp qw
/write_file/;
20 use HTML
::TreeBuilder
;
21 use Hash
::Merge qw
/merge/;
22 use List
::MoreUtils qw
/uniq/;
24 use Sort
::ByExample qw
/sbe/;
25 use YAML qw
/LoadFile/;
28 my $self = shift->SUPER::new
(@_);
31 my $cfg = LoadFile
$_;
32 $self->{cfg
} = merge
$self->{cfg
}, $cfg
34 $self->{cfg
}{vpk
} //= 'vpk';
35 $self->{cfg
}{vpk_extension
} //= 'vpk';
36 $self->{cfg
}{sort} = sbe
$self->{cfg
}{sort_order
}, { fallback
=> sub { shift cmp shift } };
42 return unless $pkg =~ /^[a-zA-Z0-9_-]+$/aa;
45 postprocess
=> sub { pop @dirs },
47 my $dest = catfile
@dirs, $_;
51 }}, catfile
'pkg', $pkg;
55 my ($self, @pkgs) = @_;
56 mkdir $self->{cfg
}{dir
};
57 my $dir = rel2abs tempdir
'workXXXX', DIR
=> $self->{cfg
}{dir
};
58 my $dest = catfile
$dir, 'pkg';
60 push @pkgs, split ',', ($self->{cfg
}{pkgs
}{$_}{deps
} // '') for @pkgs;
62 addpkg
$_, $dest for @pkgs;
63 system $self->{cfg
}{vpk
} => $dest;
64 write_file catfile
($dir, 'readme.txt'), $self->{cfg
}{readme
};
65 zip
[catfile
($dir, "pkg.$self->{cfg}{vpk_extension}"), catfile
($dir, 'readme.txt')], catfile
($dir, 'pkg.zip'), FilterName
=> sub { $_ = fileparse
$_ }, -Level
=> 1;
66 open my $fh, '<', catfile
$dir, 'pkg.zip';
68 [200, ['Content-Type' => 'application/zip', 'Content-Disposition' => 'attachment; filename=pkg.zip'], $fh]
72 my ($self, $elem, $tree, $lvl, $key) = @_;
73 my $name = HTML
::Element
->new('span', class => 'name');
74 $name->push_content($key);
75 $elem->push_content($name) if defined $key;
76 if (ref $tree eq 'ARRAY') {
77 my $sel = HTML
::Element
->new('select', name
=> 'pkg');
78 my $opt = HTML
::Element
->new('option', value
=> '');
79 $opt->push_content('None');
80 $sel->push_content($opt);
81 for my $pkg (sort { $a->{name
} cmp $b->{name
} } values $tree) {
82 my $opt = HTML
::Element
->new('option', value
=> $pkg->{pkg
}, $pkg->{default} ?
(selected
=> 'selected') : ());
83 $opt->push_content($pkg->{name
});
84 $sel->push_content($opt);
86 $elem->push_content($sel);
88 my $ul = HTML
::Element
->new('ul');
89 for my $key ($self->{cfg
}{sort}->(keys $tree)) {
90 my $li = HTML
::Element
->new('li', class => "level$lvl");
91 $self->makelist($li, $tree->{$key}, $lvl + 1, $key);
92 $ul->push_content($li);
94 $elem->push_content($ul);
100 my ($pkgs, $tree) = ($self->{cfg
}{pkgs
}, {});
102 my $ref = DiveRef
($tree, split ',', $pkgs->{$_}{path
});
103 $$ref = [] unless ref $$ref eq 'ARRAY';
104 push $$ref, {pkg
=> $_, name
=> $pkgs->{$_}{name
}, default => $pkgs->{$_}{default}};
106 my $html = HTML
::TreeBuilder
->new_from_file('index.html');
107 $self->makelist(scalar $html->look_down(id
=> 'list'), $tree, 1);
108 my $ret = $html->as_HTML('', ' ');
110 [200, ['Content-Type' => 'text/html;charset=utf-8'], [$ret]]
114 my ($self, $env) = @_;
115 my $req = Plack
::Request
->new($env);
116 return $self->makepkg($req->param('pkg')) if $req->path eq '/makepkg';
127 App::Web::VPKBuilder - Mix & match Source engine game mods
132 use App::Web::VPKBuilder;
136 App::Web::VPKBuilder->new->to_app
141 App::Web::VPKBuilder is a simple web service for building Source engine game VPK packages. It presents a list of mods sorted into (sub)categories. The user can choose a mod from each category and will get a VPK containing all of the selected packages.
145 APP::Web::VPKBuilder is configured via YAML files in the F<cfg> directory. The recommended layout is to have an F<options.yml> file with the global options, and one file for each source mod (original mod that may be split into more mods).
147 =head2 Global options
153 A string representing the contents of the readme.txt file included with the package.
157 An array of strings representing the sort order of (sub)categories. (sub)categories appear in this order. (sub)categories that are not listed appear in alphabetical order after those listed.
161 A string representing the directory in which the packages are built. Must be on the same filesystem as the package directory (F<pkg/>). Is created if it does not exist (but its parents must exist).
165 A string representing the program that makes a package out of a folder. Must behave like the vpk program included with Source engine games: that is, when called like C<vpk path/to/folder> it should create a file F<path/to/folder.ext>, where C<ext> is given by the next option. Defaults to 'vpk' (requires a script named vpk in the PATH).
169 The extension of a package. Defaults to C<vpk>
176 readme: "Place the .vpk file in your custom directory (<steam root>/SteamApps/common/Team Fortress 2/tf/custom/)"
177 sort_order: [Scout, Soldier, Pyro, Demoman, Heavy, Engineer, Medic, Sniper, Spy, Sounds, Model]
184 Each source mod is composed of one or more directories (mods) in the F<pkg/> directory and a config file. Each config file should contain a hash named C<pkgs>. For each directory the hash should contain an entry with the directory name as key. Mod directory names may only contain the characters C<a-zA-Z0-9_->.
192 A string representing the (human readable) name of the mod.
196 A comma-delimited string of the form C<category,subcategory,subcategory,...,item>. There can be any number of subcategories, but the default stylesheet is made for two-element paths (C<category,item>).
198 If multiple mods have the same path, the user will be allowed to choose at most one of them.
202 A boolean which, if true, marks this mod as the default mod for its path.
206 A comma-delimited string representing a list of mods that must be included in the final package if this mod is included. The pkgs hash need not contain an entry for the dependencies.
208 For example, if two mods share a large part of their contents, then the shared part could be split into a third mod, and both of the original mods should depend on it. This third mod should not be included in the hash, as it shouldn't need to be manually selected by the user.
218 path: "Scout,Boston Basher"
223 path: "Scout,Sandman"
232 * More/Clearer documentation
233 * Nicer user interface
237 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
239 =head1 COPYRIGHT AND LICENSE
241 Copyright (C) 2014 by Marius Gavrilescu
243 This library is free software; you can redistribute it and/or modify
244 it under the same terms as Perl itself, either Perl version 5.18.2 or,
245 at your option, any later version of Perl 5 you may have available.
This page took 0.039553 seconds and 4 git commands to generate.