Skip to content

Commit

Permalink
Support entry blacklisting. Blacklisted entry will not be exported.
Browse files Browse the repository at this point in the history
This fix #17 by removing the empty familiar entry.
  • Loading branch information
Sheep-y committed Jul 21, 2016
1 parent 08ae3bc commit 70766bb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
2 changes: 2 additions & 0 deletions java/db4e/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ public CompletableFuture<Void> startExport ( File target ) {
log.log( Level.CONFIG, "Export root: {0}", target );
new File( root ).mkdirs();

Convertor.beforeExport( categories );

checkStop( "Writing main catlog" );
exporter.writeCatalog( root, categories );

Expand Down
44 changes: 25 additions & 19 deletions java/db4e/controller/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ void writeCatalog ( String target, List<Category> categories ) throws IOExceptio
StringBuilder buffer = new StringBuilder( 300 );
try ( OutputStreamWriter writer = openStream( target + "/catalog.js" ) ) {
buffer.append( "od.reader.jsonp_catalog(20130616,{" );
for ( Category category : categories )
str( buffer, category.id ).append( ':' ).append( category.total_entry.get() ).append( ',' );
for ( Category category : categories ) {
final int total = category.total_entry.get() - category.blacklisted_entry.get();
str( buffer, category.id ).append( ':' ).append( total ).append( ',' );
}
write( "})", writer, buffer );
}
}
Expand All @@ -52,24 +54,28 @@ void writeCategory ( String target, Category category, ProgressState state ) thr
write( ",{", index, buffer );

for ( Entry entry : category.sorted ) {
str( buffer.append( '[' ), entry.id ).append( ',' );
str( buffer, entry.display_name ).append( ',' );
for ( Object field : entry.meta )
str( buffer, field.toString() ).append( ',' );
write( "],", listing, buffer );

str( buffer, entry.id ).append( ':' );
str( buffer, entry.fulltext );
write( ",", index, buffer );

try ( OutputStreamWriter item = openStream( catPath + "/" + entry.shortid + ".js" ) ) {
buffer.append( "od.reader.jsonp_data(20130330," );
str( buffer, category.id ).append( ',' );
str( buffer, entry.id ).append( ',' );
str( buffer, entry.data ).append( ',' );
write( ")", item, buffer );
if ( ! "null".equals( entry.shortid ) ) {
// Add to listing
str( buffer.append( '[' ), entry.id ).append( ',' );
str( buffer, entry.display_name ).append( ',' );
for ( Object field : entry.meta )
str( buffer, field.toString() ).append( ',' );
write( "],", listing, buffer );

// Add to full text
str( buffer, entry.id ).append( ':' );
str( buffer, entry.fulltext );
write( ",", index, buffer );

// Write actual content
try ( OutputStreamWriter item = openStream( catPath + "/" + entry.shortid + ".js" ) ) {
buffer.append( "od.reader.jsonp_data(20130330," );
str( buffer, category.id ).append( ',' );
str( buffer, entry.id ).append( ',' );
str( buffer, entry.data ).append( ',' );
write( ")", item, buffer );
}
}

state.addOne();
}

Expand Down
17 changes: 14 additions & 3 deletions java/db4e/convertor/Convertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public class Convertor {
protected final Category category;
private final boolean debug;

/**
* Called before doing any export.
* Can be used to fix entry count before catalog is saved.
*
* @param categories
*/
public static void beforeExport ( List<Category> categories ) {
categories.stream().filter( category -> category.id.equals( "Glossary" ) ).findAny().get().blacklisted_entry.set( 1 );
}

protected Convertor ( Category category, boolean debug ) {
this.category = category;
this.debug = debug;
Expand Down Expand Up @@ -98,6 +108,7 @@ protected void convertEntry ( Entry entry ) {
copyMeta( entry );
entry.data = normaliseData( entry.content );
correctEntry( entry );
if ( "null".equals( entry.shortid ) ) return;
parseSourceBook( entry );
entry.fulltext = textData( entry.data );

Expand Down Expand Up @@ -148,9 +159,9 @@ protected void correctEntry ( Entry entry ) {
case "Glossary":
switch ( entry.shortid ) {

case "glossary679": // Familiar - an empty monster keyword from Dungeon 211. Too late in development to remove in v3.5
entry.data = entry.data.replace( "</p><p class=publishedIn>Published in .",
"An enemy familiar appeared in Dungeon Magazine 211, but not even a monster. This entry should be removed.</p><p class=publishedIn>Published in Dungeon Magazine 211." );
case "glossary679":
// Familiar - an empty "monster keyword" from Dungeon 211. That don't even has a stat block.
entry.shortid = "null"; // Just blacklist it and forget it ever existed.
break;

} break;
Expand Down
4 changes: 4 additions & 0 deletions java/db4e/data/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public class Category {
public final String id; // Compendium id
public final String name; // Display name
public final String type; // Manually assigned category group - PC and DM.
// Number of entry on the compendium. Either 0 (no listing) or the final count (listing done).
public final IntegerProperty total_entry = new SimpleIntegerProperty();
// Number of entry with downloaded content. Will increase during the download process.
public final IntegerProperty downloaded_entry = new SimpleIntegerProperty();
// Number of entry that is blacklisteg and won't be exported. Must be set before exporting.
public final IntegerProperty blacklisted_entry = new SimpleIntegerProperty();

public final String[] fields; // Name (id) of compendium fields
public final List<Entry> entries = new ArrayList<>(); // Entry list
Expand Down
3 changes: 1 addition & 2 deletions java/db4e/data/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ public class Entry {

// Transformed data for export
public String display_name; // Converted name for export
public String shortid; // Simplified id for export
public String shortid; // Simplified id for export. Set to "null" (String) to skip export.
public String fulltext; // Full text index text - without name and flavour
public Object[] meta; // Transform field data
public String data; // Processed data text
public Entry parent; // Owning entry, like feat chain

public Entry ( String id, String name ) {
this.id = id;
Expand Down

0 comments on commit 70766bb

Please sign in to comment.