Planet mining settings interface
* Modified owned planet view to include a field which indicates whether mining settings are specific to the planet or come from the empire; modified "simple" game components accordingly * Modified stored procedures to only allow planet-specific mining settings updates when the planet actually uses planet-specific settings, and added a stored procedure which toggles the source of a planet's settings * Added corresponding parts to mining settings DAO and resources controller * Added session commands and server command handlers that toggle the source of the settings and that upload the settings * Split planet page template into multiple files for clarity and added the mining priorities form to the natural resources tab
This commit is contained in:
parent
51b529a09f
commit
e64f847ec3
25 changed files with 1009 additions and 152 deletions
legacyworlds-web-main/src/main/java/com/deepclone/lw/web/main/game
|
@ -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;
|
||||
|
@ -80,8 +84,8 @@ public class PlanetPage
|
|||
|
||||
|
||||
@RequestMapping( value = "/planet-{planetId}-cancel-abandon.action" , method = RequestMethod.POST )
|
||||
public String cancelAbandon( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model ,
|
||||
@PathVariable String planetId )
|
||||
public String cancelAbandon( HttpServletRequest request , @ModelAttribute( "language" ) String language ,
|
||||
Model model , @PathVariable String planetId )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
int pId;
|
||||
|
@ -233,4 +237,108 @@ public class PlanetPage
|
|||
PlayerSession pSession = this.getSession( PlayerSession.class , request );
|
||||
return this.render( model , "game" , language , "planet" , pSession.flushQueue( pId , true ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for commands that modify planet mining settings
|
||||
*
|
||||
* <p>
|
||||
* This method handles all mining settings commands, including both switching between empire-
|
||||
* and planet-specific settings and updating all priorities.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
* @param model
|
||||
* the model
|
||||
* @param planetId
|
||||
* the planet's identifier string from the path
|
||||
* @param toggle
|
||||
* this parameter from the form's <code>toggle-settings</code> value will be set if
|
||||
* the "Switch to empire-wide/planet-specific settings" button was clicked.
|
||||
*
|
||||
* @return a redirect to the overview page if the planet identifier was invalid, or a redirect
|
||||
* to the planet page's natural resources tab otherwise.
|
||||
*
|
||||
* @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 = "/planet-{planetId}-update-mset.action" , method = RequestMethod.POST )
|
||||
public String updateMiningSettings( HttpServletRequest request , Model model , @PathVariable String planetId ,
|
||||
@RequestParam( value = "toggle-settings" , required = false ) String toggle )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
int pId;
|
||||
try {
|
||||
pId = Integer.parseInt( planetId );
|
||||
} catch ( NumberFormatException e ) {
|
||||
return this.redirect( "overview" );
|
||||
}
|
||||
|
||||
PlayerSession session = this.getSession( PlayerSession.class , request );
|
||||
if ( toggle == null ) {
|
||||
Map< String , Integer > settings = this.getMiningSettings( request );
|
||||
if ( settings != null ) {
|
||||
session.updatePlanetMiningSettings( pId , settings );
|
||||
}
|
||||
} else {
|
||||
session.toggleMiningSettingsFor( pId );
|
||||
}
|
||||
|
||||
return this.redirect( "planet-" + Integer.toString( pId ) + "#natres" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract mining priorities from the HTTP request
|
||||
*
|
||||
* <p>
|
||||
* Look for all submitted fields that begin with "pms-" 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( "pms-" ) ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue