Empire mining settings

* Modified mining settings stored procedures to use text identifiers
instead of numeric identifiers

* Added DAO for mining settings and controller for resource operations

* Added UpdateEmpireMiningSettingsCommand and associated command
delegate. The command always returns NullResponse.

* Overview page templates split into multiple files for clarity, added
priority update form to the empire economy view and associated web
server handler
This commit is contained in:
Emmanuel BENOîT 2012-02-05 10:10:43 +01:00
parent 92dd01ffce
commit d38576a5cf
24 changed files with 1024 additions and 160 deletions
legacyworlds-web-main
Content/Raw/WEB-INF/fm
src/main/java/com/deepclone/lw/web/main/game

View file

@ -63,60 +63,8 @@
</@tab>
<@tab id="economy" title="Economy">
<@listview>
<@lv_line headers=true>
<@lv_column width=30>&nbsp;</@lv_column>
<@lv_column width="x">Resource</@lv_column>
<@lv_column width=100 centered=true><@over_time "Income" /></@lv_column>
<@lv_column width=100 centered=true><@over_time "Upkeep" /></@lv_column>
<@lv_column width=100 centered=true>Reserves</@lv_column>
<@lv_column width=100 centered=true>Mining priority</@lv_column>
</@lv_line>
<#list ov.economy as resource>
<#if previousCategory?has_content && !resource.category?has_content
|| resource.category?has_content && !previousCategory?has_content
|| resource.category?has_content && previousCategory?has_content
&& resource.category != previousCategory>
<@lv_line>
<#if resource.category?has_content>
<td colspan="5"><strong>${resource.category?xhtml}</strong></td>
<#else>
<td colspan="5"><hr /></td>
</#if>
</@lv_line>
<#local previousCategory=resource.category>
</#if>
<@lv_line>
<@lv_column>&nbsp;</@lv_column>
<@lv_column>${resource.title?xhtml}
<div class="auto-hide">${resource.description?xhtml}</div>
</@lv_column>
<@lv_column centered=true>${resource.income?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.upkeep?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.stockpiled?string(",##0")}</@lv_column>
<@lv_column centered=true>
<#if resource.miningPriority?has_content>
<#switch resource.miningPriority>
<#case 0>lowest<#break>
<#case 1>low<#break>
<#case 2>normal<#break>
<#case 3>high<#break>
<#case 4>highest<#break>
</#switch>
<#else>
N/A
</#if>
</@lv_column>
</@lv_line>
</#list>
</@listview>
<#include "overview/resources.ftl" />
<@overviewResources />
</@tab>
<@tab id="research" title="Research">

View file

@ -0,0 +1,64 @@
<#macro overviewResources>
<form action="update-mining-settings.action" method="POST"><@listview>
<@lv_line headers=true>
<@lv_column width=30>&nbsp;</@lv_column>
<@lv_column width="x">Resource</@lv_column>
<@lv_column width=100 centered=true><@over_time "Income" /></@lv_column>
<@lv_column width=100 centered=true><@over_time "Upkeep" /></@lv_column>
<@lv_column width=100 centered=true>Reserves</@lv_column>
<@lv_column width=100 centered=true>Mining priority</@lv_column>
</@lv_line>
<#list ov.economy as resource>
<#if previousCategory?has_content && !resource.category?has_content
|| resource.category?has_content && !previousCategory?has_content
|| resource.category?has_content && previousCategory?has_content
&& resource.category != previousCategory>
<@lv_line>
<#if resource.category?has_content>
<td colspan="5"><strong>${resource.category?xhtml}</strong></td>
<#else>
<td colspan="5"><hr /></td>
</#if>
</@lv_line>
<#local previousCategory=resource.category>
</#if>
<@lv_line>
<@lv_column>&nbsp;</@lv_column>
<@lv_column>${resource.title?xhtml}
<div class="auto-hide">${resource.description?xhtml}</div>
</@lv_column>
<@lv_column centered=true>${resource.income?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.upkeep?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.stockpiled?string(",##0")}</@lv_column>
<@lv_column centered=true>
<#if resource.miningPriority?has_content>
<select name="ems-${resource.identifier?xhtml}" class="input">
<option style="padding: 0 5px" value="0" <#if resource.miningPriority = 0>selected="selected"</#if>>lowest</option>
<option style="padding: 0 5px" value="1" <#if resource.miningPriority = 1>selected="selected"</#if>>low</option>
<option style="padding: 0 5px" value="2" <#if resource.miningPriority = 2>selected="selected"</#if>>normal</option>
<option style="padding: 0 5px" value="3" <#if resource.miningPriority = 3>selected="selected"</#if>>high</option>
<option style="padding: 0 5px" value="4" <#if resource.miningPriority = 4>selected="selected"</#if>>highest</option>
</select>
<#else>
N/A
</#if>
</@lv_column>
</@lv_line>
</#list>
<@lv_line headers=true>
<@lv_column width="x" colspan=6>&nbsp;</@lv_column>
</@lv_line>
<@lv_line>
<@lv_column colspan=4>&nbsp;</@lv_column>
<@lv_column right=true colspan=2>
<input type="submit" value="Update mining priorities" class="input" style="margin: 15px 0 0 0" />
</@lv_column>
</@lv_line>
</@listview></form>
</#macro>

View file

@ -63,60 +63,8 @@
</@tab>
<@tab id="economy" title="Économie">
<@listview>
<@lv_line headers=true>
<@lv_column width=30>&nbsp;</@lv_column>
<@lv_column width="x">Ressource</@lv_column>
<@lv_column width=100 centered=true><@over_time "Bénéfice" /></@lv_column>
<@lv_column width=100 centered=true><@over_time title="Charges" feminin=true pluriel=true /></@lv_column>
<@lv_column width=100 centered=true>Réserves</@lv_column>
<@lv_column width=100 centered=true>Priorité d'extraction</@lv_column>
</@lv_line>
<#list ov.economy as resource>
<#if previousCategory?has_content && !resource.category?has_content
|| resource.category?has_content && !previousCategory?has_content
|| resource.category?has_content && previousCategory?has_content
&& resource.category != previousCategory>
<@lv_line>
<#if resource.category?has_content>
<td colspan="5"><strong>${resource.category?xhtml}</strong></td>
<#else>
<td colspan="5"><hr /></td>
</#if>
</@lv_line>
<#local previousCategory=resource.category>
</#if>
<@lv_line>
<@lv_column>&nbsp;</@lv_column>
<@lv_column>${resource.title?xhtml}
<div class="auto-hide">${resource.description?xhtml}</div>
</@lv_column>
<@lv_column centered=true>${resource.income?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.upkeep?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.stockpiled?string(",##0")}</@lv_column>
<@lv_column centered=true>
<#if resource.miningPriority?has_content>
<#switch resource.miningPriority>
<#case 0>très basse<#break>
<#case 1>basse<#break>
<#case 2>normale<#break>
<#case 3>haute<#break>
<#case 4>très haute<#break>
</#switch>
<#else>
N/A
</#if>
</@lv_column>
</@lv_line>
</#list>
</@listview>
<#include "overview/resources.ftl" />
<@overviewResources />
</@tab>
<@tab id="research" title="Recherche">

View file

@ -0,0 +1,64 @@
<#macro overviewResources>
<form action="update-mining-settings.action" method="POST"><@listview>
<@lv_line headers=true>
<@lv_column width=30>&nbsp;</@lv_column>
<@lv_column width="x">Ressource</@lv_column>
<@lv_column width=100 centered=true><@over_time "Bénéfice" /></@lv_column>
<@lv_column width=100 centered=true><@over_time title="Charges" feminin=true pluriel=true /></@lv_column>
<@lv_column width=100 centered=true>Réserves</@lv_column>
<@lv_column width=100 centered=true>Priorité d'extraction</@lv_column>
</@lv_line>
<#list ov.economy as resource>
<#if previousCategory?has_content && !resource.category?has_content
|| resource.category?has_content && !previousCategory?has_content
|| resource.category?has_content && previousCategory?has_content
&& resource.category != previousCategory>
<@lv_line>
<#if resource.category?has_content>
<td colspan="5"><strong>${resource.category?xhtml}</strong></td>
<#else>
<td colspan="5"><hr /></td>
</#if>
</@lv_line>
<#local previousCategory=resource.category>
</#if>
<@lv_line>
<@lv_column>&nbsp;</@lv_column>
<@lv_column>${resource.title?xhtml}
<div class="auto-hide">${resource.description?xhtml}</div>
</@lv_column>
<@lv_column centered=true>${resource.income?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.upkeep?string(",##0")}</@lv_column>
<@lv_column centered=true>${resource.stockpiled?string(",##0")}</@lv_column>
<@lv_column centered=true>
<#if resource.miningPriority?has_content>
<select name="ems-${resource.identifier?xhtml}" class="input">
<option style="padding: 0 5px" value="0" <#if resource.miningPriority = 0>selected="selected"</#if>>très basse</option>
<option style="padding: 0 5px" value="1" <#if resource.miningPriority = 1>selected="selected"</#if>>basse</option>
<option style="padding: 0 5px" value="2" <#if resource.miningPriority = 2>selected="selected"</#if>>normale</option>
<option style="padding: 0 5px" value="3" <#if resource.miningPriority = 3>selected="selected"</#if>>haute</option>
<option style="padding: 0 5px" value="4" <#if resource.miningPriority = 4>selected="selected"</#if>>très haute</option>
</select>
<#else>
N/A
</#if>
</@lv_column>
</@lv_line>
</#list>
<@lv_line headers=true>
<@lv_column width="x" colspan=6>&nbsp;</@lv_column>
</@lv_line>
<@lv_line>
<@lv_column colspan=4>&nbsp;</@lv_column>
<@lv_column right=true colspan=2>
<input type="submit" value="Modifier les priorités" class="input" style="margin: 15px 0 0 0" />
</@lv_column>
</@lv_line>
</@listview></form>
</#macro>

View file

@ -10,15 +10,15 @@
</#macro>
<#macro lv_column width=0 centered=false right=false colspan=0>
<#if width?is_string>
<th style="text-align: <#if centered>center<#elseif right>right<#else>left</#if>"<#if colspan gt 1>colspan="${colspan}"</#if>>
<th style="text-align: <#if centered>center<#elseif right>right<#else>left</#if>"<#if colspan gt 1> colspan="${colspan}"</#if>>
<#nested>
</th>
<#elseif width gt 0>
<th style="width: ${width}px; text-align: <#if centered>center<#elseif right>right<#else>left</#if>"<#if colspan gt 1>colspan="${colspan}"</#if>>
<th style="width: ${width}px; text-align: <#if centered>center<#elseif right>right<#else>left</#if>"<#if colspan gt 1> colspan="${colspan}"</#if>>
<#nested>
</th>
<#else>
<td style="text-align: <#if centered>center<#elseif right>right<#else>left</#if>" <#if colspan gt 1>colspan="${colspan}"</#if>>
<td style="text-align: <#if centered>center<#elseif right>right<#else>left</#if>"<#if colspan gt 1> colspan="${colspan}"</#if>>
<#nested>
</td>
</#if>

View file

@ -1,6 +1,10 @@
package com.deepclone.lw.web.main.game;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
@ -20,6 +24,15 @@ import com.deepclone.lw.web.csess.PlayerSession;
/**
* Overview page controller
*
* <p>
* This page controller implements the "Overview" page, as well as the commands it supports
* (implement technology, update empire mining settings).
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@Controller
@SessionRequirement( value = true , redirectTo = "player-session" , subType = "game" )
@SessionAttributes( "language" )
@ -27,6 +40,29 @@ public class OverviewPage
extends PageControllerBase
{
/**
* Main overview display
*
* <p>
* This method is mapped to the overview page's URL. It will fetch the empire overview from the
* server and display the appropriate page.
*
* @param request
* the HTTP request
* @param language
* the language from the session
* @param model
* the model
*
* @return the overview page rendering order
*
* @throws SessionException
* if some error occurs on the server
* @throws SessionServerException
* if the server is unreachable
* @throws SessionMaintenanceException
* if the game is under maintenance
*/
@RequestMapping( "/overview" )
public String overview( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
@ -36,6 +72,30 @@ public class OverviewPage
}
/**
* "Implement technology" command
*
* <p>
* This method is mapped to the technology implementation command URL.
*
* @param request
* the HTTP request
* @param language
* the language from the session
* @param model
* the model
* @param tech
* the technology identifier
*
* @return the overview page rendering order
*
* @throws SessionException
* if some error occurs on the server
* @throws SessionServerException
* if the server is unreachable
* @throws SessionMaintenanceException
* if the game is under maintenance
*/
@RequestMapping( value = "/implement-{tech}.action" , method = RequestMethod.POST )
public String implement( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model ,
@PathVariable String tech )
@ -52,4 +112,67 @@ public class OverviewPage
return this.render( model , "game" , language , "overview" , pSession.implementTechnology( techId ) );
}
@RequestMapping( value = "/update-mining-settings.action" , method = RequestMethod.POST )
public String updateMiningSettings( HttpServletRequest request , @ModelAttribute( "language" ) String language ,
Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
Map< String , Integer > miningSettings = this.getMiningSettings( request );
if ( miningSettings != null ) {
this.getSession( PlayerSession.class , request ).updateEmpireMiningSettings( miningSettings );
}
return this.redirect( "overview#economy" );
}
/**
* Extract mining priorities from the HTTP request
*
* <p>
* Look for all submitted fields that begin with "ems-" then try to extract their values into a
* map that associates resource identifiers to priorities.
*
* @param request
* the HTTP request
*
* @return the map containing the submitted mining settings, or <code>null</code> if one of the
* values was incorrect.
*/
private Map< String , Integer > getMiningSettings( HttpServletRequest request )
{
Map< String , Object > input = this.getInput( request );
Map< String , Integer > miningSettings = new HashMap< String , Integer >( );
for ( Entry< String , Object > entry : input.entrySet( ) ) {
// Ignore items which are not mining settings
String name = entry.getKey( );
if ( !name.startsWith( "ems-" ) ) {
continue;
}
name = name.substring( 4 );
// Get values
if ( ! ( entry.getValue( ) instanceof String[] ) ) {
continue;
}
String[] values = (String[]) entry.getValue( );
if ( values.length < 1 ) {
continue;
}
// Pre-validate them
int value;
try {
value = Integer.parseInt( values[ 0 ] );
} catch ( NumberFormatException e ) {
value = -1;
}
if ( value < 0 || value > 4 ) {
return null;
}
miningSettings.put( name , value );
}
return miningSettings;
}
}