Commit 1af5f483 authored by MarkG's avatar MarkG Committed by TIGERs GitLab
Browse files

Resolve "Add proposed game events to game event view"

Closes #1631

See merge request main/Sumatra!1373

sumatra-commit: 26a6476ee2f11f56bb36ce9ddf0d3ea65dd270fd
parent 93dd3f38
Pipeline #16619 passed with stage
in 8 minutes and 37 seconds
/*
* Copyright (c) 2009 - 2017, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoref.presenter;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.swing.SwingUtilities;
import org.apache.commons.lang.StringUtils;
import edu.tigers.autoref.model.gamelog.GameLogTableModel;
import edu.tigers.autoref.view.gamelog.GameLogPanel;
import edu.tigers.autoreferee.IAutoRefObserver;
......@@ -22,32 +12,45 @@ import edu.tigers.autoreferee.engine.log.GameStateGameLogEntry;
import edu.tigers.autoreferee.engine.log.GameTime;
import edu.tigers.autoreferee.engine.log.RefereeCommandGameLogEntry;
import edu.tigers.autoreferee.engine.log.RefereeGameEventGameLogEntry;
import edu.tigers.autoreferee.engine.log.RefereeGameEventProposalGameLogEntry;
import edu.tigers.autoreferee.module.AutoRefModule;
import edu.tigers.moduli.listenerVariables.ModulesState;
import edu.tigers.sumatra.components.EnumCheckBoxPanel;
import edu.tigers.sumatra.model.SumatraModel;
import edu.tigers.sumatra.referee.data.GameEventProposalGroup;
import edu.tigers.sumatra.referee.gameevent.IGameEvent;
import edu.tigers.sumatra.views.ISumatraView;
import edu.tigers.sumatra.views.ISumatraViewPresenter;
import edu.tigers.sumatra.wp.AWorldPredictor;
import edu.tigers.sumatra.wp.IWorldFrameObserver;
import edu.tigers.sumatra.wp.data.WorldFrameWrapper;
import org.apache.commons.lang.StringUtils;
import javax.swing.SwingUtilities;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver,
EnumCheckBoxPanel.IEnumPanelObserver<ELogEntryType>, IWorldFrameObserver
{
private static final String ACTIVE_LOG_TYPES_KEY = GameLogPresenter.class + ".activeLogTypes";
private GameLogTableModel gameLogTableModel = new GameLogTableModel();
private GameLogPanel gameLogPanel = new GameLogPanel(gameLogTableModel);
private WorldFrameWrapper lastWorldFrameWrapper;
public GameLogPresenter()
{
EnumCheckBoxPanel<ELogEntryType> logPanel = gameLogPanel.getLogTypePanel();
Set<ELogEntryType> types = new HashSet<>();
String activeLogTypes = SumatraModel.getInstance().getUserProperty(ACTIVE_LOG_TYPES_KEY);
if (activeLogTypes == null)
......@@ -63,25 +66,25 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
}
logPanel.setSelectedBoxes(types);
gameLogPanel.setActiveLogTypes(types);
logPanel.addObserver(this);
}
@Override
public Component getComponent()
{
return gameLogPanel;
}
@Override
public ISumatraView getSumatraView()
{
return gameLogPanel;
}
@Override
public void onNewWorldFrame(final WorldFrameWrapper wfw)
{
......@@ -89,13 +92,14 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
if (lastWorldFrameWrapper != null)
{
checkForNewGameEventFromReferee(wfw);
checkForNewGameEventProposalsFromReferee(wfw);
checkForNewRefereeCommand(wfw);
checkForNewGameState(wfw);
}
lastWorldFrameWrapper = wfw;
}
private void checkForNewRefereeCommand(final WorldFrameWrapper wfw)
{
if (wfw.getRefereeMsg().getCommand() != lastWorldFrameWrapper.getRefereeMsg().getCommand())
......@@ -106,8 +110,8 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
wfw.getRefereeMsg().getCommand()));
}
}
private void checkForNewGameState(final WorldFrameWrapper wfw)
{
if (!lastWorldFrameWrapper.getGameState().equals(wfw.getGameState()))
......@@ -118,8 +122,8 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
wfw.getGameState()));
}
}
private void checkForNewGameEventFromReferee(final WorldFrameWrapper wfw)
{
final ArrayList<IGameEvent> newGameEvents = new ArrayList<>(
......@@ -133,8 +137,29 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
gameEvent));
}
}
private void checkForNewGameEventProposalsFromReferee(final WorldFrameWrapper wfw)
{
List<IGameEvent> proposals = wfw.getRefereeMsg().getGameEventProposalGroups().stream()
.map(GameEventProposalGroup::getGameEvents)
.flatMap(Collection::stream)
.collect(Collectors.toList());
List<IGameEvent> lastProposals = lastWorldFrameWrapper.getRefereeMsg().getGameEventProposalGroups().stream()
.map(GameEventProposalGroup::getGameEvents)
.flatMap(Collection::stream)
.collect(Collectors.toList());
proposals.removeAll(lastProposals);
for (IGameEvent gameEvent : proposals)
{
gameLogTableModel.add(new RefereeGameEventProposalGameLogEntry(
wfw.getTimestamp(),
GameTime.of(wfw.getRefereeMsg()),
gameEvent));
}
}
@Override
public void onNewGameEventDetected(final IGameEvent gameEvent)
{
......@@ -147,8 +172,8 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
GameTime.of(lastWorldFrameWrapper.getRefereeMsg()),
gameEvent)));
}
@Override
public void onModuliStateChanged(final ModulesState state)
{
......@@ -163,8 +188,8 @@ public class GameLogPresenter implements ISumatraViewPresenter, IAutoRefObserver
SumatraModel.getInstance().getModuleOpt(AutoRefModule.class).ifPresent(m -> m.removeObserver(this));
}
}
@Override
public void onValueTicked(final ELogEntryType type, final boolean value)
{
......
/*
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.log;
import java.awt.Color;
......@@ -16,6 +20,9 @@ public enum ELogEntryType
/** new game event received */
RECEIVED_GAME_EVENT(new Color(0, 180, 0)),
/** new proposed game event received */
RECEIVED_PROPOSED_GAME_EVENT(new Color(205, 185, 10)),
;
......
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.log;
import java.awt.Color;
import edu.tigers.sumatra.referee.gameevent.IGameEvent;
import java.awt.Color;
public abstract class GameEventGameLogEntry extends GameLogEntry
{
......@@ -28,7 +28,7 @@ public abstract class GameEventGameLogEntry extends GameLogEntry
@Override
public String workGameLogEntry()
{
return gameEvent.getType().name() + " - " + gameEvent.getDescription();
return gameEvent.getType().name() + " - " + gameEvent.getDescription() + " reported by " + gameEvent.getOrigins();
}
......
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.log;
......@@ -21,6 +21,6 @@ public class RefereeGameEventGameLogEntry extends GameEventGameLogEntry
@Override
public String getToolTipText()
{
return "Received a new referee message with command " + gameEvent.getType();
return "Received a new game event: " + gameEvent.getType();
}
}
/*
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.autoreferee.engine.log;
import edu.tigers.sumatra.referee.gameevent.IGameEvent;
public class RefereeGameEventProposalGameLogEntry extends GameEventGameLogEntry
{
public RefereeGameEventProposalGameLogEntry(
final long timestamp,
final GameTime gameTime,
final IGameEvent gameEvent)
{
super(ELogEntryType.RECEIVED_PROPOSED_GAME_EVENT, timestamp, gameTime, gameEvent);
}
@Override
public String getToolTipText()
{
return "Received a new game event proposal: " + gameEvent.getType();
}
}
......@@ -16,29 +16,36 @@ import edu.tigers.sumatra.referee.proto.SslGcGeometry;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import java.util.ArrayList;
import java.util.List;
@Persistent
@Persistent(version = 1)
public abstract class AGameEvent implements IGameEvent
{
private final EGameEvent type;
private final List<String> origins;
@SuppressWarnings("unsued") // used by berkeley
protected AGameEvent()
{
type = null;
origins = List.of();
}
protected AGameEvent(final EGameEvent type)
{
this.type = type;
this.origins = List.of();
}
protected AGameEvent(final SslGcGameEvent.GameEvent gameEvent)
{
this.type = EGameEvent.fromProto(gameEvent.getType());
this.origins = new ArrayList<>(gameEvent.getOriginList());
}
......@@ -49,6 +56,13 @@ public abstract class AGameEvent implements IGameEvent
}
@Override
public List<String> getOrigins()
{
return origins;
}
protected SslGcCommon.Team getTeam(ETeamColor color)
{
if (color == ETeamColor.YELLOW)
......
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.sumatra.referee.gameevent;
import edu.tigers.sumatra.referee.proto.SslGcGameEvent;
import java.util.List;
/**
* This interface is implemented by all GameEvent types in {@link EGameEvent}
......@@ -35,4 +37,9 @@ public interface IGameEvent
String getDescription();
/**
* @return the list of origins of this game event
*/
List<String> getOrigins();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment