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:
parent
96c296e9d5
commit
ab04752169
7 changed files with 149 additions and 7 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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( "," );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -391,6 +391,29 @@ CREATE VIEW tech.buildings_view
|
|||
ON b.name_id = bld.buildable_id;
|
||||
|
||||
|
||||
/*
|
||||
* Buildings / technology view
|
||||
* ----------------------------
|
||||
*
|
||||
* This view generates a parseable list of buildings unlocked by a technology
|
||||
* for each technology.
|
||||
*
|
||||
* Columns:
|
||||
* technology_name_id The technology's name
|
||||
* technology_buildings A list of comma-separated building identifiers
|
||||
*/
|
||||
DROP VIEW IF EXISTS defs.technology_buildings_view CASCADE;
|
||||
CREATE VIEW defs.technology_buildings_view
|
||||
AS SELECT technology_name_id ,
|
||||
array_to_string( array_agg( _name.name ) , ',' ) AS technology_buildings
|
||||
FROM defs.technologies _tech
|
||||
LEFT OUTER JOIN tech.buildings_view _building
|
||||
USING ( technology_name_id )
|
||||
LEFT OUTER JOIN defs.strings _name
|
||||
ON _name.id = _building.name_id
|
||||
GROUP BY technology_name_id;
|
||||
|
||||
|
||||
--
|
||||
-- Ships view
|
||||
--
|
||||
|
|
|
@ -447,6 +447,8 @@ CREATE VIEW emp.research_total_weights_view
|
|||
* the technology is not supposed to be visible
|
||||
* technology_dependencies The technology's dependencies from the
|
||||
* dependencies view
|
||||
* technology_buildings The buildings which are unlocked when the
|
||||
* technology is implemented
|
||||
*/
|
||||
DROP VIEW IF EXISTS emp.technologies_v2_view CASCADE;
|
||||
CREATE VIEW emp.technologies_v2_view
|
||||
|
@ -488,7 +490,13 @@ CREATE VIEW emp.technologies_v2_view
|
|||
ELSE
|
||||
NULL::INT
|
||||
END ) AS technology_price ,
|
||||
technology_dependencies
|
||||
technology_dependencies ,
|
||||
( CASE
|
||||
WHEN emptech_visible THEN
|
||||
technology_buildings
|
||||
ELSE
|
||||
''
|
||||
END ) AS technology_buildings
|
||||
FROM emp.technologies_v2
|
||||
INNER JOIN emp.technology_visibility_view
|
||||
USING ( technology_name_id , empire_id )
|
||||
|
@ -496,6 +504,8 @@ CREATE VIEW emp.technologies_v2_view
|
|||
USING ( technology_name_id )
|
||||
INNER JOIN defs.technology_dependencies_view
|
||||
USING ( technology_name_id )
|
||||
INNER JOIN defs.technology_buildings_view
|
||||
USING ( technology_name_id )
|
||||
INNER JOIN defs.strings _name_str
|
||||
ON _name_str.id = _tech.technology_name_id
|
||||
INNER JOIN defs.strings _cat_str
|
||||
|
|
|
@ -78,7 +78,10 @@ public class ResearchData
|
|||
private List< String > dependencies = new ArrayList< String >( );
|
||||
|
||||
/** List of identifiers of technologies that depend on the current technology. */
|
||||
private List< String > revDependencies = new LinkedList< String >( );
|
||||
private final List< String > revDependencies = new LinkedList< String >( );
|
||||
|
||||
/** List of buildings the current technology unlocks. */
|
||||
private List< String > buildings = new ArrayList< String >( );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -320,6 +323,41 @@ public class ResearchData
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the list of unlocked buildings
|
||||
*
|
||||
* @param buildings
|
||||
* the new list of buildings
|
||||
*/
|
||||
public void setBuildings( String[] buildings )
|
||||
{
|
||||
this.buildings = Arrays.asList( buildings );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the list of unlocked buildings
|
||||
*
|
||||
* @param buildings
|
||||
* the new list of buildings
|
||||
*/
|
||||
public void setBuildings( List< String > buildings )
|
||||
{
|
||||
this.buildings = buildings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of buildings the current technology unlocks.
|
||||
*
|
||||
* @return the list of buildings the current technology unlocks
|
||||
*/
|
||||
public List< String > getBuildings( )
|
||||
{
|
||||
return this.buildings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Research page entry comparison
|
||||
*
|
||||
|
|
|
@ -236,6 +236,15 @@
|
|||
</ul>
|
||||
</div>
|
||||
</#if>
|
||||
<#if tech.buildings?has_content>
|
||||
<div class="tech-info"><strong>Unlocks buildings:</strong>
|
||||
<ul>
|
||||
<#list tech.buildings as building>
|
||||
<li>${building}</li>
|
||||
</#list>
|
||||
</ul>
|
||||
</div>
|
||||
</#if>
|
||||
</div>
|
||||
</#list>
|
||||
</div>
|
||||
|
|
|
@ -236,6 +236,15 @@
|
|||
</ul>
|
||||
</div>
|
||||
</#if>
|
||||
<#if tech.buildings?has_content>
|
||||
<div class="tech-info"><strong>Nouveaux bâtiments:</strong>
|
||||
<ul>
|
||||
<#list tech.buildings as building>
|
||||
<li>${building}</li>
|
||||
</#list>
|
||||
</ul>
|
||||
</div>
|
||||
</#if>
|
||||
</div>
|
||||
</#list>
|
||||
</div>
|
||||
|
|
Reference in a new issue