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:
Emmanuel BENOîT 2012-02-07 17:03:55 +01:00
parent 51b529a09f
commit e64f847ec3
25 changed files with 1009 additions and 152 deletions
legacyworlds-server-beans-resources/src/main/java/com/deepclone/lw/beans/game/resources

View file

@ -27,12 +27,18 @@ class MiningSettingsDAOBean
/** <code>emp.mset_update_start(INT)</code> stored procedure */
private StoredProc pStartEmpireUpdate;
/** <code>emp.mset_update_start(INT,INT)</code> stored procedure */
private StoredProc pStartPlanetUpdate;
/** <code>emp.mset_update_set(TEXT,INT)</code> stored procedure */
private StoredProc pSetMiningPriority;
/** <code>emp.mset_update_apply()</code> stored procedure */
private StoredProc pApplyUpdate;
/** <code>emp.mset_toggle_source(INT,INT)</code> stored procedure */
private StoredProc pToggleSource;
/**
* Dependency injector that sets the data source
@ -47,6 +53,11 @@ class MiningSettingsDAOBean
this.pStartEmpireUpdate.addParameter( "_empire" , Types.INTEGER );
this.pStartEmpireUpdate.addOutput( "_success" , Types.BOOLEAN );
this.pStartPlanetUpdate = new StoredProc( dataSource , "emp" , "mset_update_start" );
this.pStartPlanetUpdate.addParameter( "_empire" , Types.INTEGER );
this.pStartPlanetUpdate.addParameter( "_planet" , Types.INTEGER );
this.pStartPlanetUpdate.addOutput( "_success" , Types.BOOLEAN );
this.pSetMiningPriority = new StoredProc( dataSource , "emp" , "mset_update_set" );
this.pSetMiningPriority.addParameter( "_resource" , Types.VARCHAR );
this.pSetMiningPriority.addParameter( "_priority" , Types.INTEGER );
@ -54,6 +65,10 @@ class MiningSettingsDAOBean
this.pApplyUpdate = new StoredProc( dataSource , "emp" , "mset_update_apply" );
this.pApplyUpdate.addOutput( "_success" , Types.BOOLEAN );
this.pToggleSource = new StoredProc( dataSource , "emp" , "mset_toggle_source" );
this.pToggleSource.addParameter( "_empire" , Types.INTEGER );
this.pToggleSource.addParameter( "_planet" , Types.INTEGER );
}
@ -65,6 +80,14 @@ class MiningSettingsDAOBean
}
/* Documented in interface */
@Override
public boolean startUpdate( int empire , int planet )
{
return (Boolean) this.pStartPlanetUpdate.execute( empire , planet ).get( "_success" );
}
/* Documented in interface */
@Override
public boolean setNewPriority( String resource , int priority )
@ -80,4 +103,12 @@ class MiningSettingsDAOBean
return (Boolean) this.pApplyUpdate.execute( ).get( "_success" );
}
/* Documented in interface */
@Override
public void togglePlanet( int empire , int planet )
{
this.pToggleSource.execute( empire , planet );
}
}

View file

@ -52,12 +52,51 @@ class ResourcesControllerBean
@Override
public void updateEmpireSettings( int empireId , Map< String , Integer > settings )
{
if ( !this.settings.startUpdate( empireId ) ) {
return;
if ( this.settings.startUpdate( empireId ) ) {
this.sendMiningSettings( settings );
}
}
/* Documented in interface */
@Override
public void togglePlanet( int empire , int planet )
{
this.settings.togglePlanet( empire , planet );
}
/**
* Update a planet's mining settings
*
* <p>
* Start a mining settings update for the specified planet / empire combination, then set each
* resource-specific priority, then apply the update. Exit whenever something goes wrong.
*/
@Override
public void updatePlanetSettings( int empire , int planet , Map< String , Integer > settings )
{
if ( this.settings.startUpdate( empire , planet ) ) {
this.sendMiningSettings( settings );
}
}
/**
* Send mining settings to the database
*
* <p>
* This method is called once a mining settings update has been started (whether it's a
* planet-specific or empire-wide update). It sends all settings to the database server, and
* aborts if anything goes wrong.
*
* @param settings
* the settings to upload
*/
private void sendMiningSettings( Map< String , Integer > settings )
{
for ( Map.Entry< String , Integer > entry : settings.entrySet( ) ) {
if ( ! this.settings.setNewPriority( entry.getKey( ) , entry.getValue( ) ) ) {
if ( !this.settings.setNewPriority( entry.getKey( ) , entry.getValue( ) ) ) {
return;
}
}