Research page - Unlocked buildings

* The research page now includes a list of buildings unlocked by each
technology when that technology is not in the "unknown" state.
This commit is contained in:
Emmanuel BENOîT 2012-04-09 13:08:08 +02:00
parent 96c296e9d5
commit ab04752169
7 changed files with 149 additions and 7 deletions
legacyworlds-server-beans-technologies/src/main/java/com/deepclone/lw/beans/game/technologies

View file

@ -1,6 +1,7 @@
package com.deepclone.lw.beans.game.technologies;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -107,6 +108,8 @@ class ResearchControllerBean
tech.setName( translations.get( tech.getName( ) ) );
tech.setDescription( translations.get( tech.getDescription( ) ) );
}
tech.setBuildings( this.translateList( tech.getBuildings( ) , translations ) );
}
// Add reverse dependency identifiers
@ -144,6 +147,7 @@ class ResearchControllerBean
identifiers.add( tech.getName( ) );
identifiers.add( tech.getDescription( ) );
}
identifiers.addAll( tech.getBuildings( ) );
}
try {
@ -154,6 +158,29 @@ class ResearchControllerBean
}
/**
* Translate a list of strings
*
* <p>
* This method fetches translations for a list of string identifiers.
*
* @param input
* the list of strings to translate
* @param translations
* the map of translations returned by {@link #getTranslationsFor(List, String)}
*
* @return the translated list of strings
*/
private List< String > translateList( List< String > input , Map< String , String > translations )
{
ArrayList< String > result = new ArrayList< String >( input.size( ) );
for ( String str : input ) {
result.add( translations.get( str ) );
}
return result;
}
/**
* Update research priorities
*

View file

@ -57,13 +57,39 @@ class ResearchRowMapper
output.setCompletion( ratio );
output.setPriority( rs.getInt( "emptech_priority" ) );
}
String dependencies = rs.getString( "technology_dependencies" );
if ( ! "".equals( dependencies ) ) {
output.setDependencies( dependencies.split( "," ) );
}
output.setDependencies( this.splitField( rs , "technology_dependencies" ) );
output.setBuildings( this.splitField( rs , "technology_buildings" ) );
return output;
}
/**
* Extract a comma-separated field
*
* <p>
* This method accesses then extracts the contents of a comma-separated field (for example
* dependencies or unlocked buildings).
*
* @param rs
* the SQL result set
* @param field
* the field's name
*
* @return an array of strings containing the field's values
*
* @throws SQLException
* if something goes wrong while accessing the field
*/
private String[] splitField( ResultSet rs , String field )
throws SQLException
{
String fValue = rs.getString( field );
if ( fValue == null || "".equals( fValue ) ) {
return new String[ 0 ];
}
return fValue.split( "," );
}
}