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-server-beans-resources/src/main
java/com/deepclone/lw/beans/game/resources
resources/configuration/game

View file

@ -0,0 +1,83 @@
package com.deepclone.lw.beans.game.resources;
import java.sql.Types;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import com.deepclone.lw.interfaces.game.resources.MiningSettingsDAO;
import com.deepclone.lw.utils.StoredProc;
/**
* Data access component for mining settings
*
* <p>
* This component implements the methods which allow mining settings to be updated by calling the
* appropriate stored procedures.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
class MiningSettingsDAOBean
implements MiningSettingsDAO
{
/** <code>emp.mset_update_start(INT)</code> stored procedure */
private StoredProc pStartEmpireUpdate;
/** <code>emp.mset_update_set(TEXT,INT)</code> stored procedure */
private StoredProc pSetMiningPriority;
/** <code>emp.mset_update_apply()</code> stored procedure */
private StoredProc pApplyUpdate;
/**
* Dependency injector that sets the data source
*
* @param dataSource
* the data source
*/
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.pStartEmpireUpdate = new StoredProc( dataSource , "emp" , "mset_update_start" );
this.pStartEmpireUpdate.addParameter( "_empire" , Types.INTEGER );
this.pStartEmpireUpdate.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 );
this.pSetMiningPriority.addOutput( "_success" , Types.BOOLEAN );
this.pApplyUpdate = new StoredProc( dataSource , "emp" , "mset_update_apply" );
this.pApplyUpdate.addOutput( "_success" , Types.BOOLEAN );
}
/* Documented in interface */
@Override
public boolean startUpdate( int empireId )
{
return (Boolean) this.pStartEmpireUpdate.execute( empireId ).get( "_success" );
}
/* Documented in interface */
@Override
public boolean setNewPriority( String resource , int priority )
{
return (Boolean) this.pSetMiningPriority.execute( resource , priority ).get( "_success" );
}
/* Documented in interface */
@Override
public boolean applyUpdate( )
{
return (Boolean) this.pApplyUpdate.execute( ).get( "_success" );
}
}

View file

@ -0,0 +1,68 @@
package com.deepclone.lw.beans.game.resources;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.deepclone.lw.interfaces.game.resources.MiningSettingsDAO;
import com.deepclone.lw.interfaces.game.resources.ResourcesController;
/**
* Resources controller component
*
* <p>
* This component implements all game actions that affect resources or resource-related information,
* such as mining priorities.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@Transactional
class ResourcesControllerBean
implements ResourcesController
{
/** The mining settings access interface */
private MiningSettingsDAO settings;
/**
* Dependency injector that sets the mining settings access interface
*
* @param settings
* the mining settings access interface
*/
@Autowired( required = true )
public void setMiningSettingsDAO( MiningSettingsDAO settings )
{
this.settings = settings;
}
/**
* Update an empire's mining settings
*
* <p>
* Start a mining settings update for the specified empire, then set each resource-specific
* priority, then apply the update. Exit whenever something goes wrong.
*/
@Override
public void updateEmpireSettings( int empireId , Map< String , Integer > settings )
{
if ( !this.settings.startUpdate( empireId ) ) {
return;
}
for ( Map.Entry< String , Integer > entry : settings.entrySet( ) ) {
if ( ! this.settings.setNewPriority( entry.getKey( ) , entry.getValue( ) ) ) {
return;
}
}
this.settings.applyUpdate( );
}
}

View file

@ -3,6 +3,8 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="miningSettingsDAO" class="com.deepclone.lw.beans.game.resources.MiningSettingsDAOBean" />
<bean id="resourcesController" class="com.deepclone.lw.beans.game.resources.ResourcesControllerBean" />
<bean id="resourcesInformationDAO" class="com.deepclone.lw.beans.game.resources.ResourcesInformationDAOBean" />
</beans>