Skip to content

Commit

Permalink
reworked the Timeline Inspector & shifting
Browse files Browse the repository at this point in the history
  • Loading branch information
RaderRMT committed Jan 21, 2021
1 parent 7f710bc commit 637ae00
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.awt.event.ActionListener;
import java.util.Arrays;

public class TranslateTimelineListener implements ActionListener {
public class MovePathListener implements ActionListener {

private Logger logger = Main.getInstance().getLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void actionPerformed(ActionEvent e) {

if(timelineInspector.positionPath.getKeyframes().size() == 0) return;

timelineInspector.timestampField.setText(String.valueOf(timelineInspector.positionPath.getKeyframes().get(selectedType).getTime()));
timelineInspector.positionKeyframeTimestampField.setText(String.valueOf(timelineInspector.positionPath.getKeyframes().get(selectedType).getTime()));

double[] rotation = (double[]) timelineInspector.positionPath.getKeyframes().get(selectedType).getProperties().get("camera:rotation");

Expand All @@ -30,6 +30,6 @@ public void actionPerformed(ActionEvent e) {
timelineInspector.yField.setText(String.valueOf(position[1]));
timelineInspector.zField.setText(String.valueOf(position[2]));

timelineInspector.spectatorKeyframeCheck.setSelected(timelineInspector.positionPath.getKeyframes().get(selectedType).getProperties().containsKey("spectate"));
timelineInspector.isSpectatorKeyframeCheck.setSelected(timelineInspector.positionPath.getKeyframes().get(selectedType).getProperties().containsKey("spectate"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public void actionPerformed(ActionEvent e) {
TimelineInspector timelineInspector = TimelineInspector.getInstance();

if(e.getSource().equals(timelineInspector.savePositionKeyframeButton)) {
int selectedKeyframe = timelineInspector.selectedKeyframeCombo.getSelectedIndex();
int selectedKeyframe = timelineInspector.selectedPositionKeyframeCombo.getSelectedIndex();

int timestamp = Integer.parseInt(timelineInspector.timestampField.getText());
int timestamp = Integer.parseInt(timelineInspector.positionKeyframeTimestampField.getText());

double[] rotation = {
Double.parseDouble(timelineInspector.yawField.getText()),
Expand All @@ -35,7 +35,7 @@ public void actionPerformed(ActionEvent e) {
Double.parseDouble(timelineInspector.zField.getText())
};

boolean isSpectator = timelineInspector.spectatorKeyframeCheck.isSelected();
boolean isSpectator = timelineInspector.isSpectatorKeyframeCheck.isSelected();

logger.writeln("Started saving position keyframe #" + selectedKeyframe);
logger.writeln("Writing timestamp: " + timestamp);
Expand All @@ -53,7 +53,7 @@ public void actionPerformed(ActionEvent e) {
} else {
int selectedKeyframe = timelineInspector.selectedTimeKeyframeCombo.getSelectedIndex();

int timestamp = Integer.parseInt(timelineInspector.keyframeTimestampField.getText());
int timestamp = Integer.parseInt(timelineInspector.timeKeyframeTimestampField.getText());

int replayTimestamp = Integer.parseInt(timelineInspector.replayTimestampField.getText());

Expand Down
64 changes: 64 additions & 0 deletions fr/rader/billy/gui/inspector/listeners/ShiftListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package fr.rader.billy.gui.inspector.listeners;

import fr.rader.billy.Logger;
import fr.rader.billy.Main;
import fr.rader.billy.gui.inspector.TimelineInspector;
import fr.rader.billy.timeline.Keyframe;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ShiftListener implements ActionListener {

private final Logger logger = Main.getInstance().getLogger();

private TimelineInspector timelineInspector;

@Override
public void actionPerformed(ActionEvent e) {
timelineInspector = TimelineInspector.getInstance();

int shift = (int) timelineInspector.shiftSpinner.getValue();
if(e.getSource().equals(timelineInspector.shiftAllKeyframesButton)) {
shiftPositionKeyframes(shift);
shiftTimeKeyframes(shift);
} else if(e.getSource().equals(timelineInspector.shiftPositionKeyframesButton)) {
shiftPositionKeyframes(shift);
} else if(e.getSource().equals(timelineInspector.shiftTimeKeyframesButton)) {
shiftTimeKeyframes(shift);
} else if(e.getSource().equals(timelineInspector.shiftReplayTimestampsButton)) {
logger.writeln("Shifting replay timestamps: " + shift);

int oldTimestamp;
for(Keyframe keyframe : timelineInspector.timePath.getKeyframes()) {
oldTimestamp = (int) keyframe.getProperties().get("timestamp");
keyframe.getProperties().replace("timestamp", oldTimestamp + shift);
}

oldTimestamp = Integer.parseInt(timelineInspector.replayTimestampField.getText());
timelineInspector.replayTimestampField.setText(String.valueOf(oldTimestamp + shift));
}
}

private void shiftPositionKeyframes(int shift) {
logger.writeln("Shifting position keyframes: " + shift);

for(Keyframe keyframe : timelineInspector.positionPath.getKeyframes()) {
keyframe.setTime(keyframe.getTime() + shift);
}

int oldTimestamp = Integer.parseInt(timelineInspector.positionKeyframeTimestampField.getText());
timelineInspector.positionKeyframeTimestampField.setText(String.valueOf(oldTimestamp + shift));
}

private void shiftTimeKeyframes(int shift) {
logger.writeln("Shifting time keyframes: " + shift);

for(Keyframe keyframe : timelineInspector.timePath.getKeyframes()) {
keyframe.setTime(keyframe.getTime() + shift);
}

int oldTimestamp = Integer.parseInt(timelineInspector.timeKeyframeTimestampField.getText());
timelineInspector.timeKeyframeTimestampField.setText(String.valueOf(oldTimestamp + shift));
}
}

This file was deleted.

34 changes: 0 additions & 34 deletions fr/rader/billy/gui/inspector/listeners/ShiftTimelineListener.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void actionPerformed(ActionEvent e) {

if(timelineInspector.timePath.getKeyframes().size() == 0) return;

timelineInspector.replayTimestampField.setText(String.valueOf(timelineInspector.timePath.getKeyframes().get(Integer.parseInt(selectedType)).getTime()));
timelineInspector.keyframeTimestampField.setText(String.valueOf(timelineInspector.timePath.getKeyframes().get(Integer.parseInt(selectedType)).getProperties().get("timestamp")));
timelineInspector.timeKeyframeTimestampField.setText(String.valueOf(timelineInspector.timePath.getKeyframes().get(Integer.parseInt(selectedType)).getTime()));
timelineInspector.replayTimestampField.setText(String.valueOf(timelineInspector.timePath.getKeyframes().get(Integer.parseInt(selectedType)).getProperties().get("timestamp")));
}
}
36 changes: 17 additions & 19 deletions fr/rader/billy/gui/main/listeners/OpenReplayListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,27 @@ public void actionPerformed(ActionEvent e) {

openReplay(openFilePrompt(), side);

startLoadingReplay(side, isOpenLeft, getVersion(files[1]));
if(hasNewReplay) startLoadingReplay(side, isOpenLeft, getVersion(files[1]));
}

private static void startLoadingReplay(String side, boolean isOpenLeft, String version) {
if(hasNewReplay) {
if(isOpenLeft && !files[1].equals(new File(""))) { // left side
mainInterface.openLeftReplayButton.setText(files[1].getName() + " (" + version + ")");
} else if(!isOpenLeft && !files[2].equals(new File(""))) { // right side
mainInterface.openRightReplayButton.setText(files[2].getName() + " (" + version + ")");
}

if(isOpenLeft) {
if(hasTimeline) mainInterface.leftTimelineList = serialization.deserialize(new File(side + "timelines.json"));
else if(mainInterface.leftTimelineList != null && !mainInterface.leftTimelineList.isEmpty()) mainInterface.leftTimelineList.clear();
else if(mainInterface.leftTimelineList == null) mainInterface.leftTimelineList = new HashMap<>();
} else {
if(hasTimeline) mainInterface.rightTimelineList = serialization.deserialize(new File(side + "timelines.json"));
else if(mainInterface.rightTimelineList != null && !mainInterface.rightTimelineList.isEmpty()) mainInterface.rightTimelineList.clear();
else if(mainInterface.rightTimelineList == null) mainInterface.rightTimelineList = new HashMap<>();
}
if(isOpenLeft && !files[1].equals(new File(""))) { // left side
mainInterface.openLeftReplayButton.setText(files[1].getName() + " (" + version + ")");
} else if(!isOpenLeft && !files[2].equals(new File(""))) { // right side
mainInterface.openRightReplayButton.setText(files[2].getName() + " (" + version + ")");
}

mainInterface.updateNames();
if(isOpenLeft) {
if(hasTimeline) mainInterface.leftTimelineList = serialization.deserialize(new File(side + "timelines.json"));
else if(mainInterface.leftTimelineList != null && !mainInterface.leftTimelineList.isEmpty()) mainInterface.leftTimelineList.clear();
else if(mainInterface.leftTimelineList == null) mainInterface.leftTimelineList = new HashMap<>();
} else {
if(hasTimeline) mainInterface.rightTimelineList = serialization.deserialize(new File(side + "timelines.json"));
else if(mainInterface.rightTimelineList != null && !mainInterface.rightTimelineList.isEmpty()) mainInterface.rightTimelineList.clear();
else if(mainInterface.rightTimelineList == null) mainInterface.rightTimelineList = new HashMap<>();
}

mainInterface.updateNames();
}

private static void openReplay(File file, String side) {
Expand Down Expand Up @@ -175,7 +173,7 @@ public static String getVersion(File file) {

Gson gson = new Gson();

Map<?, ?> map = gson.fromJson(new FileReader(new File(REPLAY_RECORDINGS + "/extracted_timelines/metaData.json")), Map.class);
Map<?, ?> map = gson.fromJson(new FileReader(REPLAY_RECORDINGS + "/extracted_timelines/metaData.json"), Map.class);

return map.get("mcversion").toString();
} catch (FileNotFoundException | ZipException e) {
Expand Down

0 comments on commit 637ae00

Please sign in to comment.