Permalink
Browse files

API change to hide more unobservable details from players.

[ADDED]     Observable - all things that can be observed by a unit or player; currently Tile and GameObject.
[UPDATED]   canObserve harmonized to deal with any observable.
[UPDATED]   getOwner -> checkOwner - hide the owner of unobservable tiles/game objects.
[UPDATED]   More centralized observation test logic.
[FIXED]     Some warnings.
  • Loading branch information...
lhunath committed Feb 27, 2014
1 parent d79c73f commit c971a841beb15f73b1aef5a6b047d39f2cbb254a
Showing with 411 additions and 397 deletions.
  1. +9 −2 .idea/inspectionProfiles/Lhunath.xml
  2. +0 −3 omicron-api/src/main/java/com/lyndir/omicron/api/model/Color.java
  3. +1 −2 omicron-api/src/main/java/com/lyndir/omicron/api/model/GameObserver.java
  4. +0 −1 omicron-api/src/main/java/com/lyndir/omicron/api/model/IPlayer.java
  5. +3 −6 omicron-api/src/main/java/com/lyndir/omicron/api/model/IPlayerController.java
  6. +1 −1 omicron-api/src/main/java/com/lyndir/omicron/api/model/ITile.java
  7. +0 −25 omicron-api/src/main/java/com/lyndir/omicron/api/model/ImmutableResourceCost.java
  8. +0 −25 omicron-api/src/main/java/com/lyndir/omicron/api/model/MutableResourceCost.java
  9. +5 −11 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicBaseModule.java
  10. +5 −3 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicConstructorModule.java
  11. +0 −3 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicGame.java
  12. +13 −13 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicGameObject.java
  13. +5 −14 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicGameObjectController.java
  14. +3 −2 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicModule.java
  15. +6 −12 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicPlayer.java
  16. +7 −14 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicPlayerController.java
  17. +13 −0 omicron-api/src/main/java/com/lyndir/omicron/api/model/PublicTile.java
  18. +0 −1 omicron-api/src/main/java/com/lyndir/omicron/api/model/Security.java
  19. +12 −0 omicron-api/src/main/java/com/lyndir/omicron/api/util/Maybe.java
  20. +3 −1 omicron-cli/src/main/java/com/lyndir/lanterna/view/TextView.java
  21. +1 −0 omicron-cli/src/main/java/com/lyndir/lanterna/view/View.java
  22. +0 −1 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/FireCommand.java
  23. +2 −0 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/ListCommand.java
  24. +1 −1 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/PrintCommand.java
  25. +1 −2 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/SetGameCommand.java
  26. +0 −3 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/ViewCommand.java
  27. +3 −1 omicron-cli/src/main/java/com/lyndir/omicron/cli/view/CommandView.java
  28. +3 −3 omicron-cli/src/main/java/com/lyndir/omicron/cli/view/MapView.java
  29. +0 −1 omicron-cli/src/main/java/com/lyndir/omicron/cli/view/OmicronView.java
  30. +37 −30 omicron-core/src/main/java/com/lyndir/omicron/api/model/BaseModule.java
  31. +2 −2 omicron-core/src/main/java/com/lyndir/omicron/api/model/ContainerModule.java
  32. +18 −3 omicron-core/src/main/java/com/lyndir/omicron/api/model/CoreUtils.java
  33. +12 −5 omicron-core/src/main/java/com/lyndir/omicron/api/model/ExtractorModule.java
  34. +3 −3 omicron-core/src/main/java/com/lyndir/omicron/api/model/Game.java
  35. +3 −3 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameController.java
  36. +24 −19 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameObject.java
  37. +30 −34 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameObjectController.java
  38. +70 −48 omicron-core/src/main/java/com/lyndir/omicron/api/model/MobilityModule.java
  39. +3 −4 omicron-core/src/main/java/com/lyndir/omicron/api/model/Module.java
  40. +2 −2 omicron-core/src/main/java/com/lyndir/omicron/api/model/Player.java
  41. +29 −28 omicron-core/src/main/java/com/lyndir/omicron/api/model/PlayerController.java
  42. +20 −1 omicron-core/src/main/java/com/lyndir/omicron/api/model/Tile.java
  43. +2 −2 omicron-core/src/main/java/com/lyndir/omicron/api/model/WeaponModule.java
  44. +2 −2 omicron-core/src/test/java/com/lyndir/omicron/api/model/AbstractTest.java
  45. +25 −25 omicron-core/src/test/java/com/lyndir/omicron/api/model/ConstructorModuleTest.java
  46. +7 −7 omicron-core/src/test/java/com/lyndir/omicron/api/model/ExtractorModuleTest.java
  47. +15 −15 omicron-core/src/test/java/com/lyndir/omicron/api/model/MobilityModuleTest.java
  48. +0 −3 omicron-web/src/main/java/com/lyndir/omicron/webapp/data/service/ServiceModule.java
  49. +4 −3 omicron-web/src/main/java/com/lyndir/omicron/webapp/data/service/StateManager.java
  50. +0 −3 omicron-web/src/main/java/com/lyndir/omicron/webapp/listener/GuiceContext.java
  51. +6 −4 omicron-web/src/main/java/com/lyndir/omicron/webapp/resource/GameResource.java
@@ -60,6 +60,14 @@
</option>
</inspection_tool>
<inspection_tool class="BadExceptionDeclared" enabled="true" level="WARNING" enabled_by_default="true">
+ <scope name="Tests" level="WARNING" enabled="false">
+ <option name="exceptionsString" value="java.lang.Throwable,java.lang.Exception,java.lang.Error,java.lang.RuntimeException,java.lang.ClassCastException,java.lang.ArrayIndexOutOfBoundsException" />
+ <option name="exceptions">
+ <value />
+ </option>
+ <option name="ignoreTestCases" value="true" />
+ <option name="ignoreLibraryOverrides" value="false" />
+ </scope>
<option name="exceptionsString" value="java.lang.Throwable,java.lang.Exception,java.lang.Error,java.lang.RuntimeException,java.lang.ClassCastException,java.lang.ArrayIndexOutOfBoundsException" />
<option name="exceptions">
<value />
@@ -477,7 +485,6 @@
</inspection_tool>
<inspection_tool class="NegatedConditionalExpression" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NegatedEqualityExpression" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="NestedSwitchStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NestedSynchronizedStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewExceptionWithoutArguments" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreWithoutParameters" value="true" />
@@ -541,7 +548,7 @@
<inspection_tool class="OverriddenMethodCallDuringObjectConstruction" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PackageDotHtmlMayBePackageInfo" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PackageInfoWithoutPackage" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="ParameterHidingMemberVariable" enabled="true" level="WARNING" enabled_by_default="true">
+ <inspection_tool class="ParameterHidingMemberVariable" enabled="true" level="BUGGY WARNING" enabled_by_default="true">
<option name="m_ignoreInvisibleFields" value="true" />
<option name="m_ignoreStaticMethodParametersHidingInstanceFields" value="true" />
<option name="m_ignoreForConstructors" value="true" />
@@ -3,10 +3,7 @@
import com.google.common.base.Splitter;
import com.lyndir.lhunath.opal.system.util.MetaObject;
import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.util.*;
-import java.util.regex.Pattern;
import javax.annotation.Nullable;
@@ -1,6 +1,5 @@
package com.lyndir.omicron.api.model;
-import com.google.common.base.Optional;
import com.lyndir.omicron.api.Authenticated;
import com.lyndir.omicron.api.model.*;
import com.lyndir.omicron.api.util.Maybool;
@@ -32,6 +31,6 @@ Maybool canObserve(@Nonnull GameObservable observable)
*/
@Nonnull
@Authenticated
- Iterable<? extends ITile> listObservableTiles()
+ Iterable<? extends ITile> iterateObservableTiles()
throws Security.NotAuthenticatedException, Security.NotObservableException;
}
@@ -1,6 +1,5 @@
package com.lyndir.omicron.api.model;
-import com.lyndir.omicron.api.util.Maybool;
import javax.annotation.Nonnull;
@@ -2,7 +2,6 @@
import static com.lyndir.omicron.api.model.Security.*;
-import com.google.common.collect.*;
import com.lyndir.omicron.api.util.Maybe;
@@ -13,13 +12,11 @@
IGameController getGameController();
/**
- * List the objects of this player.
+ * List the objects of this player observable by the current player.
*
- * NOTE: The controller must be of the currently authenticated player.
- *
- * @return A list of game objects owned by this controller's player.
+ * @return A list of game objects owned by this controller's player filtered by visibility by the current player.
*/
- ImmutableSet<? extends IGameObject> listObjects()
+ Iterable<? extends IGameObject> iterateObservableObjects()
throws NotAuthenticatedException;
/**
@@ -13,7 +13,7 @@
*
* @author lhunath
*/
-public interface ITile {
+public interface ITile extends GameObservable {
@Nonnull
Maybe<? extends IGameObject> checkContents()
@@ -41,11 +41,6 @@ protected ImmutableResourceCost(final Map<ResourceType, Integer> resourceQuantit
return resourceQuantities;
}
- /**
- * {@inheritDoc}
- *
- * @return A new immutable resource cost.
- */
@Override
public ImmutableResourceCost reduce(final ResourceType resourceType, final int term) {
Preconditions.checkArgument( term >= 0, "Amount to reduce resource cost with must be positive." );
@@ -55,11 +50,6 @@ public ImmutableResourceCost reduce(final ResourceType resourceType, final int t
.build() );
}
- /**
- * {@inheritDoc}
- *
- * @return A new immutable resource cost.
- */
@Override
public ImmutableResourceCost add(final ResourceType resourceType, final int term) {
Preconditions.checkArgument( term >= 0, "Amount to increase resource cost with must be positive." );
@@ -69,11 +59,6 @@ public ImmutableResourceCost add(final ResourceType resourceType, final int term
.build() );
}
- /**
- * {@inheritDoc}
- *
- * @return A new immutable resource cost.
- */
@Override
public ImmutableResourceCost add(final ResourceCost resourceCost) {
ImmutableMap.Builder<ResourceType, Integer> builder = ImmutableMap.builder();
@@ -83,11 +68,6 @@ public ImmutableResourceCost add(final ResourceCost resourceCost) {
return new ImmutableResourceCost( builder.build() );
}
- /**
- * {@inheritDoc}
- *
- * @return A new immutable resource cost.
- */
@Override
public ImmutableResourceCost multiply(final ResourceType resourceType, final int factor) {
return new ImmutableResourceCost( ImmutableMap.<ResourceType, Integer>builder()
@@ -96,11 +76,6 @@ public ImmutableResourceCost multiply(final ResourceType resourceType, final int
.build() );
}
- /**
- * {@inheritDoc}
- *
- * @return A new immutable resource cost.
- */
@Override
public ImmutableResourceCost multiply(final int factor) {
ImmutableMap.Builder<ResourceType, Integer> builder = ImmutableMap.builder();
@@ -42,11 +42,6 @@ protected MutableResourceCost(final Map<ResourceType, Integer> resourceQuantitie
return ImmutableMap.copyOf( resourceQuantities );
}
- /**
- * {@inheritDoc}
- *
- * @return This resource cost after applying the mutation.
- */
@Override
public MutableResourceCost reduce(final ResourceType resourceType, final int term) {
Preconditions.checkArgument( term >= 0, "Amount to reduce resource cost with must be positive." );
@@ -55,11 +50,6 @@ public MutableResourceCost reduce(final ResourceType resourceType, final int ter
return this;
}
- /**
- * {@inheritDoc}
- *
- * @return This resource cost after applying the mutation.
- */
@Override
public MutableResourceCost add(final ResourceType resourceType, final int term) {
Preconditions.checkArgument( term >= 0, "Amount to increase resource cost with must be positive." );
@@ -68,11 +58,6 @@ public MutableResourceCost add(final ResourceType resourceType, final int term)
return this;
}
- /**
- * {@inheritDoc}
- *
- * @return This resource cost after applying the mutation.
- */
@Override
public MutableResourceCost add(final ResourceCost resourceCost) {
for (final ResourceType resourceType : ResourceType.values())
@@ -81,23 +66,13 @@ public MutableResourceCost add(final ResourceCost resourceCost) {
return this;
}
- /**
- * {@inheritDoc}
- *
- * @return This resource cost after applying the mutation.
- */
@Override
public MutableResourceCost multiply(final ResourceType resourceType, final int factor) {
resourceQuantities.put( resourceType, get( resourceType ) * factor );
return this;
}
- /**
- * {@inheritDoc}
- *
- * @return This resource cost after applying the mutation.
- */
@Override
public MutableResourceCost multiply(final int factor) {
for (final ResourceType resourceType : ResourceType.values())
@@ -1,6 +1,5 @@
package com.lyndir.omicron.api.model;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.lyndir.omicron.api.Authenticated;
import com.lyndir.omicron.api.util.Maybool;
@@ -19,21 +18,16 @@
@Override
@Authenticated
- public Maybool canObserve(@Nonnull final ITile location) {
- return core.canObserve( location );
+ public Maybool canObserve(@Nonnull final GameObservable observable)
+ throws Security.NotAuthenticatedException {
+ return core.canObserve( observable );
}
@Nonnull
@Override
@Authenticated
- public Iterable<? extends ITile> listObservableTiles() {
- return core.listObservableTiles();
- }
-
- @Nonnull
- @Override
- public Optional<? extends IPlayer> getOwner() {
- return core.getOwner();
+ public Iterable<? extends ITile> iterateObservableTiles() {
+ return core.iterateObservableTiles();
}
@Override
@@ -19,7 +19,9 @@
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.lyndir.omicron.api.Authenticated;
-import com.lyndir.omicron.api.model.error.OmicronException;
+import com.lyndir.omicron.api.model.IConstructorModule.InaccessibleException;
+import com.lyndir.omicron.api.model.IConstructorModule.IncompatibleLevelException;
+import com.lyndir.omicron.api.model.IConstructorModule.OutOfRangeException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import javax.annotation.Nonnull;
@@ -106,8 +108,8 @@ public void setTarget(final IGameObject target)
@Authenticated
public IConstructionSite schedule(final IUnitType unitType, final ITile location)
throws Security.NotOwnedException, Security.NotAuthenticatedException, Security.NotObservableException,
- IConstructorModule.OutOfRangeException, IConstructorModule.InaccessibleException,
- IConstructorModule.IncompatibleLevelException {
+ OutOfRangeException, InaccessibleException,
+ IncompatibleLevelException {
assertOwned();
Security.assertObservable( location );
@@ -2,12 +2,9 @@
import com.google.common.collect.ImmutableList;
import com.lyndir.lhunath.opal.math.Size;
-import com.lyndir.lhunath.opal.system.error.InternalInconsistencyException;
import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.MetaObject;
-import com.lyndir.lhunath.opal.system.util.TypeUtils;
import com.lyndir.omicron.api.GameListener;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
@@ -21,8 +21,8 @@
*/
public class PublicGameObject extends MetaObject implements IGameObject {
- @ObjectMeta(ignoreFor = ObjectMeta.For.all)
- final Logger logger = Logger.get( getClass() );
+ @SuppressWarnings("UnusedDeclaration")
+ private static final Logger logger = Logger.get( PublicGameObject.class );
private final IGameObject core;
@@ -49,31 +49,31 @@ public boolean equals(@Nullable final Object obj) {
return core.getController();
}
- @Nonnull
- @Override
- public Optional<? extends IPlayer> checkOwner() {
- return core.checkOwner();
- }
-
@Override
@Authenticated
public boolean isOwnedByCurrentPlayer()
throws Security.NotAuthenticatedException {
return core.isOwnedByCurrentPlayer();
}
+ @Override
@Authenticated
+ public Maybe<? extends IPlayer> checkOwner() {
+ return core.checkOwner();
+ }
+
@Override
- @SuppressWarnings("ParameterHidesMemberVariable")
- public Maybool canObserve(@Nonnull final ITile location) {
- return core.canObserve( location );
+ @Authenticated
+ public Maybool canObserve(@Nonnull final GameObservable observable)
+ throws Security.NotAuthenticatedException {
+ return core.canObserve( observable );
}
@Authenticated
@Nonnull
@Override
- public Iterable<? extends ITile> listObservableTiles() {
- return core.listObservableTiles();
+ public Iterable<? extends ITile> iterateObservableTiles() {
+ return core.iterateObservableTiles();
}
@Override
@@ -1,6 +1,5 @@
package com.lyndir.omicron.api.model;
-import com.google.common.base.Optional;
import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.*;
import com.lyndir.omicron.api.Authenticated;
@@ -11,9 +10,6 @@
public class PublicGameObjectController<O extends IGameObject> extends MetaObject implements IGameObjectController<O> {
- @ObjectMeta(ignoreFor = ObjectMeta.For.all)
- protected final Logger logger = Logger.get( getClass() );
-
private final IGameObjectController<O> core;
PublicGameObjectController(final IGameObjectController<O> core) {
@@ -38,22 +34,17 @@ public O getGameObject() {
return core.getGameObject();
}
- @Nonnull
- @Override
- public Optional<? extends IPlayer> getOwner() {
- return core.getOwner();
- }
-
@Override
@Authenticated
- public Maybool canObserve(@Nonnull final ITile location) {
- return core.canObserve( location );
+ public Maybool canObserve(@Nonnull final GameObservable observable)
+ throws Security.NotAuthenticatedException {
+ return core.canObserve( observable );
}
@Nonnull
@Override
@Authenticated
- public Iterable<? extends ITile> listObservableTiles() {
- return core.listObservableTiles();
+ public Iterable<? extends ITile> iterateObservableTiles() {
+ return core.iterateObservableTiles();
}
}
@@ -25,8 +25,9 @@
public abstract class PublicModule extends MetaObject implements IModule {
- @ObjectMeta(ignoreFor = ObjectMeta.For.all)
- protected final Logger logger = Logger.get( getClass() );
+ @SuppressWarnings("UnusedDeclaration")
+ private static final Logger logger = Logger.get( PublicModule.class );
+
private final IModule coreModule;
protected PublicModule(final IModule coreModule) {
Oops, something went wrong.

0 comments on commit c971a84

Please sign in to comment.