mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 14:38:50 +00:00
Public Release
This commit is contained in:
1 parent
666398e480
commit
61bb497a22
126 files changed
+8435
-1240
No files matched your search
@@ -1,36 +1,78 @@
|
||||
package com.moulberry.flashback.state;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.FlashbackGson;
|
||||
import com.moulberry.flashback.keyframe.Keyframe;
|
||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
||||
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
||||
import com.moulberry.flashback.serialization.QuaternionTypeAdapater;
|
||||
import com.moulberry.flashback.serialization.Vector3fTypeAdapater;
|
||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||
import com.moulberry.flashback.visuals.ReplayVisuals;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EditorState {
|
||||
|
||||
public transient boolean dirty = false;
|
||||
transient boolean dirty = false;
|
||||
public transient int modCount = ThreadLocalRandom.current().nextInt();
|
||||
|
||||
public final List<KeyframeTrack> keyframeTracks = new ArrayList<>();
|
||||
public final ReplayVisuals replayVisuals = new ReplayVisuals();
|
||||
private final EditorStateHistory history = new EditorStateHistory();
|
||||
|
||||
public float zoomMin = 0.0f;
|
||||
public float zoomMax = 1.0f;
|
||||
public double zoomMin = 0.0;
|
||||
public double zoomMax = 1.0;
|
||||
public int exportStartTicks = -1;
|
||||
public int exportEndTicks = -1;
|
||||
|
||||
public void setKeyframe(int trackIndex, int tick, Keyframe keyframe) {
|
||||
if (trackIndex >= this.keyframeTracks.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<EditorStateHistoryAction> undo = new ArrayList<>();
|
||||
List<EditorStateHistoryAction> redo = new ArrayList<>();
|
||||
|
||||
String description;
|
||||
|
||||
KeyframeTrack track = this.keyframeTracks.get(trackIndex);
|
||||
Keyframe old = track.keyframesByTick.get(tick);
|
||||
if (old != null) {
|
||||
undo.add(new EditorStateHistoryAction.SetKeyframe(track.keyframeType, trackIndex, tick, old.copy()));
|
||||
description = "Replaced " + track.keyframeType + " keyframe";
|
||||
} else {
|
||||
undo.add(new EditorStateHistoryAction.RemoveKeyframe(track.keyframeType, trackIndex, tick));
|
||||
description = "Added " + track.keyframeType + " keyframe";
|
||||
}
|
||||
redo.add(new EditorStateHistoryAction.SetKeyframe(track.keyframeType, trackIndex, tick, keyframe.copy()));
|
||||
|
||||
this.push(new EditorStateHistoryEntry(undo, redo, description));
|
||||
}
|
||||
|
||||
public void push(EditorStateHistoryEntry entry) {
|
||||
if (entry.undo().isEmpty() && entry.redo().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.history.push(this, entry);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void undo(Consumer<String> descriptionConsumer) {
|
||||
this.history.undo(this, descriptionConsumer);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void redo(Consumer<String> descriptionConsumer) {
|
||||
this.history.redo(this, descriptionConsumer);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void setExportTicks(int start, int end, int totalTicks) {
|
||||
if (this.exportEndTicks < 0) {
|
||||
this.exportEndTicks = totalTicks;
|
||||
@@ -52,7 +94,7 @@ public class EditorState {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.exportStartTicks == 0 && this.exportEndTicks == totalTicks) {
|
||||
if (this.exportStartTicks <= 0 && this.exportEndTicks >= totalTicks) {
|
||||
this.exportStartTicks = -1;
|
||||
this.exportEndTicks = -1;
|
||||
}
|
||||
@@ -60,6 +102,11 @@ public class EditorState {
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public void markDirty() {
|
||||
this.dirty = true;
|
||||
this.modCount += 1;
|
||||
}
|
||||
|
||||
public void save(Path path) {
|
||||
this.dirty = false;
|
||||
|
||||
@@ -80,16 +127,23 @@ public class EditorState {
|
||||
return null;
|
||||
}
|
||||
|
||||
String serialized = null;
|
||||
try {
|
||||
String serialized = Files.readString(path);
|
||||
serialized = Files.readString(path);
|
||||
return FlashbackGson.PRETTY.fromJson(serialized, EditorState.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Flashback.LOGGER.error("Error loading editor state", e);
|
||||
Flashback.LOGGER.error("JSON: {}", serialized);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void applyKeyframes(T t, float tick) {
|
||||
public EditorState copy() {
|
||||
String serialized = FlashbackGson.COMPRESSED.toJson(this, EditorState.class);
|
||||
return FlashbackGson.COMPRESSED.fromJson(serialized, EditorState.class);
|
||||
}
|
||||
|
||||
public void applyKeyframes(KeyframeHandler keyframeHandler, float tick) {
|
||||
EnumSet<KeyframeType> applied = EnumSet.noneOf(KeyframeType.class);
|
||||
for (KeyframeTrack keyframeTrack : this.keyframeTracks) {
|
||||
// Ignore lines that are disabled
|
||||
@@ -97,14 +151,16 @@ public class EditorState {
|
||||
continue;
|
||||
}
|
||||
|
||||
KeyframeType baseType = keyframeTrack.keyframeType == KeyframeType.CAMERA_ORBIT ? KeyframeType.CAMERA : keyframeTrack.keyframeType;
|
||||
|
||||
// Already applied a keyframe of this type earlier, skip
|
||||
if (applied.contains(keyframeTrack.keyframeType)) {
|
||||
if (applied.contains(baseType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to apply keyframes, mark applied if successful
|
||||
if (keyframeTrack.tryApplyKeyframes(t, tick)) {
|
||||
applied.add(keyframeTrack.keyframeType);
|
||||
if (keyframeTrack.tryApplyKeyframes(keyframeHandler, tick)) {
|
||||
applied.add(baseType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user