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;
|
package com.deepclone.lw.beans.game.technologies;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -107,6 +108,8 @@ class ResearchControllerBean
|
||||||
tech.setName( translations.get( tech.getName( ) ) );
|
tech.setName( translations.get( tech.getName( ) ) );
|
||||||
tech.setDescription( translations.get( tech.getDescription( ) ) );
|
tech.setDescription( translations.get( tech.getDescription( ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tech.setBuildings( this.translateList( tech.getBuildings( ) , translations ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add reverse dependency identifiers
|
// Add reverse dependency identifiers
|
||||||
|
@ -144,6 +147,7 @@ class ResearchControllerBean
|
||||||
identifiers.add( tech.getName( ) );
|
identifiers.add( tech.getName( ) );
|
||||||
identifiers.add( tech.getDescription( ) );
|
identifiers.add( tech.getDescription( ) );
|
||||||
}
|
}
|
||||||
|
identifiers.addAll( tech.getBuildings( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
* Update research priorities
|
||||||
*
|
*
|
||||||
|
|
|
@ -58,12 +58,38 @@ class ResearchRowMapper
|
||||||
output.setPriority( rs.getInt( "emptech_priority" ) );
|
output.setPriority( rs.getInt( "emptech_priority" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
String dependencies = rs.getString( "technology_dependencies" );
|
output.setDependencies( this.splitField( rs , "technology_dependencies" ) );
|
||||||
if ( ! "".equals( dependencies ) ) {
|
output.setBuildings( this.splitField( rs , "technology_buildings" ) );
|
||||||
output.setDependencies( dependencies.split( "," ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
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;
|
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
|
-- Ships view
|
||||||
--
|
--
|
||||||
|
|
|
@ -447,6 +447,8 @@ CREATE VIEW emp.research_total_weights_view
|
||||||
* the technology is not supposed to be visible
|
* the technology is not supposed to be visible
|
||||||
* technology_dependencies The technology's dependencies from the
|
* technology_dependencies The technology's dependencies from the
|
||||||
* dependencies view
|
* dependencies view
|
||||||
|
* technology_buildings The buildings which are unlocked when the
|
||||||
|
* technology is implemented
|
||||||
*/
|
*/
|
||||||
DROP VIEW IF EXISTS emp.technologies_v2_view CASCADE;
|
DROP VIEW IF EXISTS emp.technologies_v2_view CASCADE;
|
||||||
CREATE VIEW emp.technologies_v2_view
|
CREATE VIEW emp.technologies_v2_view
|
||||||
|
@ -488,7 +490,13 @@ CREATE VIEW emp.technologies_v2_view
|
||||||
ELSE
|
ELSE
|
||||||
NULL::INT
|
NULL::INT
|
||||||
END ) AS technology_price ,
|
END ) AS technology_price ,
|
||||||
technology_dependencies
|
technology_dependencies ,
|
||||||
|
( CASE
|
||||||
|
WHEN emptech_visible THEN
|
||||||
|
technology_buildings
|
||||||
|
ELSE
|
||||||
|
''
|
||||||
|
END ) AS technology_buildings
|
||||||
FROM emp.technologies_v2
|
FROM emp.technologies_v2
|
||||||
INNER JOIN emp.technology_visibility_view
|
INNER JOIN emp.technology_visibility_view
|
||||||
USING ( technology_name_id , empire_id )
|
USING ( technology_name_id , empire_id )
|
||||||
|
@ -496,6 +504,8 @@ CREATE VIEW emp.technologies_v2_view
|
||||||
USING ( technology_name_id )
|
USING ( technology_name_id )
|
||||||
INNER JOIN defs.technology_dependencies_view
|
INNER JOIN defs.technology_dependencies_view
|
||||||
USING ( technology_name_id )
|
USING ( technology_name_id )
|
||||||
|
INNER JOIN defs.technology_buildings_view
|
||||||
|
USING ( technology_name_id )
|
||||||
INNER JOIN defs.strings _name_str
|
INNER JOIN defs.strings _name_str
|
||||||
ON _name_str.id = _tech.technology_name_id
|
ON _name_str.id = _tech.technology_name_id
|
||||||
INNER JOIN defs.strings _cat_str
|
INNER JOIN defs.strings _cat_str
|
||||||
|
|
|
@ -78,7 +78,10 @@ public class ResearchData
|
||||||
private List< String > dependencies = new ArrayList< String >( );
|
private List< String > dependencies = new ArrayList< String >( );
|
||||||
|
|
||||||
/** List of identifiers of technologies that depend on the current technology. */
|
/** 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
|
* Research page entry comparison
|
||||||
*
|
*
|
||||||
|
|
|
@ -236,6 +236,15 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</#if>
|
</#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>
|
</div>
|
||||||
</#list>
|
</#list>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -236,6 +236,15 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</#if>
|
</#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>
|
</div>
|
||||||
</#list>
|
</#list>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue