2014-11-13 14:48:04 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-06-08 01:41:35 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-13 14:48:04 +01:00
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.integration;
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
|
2015-03-26 10:15:33 +01:00
|
|
|
import java.util.Collection;
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.LinkedList;
|
2015-08-06 18:31:46 +02:00
|
|
|
|
2015-06-08 01:41:35 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
|
|
|
|
public enum IntegrationRegistry
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-13 14:48:04 +01:00
|
|
|
INSTANCE;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-08-06 16:01:56 +02:00
|
|
|
private static final String PACKAGE_PREFIX = "appeng.integration.modules.";
|
|
|
|
|
2015-03-26 10:15:33 +01:00
|
|
|
private final Collection<IntegrationNode> modules = new LinkedList<IntegrationNode>();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
public void add( IntegrationType type )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-08-06 16:01:56 +02:00
|
|
|
this.modules.add( new IntegrationNode( type.dspName, type.modID, type, PACKAGE_PREFIX + type.name() ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void init()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-13 19:28:53 +02:00
|
|
|
node.call( IntegrationStage.PRE_INIT );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-13 19:28:53 +02:00
|
|
|
node.call( IntegrationStage.INIT );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
public void postInit()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-13 19:28:53 +02:00
|
|
|
node.call( IntegrationStage.POST_INIT );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getStatus()
|
|
|
|
{
|
2015-03-26 10:15:33 +01:00
|
|
|
final StringBuilder builder = new StringBuilder( this.modules.size() * 3 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( builder.length() != 0 )
|
2015-03-26 10:15:33 +01:00
|
|
|
{
|
|
|
|
builder.append( ", " );
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-26 10:15:33 +01:00
|
|
|
final String integrationState = node.shortName + ":" + ( node.state == IntegrationStage.FAILED ? "OFF" : "ON" );
|
|
|
|
builder.append( integrationState );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 10:15:33 +01:00
|
|
|
return builder.toString();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-13 14:48:04 +01:00
|
|
|
public boolean isEnabled( IntegrationType name )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( node.shortName == name )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return node.isActive();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-08 01:41:35 +02:00
|
|
|
@Nonnull
|
2014-11-13 14:48:04 +01:00
|
|
|
public Object getInstance( IntegrationType name )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IntegrationNode node : this.modules )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( node.shortName == name && node.isActive() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return node.instance;
|
|
|
|
}
|
|
|
|
}
|
2015-03-23 10:14:35 +01:00
|
|
|
|
|
|
|
throw new IllegalStateException( "integration with " + name.name() + " is disabled." );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|