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/src/main/java/com/deepclone/lw/web/main/game

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;
}
}