summaryrefslogtreecommitdiff
path: root/lib/VN3/Types.pm
blob: a9dfdcaef69aa7a472f279e21092dcda47f45b31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Listings and formatting functions for various data types in the database.

package VN3::Types;

use strict;
use warnings;
use utf8;
use Tie::IxHash;
use TUWF ':Html5';
use POSIX 'strftime', 'ceil';
use Exporter 'import';

our @EXPORT = qw/
    $UID_RE $VID_RE $RID_RE $SID_RE $CID_RE $PID_RE $IID_RE $DOC_RE
    $VREV_RE $RREV_RE $PREV_RE $SREV_RE $CREV_RE $DREV_RE
    %LANG Lang
    %PLATFORMS Platform
    %MEDIA media_display
    %PRODUCER_TYPES
    ReleaseDate
    @VN_LENGTHS vn_length_time vn_length_display
    %CHAR_ROLES char_roles char_role_display
    vote_display vote_string
    date_display
    %VN_RELATIONS vn_relations vn_relation_reverse vn_relation_display
    %PRODUCER_RELATIONS producer_relation_reverse producer_relation_display
    spoil_display
    release_types
    @MINAGE minage_display minage_display_full
    %RESOLUTIONS resolution_display_full
    @VOICED
    @ANIMATED
    %GENDERS gender_display gender_icon
    %BLOOD_TYPES blood_type_display
    @VNLIST_STATUS @RLIST_STATUS
/;


# Regular expressions for use in path registration
my $num = qr{[1-9][0-9]{0,6}};
our $UID_RE = qr{u(?<id>$num)};
our $VID_RE = qr{v(?<id>$num)};
our $RID_RE = qr{r(?<id>$num)};
our $SID_RE = qr{s(?<id>$num)};
our $CID_RE = qr{c(?<id>$num)};
our $PID_RE = qr{p(?<id>$num)};
our $IID_RE = qr{i(?<id>$num)};
our $DOC_RE = qr{d(?<id>$num)};
our $VREV_RE = qr{$VID_RE(?:\.(?<rev>$num))?};
our $RREV_RE = qr{$RID_RE(?:\.(?<rev>$num))?};
our $PREV_RE = qr{$PID_RE(?:\.(?<rev>$num))?};
our $SREV_RE = qr{$SID_RE(?:\.(?<rev>$num))?};
our $CREV_RE = qr{$CID_RE(?:\.(?<rev>$num))?};
our $DREV_RE = qr{$DOC_RE(?:\.(?<rev>$num))?};


our %LANG;
tie %LANG, 'Tie::IxHash', grep !/^ *$/, split /[\s\r\n]*([^ ]+) +(.+)/, q{
    ar Arabic
    bg Bulgarian
    ca Catalan
    cs Czech
    da Danish
    de German
    el Greek
    en English
    eo Esperanto
    es Spanish
    fi Finnish
    fr French
    he Hebrew
    hr Croatian
    hu Hungarian
    id Indonesian
    it Italian
    ja Japanese
    ko Korean
    nl Dutch
    no Norwegian
    pl Polish
    pt-br Portuguese (Brazil)
    pt-pt Portuguese (Portugal)
    ro Romanian
    ru Russian
    sk Slovak
    sv Swedish
    ta Tagalog
    th Thai
    tr Turkish
    uk Ukrainian
    vi Vietnamese
    zh Chinese
};

sub Lang {
    Span class => 'lang-badge', uc $_[0];
}



# The 'unk' platform is reserved for "unknown" in release filters.
our %PLATFORMS;
tie %PLATFORMS, 'Tie::IxHash', grep !/^ *$/, split /[\s\r\n]*([^ ]+) +(.+)/, q{
    win Windows
    dos DOS
    lin Linux
    mac Mac OS
    ios Apple iProduct
    and Android
    dvd DVD Player
    bdp Blu-ray Player
    fmt FM Towns
    gba Game Boy Advance
    gbc Game Boy Color
    msx MSX
    nds Nintendo DS
    nes Famicom
    p88 PC-88
    p98 PC-98
    pce PC Engine
    pcf PC-FX
    psp PlayStation Portable
    ps1 PlayStation 1
    ps2 PlayStation 2
    ps3 PlayStation 3
    ps4 PlayStation 4
    psv PlayStation Vita
    drc Dreamcast
    sat Sega Saturn
    sfc Super Nintendo
    swi Nintendo Switch
    wii Nintendo Wii
    wiu Nintendo Wii U
    n3d Nintendo 3DS
    x68 X68000
    xb1 Xbox
    xb3 Xbox 360
    xbo Xbox One
    web Website
    oth Other
};

sub Platform {
    # TODO: Icons
    Img class => 'svg-icon', src => tuwf->conf->{url_static}.'/v3/windows.svg', title => $PLATFORMS{$_[0]};
}



# The 'unk' medium is reserved for "unknown" in release filters.
our %MEDIA;
tie %MEDIA, 'Tie::IxHash',
    cd  => { qty => 1, single => 'CD',                    plural => 'CDs',                   },
    dvd => { qty => 1, single => 'DVD',                   plural => 'DVDs',                  },
    gdr => { qty => 1, single => 'GD-ROM',                plural => 'GD-ROMs',               },
    blr => { qty => 1, single => 'Blu-ray disc',          plural => 'Blu-ray discs',         },
    flp => { qty => 1, single => 'Floppy',                plural => 'Floppies',              },
    mrt => { qty => 1, single => 'Cartridge',             plural => 'Cartridges',            },
    mem => { qty => 1, single => 'Memory card',           plural => 'Memory cards',          },
    umd => { qty => 1, single => 'UMD',                   plural => 'UMDs',                  },
    nod => { qty => 1, single => 'Nintendo Optical Disc', plural => 'Nintendo Optical Discs' },
    in  => { qty => 0, single => 'Internet download',     plural => '',                      },
    otc => { qty => 0, single => 'Other',                 plural => '',                      };

sub media_display {
    my($media, $qty) = @_;
    my $med = $MEDIA{$media};
    return $med->{single} if !$med->{qty};
    sprintf '%d %s', $qty, $qty == 1 ? $med->{single} : $med->{plural};
}



our %PRODUCER_TYPES;
tie %PRODUCER_TYPES, 'Tie::IxHash',
    co => 'Company',
    in => 'Individual',
    ng => 'Amateur group';



sub ReleaseDate {
    my $date = sprintf '%08d', shift||0;
    my $future = $date > strftime '%Y%m%d', gmtime;
    my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;

    my $str = $y ==  0 ? 'unknown' : $y == 9999 ? 'TBA' :
              $m == 99 ? sprintf('%04d', $y) :
              $d == 99 ? sprintf('%04d-%02d', $y, $m) :
                         sprintf('%04d-%02d-%02d', $y, $m, $d);

    Txt $str if !$future;
    B class => 'future', $str if $future;
}



our @VN_LENGTHS = (
    # name          time             examples
    [ 'Unknown',    '',              ''                                                  ],
    [ 'Very short', '< 2 hours',     'OMGWTFOTL, Jouka no Monshou, The world to reverse' ],
    [ 'Short',      '2 - 10 hours',  'Narcissu, Saya no Uta, Planetarian'                ],
    [ 'Medium',     '10 - 30 hours', 'Yume Miru Kusuri, Cross†Channel, Crescendo'        ],
    [ 'Long',       '30 - 50 hours', 'Tsukihime, Ever17, Demonbane'                      ],
    [ 'Very long',  '> 50 hours',    'Clannad, Umineko, Fate/Stay Night'                 ],
);

sub vn_length_time {
    my $l = $VN_LENGTHS[$_[0]];
    $l->[1] || $l->[0];
}

sub vn_length_display {
    my $l = $VN_LENGTHS[$_[0]];
    $l->[0].($l->[1] ? " ($l->[1])" : '')
}



our %CHAR_ROLES;
tie %CHAR_ROLES, 'Tie::IxHash',
    main    => [ 'Protagonist',         'Protagonists'       ],
    primary => [ 'Main character',      'Main characters'    ],
    side    => [ 'Side character',      'Side characters'    ],
    appears => [ 'Makes an appearance', 'Make an appearance' ];

sub char_roles { keys %CHAR_ROLES }

sub char_role_display {
    my($role, $num) = @_;
    $CHAR_ROLES{$role}[!$num || $num == 1 ? 0 : 1];
}



sub vote_display {
    !$_[0] ? '-' : $_[0] % 10 == 0 ? $_[0]/10 : sprintf '%.1f', $_[0]/10;
}

sub vote_string {
    ['worst ever',
     'awful',
     'bad',
     'weak',
     'so-so',
     'decent',
     'good',
     'very good',
     'excellent',
     'masterpiece']->[ceil(shift()/10)-2];
}



sub date_display {
    strftime '%Y-%m-%d', gmtime $_[0];
}



our %VN_RELATIONS;
tie %VN_RELATIONS, 'Tie::IxHash',
#   id        reverse  name
    seq  => [ 'preq', 'Sequel'              ],
    preq => [ 'seq',  'Prequel'             ],
    set  => [ 'set',  'Same setting'        ],
    alt  => [ 'alt',  'Alternative version' ],
    char => [ 'char', 'Shares characters'   ],
    side => [ 'par',  'Side story'          ],
    par  => [ 'side', 'Parent story'        ],
    ser  => [ 'ser',  'Same series'         ],
    fan  => [ 'orig', 'Fandisc'             ],
    orig => [ 'fan',  'Original game'       ];

sub vn_relations { keys %VN_RELATIONS }
sub vn_relation_reverse { $VN_RELATIONS{$_[0]}[0] }
sub vn_relation_display { $VN_RELATIONS{$_[0]}[1] }



our %PRODUCER_RELATIONS;
tie %PRODUCER_RELATIONS, 'Tie::IxHash',
#   id      reverse  name
    old => [ 'new', 'Formerly'        ],
    new => [ 'old', 'Succeeded by'    ],
    spa => [ 'ori', 'Spawned'         ],
    ori => [ 'spa', 'Originated from' ],
    sub => [ 'par', 'Subsidiary'      ],
    par => [ 'sub', 'Parent producer' ],
    imp => [ 'ipa', 'Imprint'         ],
    ipa => [ 'imp', 'Parent brand'    ];

sub producer_relation_reverse { $PRODUCER_RELATIONS{$_[0]}[0] }
sub producer_relation_display { $PRODUCER_RELATIONS{$_[0]}[1] }



sub spoil_display {
    ['No spoilers'
    ,'Minor spoilers'
    ,'Spoil me!']->[$_[0]];
}



my @RELEASE_TYPES = qw/complete partial trial/;

sub release_types { @RELEASE_TYPES }



# XXX: Apparently, unknown is stored in the DB as -1 rather than NULL, even
# though the column is marked as nullable; probably needs some fixing for
# consistency.
our @MINAGE = (0, 6..18);
my %MINAGE_EX = (
     0 => 'CERO A',
    12 => 'CERO B',
    15 => 'CERO C',
    17 => 'CERO D',
    18 => 'CERO Z',
);

sub minage_display { !defined $_[0] || $_[0] < 0 ? 'Unknown' : !$_[0] ? 'All ages' : sprintf '%d+', $_[0] }

sub minage_display_full { my $e = $MINAGE_EX{$_[0]||''}; minage_display($_[0]).($e ? " (e.g. $e)" : '') };



our %RESOLUTIONS;
tie %RESOLUTIONS, 'Tie::IxHash',
    # DB             # Display       # Category
    unknown     => [ 'Unknown / console / handheld', '' ],
    nonstandard => [ 'Non-standard', '' ],
    '640x480'   => [ '640x480',      '4:3' ],
    '800x600'   => [ '800x600',      '4:3' ],
    '1024x768'  => [ '1024x768',     '4:3' ],
    '1280x960'  => [ '1280x960',     '4:3' ],
    '1600x1200' => [ '1600x1200',    '4:3' ],
    '640x400'   => [ '640x400',      'widescreen' ],
    '960x600'   => [ '960x600',      'widescreen' ],
    '960x640'   => [ '960x640',      'widescreen' ],
    '1024x576'  => [ '1024x576',     'widescreen' ],
    '1024x600'  => [ '1024x600',     'widescreen' ],
    '1024x640'  => [ '1024x640',     'widescreen' ],
    '1280x720'  => [ '1280x720',     'widescreen' ],
    '1280x800'  => [ '1280x800',     'widescreen' ],
    '1366x768'  => [ '1366x768',     'widescreen' ],
    '1600x900'  => [ '1600x900',     'widescreen' ],
    '1920x1080' => [ '1920x1080',    'widescreen' ];

sub resolution_display_full { my $e = $RESOLUTIONS{$_[0]}; ($e->[1] ? ucfirst "$e->[1]: " : '').$e->[0] }



our @VOICED = ('Unknown', 'Not voiced', 'Only ero scenes voiced', 'Partially voiced', 'Fully voiced');

our @ANIMATED = ('Unknown', 'No animations', 'Simple animations', 'Some fully animated scenes', 'All scenes fully animated');



our %GENDERS;
tie %GENDERS, 'Tie::IxHash',
    unknown => [ 'Unknown', '' ],
    m       => [ 'Male', '♂' ],
    f       => [ 'Female', '♀' ],
    mf      => [ 'Both', '♂♀' ];

sub gender_display { $GENDERS{$_[0]}[0] }
sub gender_icon { $GENDERS{$_[0]}[1] }



our %BLOOD_TYPES;
tie %BLOOD_TYPES, 'Tie::IxHash', qw/unknown Unknown o O a A b B ab AB/;

sub blood_type_display { $BLOOD_TYPES{$_[0]} }


our @VNLIST_STATUS = ('Unknown', 'Playing', 'Finished', 'Stalled', 'Dropped');
our @RLIST_STATUS  = ('Unknown', 'Pending', 'Obtained', 'On loan', 'Deleted');

1;