Changeset 5a3c8d9


Ignore:
Timestamp:
May 19, 2010, 11:42:20 AM (10 years ago)
Author:
Michael Seifert <mseifert@…>
Branches:
master
Children:
4f1973c
Parents:
ce08ae3
Message:

Added basic interface for filtering actions;

Added an action filter for actions in SC2Replay files

Location:
src/main
Files:
5 added
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/main/java/de/erichseifert/warp/gui/APMChart.java

    rce08ae3 r5a3c8d9  
    4848import de.erichseifert.gral.plots.lines.LineRenderer2D;
    4949import de.erichseifert.gral.util.Insets2D;
     50import de.erichseifert.warp.ActionFilter;
     51import de.erichseifert.warp.ActionFilterFactory;
    5052import de.erichseifert.warp.GameAction;
    5153import de.erichseifert.warp.Player;
    5254
    5355public class APMChart extends JPanel {
     56        private ActionFilter actionFilter;
    5457
    5558        public APMChart(Player... players) {
    5659                super(new BorderLayout());
     60
     61
    5762                DataSeries[] playerData = new DataSeries[players.length];
    5863                // For each of the specified players
     
    6065                        Player player = players[playerIndex];
    6166                        List<? extends GameAction> actions = player.getActions();
     67                        actionFilter = ActionFilterFactory.getInstance().getFilter(actions.get(0));
    6268
    6369                        // Create a data set and fill it with the actions' time stamps
    6470                        DataTable timeStamps = new DataTable(Double.class, Double.class);
    6571                        for (GameAction action : actions) {
     72                                int actionValue = actionFilter.getValue(action);
    6673                                double timeInSeconds = action.getTimestamp()/25.0;
    67                                 timeStamps.add(timeInSeconds, timeInSeconds);
     74                                for (int i = 0; i < actionValue; i++) {
     75                                        timeStamps.add(timeInSeconds, timeInSeconds);
     76                                }
    6877                        }
    6978
  • src/main/java/de/erichseifert/warp/gui/ReplayCellEditor.java

    rce08ae3 r5a3c8d9  
    3232import de.erichseifert.warp.Replay;
    3333import de.erichseifert.warp.replays.sc2replay.SC2Replay;
    34 import de.erichseifert.warp.util.GUIUtil;
     34import de.erichseifert.warp.util.FileUtil;
    3535
    3636/**
     
    5858                Replay replay = (Replay) value;
    5959                this.replay = replay;
    60                 String relativePath = GUIUtil.getPathRelativeTo(parentDir, replay.getFile());
     60                String relativePath = FileUtil.getPathRelativeTo(parentDir, replay.getFile());
    6161                comp.setText(relativePath);
    6262                return comp;
  • src/main/java/de/erichseifert/warp/gui/ReplayParserGUI.java

    rce08ae3 r5a3c8d9  
    6767import de.erichseifert.warp.replays.ReplayParserFactory;
    6868import de.erichseifert.warp.replays.sc2replay.SC2Replay;
    69 import de.erichseifert.warp.util.GUIUtil;
     69import de.erichseifert.warp.util.FileUtil;
    7070
    7171/**
     
    222222                                if (compDefault instanceof JLabel) {
    223223                                        File archiveFile = ((Replay) value).getFile();
    224                                         String path = GUIUtil.getPathRelativeTo(replayDir, archiveFile);
     224                                        String path = FileUtil.getPathRelativeTo(replayDir, archiveFile);
    225225                                        ((JLabel) compDefault).setText(path);
    226226                                }
  • src/main/java/de/erichseifert/warp/gui/ReplayRowFilter.java

    rce08ae3 r5a3c8d9  
    3131import de.erichseifert.warp.Player;
    3232import de.erichseifert.warp.Replay;
    33 import de.erichseifert.warp.util.GUIUtil;
     33import de.erichseifert.warp.util.FileUtil;
    3434
    3535/**
     
    131131                                if (filterMode == FilterMode.FILE_NAME ||
    132132                                        filterMode == FilterMode.FILE_AND_PLAYER_NAME) {
    133                                         String pathRelative = GUIUtil.getPathRelativeTo(parentDir, replay.getFile()).toLowerCase();
     133                                        String pathRelative = FileUtil.getPathRelativeTo(parentDir, replay.getFile()).toLowerCase();
    134134                                        if (pathRelative.contains(filterText)) {
    135135                                                return true;
  • src/main/java/de/erichseifert/warp/replays/ReplayParserFactory.java

    rce08ae3 r5a3c8d9  
    2222package de.erichseifert.warp.replays;
    2323
    24 import java.io.BufferedReader;
    2524import java.io.File;
    26 import java.io.FileReader;
    2725import java.io.IOException;
    2826import java.lang.reflect.Constructor;
     
    3634
    3735import de.erichseifert.warp.Replay;
     36import de.erichseifert.warp.util.FileUtil;
    3837
    3938public class ReplayParserFactory {
    4039        private static ReplayParserFactory instance;
    41         private final Map<String, List<Class<? extends Replay>>> parserClasses;
     40        private final Map<String, List<Class<? extends Replay>>> parsersByExtension;
    4241
     42        @SuppressWarnings("unchecked")
    4343        private ReplayParserFactory() {
    44                 parserClasses = new HashMap<String, List<Class<? extends Replay>>>();
     44                parsersByExtension = new HashMap<String, List<Class<? extends Replay>>>();
    4545                Enumeration<URL> files;
    4646                try {
     
    5454                        String path = files.nextElement().getFile();
    5555                        try {
    56                                 parserClasses.putAll(parseFile(path));
     56                                Map<String, List<String>> mappedParsers = FileUtil.parseFile(path);
     57                                for (Map.Entry<String, List<String>> entry : mappedParsers.entrySet()) {
     58                                        String fileExtension = entry.getKey().toLowerCase();
     59                                        List<String> parserClassNames = entry.getValue();
     60                                        List<Class<? extends Replay>> parserClasses = new ArrayList<Class<? extends Replay>>(parserClassNames.size());
     61                                        for (String parserClassName : parserClassNames) {
     62                                                Class<? extends Replay> parserClass = (Class<? extends Replay>) Class.forName(parserClassName);
     63                                                parserClasses.add(parserClass);
     64                                        }
     65                                        parsersByExtension.put(fileExtension, parserClasses);
     66                                }
    5767                        } catch (IOException e) {
    5868                                e.printStackTrace();
    5969                                continue;
     70                        } catch (ClassNotFoundException e) {
     71                                // TODO Auto-generated catch block
     72                                e.printStackTrace();
    6073                        }
    6174                }
    62         }
    63 
    64         @SuppressWarnings("unchecked")
    65         private static final Map<String, List<Class<? extends Replay>>> parseFile(String path) throws IOException {
    66                 FileReader fr = new FileReader(new File(path));
    67                 BufferedReader br = new BufferedReader(fr);
    68                 Map<String, List<Class<? extends Replay>>> parserClasses = new HashMap<String, List<Class<? extends Replay>>>();
    69                 String line;
    70                 while ((line = br.readLine()) != null) {
    71                         String[] lineSplit = line.split("\\s");
    72                         String fileExtension = lineSplit[0].toLowerCase();
    73                         String parserClass = lineSplit[1];
    74                         List<Class<? extends Replay>> parsers = parserClasses.get(fileExtension);
    75                         if (parsers == null) {
    76                                 parsers = new ArrayList<Class<? extends Replay>>();
    77                                 parserClasses.put(fileExtension, parsers);
    78                         }
    79                         Class<? extends Replay> clazz;
    80                         try {
    81                                 clazz = (Class<? extends Replay>) Class.forName(parserClass);
    82                         } catch (ClassNotFoundException e) {
    83                                 e.printStackTrace();
    84                                 continue;
    85                         }
    86                         parsers.add(clazz);
    87                 }
    88                 return parserClasses;
    8975        }
    9076
     
    9278                String[] splitName = file.getName().split("\\.");
    9379                String extension = splitName[splitName.length-1].toLowerCase();
    94                 List<Class<? extends Replay>> parsers = parserClasses.get(extension);
     80                List<Class<? extends Replay>> parsers = parsersByExtension.get(extension);
    9581                if (parsers == null) {
    9682                        return null;
  • src/main/java/de/erichseifert/warp/replays/sc2replay/SC2Replay.java

    rce08ae3 r5a3c8d9  
    4444import de.erichseifert.warp.Player;
    4545import de.erichseifert.warp.replays.sc2replay.actions.SC2Action;
     46import de.erichseifert.warp.replays.sc2replay.actions.SC2ActionFactory;
    4647import de.erichseifert.warp.replays.sc2replay.util.SC2ReplayUtil;
    4748import de.erichseifert.warp.util.ReplayUtil;
  • src/main/java/de/erichseifert/warp/replays/sc2replay/actions/Group.java

    rce08ae3 r5a3c8d9  
    2525
    2626public class Group extends AbstractSC2Action {
     27        private final boolean assigned;
    2728
    2829        public Group(int timeStamp, int eventTypeCode, boolean globalEvent, int playerIndex, ByteBuffer src) {
     
    3031                int header1 = src.get();
    3132                // This most likely means that a new group was assigned
    32                 boolean flag1 = (header1 & 0x2) != 0;
     33                assigned = (header1 & 0x2) != 0;
    3334                boolean flag2 = (header1 & 0x1) != 0;
    3435                int header2 = src.get();
     
    3839                src.position(src.position()+byteCount);
    3940        }
     41
     42        public boolean isAssigned() {
     43                return assigned;
     44        }
    4045}
  • src/main/java/de/erichseifert/warp/replays/sc2replay/actions/Order.java

    rce08ae3 r5a3c8d9  
    2525
    2626public class Order extends AbstractSC2Action {
    27         private static final byte SUBGROUP_ALL = (byte) 0xF8;
     27        protected static final byte SUBGROUP_ALL = (byte) 0xF8;
    2828
    2929        //private static final byte TYPE_UNIT = 0x02;
    30         private static final OrderCode ID_STOP = new OrderCode((byte) 0x02, (short) 0x0400);
    31         private static final OrderCode ID_MOVE = new OrderCode((byte) 0x02, (short) 0x0600);
    32         private static final OrderCode ID_PATROL = new OrderCode((byte) 0x02, (short) 0x0601);
    33         private static final OrderCode ID_HOLD_POSITION = new OrderCode((byte) 0x02, (short) 0x0602);
    34         private static final OrderCode ID_ATTACK = new OrderCode((byte) 0x02, (short) 0x0900);
     30        public static final OrderCode ID_STOP = new OrderCode((byte) 0x02, (short) 0x0400);
     31        public static final OrderCode ID_MOVE = new OrderCode((byte) 0x02, (short) 0x0600);
     32        public static final OrderCode ID_PATROL = new OrderCode((byte) 0x02, (short) 0x0601);
     33        public static final OrderCode ID_HOLD_POSITION = new OrderCode((byte) 0x02, (short) 0x0602);
     34        public static final OrderCode ID_ATTACK = new OrderCode((byte) 0x02, (short) 0x0900);
    3535
    3636        //private static final byte TYPE_MISC = 0x05;
    37         private static final OrderCode ID_WAYPOINT = new OrderCode((byte) 0x05, (short) 0x0500);
     37        public static final OrderCode ID_WAYPOINT = new OrderCode((byte) 0x05, (short) 0x0500);
    3838
    3939        //private static final byte TYPE_BUILD = 0x06;
    40         private static final OrderCode ID_GATHER = new OrderCode((byte) 0x06, (short) 0x0400);
    41         private static final OrderCode ID_RETURN_CARGO = new OrderCode((byte) 0x06, (short) 0x0401);
    42         private static final OrderCode ID_CANCEL = new OrderCode((byte) 0x06, (short) 0x0800);
    43         private static final OrderCode ID_BUILD_SUPPLY_DEPOT = new OrderCode((byte) 0x06, (short) 0x0D01);
    44         private static final OrderCode ID_BUILD_REFINERY = new OrderCode((byte) 0x06, (short) 0x0D02);
     40        public static final OrderCode ID_GATHER = new OrderCode((byte) 0x06, (short) 0x0400);
     41        public static final OrderCode ID_RETURN_CARGO = new OrderCode((byte) 0x06, (short) 0x0401);
     42        public static final OrderCode ID_CANCEL = new OrderCode((byte) 0x06, (short) 0x0800);
     43        public static final OrderCode ID_BUILD_SUPPLY_DEPOT = new OrderCode((byte) 0x06, (short) 0x0D01);
     44        public static final OrderCode ID_BUILD_REFINERY = new OrderCode((byte) 0x06, (short) 0x0D02);
    4545
    4646        //private static final byte TYPE_COMMAND_CENTER = 0x08;
    47         private static final OrderCode ID_BUILD_SCV = new OrderCode((byte) 0x08, (short) 0x0700);
     47        public static final OrderCode ID_BUILD_SCV = new OrderCode((byte) 0x08, (short) 0x0700);
    4848
    4949        //private static final byte TYPE_CLICK = (byte) 0xFF;
    50         private static final OrderCode ID_CLICK = new OrderCode((byte) 0xFF, (short) 0xFF0F);
     50        public static final OrderCode ID_CLICK = new OrderCode((byte) 0xFF, (short) 0xFF0F);
    5151
    52         private static class OrderCode {
     52        public static class OrderCode {
    5353                private final byte type;
    5454                private final short id;
     
    8181
    8282        private final byte subgroup;
    83         private final OrderCode code;
     83        private final OrderCode orderCode;
    8484
    8585        public Order(int timeStamp, int eventTypeCode, boolean globalEvent, int playerIndex, ByteBuffer src) {
     
    9292                byte actionType = src.get();
    9393                short actionID = src.getShort();
    94                 code = new OrderCode(actionType, actionID);
     94                orderCode = new OrderCode(actionType, actionID);
    9595
    9696                byte unknown = src.get();
     
    102102                }
    103103        }
     104
     105        public OrderCode getOrderCode() {
     106                return orderCode;
     107        }
    104108}
  • src/main/java/de/erichseifert/warp/replays/sc2replay/actions/SC2ActionFactory.java

    rce08ae3 r5a3c8d9  
    2020 */
    2121
    22 package de.erichseifert.warp.replays.sc2replay;
     22package de.erichseifert.warp.replays.sc2replay.actions;
    2323
    2424import java.nio.ByteBuffer;
     
    2727
    2828import de.erichseifert.warp.GameActionFactory;
    29 import de.erichseifert.warp.replays.sc2replay.actions.EnterGame;
    30 import de.erichseifert.warp.replays.sc2replay.actions.Group;
    31 import de.erichseifert.warp.replays.sc2replay.actions.LeaveGame;
    32 import de.erichseifert.warp.replays.sc2replay.actions.MoveScreen;
    33 import de.erichseifert.warp.replays.sc2replay.actions.Order;
    34 import de.erichseifert.warp.replays.sc2replay.actions.SC2Action;
    35 import de.erichseifert.warp.replays.sc2replay.actions.Select;
    36 import de.erichseifert.warp.replays.sc2replay.actions.SendResources;
    37 import de.erichseifert.warp.replays.sc2replay.actions.StartGame;
    38 import de.erichseifert.warp.replays.sc2replay.actions.Sync;
    39 import de.erichseifert.warp.replays.sc2replay.actions.Unknown;
    40 import de.erichseifert.warp.replays.sc2replay.actions.Unknown2;
    41 import de.erichseifert.warp.replays.sc2replay.actions.Unknown3;
     29import de.erichseifert.warp.replays.sc2replay.SC2Replay;
    4230import de.erichseifert.warp.replays.sc2replay.util.SC2ReplayUtil;
    4331
  • src/main/java/de/erichseifert/warp/util/GUIUtil.java

    rce08ae3 r5a3c8d9  
    2323
    2424import java.awt.Color;
    25 import java.io.File;
    2625
    2726/**
     
    4746                return colorHex;
    4847        }
    49 
    50         public static String getPathRelativeTo(File parent, File child) {
    51                 String path = child.getName();
    52                 if (parent == null) {
    53                         return path;
    54                 }
    55                 File childParent = child.getParentFile();
    56                 while (childParent != null && !childParent.getAbsolutePath().equals(parent.getAbsolutePath())) {
    57                         path = childParent.getName() + File.separator + path;
    58                         childParent = childParent.getParentFile();
    59                 }
    60 
    61                 return path;
    62         }
    6348}
Note: See TracChangeset for help on using the changeset viewer.