Compare commits
67 Commits
1.10.2-2.0
...
1.8.9-2.0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed566732df | ||
|
|
91573d9487 | ||
|
|
d71358bcba | ||
|
|
1a55983986 | ||
|
|
18c5bcd469 | ||
|
|
c054fe83f6 | ||
|
|
f13297c5a5 | ||
|
|
391f304c5f | ||
|
|
0e0eaaa9a7 | ||
|
|
a34bbbcd68 | ||
|
|
60879fbbed | ||
|
|
dfafbecf35 | ||
|
|
8a6ec5191b | ||
|
|
5677fc54cb | ||
|
|
748a91e7b2 | ||
|
|
ee24866f29 | ||
|
|
dba085c700 | ||
|
|
3f0e3e725e | ||
|
|
40e1d850da | ||
|
|
03aada1f5f | ||
|
|
0c1dc658ad | ||
|
|
fcbbbc9ea1 | ||
|
|
fe6ded0143 | ||
|
|
f58fa8f9c2 | ||
|
|
4fc3a3166c | ||
|
|
24c58cbbe7 | ||
|
|
1ffeb010d5 | ||
|
|
c122d30065 | ||
|
|
27fd25ae84 | ||
|
|
db6b0ff5a6 | ||
|
|
d61d0ac670 | ||
|
|
f7460f9bf5 | ||
|
|
bdbffd5c33 | ||
|
|
5cbfd2884e | ||
|
|
6095aef3d1 | ||
|
|
3f52336852 | ||
|
|
c6293bcbb0 | ||
|
|
c8126edbb2 | ||
|
|
64898ce288 | ||
|
|
70e3e54038 | ||
|
|
3f2b3d62f7 | ||
|
|
d2def94fc1 | ||
|
|
2c64030459 | ||
|
|
4deb374a7f | ||
|
|
5302bcaed4 | ||
|
|
057edccf26 | ||
|
|
01acbc6f1f | ||
|
|
1c606874ff | ||
|
|
d9b796db5e | ||
|
|
6bbff3bba7 | ||
|
|
6f3ac71a8b | ||
|
|
cd16211309 | ||
|
|
b0a1cdfce2 | ||
|
|
d46589193e | ||
|
|
1b099f9ef6 | ||
|
|
03534c6515 | ||
|
|
4388d6977d | ||
|
|
7ad19aa025 | ||
|
|
655bea0b2d | ||
|
|
458dad6f9a | ||
|
|
eb5ccb2fd5 | ||
|
|
6498d625ad | ||
|
|
2c898a8192 | ||
|
|
5d520a5a3c | ||
|
|
c681742a69 | ||
|
|
fbf165e618 | ||
|
|
6163585fe5 |
@@ -3,8 +3,10 @@ pipeline:
|
||||
image: plugins/git
|
||||
tags: true
|
||||
build:
|
||||
image: openjdk:8
|
||||
image: maven:3.3.9-jdk-8
|
||||
commands:
|
||||
- curl --fail --create-dirs -o $HOME/.gradle/init.d/mirror.gradle https://maven.johni0702.de/config/gradle
|
||||
- curl --fail --create-dirs -o $HOME/.m2/settings.xml https://maven.johni0702.de/config/maven
|
||||
- ./gradlew setupCIWorkspace
|
||||
- ./gradlew :build
|
||||
archive:
|
||||
|
||||
@@ -1 +1 @@
|
||||
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgY2xvbmU6CiAgICBpbWFnZTogcGx1Z2lucy9naXQKICAgIHRhZ3M6IHRydWUKICBidWlsZDoKICAgIGltYWdlOiBvcGVuamRrOjgKICAgIGNvbW1hbmRzOgogICAgICAtIC4vZ3JhZGxldyBzZXR1cENJV29ya3NwYWNlCiAgICAgIC0gLi9ncmFkbGV3IDpidWlsZAogIGFyY2hpdmU6CiAgICBpbWFnZTogcGx1Z2lucy9zMwogICAgYWNsOiBwdWJsaWMtcmVhZAogICAgcmVnaW9uOiAidXMtZWFzdC0xIgogICAgYnVja2V0OiAicmVwbGF5bW9kIgogICAgcGF0aF9zdHlsZTogdHJ1ZQogICAgc291cmNlOiBidWlsZC9saWJzLyoKICAgIHN0cmlwX3ByZWZpeDogYnVpbGQvbGlicy8KICAgIHRhcmdldDogLwo.3ewpTHsEfDOaNv6osutaNlflSq_Qtf3wN7PoRnPvxsE
|
||||
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgY2xvbmU6CiAgICBpbWFnZTogcGx1Z2lucy9naXQKICAgIHRhZ3M6IHRydWUKICBidWlsZDoKICAgIGltYWdlOiBtYXZlbjozLjMuOS1qZGstOAogICAgY29tbWFuZHM6CiAgICAgIC0gY3VybCAtLWZhaWwgLS1jcmVhdGUtZGlycyAtbyAkSE9NRS8uZ3JhZGxlL2luaXQuZC9taXJyb3IuZ3JhZGxlIGh0dHBzOi8vbWF2ZW4uam9obmkwNzAyLmRlL2NvbmZpZy9ncmFkbGUKICAgICAgLSBjdXJsIC0tZmFpbCAtLWNyZWF0ZS1kaXJzIC1vICRIT01FLy5tMi9zZXR0aW5ncy54bWwgaHR0cHM6Ly9tYXZlbi5qb2huaTA3MDIuZGUvY29uZmlnL21hdmVuCiAgICAgIC0gLi9ncmFkbGV3IHNldHVwQ0lXb3Jrc3BhY2UKICAgICAgLSAuL2dyYWRsZXcgOmJ1aWxkCiAgYXJjaGl2ZToKICAgIGltYWdlOiBwbHVnaW5zL3MzCiAgICBhY2w6IHB1YmxpYy1yZWFkCiAgICByZWdpb246ICJ1cy1lYXN0LTEiCiAgICBidWNrZXQ6ICJyZXBsYXltb2QiCiAgICBwYXRoX3N0eWxlOiB0cnVlCiAgICBzb3VyY2U6IGJ1aWxkL2xpYnMvKgogICAgc3RyaXBfcHJlZml4OiBidWlsZC9saWJzLwogICAgdGFyZ2V0OiAvCg.riE6lhwfdNUhI7LO2SxEKFOjzjaX40ne7Ae9gyP75KE
|
||||
4
.gitmodules
vendored
@@ -5,3 +5,7 @@
|
||||
[submodule "ReplayStudio"]
|
||||
path = ReplayStudio
|
||||
url = https://github.com/ReplayMod/ReplayStudio
|
||||
|
||||
[submodule "src/main/resources/assets/replaymod/lang"]
|
||||
path = src/main/resources/assets/replaymod/lang
|
||||
url = https://github.com/ReplayMod/Translations
|
||||
|
||||
64
build.gradle
@@ -1,7 +1,5 @@
|
||||
import groovy.json.JsonOutput
|
||||
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -19,7 +17,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.0-SNAPSHOT'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
||||
classpath 'org.spongepowered:mixingradle:0.3-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
@@ -36,9 +34,11 @@ archivesBaseName = "replaymod"
|
||||
|
||||
minecraft {
|
||||
coreMod = 'com.replaymod.core.LoadingPlugin'
|
||||
version = '1.8-11.14.4.1563'
|
||||
version = '1.8.9-11.15.1.1722'
|
||||
runDir = "eclipse"
|
||||
mappings = "snapshot_nodoc_20141130"
|
||||
mappings = "stable_22"
|
||||
replace '@MOD_VERSION@', project.version
|
||||
replace '@MC_VERSION@', project.minecraft.version
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -59,7 +59,7 @@ configurations {
|
||||
dependencies {
|
||||
compile 'org.projectlombok:lombok:1.16.4'
|
||||
|
||||
compile 'org.spongepowered:mixin:0.4.3'
|
||||
compile 'org.spongepowered:mixin:0.6.8-SNAPSHOT'
|
||||
shade 'com.googlecode.mp4parser:isoparser:1.1.7'
|
||||
shade 'org.apache.commons:commons-exec:1.3'
|
||||
shade 'com.google.apis:google-api-services-youtube:v3-rev178-1.22.0'
|
||||
@@ -101,27 +101,6 @@ jar {
|
||||
}
|
||||
from noticeDir
|
||||
|
||||
def langDir = file("$buildDir/languages")
|
||||
doFirst {
|
||||
try {
|
||||
langDir.deleteDir()
|
||||
langDir.mkdirs()
|
||||
def dir = new File(langDir, 'assets/replaymod/lang/')
|
||||
dir.mkdirs()
|
||||
def zip = new ZipInputStream(new URL('http://replaymod.com/api/grab_languages').openStream())
|
||||
def e;
|
||||
while ((e = zip.nextEntry) != null) {
|
||||
new File(dir, e.getName()) << zip
|
||||
zip.closeEntry()
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
from (langDir) {
|
||||
exclude '**/en_US.lang'
|
||||
}
|
||||
|
||||
from ({shade().collect { it.isDirectory() ? it : zipTree(it) }}) {
|
||||
exclude '**/NOTICE*'
|
||||
// exclude everything taken in from jGui for running the mod in a dev environment
|
||||
@@ -186,6 +165,13 @@ sourceSets {
|
||||
}
|
||||
refMap = "mixins.replaymod.refmap.json"
|
||||
}
|
||||
integrationTest {
|
||||
compileClasspath += main.runtimeClasspath + main.output
|
||||
java {
|
||||
srcDir file('src/integration-test/java')
|
||||
}
|
||||
resources.srcDir file('src/integration-test/resources')
|
||||
}
|
||||
}
|
||||
|
||||
task copySrg(type: Copy, dependsOn: 'genSrgs') {
|
||||
@@ -197,6 +183,30 @@ setupDecompWorkspace.dependsOn copySrg
|
||||
setupDevWorkspace.dependsOn copySrg
|
||||
project.tasks.idea.dependsOn copySrg
|
||||
|
||||
task runIntegrationTest(type: JavaExec, dependsOn: ["makeStart", "jar"]) {
|
||||
main = 'GradleStart'
|
||||
standardOutput = System.out
|
||||
errorOutput = System.err
|
||||
workingDir file(minecraft.runDir)
|
||||
|
||||
def testDir = new File(minecraft.runDir, "integration-test")
|
||||
doFirst {
|
||||
testDir.deleteDir()
|
||||
testDir.mkdirs()
|
||||
}
|
||||
|
||||
doLast {
|
||||
testDir.deleteDir()
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
def runClient = tasks.getByName("runClient")
|
||||
runIntegrationTest.jvmArgs = runClient.jvmArgs + "-Dfml.noGrab=true"
|
||||
runIntegrationTest.args = runClient.args + "--gameDir" + testDir.canonicalPath
|
||||
runIntegrationTest.classpath runClient.classpath + sourceSets.integrationTest.output
|
||||
}
|
||||
}
|
||||
|
||||
def generateVersionsJson() {
|
||||
// List all tags
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
## Installing the Replay Mod [replaymod]
|
||||
The **ReplayMod** requires **Minecraft Forge** to be installed.
|
||||
|
||||
For the use with the **Replay Mod**, we recommend using Forge Version `1.8-11.14.3.1450`, which can be downloaded [here](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.8.html)
|
||||
Depending on your **Replay Mod** version we recommend the following **Forge** versions:
|
||||
|
||||
- Replay Mod 2.0.0 or later for Minecraft 1.11: Forge [1.11-13.19.1.2189](https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.11.html)
|
||||
- Replay Mod 2.0.0 or later for Minecraft 1.10.2: Forge [1.10.2-12.18.2.2099](https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.10.2.html)
|
||||
- Replay Mod 2.0.0 or later for Minecraft 1.9.4: Forge [1.9.4-12.17.0.1976](https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.9.4.html)
|
||||
- Replay Mod 2.0.0 or later for Minecraft 1.8: Forge [1.8-11.14.4.1563](https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.8.html)
|
||||
- Replay Mod 1.0.8 or older for Minecraft 1.8: Forge [1.8-11.14.3.1450](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.8.html)
|
||||
|
||||
Other Forge Versions might, but don't necessarily work.
|
||||
|
||||
If you don't know how to install Forge, follow [this tutorial](https://www.youtube.com/watch?v=4i7-RystzC4).
|
||||
@@ -25,6 +32,10 @@ Next, download this **Batch Script** to quickly install FFmpeg: <https://replaym
|
||||
Put the downloaded script into the folder where you extracted FFmpeg and run itt by double-clicking it.
|
||||
If you see a success message in the console, you've sucessfully installed **FFmpeg**!
|
||||
|
||||
Alternatively, starting with ReplayMod 2.0.0-b5, you can also extract the downloaded `.7z` file into a `ffmpeg` folder
|
||||
(you have to create it, it doesn't exist by default) in your `.minecraft` folder. No need to run any **Batch Script**.
|
||||
The FFmpeg executable should end up at `.minecraft/ffmpeg/bin/ffmpeg.exe`.
|
||||
|
||||
### Mac OSX [mac]
|
||||
On OSX, you can install **FFmpeg** with **[Homebrew](http://brew.sh/)** using `brew install ffmpeg`.
|
||||
|
||||
@@ -37,26 +48,35 @@ If in doubt, consult the documentation of your distribution.
|
||||
## Compatibility with other Mods [compatibility]
|
||||
### General information [general]
|
||||
In General, the Replay Mod _should_ be compatible with most Forge Mods.
|
||||
However, due to the way that recording works, many Mods that add new Blocks, Mobs or Game Mechanics are not supported.
|
||||
Mods that simply modify the client (like the [PixelCam Mod](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2327429-pixelcam-camera-studio-for-minecraft-1-8)
|
||||
or the [CommandGroups Mod](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2443430-command-groups-mod-order-label-and-color-command)) usually work.
|
||||
|
||||
### Optifine [optifine]
|
||||
The **Replay Mod** is compatible with `Optifine 1.8.0 HD U D5`, which can be downloaded at <https://optifine.net/downloads>.
|
||||
Other Optifine versions for Minecraft 1.8.0 might, but don't have to be compatible as well.
|
||||
|
||||
> **Warning:** If you have Optifine installed, you **can not render videos** from within the Replay Mod.
|
||||
This might change in future Replay Mod versions.
|
||||
|
||||
### Shaders Mod [shaders]
|
||||
You can use the Replay Mod together with [karyonix' Shaders Mod](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1286604-shaders-mod-updated-by-karyonix),
|
||||
but rendering videos results in **possible crashes** and **malformed videos**.
|
||||
Therefore, you have to **uninstall the Shaders Mod before rendering**.
|
||||
[Karyonix' Shaders Mod](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1286604-shaders-mod-updated-by-karyonix)
|
||||
is no longer compatible with Minecraft Forge starting with 1.9.4. As such it is not compatible with the Replay Mod either.
|
||||
Please use [Optifine](https://optifine.net/) instead.
|
||||
|
||||
### Custom Main Menu [custom-main-menu]
|
||||
The [Custom Main Menu](https://mods.curse.com/mc-mods/minecraft/226406-custom-main-menu) mod is often used in mod packs to customize their Main Menu with a button layout fitting the background image, links to their website / bug tracker and similar.
|
||||
If you are familiar with it, the button ids for the Replay Mod are: **17890234** (text: `replaymod.gui.replayviewer`), **17890237** (text: `replaymod.gui.replayeditor`) and **17890236** (text: `replaymod.gui.replaycenter`)
|
||||
|
||||
Due to the nature of this Custom Main Menu mod, buttons added to the Main Menu by 3rd party mods like the **Replay Mod** will not show up by default.
|
||||
Thus, to access the Replay Viewer/Editor/Center, you need to manually configure the position for those buttons.
|
||||
To do so, you need to modify the Custom Main Menu configuration file.
|
||||
Usually, you can find it at `.minecraft/config/CustomMainMenu/mainmenu.json` (if you're using a mod pack launcher, it normally has its own .minecraft folder).
|
||||
For an explanation of this config file, have a look at Custom Main Menu's page.
|
||||
|
||||
You can find a list of already modified config files [here](https://gist.github.com/Johni0702/3f3fab81dbf7ada83d045d9fe8f345aa).
|
||||
|
||||
## Troubleshooting [troubleshooting]
|
||||
If you need help installing the **Replay Mod** or **FFmpeg**, please read [this forum thread](https://www.replaymod.com/forum/thread/220)
|
||||
by [bela333](https://www.replaymod.com/user/bela333) - it covers most of the problems that users encountered so far.
|
||||
|
||||
## Settings [settings]
|
||||
To access the **Replay Mod Settings** from the Main Menu click the **"Mods"** button, select the **Replay Mod** from the list and
|
||||
the click the **"Config"** button.
|
||||
|
||||
When in a Replay, you can either bind a hotkey to the **Replay Mod Settings** in Minecraft's Control settings
|
||||
or use the hotkey GUI by clicking on the arrow button in the lower left corner.
|
||||
|
||||
# Recording [recording]
|
||||

|
||||
The **Recording Indicator** which is displayed while recording
|
||||
@@ -88,6 +108,8 @@ You can move through block similar to Spectator Mode.
|
||||
|
||||
Using the **Mouse Wheel**, you can modify your flying speed. Scrolling **up** causes you to fly faster, while scrolling **down** slows you down.
|
||||
|
||||
If you prefer the camera to be controlled similar to vanilla Creative Mode, you can change that in the **Replay Settings**.
|
||||
|
||||
### Camera Roll [roll]
|
||||

|
||||
A Screenshot taken with a **tilted camera**
|
||||
@@ -251,13 +273,15 @@ The **Keyframe Repository** with two **Path Presets**
|
||||
|
||||
Using the `X` key, you can open the **Keyframe Repository**. Every Replay File has a separate Keyframe Repository which can contain several **Keyframe Presets**.
|
||||
|
||||
To save the Keyframes currently on your Timeline, click the **"Save current Path"** button.
|
||||
You can change the Preset's name using the Text Input Field in the upper right corner.
|
||||
To load a Keyframe Preset, select a Preset from the list on the left side and click the **"Load"** button.
|
||||
To save the Keyframes currently on your Timeline, click the **"Save as..."** button.
|
||||
You can change a Preset's name, select it from the list and click the **"Rename"** button.
|
||||
To load a Keyframe Preset, select a Preset from the list and click the **"Load"** button.
|
||||
Using the **"Remove"** button, you can permanently delete a Keyframe Preset from the **Keyframe Repository**.
|
||||
|
||||
## Custom Objects [objects]
|
||||
|
||||
> Custom Objects are not available in the 2.0.0 versions. They are expected to return eventually.
|
||||
|
||||
[YouTube](_Xdpg828fbE)
|
||||
|
||||
### Introduction [introduction]
|
||||
@@ -416,12 +440,10 @@ There are **7 Encoding Presets** you can choose from:
|
||||
|
||||
### Advanced Settings [advanced]
|
||||

|
||||
The **Advanced Render Settings** Screen
|
||||
The **Advanced Render Settings**
|
||||
|
||||
By clicking the **"Advanced Settings" Button** in the lower right corner, you can access more settings.
|
||||
|
||||
#### Hide Nametags [nametags]
|
||||
If you don't want to see Entity's Nametags in the rendered video, simply tick the checkbox. Hidden Nametags also include Nametags of **Armor Stands** and **Mobs**, **not only Players**!
|
||||
#### Render Nametags [nametags]
|
||||
If you don't want to see Entity's Nametags in the rendered video, simply un-tick the checkbox. Hidden Nametags also include Nametags of **Armor Stands** and **Mobs**, **not only Players**!
|
||||
|
||||
#### Stabilize Camera [stabilize]
|
||||
This setting is only applicable for **Cubic Rendering** and **Equirectangular Rendering**.
|
||||
@@ -443,14 +465,14 @@ Using a **Video Editing Software** like **Adobe After Effects** or **Sony Vegas*
|
||||
|
||||
### Command Line Settings [commandline]
|
||||

|
||||
The **Command Line Render Settings** Screen
|
||||
The **Command Line Render Settings**
|
||||
|
||||
|
||||
> **Note**: This is for advanced users only. If you do not know what your're doing, leave these settings as they are.
|
||||
|
||||
The **Replay Mod** runs [FFmpeg](http://ffmpeg.org/) via the **Command Line** to encode videos.
|
||||
|
||||
You can customize both the **executed Command** and the **Command Line Arguments** in the **Command Line Settings** Tag of the **Render Settings Screen**.
|
||||
You can customize both the **executed Command** and the **Command Line Arguments** in the **Command Line Settings** part of the **Render Settings Screen**.
|
||||
|
||||
#### Custom Command [command]
|
||||
If you leave the left input field blank, `ffmpeg` will be used as **command**. If you haven't set your **PATH variable** to link to your FFmpeg distribution, simply enter the full path to your FFmpeg executable (e.g. `C:/ffmpeg/ffmpeg.exe` or `/usr/local/bin/ffmpeg`).
|
||||
@@ -532,7 +554,7 @@ By clicking on a player's **Name or Head**, you can **spectate** this player.
|
||||
|
||||
Next to each player, there's a **checkbox** using which you can toggle the player's **visibility**.
|
||||
This way, you can hide certain players from the Replay.
|
||||
Above the individual checkboxes, there are two checkbox buttons - one to **hide all players** and one to **show all players**.
|
||||
Below the individual checkboxes, there are two checkbox buttons - one to **hide all players** and one to **show all players**.
|
||||
|
||||
If you want to **save the player visibility settings**, check **"Remember Hidden Players" checkbox**.
|
||||
If checked, invisible players will stay invisible after closing the Replay (this can of course be reverted),
|
||||
|
||||
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 147 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 51 KiB |
BIN
docs/img/player-overview.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 85 KiB |
BIN
docs/img/rendersettings-advanced.png
Normal file
|
After Width: | Height: | Size: 147 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 108 KiB |
BIN
docs/img/rendersettings-commandline.png
Normal file
|
After Width: | Height: | Size: 150 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 110 KiB |
BIN
docs/img/rendersettings-video.png
Normal file
|
After Width: | Height: | Size: 140 KiB |
2
jGui
30
src/integration-test/java/IntegrationTest.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Entry point for running integration tests from within the IDE.
|
||||
* This is <b>not</b> called when running integration tests directly from gradle.
|
||||
*/
|
||||
public class IntegrationTest {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// Prevent MC from grabbing our mouse during the test (it's not needed)
|
||||
System.setProperty("fml.noGrab", "true");
|
||||
|
||||
// Make sure the test folder exists and is fresh
|
||||
File gameDir = new File(System.getProperty("user.dir"), "integration-test");
|
||||
if (gameDir.exists()) {
|
||||
FileUtils.forceDelete(gameDir);
|
||||
}
|
||||
FileUtils.forceMkdir(gameDir);
|
||||
|
||||
// Set game dir to test folder and call regular entry point
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args));
|
||||
argsList.add("--gameDir");
|
||||
argsList.add(gameDir.getCanonicalPath());
|
||||
GradleStart.main(argsList.toArray(new String[argsList.size()]));
|
||||
}
|
||||
}
|
||||
342
src/integration-test/java/com/replaymod/core/AbstractTask.java
Normal file
@@ -0,0 +1,342 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiOverlay;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiOverlay;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiTexturedButton;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.LOGGER;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
public abstract class AbstractTask implements Task {
|
||||
public static Task create(Consumer<AbstractTask> init) {
|
||||
return new AbstractTask() {
|
||||
@Override
|
||||
protected void init() {
|
||||
init.consume(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static final Minecraft mc = Minecraft.getMinecraft();
|
||||
public final ReplayMod core = ReplayMod.instance;
|
||||
public SettableFuture<Void> future;
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> execute() {
|
||||
future = SettableFuture.create();
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
addCallback(future, success -> {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}, error -> {});
|
||||
|
||||
init();
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
protected void init() {}
|
||||
|
||||
protected void runLater(Runnable runnable) {
|
||||
core.runLater(() -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable t) {
|
||||
future.setException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void expectGuiClosed(Runnable onClosed) {
|
||||
expectGuiClosed0(10, onClosed);
|
||||
}
|
||||
|
||||
public void expectGuiClosed(int timeout, Runnable onClosed) {
|
||||
expectGuiClosed0(timeout, onClosed);
|
||||
}
|
||||
|
||||
private void expectGuiClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
class EventHandler {
|
||||
final net.minecraft.client.gui.GuiScreen currentScreen = mc.currentScreen;
|
||||
int framesPassed;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (currentScreen != mc.currentScreen) {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
onClosed.run();
|
||||
} else {
|
||||
if (framesPassed < timeout) {
|
||||
framesPassed++;
|
||||
} else {
|
||||
Object gui = (gui = GuiScreen.from(currentScreen)) == null ? currentScreen : gui;
|
||||
Exception e = new TimeoutException("Timeout while waiting for " + gui + " to be closed.");
|
||||
e.setStackTrace(Arrays.copyOfRange(stackTrace, 3, stackTrace.length));
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
}
|
||||
|
||||
public void expectPopupClosed(Runnable onClosed) {
|
||||
expectPopupClosed0(10, onClosed);
|
||||
}
|
||||
|
||||
public void expectPopupClosed(int timeout, Runnable onClosed) {
|
||||
expectPopupClosed0(timeout, onClosed);
|
||||
}
|
||||
|
||||
private void expectPopupClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
AbstractGuiPopup popup = getPopup(mc.currentScreen);
|
||||
if (popup == null) {
|
||||
throw new IllegalStateException("No popup found.");
|
||||
}
|
||||
class EventHandler {
|
||||
int framesPassed;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (getPopup(mc.currentScreen) != popup) {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
onClosed.run();
|
||||
} else {
|
||||
if (framesPassed < timeout) {
|
||||
framesPassed++;
|
||||
} else {
|
||||
Exception e = new TimeoutException("Timeout while waiting for " + popup + " to be closed.");
|
||||
e.setStackTrace(Arrays.copyOfRange(stackTrace, 3, stackTrace.length));
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
}
|
||||
|
||||
private AbstractGuiPopup getPopup(net.minecraft.client.gui.GuiScreen minecraft) {
|
||||
GuiContainer<?> container = GuiOverlay.from(minecraft);
|
||||
if (container == null) {
|
||||
container = GuiScreen.from(minecraft);
|
||||
}
|
||||
if (container != null) {
|
||||
while (container.getContainer() != null) {
|
||||
container = container.getContainer();
|
||||
}
|
||||
GuiElement popup = Iterables.getLast(container.getChildren());
|
||||
if (popup instanceof AbstractGuiPopup) {
|
||||
return (AbstractGuiPopup) popup;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> void expectGui(Class<T> guiClass, Consumer<T> onOpen) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
class EventHandler {
|
||||
net.minecraft.client.gui.GuiScreen currentScreen;
|
||||
int framesPassed;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (currentScreen != mc.currentScreen) {
|
||||
currentScreen = mc.currentScreen;
|
||||
framesPassed = 0;
|
||||
}
|
||||
if (framesPassed < 10) {
|
||||
framesPassed++;
|
||||
return;
|
||||
}
|
||||
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
|
||||
Object foundGui = null;
|
||||
if (AbstractGuiScreen.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(currentScreen);
|
||||
if (guiClass.isInstance(guiScreen)) {
|
||||
onOpen.consume(guiClass.cast(guiScreen));
|
||||
return;
|
||||
}
|
||||
foundGui = guiScreen;
|
||||
} else if (AbstractGuiOverlay.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiOverlay guiScreen = GuiOverlay.from(currentScreen);
|
||||
if (guiClass.isInstance(guiScreen)) {
|
||||
onOpen.consume(guiClass.cast(guiScreen));
|
||||
return;
|
||||
}
|
||||
foundGui = guiScreen;
|
||||
} else if (AbstractGuiPopup.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiPopup popup = getPopup(currentScreen);
|
||||
if (guiClass.isInstance(popup)) {
|
||||
onOpen.consume(guiClass.cast(popup));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (guiClass.isInstance(currentScreen)) {
|
||||
onOpen.consume(guiClass.cast(currentScreen));
|
||||
return;
|
||||
}
|
||||
}
|
||||
class UnexpectedGuiException extends Exception {
|
||||
UnexpectedGuiException(Object foundGui) {
|
||||
super("Expected instance of " + guiClass + " but found " + foundGui);
|
||||
setStackTrace(Arrays.copyOfRange(stackTrace, 2, stackTrace.length));
|
||||
}
|
||||
}
|
||||
future.setException(new UnexpectedGuiException(foundGui == null ? currentScreen : foundGui));
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
}
|
||||
|
||||
private void clickNow(int x, int y) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("mouseClicked", int.class, int.class, int.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, x, y, 0);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void click(int x, int y) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Clicking at {}/{}", x, y);
|
||||
clickNow(x, y);
|
||||
});
|
||||
}
|
||||
|
||||
private void dragNow(int x, int y) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("mouseClickMove", int.class, int.class, int.class, long.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, x, y, 0, 0);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Dragging to {}/{}", x, y);
|
||||
dragNow(x, y);
|
||||
});
|
||||
}
|
||||
|
||||
public void click(GuiButton button) {
|
||||
runLater(() -> {
|
||||
if (!button.isEnabled()) {
|
||||
future.setException(new IllegalStateException("Button is disabled: " + button.getLabel()));
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Clicking button {}", button.getLabel());
|
||||
button.onClick();
|
||||
});
|
||||
}
|
||||
|
||||
public void click(GuiTexturedButton button) {
|
||||
runLater(() -> {
|
||||
if (!button.isEnabled()) {
|
||||
future.setException(new IllegalStateException("Button is disabled: " + button.getTexture()));
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Clicking textured button {}", button.getTexture());
|
||||
button.onClick();
|
||||
});
|
||||
}
|
||||
|
||||
public void click(String buttonText) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Clicking button {}", buttonText);
|
||||
try {
|
||||
Field field = net.minecraft.client.gui.GuiScreen.class.getDeclaredField("buttonList");
|
||||
field.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<net.minecraft.client.gui.GuiButton> buttonList = (List)
|
||||
field.get(mc.currentScreen);
|
||||
|
||||
net.minecraft.client.gui.GuiButton button = null;
|
||||
for (net.minecraft.client.gui.GuiButton guiButton : buttonList) {
|
||||
if (guiButton.displayString.equals(buttonText)) {
|
||||
button = guiButton;
|
||||
}
|
||||
}
|
||||
if (button == null) {
|
||||
future.setException(new NoSuchElementException("No button with label: " + buttonText));
|
||||
return;
|
||||
}
|
||||
|
||||
clickNow(button.xPosition + 5, button.yPosition + 5);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void type(String string) {
|
||||
for (char c : string.toCharArray()) {
|
||||
press(c, Keyboard.getKeyIndex(String.valueOf(c).toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
public void press(int keyCode) {
|
||||
String keyName = Keyboard.getKeyName(keyCode);
|
||||
char character = keyName.length() == 1 ? keyName.charAt(0) : '\0';
|
||||
press(character, keyCode);
|
||||
}
|
||||
|
||||
public void press(char character, int keyCode) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Pressing key {}", Keyboard.getKeyName(keyCode));
|
||||
if (mc.currentScreen == null || mc.currentScreen.allowUserInput) {
|
||||
KeyBinding.onTick(keyCode);
|
||||
FMLCommonHandler.instance().fireKeyInput();
|
||||
}
|
||||
if (mc.currentScreen != null) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("keyTyped", char.class, int.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, character, keyCode);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.LOGGER;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
public class CompositeTask implements Task {
|
||||
private SettableFuture<Void> future;
|
||||
protected final Task[] children;
|
||||
|
||||
public CompositeTask(Task[] children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> execute() {
|
||||
future = SettableFuture.create();
|
||||
executeChild(0);
|
||||
return future;
|
||||
}
|
||||
|
||||
private void executeChild(int childIndex) {
|
||||
if (future.isDone()) return;
|
||||
if (childIndex < children.length) {
|
||||
ReplayMod.instance.runLater(() -> {
|
||||
try {
|
||||
Task task = children[childIndex];
|
||||
LOGGER.info("Running task {}", task);
|
||||
ListenableFuture<Void> childFuture = task.execute();
|
||||
addCallback(childFuture, done -> executeChild(childIndex + 1), err -> future.setException(err));
|
||||
} catch (Throwable t) {
|
||||
future.setException(t);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
future.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.regression.RegressionTest60;
|
||||
import com.replaymod.core.regression.RegressionTest61;
|
||||
import com.replaymod.core.regression.RegressionTest62;
|
||||
import com.replaymod.extra.DownloadOpenEye;
|
||||
import com.replaymod.online.SkipLogin;
|
||||
import com.replaymod.recording.CreateSPWorld;
|
||||
import com.replaymod.recording.ExitSPWorld;
|
||||
import com.replaymod.replay.ExitReplay;
|
||||
import com.replaymod.replay.LoadReplay;
|
||||
import com.replaymod.replay.OpenReplayViewer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.replaymod.core.AbstractTask.mc;
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.MOD_ID;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
/**
|
||||
* Helper mod that initiates the integration tests.
|
||||
*/
|
||||
@Mod(modid = MOD_ID)
|
||||
public class ReplayModIntegrationTest {
|
||||
public static final String MOD_ID = "replaymod-integration-test";
|
||||
|
||||
public static Logger LOGGER;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLPreInitializationEvent event) {
|
||||
LOGGER = event.getModLog();
|
||||
|
||||
// Make sure the game window doesn't have to remain in focus during the test
|
||||
mc.gameSettings.pauseOnLostFocus = false;
|
||||
|
||||
runTasks(
|
||||
new SkipLogin(),
|
||||
new DownloadOpenEye(),
|
||||
new CreateSPWorld(),
|
||||
new Wait(5000),
|
||||
new ExitSPWorld(),
|
||||
new OpenReplayViewer(),
|
||||
new LoadReplay(),
|
||||
|
||||
new RegressionTest60(),
|
||||
new RegressionTest61(),
|
||||
new RegressionTest62(),
|
||||
|
||||
// new AbstractTask() {}, // Uncomment to not exit on success (useful for writing more tests)
|
||||
new ExitReplay()
|
||||
);
|
||||
}
|
||||
|
||||
private void runTasks(Task... tests) {
|
||||
addCallback(new CompositeTask(tests).execute(), success -> {
|
||||
if (!Minecraft.getMinecraft().hasCrashed) {
|
||||
LOGGER.info("===================================================");
|
||||
LOGGER.info("= ALL TESTS PASSED =");
|
||||
LOGGER.info("===================================================");
|
||||
FMLCommonHandler.instance().exitJava(0, false);
|
||||
}
|
||||
}, error -> {
|
||||
LOGGER.error("Failed task:", error);
|
||||
LOGGER.error("===================================================");
|
||||
LOGGER.error("= TEST FAILED =");
|
||||
LOGGER.error("===================================================");
|
||||
FMLCommonHandler.instance().exitJava(1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
35
src/integration-test/java/com/replaymod/core/Task.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
public interface Task {
|
||||
ListenableFuture<Void> execute();
|
||||
|
||||
static Task click(int x, int y) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.click(x, y);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task drag(int x, int y) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.drag(x, y);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task pressKey(int keyCode) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.press(keyCode);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task pressKey(char character, int keyCode) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.press(character, keyCode);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
9
src/integration-test/java/com/replaymod/core/Utils.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public class Utils {
|
||||
public static void times(int x, Runnable runnable) {
|
||||
for (int i = 0; i < x; i++) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/integration-test/java/com/replaymod/core/Wait.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public class Wait extends AbstractTask {
|
||||
private final int duration;
|
||||
|
||||
public Wait(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(duration);
|
||||
runLater(() -> future.set(null));
|
||||
} catch (InterruptedException e) {
|
||||
runLater(() -> future.setException(e));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.SpectatePlayer;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
import com.replaymod.simplepathing.gui.GuiEditKeyframe;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static com.replaymod.core.AbstractTask.mc;
|
||||
import static com.replaymod.core.Utils.times;
|
||||
|
||||
/**
|
||||
* Regression test: #60 Crash in path preview when two spectator keyframes are closer than 50ms
|
||||
*/
|
||||
public class RegressionTest60 extends CompositeTask {
|
||||
public RegressionTest60() {
|
||||
super(new Task[]{
|
||||
new SpectatePlayer(),
|
||||
OverlayGui.whileOpened(
|
||||
// Place first spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Place second spectator keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Move second keyframe to 20ms on the keyframe timeline
|
||||
AbstractTask.create(task -> {
|
||||
// Double click keyframe
|
||||
task.click(130, 50);
|
||||
task.click(130, 50);
|
||||
task.expectGui(GuiEditKeyframe.Spectator.class, gui -> {
|
||||
// Set ms field to 20
|
||||
task.click(mc.currentScreen.width / 2 + 80, mc.currentScreen.height / 2);
|
||||
times(4, () -> task.press(Keyboard.KEY_BACK));
|
||||
task.type("20");
|
||||
// Set other fields to 0
|
||||
times(2, () -> {
|
||||
task.press(Keyboard.KEY_TAB);
|
||||
times(4, () -> task.press(Keyboard.KEY_BACK));
|
||||
task.press(Keyboard.KEY_0);
|
||||
});
|
||||
task.click(gui.saveButton);
|
||||
task.expectPopupClosed(() -> task.future.set(null));
|
||||
});
|
||||
}),
|
||||
// Place second spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton()
|
||||
),
|
||||
// Stop spectating player
|
||||
new SpectatePlayer.End(),
|
||||
// Enable path preview
|
||||
Task.pressKey(Keyboard.KEY_H),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline(),
|
||||
Task.pressKey(Keyboard.KEY_H),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
import com.replaymod.simplepathing.gui.GuiEditKeyframe;
|
||||
|
||||
/**
|
||||
* Regression test: #61 NPE when saving in edit keyframe gui of last keyframe
|
||||
*/
|
||||
public class RegressionTest61 extends CompositeTask {
|
||||
public RegressionTest61() {
|
||||
super(new Task[]{
|
||||
OverlayGui.whileOpened(
|
||||
// Place keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
AbstractTask.create(task -> {
|
||||
// Double click keyframe
|
||||
task.click(130, 50);
|
||||
task.click(130, 50);
|
||||
task.expectGui(GuiEditKeyframe.Position.class, gui -> {
|
||||
task.click(gui.saveButton);
|
||||
task.expectPopupClosed(() -> task.future.set(null));
|
||||
});
|
||||
}),
|
||||
// Place second spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton()
|
||||
),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
|
||||
/**
|
||||
* Regression test: #62 Swapping the only two existing keyframes causes NPE
|
||||
*/
|
||||
public class RegressionTest62 extends CompositeTask {
|
||||
public RegressionTest62() {
|
||||
super(new Task[]{
|
||||
OverlayGui.whileOpened(
|
||||
// Place first keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Place second keyframe
|
||||
Task.click(150, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Move first keyframe past second keyframe
|
||||
Task.click(130,50),
|
||||
Task.drag(170,50)
|
||||
),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.replaymod.extra;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.OpenEyeExtra;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
|
||||
public class DownloadOpenEye extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(OpenEyeExtra.OfferGui.class, offerGui -> {
|
||||
click(offerGui.yesButton);
|
||||
expectGuiClosed(20 * 1000, () -> {
|
||||
File targetFile = new File(mc.mcDataDir, "mods/" + Loader.MC_VERSION + "/OpenEye.jar");
|
||||
if (!targetFile.exists()) {
|
||||
future.setException(new NoSuchFileException(targetFile.getAbsolutePath()));
|
||||
} else {
|
||||
future.set(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.replaymod.online;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.online.gui.GuiLoginPrompt;
|
||||
|
||||
public class SkipLogin extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiLoginPrompt.class, gui -> {
|
||||
click(gui.cancelButton);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import net.minecraft.client.gui.GuiCreateWorld;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class CreateSPWorld extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiMainMenu.class, mainMenu -> {
|
||||
click("Singleplayer");
|
||||
expectGui(GuiSelectWorld.class, selectWorld -> {
|
||||
click("Create New World");
|
||||
expectGui(GuiCreateWorld.class, createWorld -> {
|
||||
click("Create New World");
|
||||
class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ExitSPWorld extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
mc.displayInGameMenu();
|
||||
expectGui(GuiIngameMenu.class, ingameMenu -> {
|
||||
click("Save and Quit to Title");
|
||||
expectGui(GuiMainMenu.class, mainMenu -> new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
String[] dirs = core.getReplayFolder().list(DirectoryFileFilter.DIRECTORY);
|
||||
if (dirs == null) {
|
||||
future.setException(new NullPointerException("dirs is null"));
|
||||
return;
|
||||
}
|
||||
if (dirs.length == 0) {
|
||||
runLater(() -> future.set(null));
|
||||
return;
|
||||
}
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}).start());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
|
||||
public class ExitReplay extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
mc.displayInGameMenu();
|
||||
expectGui(GuiIngameMenu.class, ingameMenu -> {
|
||||
click("Exit Replay");
|
||||
expectGui(GuiMainMenu.class, mainMenu -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import de.johni0702.minecraft.gui.function.Clickable;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.util.Point;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
public class LoadReplay extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiReplayViewer.class, replayViewer -> runLater(() -> {
|
||||
ReadableDimension size = replayViewer.getMaxSize();
|
||||
// Select first entry
|
||||
replayViewer.forEach(Clickable.class).mouseClick(new Point(size.getWidth() / 2, 40), 0);
|
||||
// Load first replay
|
||||
click(replayViewer.loadButton);
|
||||
|
||||
class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
|
||||
public class OpenReplayViewer extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiMainMenu.class, mainMenu -> {
|
||||
click("Replay Viewer");
|
||||
expectGui(GuiReplayViewer.class, replayViewer -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverviewGui;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class SpectatePlayer extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_B);
|
||||
expectGui(PlayerOverviewGui.class, overview -> {
|
||||
click(overview.getMaxSize().getWidth() / 2 - 60, 60);
|
||||
press(Keyboard.KEY_ESCAPE);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
public static class End extends AbstractTask {
|
||||
private int timeout;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
runLater(() -> press(Keyboard.KEY_LSHIFT));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (timeout++ > 20) {
|
||||
future.setException(new TimeoutException("Camera hasn't stopped spectating."));
|
||||
return;
|
||||
}
|
||||
if (mc.getRenderViewEntity() == mc.thePlayer) {
|
||||
future.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.replaymod.replay.overlay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class OverlayGui {
|
||||
public static Task whileOpened(Task...tasks) {
|
||||
Task[] nTasks = new Task[tasks.length + 2];
|
||||
System.arraycopy(tasks, 0, nTasks, 1, tasks.length);
|
||||
nTasks[0] = new Open();
|
||||
nTasks[tasks.length + 1] = new Close();
|
||||
return new CompositeTask(nTasks);
|
||||
}
|
||||
|
||||
public static class Open extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_T);
|
||||
expectGui(GuiReplayOverlay.class, done -> future.set(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Close extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_ESCAPE);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.simplepathing;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import com.replaymod.simplepathing.gui.GuiPathing;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public abstract class GuiPathingTasks extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiReplayOverlay.class, ign -> init0(ReplayModSimplePathing.instance.getGuiPathing()));
|
||||
}
|
||||
|
||||
protected abstract void init0(GuiPathing guiPathing);
|
||||
|
||||
public static class ClickPositionKeyframeButton extends GuiPathingTasks {
|
||||
@Override
|
||||
protected void init0(GuiPathing guiPathing) {
|
||||
click(guiPathing.positionKeyframeButton);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClearKeyframeTimeline extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_C);
|
||||
expectGui(GuiYesNoPopup.class, popup -> {
|
||||
click(popup.getYesButton());
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,18 @@ package com.replaymod.compat;
|
||||
|
||||
import com.replaymod.compat.optifine.DisableFastRender;
|
||||
import com.replaymod.compat.shaders.ShaderBeginRender;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
|
||||
@Mod(modid = ReplayModCompat.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModCompat.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModCompat {
|
||||
public static final String MOD_ID = "replaymod-compat";
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.replaymod.compat.shaders.mixin;
|
||||
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Pseudo
|
||||
@Mixin(targets = "shadersmod/client/ShadersRender", remap = false)
|
||||
public abstract class MixinShadersRender {
|
||||
|
||||
@Inject(method = "renderHand0", at = @At("HEAD"), cancellable = true)
|
||||
private static void replayModCompat_disableRenderHand0(EntityRenderer er, float partialTicks, int renderPass, CallbackInfo ci) {
|
||||
if (ForgeHooksClient.renderFirstPersonHand(er.mc.renderGlobal, partialTicks, renderPass)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -16,10 +16,10 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
public LoadingPlugin() {
|
||||
MixinBootstrap.init();
|
||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.recording.replaymod.json");
|
||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.render.replaymod.json");
|
||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.replay.replaymod.json");
|
||||
MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.recording.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.render.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.replay.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||
|
||||
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||
if (codeSource != null) {
|
||||
@@ -29,7 +29,7 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
if (file.isFile()) {
|
||||
// This forces forge to reexamine the jar file for FML mods
|
||||
// Should eventually be handled by Mixin itself, maybe?
|
||||
CoreModManager.getLoadedCoremods().remove(file.getName());
|
||||
CoreModManager.getIgnoredMods().remove(file.getName());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -14,7 +14,12 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
@@ -31,10 +36,11 @@ import org.apache.commons.io.FileUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
@Mod(modid = ReplayMod.MOD_ID,
|
||||
useMetadata = true,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
updateJSON = "https://raw.githubusercontent.com/ReplayMod/ReplayMod/master/versions.json",
|
||||
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
public class ReplayMod {
|
||||
@@ -124,150 +130,7 @@ public class ReplayMod {
|
||||
if(!FMLClientHandler.instance().hasOptifine())
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
|
||||
if (System.getProperty("replaymod.render.file") != null) {
|
||||
final File file = new File(System.getProperty("replaymod.render.file"));
|
||||
if (!file.exists()) {
|
||||
throw new IOException("File \"" + file.getPath() + "\" not found.");
|
||||
}
|
||||
|
||||
final String path = System.getProperty("replaymod.render.path");
|
||||
String type = System.getProperty("replaymod.render.type");
|
||||
String bitrate = System.getProperty("replaymod.render.bitrate");
|
||||
String fps = System.getProperty("replaymod.render.fps");
|
||||
String waitForChunks = System.getProperty("replaymod.render.waitforchunks");
|
||||
String linearMovement = System.getProperty("replaymod.render.linearmovement");
|
||||
String skyColor = System.getProperty("replaymod.render.skycolor");
|
||||
String width = System.getProperty("replaymod.render.width");
|
||||
String height = System.getProperty("replaymod.render.height");
|
||||
String exportCommand = System.getProperty("replaymod.render.exportcommand");
|
||||
String exportCommandArgs = System.getProperty("replaymod.render.exportcommandargs");
|
||||
/*
|
||||
final RenderOptions options = new RenderOptions();
|
||||
if (bitrate != null) {
|
||||
options.setBitrate(bitrate);
|
||||
}
|
||||
if (fps != null) {
|
||||
options.setFps(Integer.parseInt(fps));
|
||||
}
|
||||
if (waitForChunks != null) {
|
||||
options.setWaitForChunks(Boolean.parseBoolean(waitForChunks));
|
||||
}
|
||||
if (linearMovement != null) {
|
||||
options.setLinearMovement(Boolean.parseBoolean(linearMovement));
|
||||
}
|
||||
if (skyColor != null) {
|
||||
if (skyColor.startsWith("0x")) {
|
||||
options.setSkyColor(Integer.parseInt(skyColor.substring(2), 16));
|
||||
} else {
|
||||
options.setSkyColor(Integer.parseInt(skyColor));
|
||||
}
|
||||
}
|
||||
if (width != null) {
|
||||
options.setWidth(Integer.parseInt(width));
|
||||
}
|
||||
if (height != null) {
|
||||
options.setHeight(Integer.parseInt(height));
|
||||
}
|
||||
|
||||
if (exportCommand != null) {
|
||||
options.setExportCommand(exportCommand);
|
||||
}
|
||||
if (exportCommandArgs != null) {
|
||||
options.setExportCommandArgs(exportCommandArgs);
|
||||
} else {
|
||||
options.setExportCommandArgs(EncodingPreset.MP4DEFAULT.getCommandLineArgs());
|
||||
}
|
||||
|
||||
options.setOutputFile(new File(String.valueOf(System.currentTimeMillis())));
|
||||
|
||||
Pipelines.Preset pipelinePreset = Pipelines.Preset.DEFAULT;
|
||||
if (type != null) {
|
||||
String[] parts = type.split(":");
|
||||
type = parts[0].toUpperCase();
|
||||
if ("NORMAL".equals(type) || "DEFAULT".equals(type)) {
|
||||
pipelinePreset = Pipelines.Preset.DEFAULT;
|
||||
} else if ("STEREO".equals(type) || "STEREOSCOPIC".equals(type)) {
|
||||
pipelinePreset = Pipelines.Preset.STEREOSCOPIC;
|
||||
} else if ("CUBIC".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("Cubic renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.CUBIC;
|
||||
} else if ("EQUIRECTANGULAR".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("Equirectangular renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.EQUIRECTANGULAR;
|
||||
} else if ("ODS".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("ODS renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.ODS;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown type: " + parts[0]);
|
||||
}
|
||||
}
|
||||
options.setMode(pipelinePreset);
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Queue<ListenableFutureTask> tasks = mc.scheduledTasks;
|
||||
synchronized (mc.scheduledTasks) {
|
||||
tasks.add(ListenableFutureTask.create(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String renderDistance = System.getProperty("replaymod.render.mc.renderdistance");
|
||||
String clouds = System.getProperty("replaymod.render.mc.clouds");
|
||||
if (renderDistance != null) {
|
||||
mc.gameSettings.renderDistanceChunks = Integer.parseInt(renderDistance);
|
||||
}
|
||||
if (clouds != null) {
|
||||
mc.gameSettings.clouds = Boolean.parseBoolean(clouds);
|
||||
}
|
||||
|
||||
System.out.println("Loading replay...");
|
||||
// TODO
|
||||
// try {
|
||||
// ReplayHandler.startReplay(file, false);
|
||||
// } catch (Throwable t) {
|
||||
// t.printStackTrace();
|
||||
// FMLCommonHandler.instance().exitJava(1, false);
|
||||
// }
|
||||
//
|
||||
// int index = 0;
|
||||
// if (path != null) {
|
||||
// for (KeyframeSet set : ReplayHandler.getKeyframeRepository()) {
|
||||
// if (set.getName().equals(path)) {
|
||||
// break;
|
||||
// }
|
||||
// index++;
|
||||
// }
|
||||
// if (index >= ReplayHandler.getKeyframeRepository().length) {
|
||||
// throw new IllegalArgumentException("No path named \"" + path + "\".");
|
||||
// }
|
||||
// } else if (ReplayHandler.getKeyframeRepository().length == 0) {
|
||||
// throw new IllegalArgumentException("Replay file has no paths defined.");
|
||||
// }
|
||||
// ReplayHandler.useKeyframePresetFromRepository(index);
|
||||
//
|
||||
// System.out.println("Rendering started...");
|
||||
// try {
|
||||
// ReplayProcess.startReplayProcess(options, true);
|
||||
// } catch (Throwable t) {
|
||||
// t.printStackTrace();
|
||||
// FMLCommonHandler.instance().exitJava(1, false);
|
||||
// }
|
||||
// if (mc.hasCrashed) {
|
||||
// System.out.println(mc.crashReporter.getCompleteReport());
|
||||
// }
|
||||
// System.out.println("Rendering done. Shutting down...");
|
||||
// mc.shutdown();
|
||||
}
|
||||
}, null));
|
||||
}
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
}
|
||||
testIfMoeshAndExitMinecraft();
|
||||
|
||||
runLater(() -> {
|
||||
// Cleanup deleted corrupted replays
|
||||
@@ -304,10 +167,8 @@ public class ReplayMod {
|
||||
}
|
||||
|
||||
public void runLater(Runnable runnable) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Queue<ListenableFutureTask> tasks = mc.scheduledTasks;
|
||||
synchronized (mc.scheduledTasks) {
|
||||
tasks.add(ListenableFutureTask.create(runnable, null));
|
||||
mc.scheduledTasks.add(ListenableFutureTask.create(runnable, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.replaymod.core.gui;
|
||||
import com.google.common.io.Files;
|
||||
import com.replaymod.replaystudio.PacketData;
|
||||
import com.replaymod.replaystudio.io.ReplayInputStream;
|
||||
import com.replaymod.replaystudio.io.ReplayOutputStream;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ReplayMetaData;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
@@ -45,15 +46,19 @@ public class RestoreReplayGui extends AbstractGuiScreen<RestoreReplayGui> {
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
if (metaData != null && metaData.getDuration() == 0) {
|
||||
// Try to restore replay duration
|
||||
try (ReplayInputStream in = replayFile.getPacketData()) {
|
||||
// We need to re-write the packet data in case there are any incomplete packets dangling at the end
|
||||
try (ReplayInputStream in = replayFile.getPacketData();
|
||||
ReplayOutputStream out = replayFile.writePacketData()) {
|
||||
PacketData last = null;
|
||||
while ((last = in.readPacket()) != null) {
|
||||
metaData.setDuration((int) last.getTime());
|
||||
out.write(last);
|
||||
}
|
||||
replayFile.writeMetaData(metaData);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
// Write back the actual duration
|
||||
replayFile.writeMetaData(metaData);
|
||||
}
|
||||
replayFile.save();
|
||||
replayFile.close();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.replaymod.core.utils;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -34,14 +35,14 @@ public class OpenGLUtils {
|
||||
float f5 = 1.0F / textureHeight;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
WorldRenderer vertexBuffer = tessellator.getWorldRenderer();
|
||||
GlStateManager.translate(x+(width/2), y+(width/2), 0);
|
||||
GlStateManager.rotate(rotation, 0, 0, 1);
|
||||
worldrenderer.startDrawingQuads();
|
||||
worldrenderer.addVertexWithUV(-width / 2, height / 2, 0.0D, (double) (u * f4), (double) ((v + (float) height) * f5));
|
||||
worldrenderer.addVertexWithUV(width/2, height/2, 0.0D, (double)((u + (float)width) * f4), (double)((v + (float)height) * f5));
|
||||
worldrenderer.addVertexWithUV(width/2, -height/2, 0.0D, (double)((u + (float)width) * f4), (double)(v * f5));
|
||||
worldrenderer.addVertexWithUV(-width/2, -height/2, 0.0D, (double)(u * f4), (double)(v * f5));
|
||||
vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
vertexBuffer.pos(-width / 2, height / 2, 0.0D).tex((double) (u * f4), (double) ((v + (float) height) * f5)).endVertex();
|
||||
vertexBuffer.pos(width/2, height/2, 0.0D).tex((double)((u + (float)width) * f4), (double)((v + (float)height) * f5)).endVertex();
|
||||
vertexBuffer.pos(width/2, -height/2, 0.0D).tex((double)((u + (float)width) * f4), (double)(v * f5)).endVertex();
|
||||
vertexBuffer.pos(-width/2, -height/2, 0.0D).tex((double)(u * f4), (double)(v * f5)).endVertex();
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
@@ -1,16 +1,55 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScrollable;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScrollable;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
|
||||
public class Utils {
|
||||
|
||||
@@ -27,6 +66,42 @@ public class Utils {
|
||||
DEFAULT_THUMBNAIL = thumbnail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Neither the root certificate of LetsEncrypt nor the root that cross-signed it is included in the default
|
||||
* Java keystore prior to 8u101.
|
||||
* Therefore whenever a connection to the replaymod.com site is made, this SSLContext has to be used instead.
|
||||
* It has been constructed to include the necessary root certificates.
|
||||
* @see #SSL_SOCKET_FACTORY
|
||||
*/
|
||||
public static final SSLContext SSL_CONTEXT;
|
||||
|
||||
/**
|
||||
* @see #SSL_CONTEXT
|
||||
*/
|
||||
public static final SSLSocketFactory SSL_SOCKET_FACTORY;
|
||||
|
||||
static {
|
||||
// Largely from https://community.letsencrypt.org/t/134/37
|
||||
try (InputStream in = Utils.class.getResourceAsStream("/dst_root_ca_x3.pem")){
|
||||
Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(in);
|
||||
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, null);
|
||||
keyStore.setCertificateEntry("1", certificate);
|
||||
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(keyStore);
|
||||
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
SSL_CONTEXT = ctx;
|
||||
SSL_SOCKET_FACTORY = ctx.getSocketFactory();
|
||||
} catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertSecondsToShortString(int seconds) {
|
||||
int hours = seconds/(60*60);
|
||||
int min = seconds/60 - hours*60;
|
||||
@@ -63,7 +138,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static ResourceLocation getResourceLocationForPlayerUUID(UUID uuid) {
|
||||
NetworkPlayerInfo info = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(uuid);
|
||||
NetworkPlayerInfo info = getMinecraft().getNetHandler().getPlayerInfo(uuid);
|
||||
ResourceLocation skinLocation;
|
||||
if (info != null && info.hasLocationSkin()) {
|
||||
skinLocation = info.getLocationSkin();
|
||||
@@ -76,4 +151,94 @@ public class Utils {
|
||||
public static boolean isCtrlDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
}
|
||||
|
||||
public static <T> void addCallback(ListenableFuture<T> future, Consumer<T> onSuccess, Consumer<Throwable> onFailure) {
|
||||
Futures.addCallback(future, new FutureCallback<T>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable T result) {
|
||||
onSuccess.accept(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable t) {
|
||||
onFailure.accept(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GuiInfoPopup error(Logger logger, GuiContainer container, CrashReport crashReport, Runnable onClose) {
|
||||
// Convert crash report to string
|
||||
String crashReportStr = crashReport.getCompleteReport();
|
||||
|
||||
// Log via logger
|
||||
logger.error(crashReportStr);
|
||||
|
||||
// Try to save the crash report
|
||||
if (crashReport.getFile() == null) {
|
||||
try {
|
||||
File folder = new File(getMinecraft().mcDataDir, "crash-reports");
|
||||
File file = new File(folder, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-client.txt");
|
||||
logger.debug("Saving crash report to file: {}", file);
|
||||
crashReport.saveToFile(file);
|
||||
} catch (Throwable t) {
|
||||
logger.error("Saving crash report file:", t);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Not saving crash report as file already exists: {}", crashReport.getFile());
|
||||
}
|
||||
|
||||
logger.trace("Opening crash report popup GUI");
|
||||
GuiCrashReportPopup popup = new GuiCrashReportPopup(container, crashReportStr);
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Void result) {
|
||||
logger.trace("Crash report popup closed");
|
||||
if (onClose != null) {
|
||||
onClose.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
logger.error("During error popup:", t);
|
||||
}
|
||||
});
|
||||
return popup;
|
||||
}
|
||||
|
||||
private static class GuiCrashReportPopup extends GuiInfoPopup {
|
||||
private final GuiScrollable scrollable;
|
||||
|
||||
public GuiCrashReportPopup(GuiContainer container, String crashReport) {
|
||||
super(container);
|
||||
setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
|
||||
// Add crash report to scrollable info
|
||||
getInfo().addElements(new VerticalLayout.Data(0.5),
|
||||
new GuiLabel().setColor(Colors.BLACK).setI18nText("replaymod.gui.unknownerror"),
|
||||
scrollable = new GuiScrollable().setScrollDirection(AbstractGuiScrollable.Direction.VERTICAL)
|
||||
.setLayout(new VerticalLayout().setSpacing(2))
|
||||
.addElements(null,Arrays.stream(crashReport.replace("\t", " ").split("\n")).map(
|
||||
l -> new GuiLabel().setText(l).setColor(Colors.BLACK)).toArray(GuiElement[]::new)));
|
||||
|
||||
// Replace close button with panel containing close and copy buttons
|
||||
GuiButton copyToClipboardButton = new GuiButton().setI18nLabel("chat.copy").onClick(() ->
|
||||
GuiScreen.setClipboardString(crashReport)).setSize(150, 20);
|
||||
GuiButton closeButton = getCloseButton();
|
||||
popup.removeElement(closeButton);
|
||||
popup.addElements(new VerticalLayout.Data(1),
|
||||
new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5)).setSize(305, 20)
|
||||
.addElements(null, copyToClipboardButton, closeButton));
|
||||
|
||||
// And open it
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
// Re-size the scrollable containing the crash report to 3/4 of the screen
|
||||
scrollable.setSize(size.getWidth() * 3 / 4, size.getHeight() * 3 / 4);
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class WrappedTimer extends Timer {
|
||||
to.elapsedPartialTicks = from.elapsedPartialTicks;
|
||||
to.lastSyncSysClock = from.lastSyncSysClock;
|
||||
to.lastSyncHRClock = from.lastSyncHRClock;
|
||||
to.field_74285_i = from.field_74285_i;
|
||||
to.counter = from.counter;
|
||||
to.timeSyncAdjustment = from.timeSyncAdjustment;
|
||||
}
|
||||
}
|
||||
|
||||
41
src/main/java/com/replaymod/editor/ReplayModEditor.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.replaymod.editor;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.editor.handler.GuiHandler;
|
||||
import com.replaymod.online.Setting;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = ReplayModEditor.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModEditor {
|
||||
public static final String MOD_ID = "replaymod-editor";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModEditor instance;
|
||||
|
||||
private ReplayMod core;
|
||||
|
||||
public static Logger LOGGER;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
ReplayModEditor.LOGGER = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
new GuiHandler(this).register();
|
||||
}
|
||||
|
||||
public ReplayMod getCore() {
|
||||
return core;
|
||||
}
|
||||
}
|
||||
389
src/main/java/com/replaymod/editor/gui/GuiReplayEditor.java
Normal file
@@ -0,0 +1,389 @@
|
||||
package com.replaymod.editor.gui;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replaystudio.PacketData;
|
||||
import com.replaymod.replaystudio.Studio;
|
||||
import com.replaymod.replaystudio.filter.StreamFilter;
|
||||
import com.replaymod.replaystudio.io.ReplayInputStream;
|
||||
import com.replaymod.replaystudio.io.ReplayOutputStream;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ReplayMetaData;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
import com.replaymod.replaystudio.stream.PacketStream;
|
||||
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.replaymod.editor.ReplayModEditor.LOGGER;
|
||||
|
||||
public class GuiReplayEditor extends GuiScreen {
|
||||
private final ReplayMod mod;
|
||||
|
||||
private volatile ProcessingStage processingStage;
|
||||
private volatile double progress;
|
||||
private GuiProcessingProgressPopup popup;
|
||||
|
||||
public GuiButton currentTabButton;
|
||||
public GuiPanel currentTabPanel;
|
||||
|
||||
public final GuiLabel warningLabel = new GuiLabel(this).setColor(Colors.RED)
|
||||
.setI18nText("replaymod.gui.editor.disclaimer");
|
||||
|
||||
public final GuiPanel tabButtons = new GuiPanel(this).setLayout(new GridLayout().setSpacingX(5));
|
||||
public final List<GuiPanel> tabPanels = new ArrayList<>();
|
||||
|
||||
public final GuiButton saveButton = new GuiButton().setI18nLabel("replaymod.gui.save").setSize(100, 20);
|
||||
public final GuiButton backButton = new GuiButton().setI18nLabel("replaymod.gui.back").setSize(100, 20);
|
||||
|
||||
public final GuiPanel buttonPanel = new GuiPanel(this).setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, saveButton, backButton);
|
||||
|
||||
public GuiReplayEditor(GuiScreen parent, ReplayMod mod) {
|
||||
this.mod = mod;
|
||||
backButton.onClick(parent::display);
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.replayeditor"));
|
||||
|
||||
makeTab("trim", () -> new GuiTrimPanel(this));
|
||||
makeTab("connect", GuiPanel::new).setDisabled(); // Not yet implemented
|
||||
makeTab("modify", GuiPanel::new).setDisabled(); // Not yet implemented
|
||||
|
||||
setLayout(new CustomLayout<GuiScreen>() {
|
||||
@Override
|
||||
protected void layout(GuiScreen container, int width, int height) {
|
||||
// Move all inactive panels aside
|
||||
tabPanels.forEach(e -> pos(e, Integer.MIN_VALUE, Integer.MIN_VALUE));
|
||||
|
||||
pos(warningLabel, 10, 22);
|
||||
size(warningLabel, width - 20, 10);
|
||||
|
||||
pos(tabButtons, 10, y(warningLabel) + height(warningLabel) + 2);
|
||||
size(tabButtons, width - 20, 20);
|
||||
|
||||
pos(buttonPanel, width - 10 - width(buttonPanel), height - 10 - height(buttonPanel));
|
||||
|
||||
if (currentTabPanel != null) {
|
||||
pos(currentTabPanel, 10, y(tabButtons) + height(tabButtons) + 10);
|
||||
size(currentTabPanel, width - 20, y(buttonPanel) - 10 - y(currentTabPanel));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public GuiButton makeTab(String name, Supplier<GuiPanel> panel) {
|
||||
GuiButton button = new GuiButton().setI18nLabel("replaymod.gui.editor." + name + ".title")
|
||||
.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.editor." + name + ".description"))
|
||||
.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
button.onClick(() -> {
|
||||
// Remove previous tab
|
||||
if (currentTabButton != null) {
|
||||
currentTabButton.setEnabled();
|
||||
removeElement(currentTabPanel);
|
||||
}
|
||||
|
||||
// Activate new tab
|
||||
currentTabButton = button.setDisabled();
|
||||
addElements(null, currentTabPanel = panel.get());
|
||||
});
|
||||
// Add new tab button to tabs panel
|
||||
tabButtons.addElements(null, button);
|
||||
((GridLayout) tabButtons.getLayout()).setColumns(tabButtons.getChildren().size());
|
||||
return button;
|
||||
}
|
||||
|
||||
public void save(File inputFile, PacketStream.FilterInfo...filters) {
|
||||
save(FilenameUtils.getBaseName(inputFile.getName()), (outputFile) -> {
|
||||
Studio studio = new ReplayStudio();
|
||||
File tmpDir = null;
|
||||
try {
|
||||
File actualOutputFile = outputFile;
|
||||
if (outputFile.getCanonicalPath().equals(inputFile.getCanonicalPath())) {
|
||||
// Input and output files are identical. Due to the way the ZipReplayFile stores its temporary
|
||||
// data, the same replay file must not be opened twice for writing (tmp files will be deleted once
|
||||
// either one is closed or, on Windows, will throw an exception when deleted).
|
||||
tmpDir = Files.createTempDir();
|
||||
outputFile = new File(tmpDir, "replay.mcpr");
|
||||
LOGGER.debug("Output file is identical to input file, using temporary output file {} instead",
|
||||
outputFile);
|
||||
}
|
||||
try (ReplayFile outputReplay = new ZipReplayFile(studio, inputFile, outputFile);
|
||||
ReplayOutputStream out = outputReplay.writePacketData();
|
||||
ReplayFile inputReplay = new ZipReplayFile(studio, inputFile);
|
||||
ReplayInputStream in = inputReplay.getPacketData()) {
|
||||
ReplayMetaData metaData = inputReplay.getMetaData();
|
||||
PacketStream stream = studio.createReplayStream(in, true);
|
||||
|
||||
stream.addFilter(new ProgressFilter(metaData.getDuration()));
|
||||
for (PacketStream.FilterInfo info : filters) {
|
||||
stream.addFilter(info.getFilter(), info.getFrom(), info.getTo());
|
||||
LOGGER.debug("Added filter {}", info);
|
||||
}
|
||||
|
||||
LOGGER.info("Built pipeline: {}", stream);
|
||||
stream.start();
|
||||
|
||||
long lastTimestamp = 0;
|
||||
|
||||
PacketData data;
|
||||
while ((data = stream.next()) != null) {
|
||||
out.write(data);
|
||||
lastTimestamp = data.getTime();
|
||||
}
|
||||
|
||||
for (PacketData d : stream.end()) {
|
||||
out.write(d);
|
||||
lastTimestamp = d.getTime();
|
||||
}
|
||||
|
||||
updateProgress(ProcessingStage.FINALIZING, 0);
|
||||
|
||||
// Update duration of new replay
|
||||
metaData.setDuration((int) lastTimestamp);
|
||||
outputReplay.writeMetaData(metaData);
|
||||
|
||||
out.close();
|
||||
outputReplay.save();
|
||||
}
|
||||
if (outputFile != actualOutputFile) {
|
||||
LOGGER.debug("Moving temporary output file {} to {}");
|
||||
FileUtils.forceDelete(actualOutputFile);
|
||||
FileUtils.moveFile(outputFile, actualOutputFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (tmpDir != null && !FileUtils.deleteQuietly(tmpDir)) {
|
||||
LOGGER.warn("Failed to delete temporary directory {}", tmpDir);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void save(String sourceName, Consumer<File> runnable) {
|
||||
GuiTextField nameField = new GuiTextField().setSize(200, 20).setFocused(true).setText(sourceName);
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(this,
|
||||
nameField
|
||||
).setYesI18nLabel("replaymod.gui.editor.savemode.override").setNoI18nLabel("replaymod.gui.cancel");
|
||||
nameField.onEnter(() -> {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
}
|
||||
}).onTextChanged(obj -> {
|
||||
popup.getYesButton().setEnabled(!nameField.getText().isEmpty());
|
||||
popup.setYesI18nLabel("replaymod.gui.editor.savemode." +
|
||||
(nameField.getText().equals(sourceName) ? "override" : "newfile"));
|
||||
});
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Boolean result) {
|
||||
if (result == Boolean.TRUE) {
|
||||
// Sanitize their input
|
||||
String name = nameField.getText().trim().replace("[^a-zA-Z0-9\\.\\- ]", "_");
|
||||
// This file is what they want
|
||||
File replayFolder;
|
||||
try {
|
||||
replayFolder = mod.getReplayFolder();
|
||||
} catch (IOException e) {
|
||||
Utils.error(LOGGER, GuiReplayEditor.this, CrashReport.makeCrashReport(e, "Getting replay folder"), null);
|
||||
return;
|
||||
}
|
||||
File targetFile = new File(replayFolder, name + ".mcpr");
|
||||
if (targetFile.exists()) {
|
||||
LOGGER.trace("Selected file already exists, asking for confirmation");
|
||||
Futures.addCallback(GuiYesNoPopup.open(GuiReplayEditor.this,
|
||||
new GuiLabel().setColor(Colors.BLACK)
|
||||
.setI18nText("replaymod.gui.replaymodified.warning1", name),
|
||||
new GuiLabel().setColor(Colors.BLACK)
|
||||
.setI18nText("replaymod.gui.replaymodified.warning2"))
|
||||
.setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no")
|
||||
.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Boolean result) {
|
||||
if (result == Boolean.TRUE) {
|
||||
LOGGER.trace("Saving output in {}", targetFile);
|
||||
runEdit(() -> runnable.accept(targetFile));
|
||||
} else {
|
||||
LOGGER.trace("Not overwriting file {}, reopening naming dialog", targetFile);
|
||||
save(sourceName, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
LOGGER.error("During save file confirmation dialog:", t);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
LOGGER.trace("Saving output in {}", targetFile);
|
||||
runEdit(() -> runnable.accept(targetFile));
|
||||
}
|
||||
} else {
|
||||
LOGGER.trace("Saving cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
LOGGER.error("During save file dialog:", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runEdit(Runnable runnable) {
|
||||
popup = new GuiProcessingProgressPopup(this);
|
||||
processingStage = ProcessingStage.INITIALIZING;
|
||||
progress = 0;
|
||||
new Thread(() -> {
|
||||
LOGGER.info("Starting editing of replay");
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable t) {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(t, "Editing replay file");
|
||||
mod.runLater(() -> Utils.error(LOGGER, this, crashReport, popup::close));
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Successfully finished editing");
|
||||
mod.runLater(() -> {
|
||||
popup.close();
|
||||
GuiInfoPopup.open(this, "replaymod.gui.editor.progress.status.finished");
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void updateProgress(ProcessingStage stage, double progress) {
|
||||
if (this.processingStage != stage) {
|
||||
LOGGER.trace("Changing state from {} to {}", this.processingStage, stage);
|
||||
}
|
||||
this.processingStage = stage;
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public ReplayMod getMod() {
|
||||
return mod;
|
||||
}
|
||||
|
||||
public enum ProcessingStage {
|
||||
INITIALIZING("initializing", 0.01),
|
||||
WORKING("writing.raw", 0.89),
|
||||
FINALIZING("writing.final", 0.1),
|
||||
DONE("finished", 0);
|
||||
|
||||
private final String i18nKey;
|
||||
private final double progressFraction;
|
||||
|
||||
ProcessingStage(String i18nKey, double progressFraction) {
|
||||
this.i18nKey = "replaymod.gui.editor.progress.status." + i18nKey;
|
||||
this.progressFraction = progressFraction;
|
||||
}
|
||||
|
||||
public double getOverallProgress(double progress) {
|
||||
progress *= progressFraction;
|
||||
for (ProcessingStage processingStage : values()) {
|
||||
if (processingStage == this) break;
|
||||
progress += processingStage.progressFraction;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
private class ProgressFilter implements StreamFilter {
|
||||
private final long total;
|
||||
|
||||
public ProgressFilter(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "progress";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Studio studio, JsonObject config) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(PacketStream stream) {
|
||||
updateProgress(ProcessingStage.WORKING, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPacket(PacketStream stream, PacketData data) {
|
||||
updateProgress(ProcessingStage.WORKING, (double) data.getTime() / total);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd(PacketStream stream, long timestamp) {}
|
||||
}
|
||||
|
||||
private class GuiProcessingProgressPopup extends AbstractGuiPopup<GuiProcessingProgressPopup> {
|
||||
private final GuiProgressBar progressBar = new GuiProgressBar().setSize(300, 20);
|
||||
|
||||
{
|
||||
popup.setLayout(new VerticalLayout().setSpacing(10));
|
||||
popup.addElements(new VerticalLayout.Data(0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editor.progress.title").setColor(Colors.BLACK),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editor.progress.pleasewait").setColor(Colors.BLACK),
|
||||
progressBar);
|
||||
}
|
||||
|
||||
public GuiProcessingProgressPopup(GuiContainer container) {
|
||||
super(container);
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
// Update progress bar
|
||||
progressBar.setI18nLabel(processingStage.i18nKey);
|
||||
progressBar.setProgress((float) processingStage.getOverallProgress(progress));
|
||||
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiProcessingProgressPopup getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
202
src/main/java/com/replaymod/editor/gui/GuiTrimPanel.java
Normal file
@@ -0,0 +1,202 @@
|
||||
package com.replaymod.editor.gui;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replaystudio.data.Marker;
|
||||
import com.replaymod.replaystudio.filter.ChangeTimestampFilter;
|
||||
import com.replaymod.replaystudio.filter.RemoveFilter;
|
||||
import com.replaymod.replaystudio.filter.SquashFilter;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ReplayMetaData;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
import com.replaymod.replaystudio.stream.PacketStream;
|
||||
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiNumberField;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOCase;
|
||||
import org.apache.commons.io.filefilter.SuffixFileFilter;
|
||||
import org.lwjgl.util.Dimension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.replaymod.editor.ReplayModEditor.LOGGER;
|
||||
import static java.util.Optional.ofNullable;
|
||||
|
||||
public class GuiTrimPanel extends GuiPanel {
|
||||
private static GuiNumberField newGuiNumberField() {
|
||||
return new GuiNumberField().setMaxLength(2).setSize(20, 20).setValidateOnFocusChange(true);
|
||||
}
|
||||
|
||||
// Special value indicating no replay files were found
|
||||
private static final File NO_REPLAY = new File(".");
|
||||
// Special value for the initial "Select Marker Keyframe" entry
|
||||
private static final Marker NO_MARKER = new Marker(); static {NO_MARKER.setTime(-1);}
|
||||
|
||||
private final GuiReplayEditor gui;
|
||||
|
||||
public final GuiDropdownMenu<File> inputReplays = new GuiDropdownMenu<File>(this)
|
||||
.setMinSize(new Dimension(200, 20)).onSelection(i -> updateSelectedReplay())
|
||||
.setToString(f -> f == NO_REPLAY ? "" : FilenameUtils.getBaseName(f.getName()));
|
||||
|
||||
public final GuiNumberField startHour = newGuiNumberField();
|
||||
public final GuiNumberField startMin = newGuiNumberField();
|
||||
public final GuiNumberField startSec = newGuiNumberField();
|
||||
public final GuiNumberField startMilli = newGuiNumberField().setSize(40, 20).setMaxLength(4);
|
||||
public final GuiDropdownMenu<Marker> startMarker = new GuiDropdownMenu<>();
|
||||
|
||||
public final GuiNumberField endHour = newGuiNumberField();
|
||||
public final GuiNumberField endMin = newGuiNumberField();
|
||||
public final GuiNumberField endSec = newGuiNumberField();
|
||||
public final GuiNumberField endMilli = newGuiNumberField().setSize(40, 20).setMaxLength(4);
|
||||
public final GuiDropdownMenu<Marker> endMarker = new GuiDropdownMenu<>();
|
||||
|
||||
public final GuiPanel timePanel = new GuiPanel(this)
|
||||
.setLayout(new GridLayout().setCellsEqualSize(false).setSpacingX(20).setSpacingY(5).setColumns(3))
|
||||
.addElements(new GridLayout.Data(0, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.start"),
|
||||
new GuiPanel().setLayout(new HorizontalLayout().setSpacing(2)).addElements(
|
||||
new HorizontalLayout.Data(0.5),
|
||||
startHour, new GuiLabel().setI18nText("replaymod.gui.hours"),
|
||||
startMin, new GuiLabel().setI18nText("replaymod.gui.minutes"),
|
||||
startSec, new GuiLabel().setI18nText("replaymod.gui.seconds"),
|
||||
startMilli, new GuiLabel().setI18nText("replaymod.gui.milliseconds")
|
||||
), startMarker,
|
||||
new GuiLabel().setI18nText("replaymod.gui.end"),
|
||||
new GuiPanel().setLayout(new HorizontalLayout().setSpacing(2)).addElements(
|
||||
new HorizontalLayout.Data(0.5),
|
||||
endHour, new GuiLabel().setI18nText("replaymod.gui.hours"),
|
||||
endMin, new GuiLabel().setI18nText("replaymod.gui.minutes"),
|
||||
endSec, new GuiLabel().setI18nText("replaymod.gui.seconds"),
|
||||
endMilli, new GuiLabel().setI18nText("replaymod.gui.milliseconds")
|
||||
), endMarker);
|
||||
|
||||
public GuiTrimPanel(GuiReplayEditor gui) {
|
||||
this.gui = gui;
|
||||
|
||||
setLayout(new VerticalLayout().setSpacing(10));
|
||||
|
||||
Function<Marker, String> toString = m -> {
|
||||
if (m == NO_MARKER) {
|
||||
return I18n.format("replaymod.gui.editor.trim.marker");
|
||||
} else {
|
||||
return ofNullable(m.getName()).orElse(I18n.format("replaymod.gui.ingame.unnamedmarker"))
|
||||
+ " (" + Utils.convertSecondsToShortString(m.getTime() / 1000) + ")";
|
||||
}
|
||||
};
|
||||
startMarker.setToString(toString).setMinSize(new Dimension(100, 20)).onSelection(i ->
|
||||
onSelectedMarkerChanged(startMarker, startHour, startMin, startSec, startMilli));
|
||||
endMarker.setToString(toString).setMinSize(new Dimension(100, 20)).onSelection(i ->
|
||||
onSelectedMarkerChanged(endMarker, endHour, endMin, endSec, endMilli));
|
||||
|
||||
File[] files = null;
|
||||
try {
|
||||
File folder = gui.getMod().getReplayFolder();
|
||||
files = folder.listFiles((FileFilter) new SuffixFileFilter(".mcpr", IOCase.INSENSITIVE));
|
||||
} catch (IOException e) {
|
||||
Utils.error(LOGGER, gui, CrashReport.makeCrashReport(e, "Listing available replays"), gui.backButton::onClick);
|
||||
}
|
||||
if (files == null) {
|
||||
LOGGER.warn("Replay file list is null, has the replay folder been deleted?");
|
||||
files = new File[0];
|
||||
} else {
|
||||
LOGGER.debug("Found {} replays in the replay folder", files.length);
|
||||
}
|
||||
if (files.length == 0) {
|
||||
inputReplays.setValues(NO_REPLAY);
|
||||
} else {
|
||||
inputReplays.setValues(files);
|
||||
}
|
||||
|
||||
updateSelectedReplay();
|
||||
updateReadyState();
|
||||
|
||||
gui.saveButton.onClick(() -> {
|
||||
// Read start and end times
|
||||
int start = ((startHour.getInteger() * 60 + startMin.getInteger()) * 60 + startSec.getInteger()) * 1000 + startMilli.getInteger();
|
||||
int end = ((endHour.getInteger() * 60 + endMin.getInteger()) * 60 + endSec.getInteger()) * 1000 + endMilli.getInteger();
|
||||
// Configure offset of change timestamp filter
|
||||
ChangeTimestampFilter ctf = new ChangeTimestampFilter();
|
||||
JsonObject config = new JsonObject();
|
||||
config.addProperty("offset", -start);
|
||||
ctf.init(null, config);
|
||||
// Pass filters to save dialog
|
||||
gui.save(inputReplays.getSelectedValue(),
|
||||
new PacketStream.FilterInfo(new SquashFilter(), -1, start),
|
||||
new PacketStream.FilterInfo(ctf, start, end),
|
||||
new PacketStream.FilterInfo(new RemoveFilter(), end, -1)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private void onSelectedMarkerChanged(GuiDropdownMenu<Marker> dropdown, GuiNumberField hour, GuiNumberField min,
|
||||
GuiNumberField sec, GuiNumberField milli) {
|
||||
Marker marker = dropdown.getSelectedValue();
|
||||
if (marker != NO_MARKER) {
|
||||
int time = marker.getTime();
|
||||
setTime(time, hour, min, sec, milli);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTime(int time, GuiNumberField hour, GuiNumberField min,
|
||||
GuiNumberField sec, GuiNumberField milli) {
|
||||
milli.setValue(time % 1000); time /= 1000;
|
||||
sec.setValue(time % 60); time /= 60;
|
||||
min.setValue(time % 60); time /= 60;
|
||||
hour.setValue(time);
|
||||
}
|
||||
|
||||
private void updateSelectedReplay() {
|
||||
File file = inputReplays.getSelectedValue();
|
||||
// Load markers and meta data from replay file
|
||||
ReplayMetaData metaData;
|
||||
Set<Marker> markers;
|
||||
if (file == NO_REPLAY) {
|
||||
metaData = new ReplayMetaData();
|
||||
markers = Collections.emptySet();
|
||||
} else {
|
||||
try (ReplayFile replayFile = new ZipReplayFile(new ReplayStudio(), file)) {
|
||||
metaData = replayFile.getMetaData();
|
||||
markers = replayFile.getMarkers().or(Collections.emptySet());
|
||||
LOGGER.debug("Loaded {} markers from replay {}", markers.size(), file);
|
||||
} catch (Exception e) {
|
||||
Utils.error(LOGGER, gui, CrashReport.makeCrashReport(e, "Reading markers from replay"), null);
|
||||
metaData = new ReplayMetaData();
|
||||
markers = Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
// Sort and add initial "Select Event Marker" element
|
||||
List<Marker> markerList = new ArrayList<>(markers);
|
||||
markerList.sort(Comparator.comparing(Marker::getTime));
|
||||
markerList.add(0, NO_MARKER);
|
||||
|
||||
// Set marker dropdown values
|
||||
Marker[] markerArray = markerList.stream().toArray(Marker[]::new);
|
||||
startMarker.setValues(markerArray).setSelected(0);
|
||||
endMarker.setValues(markerArray).setSelected(0);
|
||||
|
||||
// Set start and end time values
|
||||
setTime(0, startHour, startMin, startSec, startMilli);
|
||||
setTime(metaData.getDuration(), endHour, endMin, endSec, endMilli);
|
||||
}
|
||||
|
||||
private void updateReadyState() {
|
||||
gui.saveButton.setEnabled(inputReplays.getSelectedValue() != NO_REPLAY);
|
||||
}
|
||||
}
|
||||
54
src/main/java/com/replaymod/editor/handler/GuiHandler.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.replaymod.editor.handler;
|
||||
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
import com.replaymod.editor.gui.GuiReplayEditor;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GuiHandler {
|
||||
private static final int BUTTON_REPLAY_EDITOR = 17890237;
|
||||
|
||||
private final ReplayModEditor mod;
|
||||
|
||||
public GuiHandler(ReplayModEditor mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
if (!(event.gui instanceof GuiMainMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = event.buttonList;
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_EDITOR, event.gui.width / 2 + 2,
|
||||
event.gui.height / 4 + 10 + 3 * 24, I18n.format("replaymod.gui.replayeditor"));
|
||||
button.width = button.width / 2 - 2;
|
||||
buttonList.add(button);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if(!event.button.enabled) return;
|
||||
|
||||
if (event.gui instanceof GuiMainMenu) {
|
||||
if (event.button.id == BUTTON_REPLAY_EDITOR) {
|
||||
new GuiReplayEditor(GuiScreen.wrap(event.gui), mod.getCore()).display();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,12 @@ import de.johni0702.minecraft.gui.element.IGuiImage;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class FullBrightness implements Extra {
|
||||
@Mod.Instance(ReplayModReplay.MOD_ID)
|
||||
private static ReplayModReplay module;
|
||||
private ReplayModReplay module;
|
||||
|
||||
private final IGuiImage indicator = new GuiImage().setTexture(ReplayMod.TEXTURE, 90, 20, 19, 13).setSize(19, 13);
|
||||
|
||||
@@ -27,6 +25,7 @@ public class FullBrightness implements Extra {
|
||||
|
||||
@Override
|
||||
public void register(final ReplayMod mod) throws Exception {
|
||||
this.module = ReplayModReplay.instance;
|
||||
this.gameSettings = mod.getMinecraft().gameSettings;
|
||||
|
||||
mod.getKeyBindingRegistry().registerKeyBinding("replaymod.input.lighting", Keyboard.KEY_Z, new Runnable() {
|
||||
|
||||
@@ -1,102 +1,106 @@
|
||||
package com.replaymod.extras;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.data.IMetadataSection;
|
||||
import net.minecraft.client.resources.data.IMetadataSerializer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import static com.replaymod.extras.ReplayModExtras.LOGGER;
|
||||
|
||||
public class LocalizationExtra implements Extra {
|
||||
@Mod.Instance(ReplayModOnline.MOD_ID)
|
||||
private static ReplayModOnline module;
|
||||
private static final String ZIP_FILE_URL = "https://github.com/ReplayMod/Translations/archive/master.zip";
|
||||
private static final String LANG_PREFIX = "Translations-master/";
|
||||
|
||||
@Override
|
||||
public void register(ReplayMod mod) throws Exception {
|
||||
final Minecraft mc = mod.getMinecraft();
|
||||
Thread localizedResourcePackLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (Boolean.parseBoolean(System.getProperty("replaymod.offline", "false"))) {
|
||||
return;
|
||||
}
|
||||
Thread localizedResourcePackLoader = new Thread(() -> {
|
||||
try {
|
||||
// Download zip of lang files
|
||||
LOGGER.debug("Downloading languages from {}", ZIP_FILE_URL);
|
||||
Map<String, byte[]> languages = new HashMap<>();
|
||||
try (InputStream urlIn = new URL(ZIP_FILE_URL).openStream();
|
||||
ZipInputStream in = new ZipInputStream(urlIn)) {
|
||||
ZipEntry entry;
|
||||
while ((entry = in.getNextEntry()) != null) {
|
||||
String name = entry.getName();
|
||||
if (!name.startsWith(LANG_PREFIX) || !name.endsWith(".lang")) {
|
||||
continue;
|
||||
}
|
||||
name = name.substring(LANG_PREFIX.length());
|
||||
languages.put(name, IOUtils.toByteArray(in));
|
||||
LOGGER.debug("Added language file {}", name);
|
||||
}
|
||||
}
|
||||
LOGGER.debug("Downloaded {} languages", languages.size());
|
||||
|
||||
// Add lang files as resource pack
|
||||
mc.addScheduledTask(() -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IResourcePack> defaultResourcePacks = mc.defaultResourcePacks;
|
||||
defaultResourcePacks.add(new LocalizedResourcePack(module.getApiClient()));
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mc.refreshResources();
|
||||
}
|
||||
});
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
defaultResourcePacks.add(new LocalizedResourcePack(languages));
|
||||
mc.getLanguageManager().onResourceManagerReload(mc.getResourceManager());
|
||||
LOGGER.debug("Added language files to resource packs and reloaded LanguageManager");
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
LOGGER.error("Loading localized resource pack:", t);
|
||||
}
|
||||
}, "localizedResourcePackLoader");
|
||||
localizedResourcePackLoader.setDaemon(true);
|
||||
localizedResourcePackLoader.start();
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class LocalizedResourcePack implements IResourcePack {
|
||||
private final ApiClient apiClient;
|
||||
private Map<String, String> availableLanguages = new HashMap<>();
|
||||
private boolean websiteAvailable = true;
|
||||
private final Pattern LANG_PATTERN = Pattern.compile("^lang/([.+].lang)$");
|
||||
private final Map<String, byte[]> languages;
|
||||
|
||||
public LocalizedResourcePack(Map<String, byte[]> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream(ResourceLocation loc) {
|
||||
if(!loc.getResourcePath().endsWith(".lang")) return null;
|
||||
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
||||
if(availableLanguages.containsKey(langcode)) return new ByteArrayInputStream(availableLanguages.get(langcode).getBytes(Charsets.UTF_8));
|
||||
if (!"replaymod".equals(loc.getResourceDomain())) return null;
|
||||
Matcher matcher = LANG_PATTERN.matcher(loc.getResourcePath());
|
||||
if (matcher.matches()) {
|
||||
byte[] bytes = languages.get(matcher.group());
|
||||
if (bytes != null) {
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation loc) {
|
||||
if(!(loc.getResourcePath().endsWith(".lang"))) return false;
|
||||
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
||||
if(availableLanguages.containsKey(langcode)) return true;
|
||||
if(!websiteAvailable) return false;
|
||||
try {
|
||||
if (Boolean.parseBoolean(System.getProperty("replaymod.offline", "false"))) {
|
||||
return false;
|
||||
}
|
||||
String lang = apiClient.getTranslation(langcode);
|
||||
String prop = StringEscapeUtils.unescapeHtml4(lang);
|
||||
availableLanguages.put(langcode, prop);
|
||||
return true;
|
||||
} catch (ApiException e) {
|
||||
if (e.getError().getId() != 16) { // This language has not been translated
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch(ConnectException ce) {
|
||||
websiteAvailable = false;
|
||||
ce.printStackTrace();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
// Assumes that getInputStream returns a ByteArrayInputStream that doesn't need to be closed
|
||||
return getInputStream(loc) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set getResourceDomains() {
|
||||
return ImmutableSet.of("minecraft", "replaymod");
|
||||
return ImmutableSet.of("replaymod");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
@@ -24,8 +25,10 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.SSL_SOCKET_FACTORY;
|
||||
|
||||
public class OpenEyeExtra implements Extra {
|
||||
private static final String DOWNLOAD_URL = "http://www.replaymod.com/dl/openeye/" + Loader.MC_VERSION;
|
||||
private static final String DOWNLOAD_URL = "https://www.replaymod.com/dl/openeye/" + Loader.MC_VERSION;
|
||||
private static final Setting<Boolean> ASK_FOR_OPEN_EYE = new Setting<>("advanced", "askForOpenEye", null, true);
|
||||
|
||||
private ReplayMod mod;
|
||||
@@ -40,7 +43,7 @@ public class OpenEyeExtra implements Extra {
|
||||
}
|
||||
}
|
||||
|
||||
private class OfferGui extends AbstractGuiScreen<OfferGui> {
|
||||
public class OfferGui extends AbstractGuiScreen<OfferGui> {
|
||||
public final GuiScreen parent;
|
||||
public final GuiPanel textPanel = new GuiPanel().setLayout(new VerticalLayout().setSpacing(3))
|
||||
.addElements(new VerticalLayout.Data(0.5),
|
||||
@@ -66,10 +69,12 @@ public class OpenEyeExtra implements Extra {
|
||||
GuiPopup popup = new GuiPopup(OfferGui.this);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
File targetFile = new File("mods/" + Loader.MC_VERSION, "OpenEye.jar");
|
||||
File targetFile = new File(mod.getMinecraft().mcDataDir, "mods/" + Loader.MC_VERSION + "/OpenEye.jar");
|
||||
FileUtils.forceMkdir(targetFile.getParentFile());
|
||||
|
||||
ReadableByteChannel in = Channels.newChannel(new URL(DOWNLOAD_URL).openStream());
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(DOWNLOAD_URL).openConnection();
|
||||
connection.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
ReadableByteChannel in = Channels.newChannel(connection.getInputStream());
|
||||
FileChannel out = new FileOutputStream(targetFile).getChannel();
|
||||
out.transferFrom(in, 0, Long.MAX_VALUE);
|
||||
} catch (Throwable e) {
|
||||
@@ -102,7 +107,7 @@ public class OpenEyeExtra implements Extra {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GuiPopup extends AbstractGuiPopup<GuiPopup> {
|
||||
public static final class GuiPopup extends AbstractGuiPopup<GuiPopup> {
|
||||
GuiPopup(GuiContainer container) {
|
||||
super(container);
|
||||
popup.addElements(null, new GuiIndicator().setColor(Colors.BLACK));
|
||||
|
||||
@@ -12,16 +12,16 @@ import org.apache.logging.log4j.Logger;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = ReplayModExtras.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModExtras.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModExtras {
|
||||
public static final String MOD_ID = "replaymod-extras";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModExtras instance;
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
|
||||
private static final List<Class<? extends Extra>> builtin = Arrays.asList(
|
||||
PlayerOverview.class,
|
||||
UriSchemeExtra.class,
|
||||
@@ -32,11 +32,11 @@ public class ReplayModExtras {
|
||||
OpenEyeExtra.class
|
||||
);
|
||||
|
||||
private Logger logger;
|
||||
public static Logger LOGGER;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
LOGGER = event.getModLog();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -44,9 +44,9 @@ public class ReplayModExtras {
|
||||
for (Class<? extends Extra> cls : builtin) {
|
||||
try {
|
||||
Extra extra = cls.newInstance();
|
||||
extra.register(core);
|
||||
extra.register(ReplayMod.instance);
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Failed to load extra " + cls.getName() + ": ", t);
|
||||
LOGGER.warn("Failed to load extra " + cls.getName() + ": ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@@ -21,14 +23,15 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerOverview implements Extra {
|
||||
@Mod.Instance(ReplayModReplay.MOD_ID)
|
||||
private static ReplayModReplay module;
|
||||
private ReplayModReplay module;
|
||||
|
||||
private final Set<UUID> hiddenPlayers = new HashSet<>();
|
||||
private boolean savingEnabled;
|
||||
|
||||
@Override
|
||||
public void register(final ReplayMod mod) throws Exception {
|
||||
this.module = ReplayModReplay.instance;
|
||||
|
||||
mod.getKeyBindingRegistry().registerKeyBinding("replaymod.input.playeroverview", Keyboard.KEY_B, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -56,6 +59,7 @@ public class PlayerOverview implements Extra {
|
||||
});
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
RenderManager renderManager = mod.getMinecraft().getRenderManager();
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -92,6 +96,14 @@ public class PlayerOverview implements Extra {
|
||||
hiddenPlayers.clear();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void oRenderHand(RenderHandEvent event) {
|
||||
Entity view = module.getCore().getMinecraft().getRenderViewEntity();
|
||||
if (view != null && isHidden(view.getUniqueID())) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSavingEnabled() {
|
||||
return savingEnabled;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.*;
|
||||
import de.johni0702.minecraft.gui.container.GuiClickable;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.function.Closeable;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
@@ -36,6 +41,7 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
public final GuiVerticalList playersScrollable = new GuiVerticalList(contentPanel)
|
||||
.setDrawSlider(true).setDrawShadow(true);
|
||||
public final GuiCheckbox saveCheckbox = new GuiCheckbox(contentPanel)
|
||||
.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.remembersettings.description"))
|
||||
.setI18nLabel("replaymod.gui.playeroverview.remembersettings");
|
||||
public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
@@ -43,14 +49,14 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||
playersScrollable.forEach(IGuiCheckbox.class).setChecked(true);
|
||||
}
|
||||
}.setLabel("").setChecked(true);
|
||||
}.setLabel("").setChecked(true).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.showall"));
|
||||
public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
public void onClick() {
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||
playersScrollable.forEach(IGuiCheckbox.class).setChecked(false);
|
||||
}
|
||||
}.setLabel("").setChecked(false);
|
||||
}.setLabel("").setChecked(false).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.hideall"));
|
||||
|
||||
{
|
||||
setBackground(Background.NONE);
|
||||
@@ -90,7 +96,7 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
renderer.bindTexture(texture);
|
||||
renderer.drawTexturedRect(0, 0, 8, 8, 16, 16, 8, 8, 64, 64);
|
||||
if (p.func_175148_a(EnumPlayerModelParts.HAT)) {
|
||||
if (p.isWearing(EnumPlayerModelParts.HAT)) {
|
||||
renderer.drawTexturedRect(0, 0, 40, 8, size.getWidth(), size.getHeight(), 8, 8, 64, 64);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.replaymod.extras.playeroverview;
|
||||
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.culling.ICamera;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class PlayerRenderHook extends RenderPlayer {
|
||||
private final PlayerOverview extra;
|
||||
@@ -14,7 +14,7 @@ public class PlayerRenderHook extends RenderPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(Entity entity, ICamera camera, double camX, double camY, double camZ) {
|
||||
public boolean shouldRender(AbstractClientPlayer entity, ICamera camera, double camX, double camY, double camZ) {
|
||||
return !extra.isHidden(entity.getUniqueID()) && super.shouldRender(entity, camera, camX, camY, camZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.Extra;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,14 +12,14 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
public class UriSchemeExtra implements Extra {
|
||||
@Mod.Instance(ReplayModOnline.MOD_ID)
|
||||
private static ReplayModOnline module;
|
||||
private ReplayModOnline module;
|
||||
|
||||
private ReplayMod mod;
|
||||
|
||||
@Override
|
||||
public void register(final ReplayMod mod) throws Exception {
|
||||
this.mod = mod;
|
||||
this.module = ReplayModOnline.instance;
|
||||
|
||||
UriScheme uriScheme = UriScheme.create();
|
||||
if (uriScheme == null) {
|
||||
|
||||
@@ -26,18 +26,19 @@ import java.io.IOException;
|
||||
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
|
||||
@Mod(modid = ReplayModOnline.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModOnline.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModOnline {
|
||||
public static final String MOD_ID = "replaymod-online";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModOnline instance;
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
private ReplayMod core;
|
||||
|
||||
@Mod.Instance(ReplayModReplay.MOD_ID)
|
||||
private static ReplayModReplay replayModule;
|
||||
private ReplayModReplay replayModule;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
@@ -53,6 +54,8 @@ public class ReplayModOnline {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
replayModule = ReplayModReplay.instance;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
@@ -64,8 +67,10 @@ public class ReplayModOnline {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
if (!getDownloadsFolder().mkdirs()) {
|
||||
logger.warn("Failed to create downloads folder: " + getDownloadsFolder());
|
||||
if (!getDownloadsFolder().exists()){
|
||||
if (!getDownloadsFolder().mkdirs()) {
|
||||
logger.warn("Failed to create downloads folder: " + getDownloadsFolder());
|
||||
}
|
||||
}
|
||||
|
||||
new GuiHandler(this).register();
|
||||
@@ -77,7 +82,7 @@ public class ReplayModOnline {
|
||||
// Initial login prompt
|
||||
if (!core.getSettingsRegistry().get(Setting.SKIP_LOGIN_PROMPT)) {
|
||||
if (!isLoggedIn()) {
|
||||
new GuiLoginPrompt(apiClient, null, null, false).display();
|
||||
core.runLater(() -> new GuiLoginPrompt(apiClient, GuiScreen.wrap(getMinecraft().currentScreen), null, false).display());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,19 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.SSL_SOCKET_FACTORY;
|
||||
|
||||
public class ApiClient {
|
||||
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
@@ -130,7 +136,11 @@ public class ApiClient {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.get_thumbnail);
|
||||
builder.put("id", file);
|
||||
URL url = new URL(builder.toString());
|
||||
return ImageIO.read(url);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
try (InputStream in = connection.getInputStream()) {
|
||||
return ImageIO.read(in);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cancelDownload = false;
|
||||
@@ -143,7 +153,8 @@ public class ApiClient {
|
||||
builder.put("id", file);
|
||||
String url = builder.toString();
|
||||
URL website = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) website.openConnection();
|
||||
HttpsURLConnection con = (HttpsURLConnection) website.openConnection();
|
||||
con.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
|
||||
int fileSize = con.getContentLength();
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@ import com.google.gson.JsonParser;
|
||||
import com.replaymod.online.api.replay.holders.ApiError;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.SSL_SOCKET_FACTORY;
|
||||
|
||||
public class SimpleApiClient {
|
||||
|
||||
private static final JsonParser jsonParser = new JsonParser();
|
||||
@@ -72,10 +74,11 @@ public class SimpleApiClient {
|
||||
// read response
|
||||
String responseContent = null;
|
||||
InputStream is = null;
|
||||
HttpURLConnection httpUrlConnection = null;
|
||||
HttpsURLConnection httpUrlConnection = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
httpUrlConnection = (HttpURLConnection) url.openConnection();
|
||||
httpUrlConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpUrlConnection.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
|
||||
httpUrlConnection.setRequestMethod("GET");
|
||||
|
||||
|
||||
@@ -9,16 +9,18 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.SSL_SOCKET_FACTORY;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class FileUploader {
|
||||
private static final Gson gson = new Gson();
|
||||
@@ -48,7 +50,8 @@ public class FileUploader {
|
||||
postData += "&name=" + URLEncoder.encode(filename, "UTF-8");
|
||||
|
||||
String url = ReplayModApiMethods.upload_file + postData;
|
||||
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
|
||||
con.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
con.setUseCaches(false);
|
||||
con.setDoOutput(true);
|
||||
con.setRequestMethod("POST");
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.replaymod.online.api.replay;
|
||||
|
||||
public class ReplayModApiMethods {
|
||||
|
||||
public static final String REPLAYMOD_BASE_URL = "http://ReplayMod.com/api/";
|
||||
public static final String REPLAYMOD_BASE_URL = "https://ReplayMod.com/api/";
|
||||
|
||||
public static final String register = REPLAYMOD_BASE_URL+"register";
|
||||
public static final String check_authkey = REPLAYMOD_BASE_URL+"check_authkey";
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
|
||||
private GuiLabel noAccountLabel = new GuiLabel(this).setI18nText("replaymod.gui.login.noacc");
|
||||
private GuiLabel statusLabel = new GuiLabel(this);
|
||||
private GuiButton loginButton = new GuiButton(this).setI18nLabel("replaymod.gui.login").setSize(150, 20).setEnabled(false);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
public GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20);
|
||||
private GuiTextField username = new GuiTextField(this).setSize(145, 20).setMaxLength(16).setFocused(true);
|
||||
private GuiPasswordField password = new GuiPasswordField(this).setSize(145, 20)
|
||||
|
||||
@@ -28,6 +28,7 @@ import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiButton;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiResourceLoadingList;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
@@ -109,6 +110,7 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
public void run() {
|
||||
GuiReplayEntry selected = list.getSelected();
|
||||
replayButtonPanel.forEach(IGuiButton.class).setEnabled(selected != null);
|
||||
replayButtonPanel.forEach(IGuiButton.class).setTooltip(null);
|
||||
if (selected != null) {
|
||||
int replayId = selected.fileInfo.getId();
|
||||
boolean favorited = favoritedReplays.contains(replayId);
|
||||
@@ -123,10 +125,22 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
favoriteButton.setI18nLabel("replaymod.gui.center." + (favorited ? "unfavorite" : "favorite"));
|
||||
// Only allow button usage for either unfavorite or favorite after they've actually downloaded it
|
||||
favoriteButton.setEnabled(favorited || selected.downloaded);
|
||||
if (favoriteButton.isEnabled()) {
|
||||
favoriteButton.setTooltip(null);
|
||||
} else {
|
||||
favoriteButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
}
|
||||
|
||||
// Similar for like/dislike buttons
|
||||
likeButton.setEnabled(selected.downloaded);
|
||||
dislikeButton.setEnabled(selected.downloaded);
|
||||
if (likeButton.isEnabled()) {
|
||||
likeButton.setTooltip(null);
|
||||
dislikeButton.setTooltip(null);
|
||||
} else {
|
||||
likeButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
dislikeButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
}
|
||||
likeButton.setI18nLabel("replaymod.gui." + (liked ? "removelike" : "like"));
|
||||
dislikeButton.setI18nLabel("replaymod.gui." + (disliked ? "removedislike" : "dislike"));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,12 @@ import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiTextArea;
|
||||
@@ -234,6 +239,8 @@ public class GuiUploadReplay extends GuiScreen {
|
||||
});
|
||||
|
||||
validateInputs();
|
||||
name.onTextChanged(s -> validateInputs());
|
||||
tags.onTextChanged(s -> validateInputs());
|
||||
}
|
||||
|
||||
public void validateInputs() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
@@ -11,7 +12,11 @@ import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.*;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiClickableContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
@@ -41,9 +46,16 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
||||
public final GuiButton overwriteButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
timelines.put(selectedEntry.name, currentTimeline);
|
||||
overwriteButton.setDisabled();
|
||||
save();
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this,
|
||||
new GuiLabel().setI18nText("replaymod.gui.keyframerepo.overwrite").setColor(Colors.BLACK)
|
||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||
Utils.addCallback(popup.getFuture(), doIt -> {
|
||||
if (doIt) {
|
||||
timelines.put(selectedEntry.name, currentTimeline);
|
||||
overwriteButton.setDisabled();
|
||||
save();
|
||||
}
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
}).setSize(75, 20).setI18nLabel("replaymod.gui.overwrite").setDisabled();
|
||||
public final GuiButton saveAsButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Restrictions;
|
||||
import com.replaymod.recording.handler.ConnectionEventHandler;
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -14,15 +16,17 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@Mod(modid = ReplayModRecording.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModRecording.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModRecording {
|
||||
public static final String MOD_ID = "replaymod-recording";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModRecording instance;
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
private ReplayMod core;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
@@ -31,6 +35,7 @@ public class ReplayModRecording {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
@@ -51,9 +56,12 @@ public class ReplayModRecording {
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
bus.register(connectionEventHandler = new ConnectionEventHandler(logger, core));
|
||||
|
||||
NetworkRegistry.INSTANCE.newSimpleChannel(Restrictions.PLUGIN_CHANNEL);
|
||||
NetworkRegistry.INSTANCE.newChannel(Restrictions.PLUGIN_CHANNEL, new RestrictionsChannelHandler());
|
||||
}
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
private static class RestrictionsChannelHandler extends ChannelDuplexHandler {}
|
||||
|
||||
public void initiateRecording(NetworkManager networkManager) {
|
||||
connectionEventHandler.onConnectedToServerEvent(networkManager);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.replaymod.recording.handler;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import net.minecraftforge.fml.common.network.handshake.FMLHandshakeMessage;
|
||||
|
||||
/**
|
||||
* Filters out all handshake packets that were sent for recording but must
|
||||
* not actually be handled.
|
||||
* This handler is only present when connected to the integrated server as
|
||||
* otherwise all packets must be handled.
|
||||
*
|
||||
* When in single player, the game state packets must never be handled
|
||||
* otherwise wired bugs related to semi-singletons can occur.
|
||||
* See https://bugs.replaymod.com/show_bug.cgi?id=44
|
||||
*/
|
||||
public class FMLHandshakeFilter extends SimpleChannelInboundHandler<FMLHandshakeMessage> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, FMLHandshakeMessage msg) throws Exception {
|
||||
if (!(msg instanceof FMLHandshakeMessage.RegistryData)) {
|
||||
// Pass on everything but RegistryData messages
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -41,14 +40,12 @@ public abstract class MixinNetHandlerPlayClient {
|
||||
if (gameController.thePlayer == null) return;
|
||||
|
||||
RecordingEventHandler handler = getRecordingEventHandler();
|
||||
if (handler != null && packet.func_179768_b() == S38PacketPlayerListItem.Action.ADD_PLAYER) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<S38PacketPlayerListItem.AddPlayerData> dataList = packet.func_179767_a();
|
||||
for (S38PacketPlayerListItem.AddPlayerData data : dataList) {
|
||||
if (data.func_179962_a() == null || data.func_179962_a().getId() == null) continue;
|
||||
if (handler != null && packet.getAction() == S38PacketPlayerListItem.Action.ADD_PLAYER) {
|
||||
for (S38PacketPlayerListItem.AddPlayerData data : packet.getEntries()) {
|
||||
if (data.getProfile() == null || data.getProfile().getId() == null) continue;
|
||||
// Only add spawn packet for our own player and only if he isn't known yet
|
||||
if (data.func_179962_a().getId().equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getId())
|
||||
&& !playerInfoMap.containsKey(data.func_179962_a().getId())) {
|
||||
if (data.getProfile().getId().equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getId())
|
||||
&& !playerInfoMap.containsKey(data.getProfile().getId())) {
|
||||
handler.onPlayerJoin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.FMLHandshakeFilter;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraftforge.fml.common.network.handshake.FMLHandshakeCodec;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -11,17 +15,32 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(value = NetworkDispatcher.class, remap = false)
|
||||
public abstract class MixinNetworkDispatcher {
|
||||
|
||||
@Shadow
|
||||
private Side side;
|
||||
|
||||
@Shadow
|
||||
private EmbeddedChannel handshakeChannel;
|
||||
|
||||
/**
|
||||
* Always sets fml:isLocal to false.
|
||||
* Always sets fml:isLocal to false on the server side.
|
||||
* This effectively removes the difference in the FML handshake between SP and MP
|
||||
* and forces the block/item ids, etc. to always be send.
|
||||
* This might have undesired side effects but at least it works at all.
|
||||
* Injects a {@link FMLHandshakeFilter} on the client side to filter out
|
||||
* those extra, unexpected packets.
|
||||
*/
|
||||
@Inject(method = "insertIntoChannel", at=@At("HEAD"))
|
||||
public void replayModRecording_forceIsLocalToFalse(CallbackInfo cb) {
|
||||
handshakeChannel.attr(NetworkDispatcher.IS_LOCAL).set(false);
|
||||
public void replayModRecording_setupForLocalRecording(CallbackInfo cb) {
|
||||
// If we're in multiplayer, everything is fine as is
|
||||
if (!handshakeChannel.attr(NetworkDispatcher.IS_LOCAL).get()) return;
|
||||
|
||||
if (side == Side.SERVER) {
|
||||
// On the server side, force all packets to be sent
|
||||
handshakeChannel.attr(NetworkDispatcher.IS_LOCAL).set(false);
|
||||
} else {
|
||||
// On the client side, discard additional packets
|
||||
ChannelPipeline pipeline = handshakeChannel.pipeline();
|
||||
pipeline.addAfter(pipeline.context(FMLHandshakeCodec.class).name(),
|
||||
"replaymod_filter", new FMLHandshakeFilter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
public void save(Packet packet) {
|
||||
try {
|
||||
if(packet instanceof S0CPacketSpawnPlayer) {
|
||||
UUID uuid = ((S0CPacketSpawnPlayer) packet).func_179819_c();
|
||||
UUID uuid = ((S0CPacketSpawnPlayer) packet).getPlayer();
|
||||
Set<String> uuids = new HashSet<>(Arrays.asList(metaData.getPlayers()));
|
||||
uuids.add(uuid.toString());
|
||||
metaData.setPlayers(uuids.toArray(new String[uuids.size()]));
|
||||
@@ -153,7 +153,7 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(packet instanceof S0DPacketCollectItem) {
|
||||
if(mc.thePlayer != null ||
|
||||
((S0DPacketCollectItem) packet).func_149353_d() == mc.thePlayer.getEntityId()) {
|
||||
((S0DPacketCollectItem) packet).getEntityID() == mc.thePlayer.getEntityId()) {
|
||||
super.channelRead(ctx, msg);
|
||||
return;
|
||||
}
|
||||
@@ -205,11 +205,11 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(packet instanceof S0CPacketSpawnPlayer) {
|
||||
S0CPacketSpawnPlayer p = (S0CPacketSpawnPlayer) packet;
|
||||
if (p.field_148960_i == null) {
|
||||
p.field_148960_i = new DataWatcher(null);
|
||||
if (p.watcher == null) {
|
||||
p.watcher = new DataWatcher(null);
|
||||
if(p.func_148944_c() != null) {
|
||||
for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_148944_c()) {
|
||||
p.field_148960_i.addObject(wo.getDataValueId(), wo.getObject());
|
||||
for(DataWatcher.WatchableObject wo : p.func_148944_c()) {
|
||||
p.watcher.addObject(wo.getDataValueId(), wo.getObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,9 @@ public class ResourcePackRecorder {
|
||||
boolean doWrite = false; // Whether we are the first and have to write it
|
||||
synchronized (replayFile) { // Need to read, modify and write the resource pack index atomically
|
||||
Map<Integer, String> index = replayFile.getResourcePackIndex();
|
||||
if (index == null) {
|
||||
index = new HashMap<>();
|
||||
}
|
||||
if (!index.containsValue(hash)) {
|
||||
// Hash is unknown, we have to write the resource pack ourselves
|
||||
doWrite = true;
|
||||
@@ -74,8 +78,8 @@ public class ResourcePackRecorder {
|
||||
final int requestId = nextRequestId++;
|
||||
final NetHandlerPlayClient netHandler = mc.getNetHandler();
|
||||
final NetworkManager netManager = netHandler.getNetworkManager();
|
||||
final String url = packet.func_179783_a();
|
||||
final String hash = packet.func_179784_b();
|
||||
final String url = packet.getURL();
|
||||
final String hash = packet.getHash();
|
||||
|
||||
if (url.startsWith("level://")) {
|
||||
String levelName = url.substring("level://".length());
|
||||
@@ -84,7 +88,7 @@ public class ResourcePackRecorder {
|
||||
|
||||
if (levelDir.isFile()) {
|
||||
netManager.sendPacket(new C19PacketResourcePackStatus(hash, C19PacketResourcePackStatus.Action.ACCEPTED));
|
||||
Futures.addCallback(mc.getResourcePackRepository().func_177319_a(levelDir), new FutureCallback() {
|
||||
Futures.addCallback(mc.getResourcePackRepository().setResourcePackInstance(levelDir), new FutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
recordResourcePack(levelDir, requestId);
|
||||
@@ -161,16 +165,16 @@ public class ResourcePackRecorder {
|
||||
}
|
||||
|
||||
final File file = new File(repo.dirServerResourcepacks, fileName);
|
||||
repo.field_177321_h.lock();
|
||||
repo.lock.lock();
|
||||
try {
|
||||
repo.func_148529_f();
|
||||
repo.clearResourcePack();
|
||||
|
||||
if (file.exists() && hash.length() == 40) {
|
||||
try {
|
||||
String fileHash = Hashing.sha1().hashBytes(Files.toByteArray(file)).toString();
|
||||
if (fileHash.equals(hash)) {
|
||||
recordResourcePack(file, requestId);
|
||||
return repo.func_177319_a(file);
|
||||
return repo.setResourcePackInstance(file);
|
||||
}
|
||||
|
||||
logger.warn("File " + file + " had wrong hash (expected " + hash + ", found " + fileHash + "). Deleting it.");
|
||||
@@ -186,13 +190,13 @@ public class ResourcePackRecorder {
|
||||
|
||||
Futures.getUnchecked(mc.addScheduledTask(() -> mc.displayGuiScreen(guiScreen)));
|
||||
|
||||
Map sessionInfo = Minecraft.getSessionInfo();
|
||||
repo.field_177322_i = HttpUtil.func_180192_a(file, url, sessionInfo, 50 * 1024 * 1024, guiScreen, mc.getProxy());
|
||||
Futures.addCallback(repo.field_177322_i, new FutureCallback() {
|
||||
Map<String, String> sessionInfo = Minecraft.getSessionInfo();
|
||||
repo.downloadingPacks = HttpUtil.downloadResourcePack(file, url, sessionInfo, 50 * 1024 * 1024, guiScreen, mc.getProxy());
|
||||
Futures.addCallback(repo.downloadingPacks, new FutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object value) {
|
||||
recordResourcePack(file, requestId);
|
||||
repo.func_177319_a(file);
|
||||
repo.setResourcePackInstance(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,9 +204,9 @@ public class ResourcePackRecorder {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
return repo.field_177322_i;
|
||||
return repo.downloadingPacks;
|
||||
} finally {
|
||||
repo.field_177321_h.unlock();
|
||||
repo.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.replaymod.render;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.lwjgl.util.ReadableColor;
|
||||
|
||||
@@ -45,7 +47,7 @@ public class RenderSettings {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return "-y -f rawvideo -pix_fmt rgb24 -s %WIDTH%x%HEIGHT% -r %FPS% -i - " + preset;
|
||||
return "-y -f rawvideo -pix_fmt rgb24 -s %WIDTH%x%HEIGHT% -r %FPS% -i - %FILTERS%" + preset;
|
||||
}
|
||||
|
||||
public String getFileExtension() {
|
||||
@@ -64,6 +66,19 @@ public class RenderSettings {
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum AntiAliasing {
|
||||
NONE(1), X2(2), X4(4), X8(8);
|
||||
|
||||
@Getter
|
||||
private final int factor;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return I18n.format("replaymod.gui.rendersettings.antialiasing." + name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
private final RenderMethod renderMethod;
|
||||
private final EncodingPreset encodingPreset;
|
||||
private final int videoWidth;
|
||||
@@ -78,9 +93,48 @@ public class RenderSettings {
|
||||
private final boolean stabilizeRoll;
|
||||
private final ReadableColor chromaKeyingColor;
|
||||
private final boolean inject360Metadata;
|
||||
private final AntiAliasing antiAliasing;
|
||||
|
||||
private final String exportCommand;
|
||||
private final String exportArguments;
|
||||
|
||||
private final boolean highPerformance;
|
||||
|
||||
/**
|
||||
* @return the width of the output video during rendering, including the upscale for Anti-Aliasing.
|
||||
*/
|
||||
public int getVideoWidth() {
|
||||
return videoWidth * antiAliasing.getFactor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the height of the output video during rendering, including the upscale for Anti-Aliasing.
|
||||
*/
|
||||
public int getVideoHeight() {
|
||||
return videoHeight * antiAliasing.getFactor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actual width of the output video.
|
||||
*/
|
||||
public int getTargetVideoWidth() {
|
||||
return videoWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actual height of the output video.
|
||||
*/
|
||||
public int getTargetVideoHeight() {
|
||||
return videoHeight;
|
||||
}
|
||||
|
||||
public String getVideoFilters() {
|
||||
if (antiAliasing == AntiAliasing.NONE) {
|
||||
return "";
|
||||
} else {
|
||||
double factor = 1.0 / antiAliasing.getFactor();
|
||||
return String.format("-vf scale=iw*%1$s:ih*%1$s ", factor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,39 @@
|
||||
package com.replaymod.render;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.render.utils.RenderJob;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = ReplayModRender.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModRender.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModRender {
|
||||
public static final String MOD_ID = "replaymod-render";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModRender instance;
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
private ReplayMod core;
|
||||
|
||||
private Logger logger;
|
||||
public static Logger LOGGER;
|
||||
|
||||
private Configuration configuration;
|
||||
private final List<RenderJob> renderQueue = new ArrayList<>();
|
||||
|
||||
public ReplayMod getCore() {
|
||||
return core;
|
||||
@@ -32,12 +41,20 @@ public class ReplayModRender {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
LOGGER = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
configuration = new Configuration(event.getSuggestedConfigurationFile());
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onReplayClose(ReplayCloseEvent.Post event) {
|
||||
renderQueue.clear();
|
||||
}
|
||||
|
||||
public File getVideoFolder() {
|
||||
String path = core.getSettingsRegistry().get(Setting.RENDER_PATH);
|
||||
File folder = new File(path.startsWith("./") ? core.getMinecraft().mcDataDir : null, path);
|
||||
@@ -52,4 +69,8 @@ public class ReplayModRender {
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public List<RenderJob> getRenderQueue() {
|
||||
return renderQueue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,27 @@ import com.replaymod.render.utils.StreamPipe;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.fml.common.versioning.ComparableVersion;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.output.TeeOutputStream;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
import static org.apache.commons.lang3.Validate.isTrue;
|
||||
|
||||
public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
@@ -43,10 +53,11 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
.replace("%HEIGHT%", String.valueOf(settings.getVideoHeight()))
|
||||
.replace("%FPS%", String.valueOf(settings.getFramesPerSecond()))
|
||||
.replace("%FILENAME%", fileName)
|
||||
.replace("%BITRATE%", String.valueOf(settings.getBitRate()));
|
||||
.replace("%BITRATE%", String.valueOf(settings.getBitRate()))
|
||||
.replace("%FILTERS%", settings.getVideoFilters());
|
||||
|
||||
String executable = settings.getExportCommand().isEmpty() ? "ffmpeg" : settings.getExportCommand();
|
||||
System.out.println("Starting " + settings.getExportCommand() + " with args: " + commandArgs);
|
||||
String executable = settings.getExportCommand().isEmpty() ? findFFmpeg() : settings.getExportCommand();
|
||||
System.out.println("Starting " + executable + " with args: " + commandArgs);
|
||||
String[] cmdline = new CommandLine(executable).addArguments(commandArgs).toStrings();
|
||||
process = new ProcessBuilder(cmdline).directory(outputFolder).start();
|
||||
File exportLogFile = new File(Minecraft.getMinecraft().mcDataDir, "export.log");
|
||||
@@ -57,6 +68,54 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
channel = Channels.newChannel(outputStream);
|
||||
}
|
||||
|
||||
private String findFFmpeg() {
|
||||
switch (Util.getOSType()) {
|
||||
case WINDOWS:
|
||||
// Allow windows users to unpack the ffmpeg archive into a sub-folder of their .minecraft folder
|
||||
File inDotMinecraft = new File(Minecraft.getMinecraft().mcDataDir, "ffmpeg/bin/ffmpeg.exe");
|
||||
if (inDotMinecraft.exists()) {
|
||||
LOGGER.debug("FFmpeg found in .minecraft/ffmpeg");
|
||||
return inDotMinecraft.getAbsolutePath();
|
||||
}
|
||||
break;
|
||||
case OSX:
|
||||
// The PATH doesn't seem to be set as expected on OSX, therefore we check some common locations ourselves
|
||||
for (String path : new String[]{"/usr/local/bin/ffmpeg", "/usr/bin/ffmpeg"}) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
LOGGER.debug("Found FFmpeg at {}", path);
|
||||
return path;
|
||||
} else {
|
||||
LOGGER.debug("FFmpeg not located at {}", path);
|
||||
}
|
||||
}
|
||||
// Homebrew doesn't seem to reliably symlink its installed binaries either
|
||||
File homebrewFolder = new File("/usr/local/Cellar/ffmpeg");
|
||||
String[] homebrewVersions = homebrewFolder.list();
|
||||
if (homebrewVersions != null) {
|
||||
Optional<File> latestOpt = Arrays.stream(homebrewVersions)
|
||||
.map(ComparableVersion::new) // Convert file name to comparable version
|
||||
.sorted(Comparator.reverseOrder()) // Sort for latest version
|
||||
.map(ComparableVersion::toString) // Convert back to file name
|
||||
.map(v -> new File(new File(homebrewFolder, v), "bin/ffmpeg")) // Convert to binary files
|
||||
.filter(File::exists) // Filter invalid installations (missing executable)
|
||||
.findFirst(); // Take first one
|
||||
if (latestOpt.isPresent()) {
|
||||
File latest = latestOpt.get();
|
||||
LOGGER.debug("Found {} versions of FFmpeg installed with homebrew, chose {}",
|
||||
homebrewVersions.length, latest);
|
||||
return latest.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LINUX: // Linux users are entrusted to have their PATH configured correctly (most package manager do this)
|
||||
case SOLARIS: // Never heard of anyone running this mod on Solaris having any problems
|
||||
case UNKNOWN: // Unknown OS, just try to use "ffmpeg"
|
||||
}
|
||||
LOGGER.debug("Using default FFmpeg executable");
|
||||
return "ffmpeg";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
|
||||
@@ -75,9 +75,9 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
linkState(1, "lightMapEnabled");
|
||||
linkState(2, "hurtTextureEnabled");
|
||||
final Program.Uniform uniform = shaderProgram.getUniformVariable("fogEnabled");
|
||||
previousFogState = GlStateManager.fogState.field_179049_a;
|
||||
previousFogState = GlStateManager.fogState.fog;
|
||||
uniform.set(previousFogState.currentState);
|
||||
GlStateManager.fogState.field_179049_a = new BooleanState(previousFogState.capability) {
|
||||
GlStateManager.fogState.fog = new BooleanState(previousFogState.capability) {
|
||||
@Override
|
||||
public void setState(boolean state) {
|
||||
super.setState(state);
|
||||
@@ -135,7 +135,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
GlStateManager.textureState[i].texture2DState = previousStates[i];
|
||||
}
|
||||
GlStateManager.fogState.field_179049_a = previousFogState;
|
||||
GlStateManager.fogState.fog = previousFogState;
|
||||
}
|
||||
|
||||
private class CubicStereoFrameCapturer extends CubicPboOpenGlFrameCapturer {
|
||||
|
||||
277
src/main/java/com/replaymod/render/gui/GuiRenderQueue.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.replaymod.render.gui;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.replaymod.render.ReplayModRender;
|
||||
import com.replaymod.render.rendering.VideoRenderer;
|
||||
import com.replaymod.render.utils.RenderJob;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.util.I18n;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiClickableContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
|
||||
public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> {
|
||||
private final GuiLabel title = new GuiLabel().setI18nText("replaymod.gui.renderqueue.title").setColor(Colors.BLACK);
|
||||
private final GuiVerticalList list = new GuiVerticalList().setDrawShadow(true).setDrawSlider(true);
|
||||
private final GuiButton addButton = new GuiButton().setI18nLabel("replaymod.gui.renderqueue.add").setSize(150, 20);
|
||||
private final GuiButton renameButton = new GuiButton().setI18nLabel("replaymod.gui.rename").setSize(73, 20);
|
||||
private final GuiButton removeButton = new GuiButton().setI18nLabel("replaymod.gui.remove").setSize(73, 20);
|
||||
private final GuiButton renderButton = new GuiButton().setI18nLabel("replaymod.gui.render").setSize(150, 20);
|
||||
private final GuiButton closeButton = new GuiButton().setI18nLabel("replaymod.gui.close").setSize(150, 20).onClick(this::close);
|
||||
|
||||
/*
|
||||
|
||||
|---------------------------------|
|
||||
| Add | Render |
|
||||
|---------------------------------|
|
||||
| Rename | Remove | Close |
|
||||
|---------------------------------|
|
||||
|
||||
*/
|
||||
private final GuiPanel buttonPanel = new GuiPanel()
|
||||
.setLayout(new GridLayout().setSpacingX(5).setSpacingY(5).setColumns(2))
|
||||
.addElements(null,
|
||||
addButton,
|
||||
renderButton,
|
||||
new GuiPanel().setLayout(new HorizontalLayout().setSpacing(4)).addElements(null,
|
||||
renameButton, removeButton),
|
||||
closeButton);
|
||||
|
||||
private final GuiContainer container;
|
||||
private Entry selectedEntry;
|
||||
|
||||
{
|
||||
popup.setLayout(new CustomLayout<GuiPanel>() {
|
||||
@Override
|
||||
protected void layout(GuiPanel container, int width, int height) {
|
||||
pos(title, width / 2 - width(title) / 2, 0);
|
||||
pos(list, 0, y(title) + height(title) + 5);
|
||||
pos(buttonPanel, width / 2 - width(buttonPanel) / 2, height - height(buttonPanel));
|
||||
size(list, width, y(buttonPanel) - y(list) - 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||
ReadableDimension screenSize = GuiRenderQueue.this.container.getMinSize();
|
||||
return new Dimension(screenSize.getWidth() - 40,
|
||||
screenSize.getHeight() - 20 - buttonPanel.getMinSize().getHeight() - title.getMinSize().getHeight());
|
||||
}
|
||||
}).addElements(null, title, list, buttonPanel);
|
||||
}
|
||||
|
||||
public GuiRenderQueue(GuiContainer container, GuiRenderSettings guiRenderSettings, ReplayHandler replayHandler, Timeline timeline) {
|
||||
super(container);
|
||||
this.container = container;
|
||||
LOGGER.trace("Opening render queue popup");
|
||||
|
||||
setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
|
||||
List<RenderJob> queue = ReplayModRender.instance.getRenderQueue();
|
||||
|
||||
for (RenderJob renderJob : queue) {
|
||||
LOGGER.trace("Adding {} to job queue list", renderJob);
|
||||
list.getListPanel().addElements(null, new Entry(renderJob));
|
||||
}
|
||||
|
||||
addButton.onClick(() -> {
|
||||
LOGGER.trace("Add button clicked");
|
||||
// Open popup
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(container)
|
||||
.setYesI18nLabel("replaymod.gui.add").setNoI18nLabel("replaymod.gui.cancel");
|
||||
popup.getInfo().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER).setSpacing(5));
|
||||
// Add content
|
||||
GuiLabel label = new GuiLabel().setI18nText("replaymod.gui.renderqueue.jobname").setColor(Colors.BLACK);
|
||||
GuiTextField nameField = new GuiTextField().setSize(150, 20).setFocused(true);
|
||||
popup.getInfo().addElements(new HorizontalLayout.Data(0.5), label, nameField);
|
||||
// Disable "Yes" button while name is empty
|
||||
nameField.onTextChanged(old -> popup.getYesButton().setEnabled(!nameField.getText().isEmpty())).onEnter(() -> {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
}
|
||||
});
|
||||
popup.getYesButton().setDisabled();
|
||||
// Register callback
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Boolean result) {
|
||||
if (result == Boolean.TRUE) {
|
||||
RenderJob newJob = new RenderJob();
|
||||
newJob.setName(nameField.getText());
|
||||
newJob.setSettings(guiRenderSettings.save(false));
|
||||
newJob.setTimeline(timeline);
|
||||
LOGGER.trace("Adding new job: {}", newJob);
|
||||
queue.add(newJob);
|
||||
list.getListPanel().addElements(null, new Entry(newJob));
|
||||
} else {
|
||||
LOGGER.trace("Adding cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
LOGGER.error("Add Job popup:", t);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (guiRenderSettings != null) {
|
||||
addButton.setEnabled(guiRenderSettings.renderButton.isEnabled());
|
||||
}
|
||||
|
||||
renameButton.onClick(() -> {
|
||||
LOGGER.trace("Rename button clicked for {}", selectedEntry.job);
|
||||
// Open popup
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(container)
|
||||
.setYesI18nLabel("replaymod.gui.rename").setNoI18nLabel("replaymod.gui.cancel");
|
||||
popup.getInfo().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER).setSpacing(5));
|
||||
// Add content
|
||||
GuiLabel label = new GuiLabel().setI18nText("replaymod.gui.renderqueue.jobname").setColor(Colors.BLACK);
|
||||
GuiTextField nameField = new GuiTextField().setSize(150, 20).setFocused(true)
|
||||
.setText(selectedEntry.job.getName());
|
||||
popup.getInfo().addElements(new HorizontalLayout.Data(0.5), label, nameField);
|
||||
// Disable "Yes" button while name is empty
|
||||
nameField.onTextChanged(old -> popup.getYesButton().setEnabled(!nameField.getText().isEmpty())).onEnter(() -> {
|
||||
if (popup.getYesButton().isEnabled()) {
|
||||
popup.getYesButton().onClick();
|
||||
}
|
||||
});
|
||||
// Register callback
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Boolean result) {
|
||||
if (result == Boolean.TRUE) {
|
||||
LOGGER.trace("Renaming {} to \"{}\"", selectedEntry.job, nameField.getText());
|
||||
selectedEntry.setName(nameField.getText());
|
||||
} else {
|
||||
LOGGER.trace("Renaming cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
LOGGER.error("Rename Job popup:", t);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
removeButton.onClick(() -> {
|
||||
LOGGER.trace("Remove button clicked for {}", selectedEntry.job);
|
||||
list.getListPanel().removeElement(selectedEntry);
|
||||
queue.remove(selectedEntry.job);
|
||||
selectedEntry = null;
|
||||
updateButtons();
|
||||
});
|
||||
|
||||
renderButton.onClick(() -> {
|
||||
LOGGER.trace("Render button clicked");
|
||||
// Close all GUIs (so settings in GuiRenderSettings are saved)
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
// Start rendering
|
||||
for (RenderJob renderJob : queue) {
|
||||
LOGGER.info("Starting render job {}", renderJob);
|
||||
try {
|
||||
VideoRenderer videoRenderer = new VideoRenderer(renderJob.getSettings(), replayHandler, renderJob.getTimeline());
|
||||
videoRenderer.renderVideo();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Rendering video:", e);
|
||||
GuiErrorScreen errorScreen = new GuiErrorScreen(I18n.format("replaymod.gui.rendering.error.title"),
|
||||
I18n.format("replaymod.gui.rendering.error.message"));
|
||||
getMinecraft().displayGuiScreen(errorScreen);
|
||||
return;
|
||||
} catch (Throwable t) {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(t, "Rendering video");
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiRenderQueue getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void updateButtons() {
|
||||
renameButton.setEnabled(selectedEntry != null);
|
||||
removeButton.setEnabled(selectedEntry != null);
|
||||
renderButton.setEnabled(!list.getListPanel().getChildren().isEmpty());
|
||||
}
|
||||
|
||||
public class Entry extends AbstractGuiClickableContainer<Entry> {
|
||||
public final GuiLabel label = new GuiLabel(this);
|
||||
public final RenderJob job;
|
||||
|
||||
public Entry(RenderJob job) {
|
||||
this.job = job;
|
||||
|
||||
setLayout(new CustomLayout<Entry>() {
|
||||
@Override
|
||||
protected void layout(Entry container, int width, int height) {
|
||||
pos(label, 5, height / 2 - height(label) / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||
return new Dimension(buttonPanel.calcMinSize().getWidth(), 16);
|
||||
}
|
||||
});
|
||||
label.setText(job.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
selectedEntry = this;
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
if (selectedEntry == this) {
|
||||
renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), Colors.BLACK);
|
||||
renderer.drawRect(0, 0, 2, size.getHeight(), Colors.WHITE);
|
||||
}
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
job.setName(name);
|
||||
label.setText(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entry getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,14 @@ import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import org.lwjgl.util.Color;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableColor;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
@@ -79,8 +80,8 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
}
|
||||
}).setMinSize(new Dimension(0, 20)).setValues(RenderSettings.EncodingPreset.values());
|
||||
|
||||
public final GuiNumberField videoWidth = new GuiNumberField().setSize(50, 20).setMinValue(1);
|
||||
public final GuiNumberField videoHeight = new GuiNumberField().setSize(50, 20).setMinValue(1);
|
||||
public final GuiNumberField videoWidth = new GuiNumberField().setSize(50, 20).setMinValue(1).setValidateOnFocusChange(true);
|
||||
public final GuiNumberField videoHeight = new GuiNumberField().setSize(50, 20).setMinValue(1).setValidateOnFocusChange(true);
|
||||
public final GuiSlider frameRateSlider = new GuiSlider().onValueChanged(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -92,7 +93,7 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
.setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(2))
|
||||
.addElements(new HorizontalLayout.Data(0.5), videoWidth, new GuiLabel().setText("*"), videoHeight);
|
||||
|
||||
public final GuiNumberField bitRateField = new GuiNumberField().setValue(10).setSize(50, 20);
|
||||
public final GuiNumberField bitRateField = new GuiNumberField().setValue(10).setSize(50, 20).setValidateOnFocusChange(true);
|
||||
public final GuiDropdownMenu<String> bitRateUnit = new GuiDropdownMenu<String>()
|
||||
.setSize(50, 20).setValues("bps", "kbps", "mbps").setSelected("mbps");
|
||||
|
||||
@@ -149,13 +150,18 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
public final GuiCheckbox inject360Metadata = new GuiCheckbox()
|
||||
.setI18nLabel("replaymod.gui.rendersettings.360metadata");
|
||||
|
||||
public final GuiDropdownMenu<RenderSettings.AntiAliasing> antiAliasingDropdown = new GuiDropdownMenu<RenderSettings.AntiAliasing>()
|
||||
.setSize(200, 20).setValues(RenderSettings.AntiAliasing.values()).setSelected(RenderSettings.AntiAliasing.NONE);
|
||||
|
||||
public final GuiPanel advancedPanel = new GuiPanel().setLayout(new VerticalLayout().setSpacing(15))
|
||||
.addElements(null, nametagCheckbox, new GuiPanel().setLayout(
|
||||
new GridLayout().setCellsEqualSize(false).setColumns(2).setSpacingX(5).setSpacingY(15))
|
||||
.addElements(new GridLayout.Data(0, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendersettings.stabilizecamera"), stabilizePanel,
|
||||
chromaKeyingCheckbox, chromaKeyingColor,
|
||||
inject360Metadata));
|
||||
inject360Metadata,
|
||||
new GuiLabel(), // to show the anti-aliasing options in a new line
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendersettings.antialiasing"), antiAliasingDropdown));
|
||||
|
||||
public final GuiTextField exportCommand = new GuiTextField().setI18nHint("replaymod.gui.rendersettings.command")
|
||||
.setSize(55, 20).setMaxLength(100);
|
||||
@@ -179,6 +185,12 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
|
||||
|
||||
public final GuiPanel buttonPanel = new GuiPanel(contentPanel).setLayout(new HorizontalLayout().setSpacing(4));
|
||||
public final GuiButton queueButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new GuiRenderQueue(GuiRenderSettings.this, GuiRenderSettings.this, replayHandler, timeline).open();
|
||||
}
|
||||
}).setSize(100, 20).setI18nLabel("replaymod.gui.renderqueue.open");
|
||||
public final GuiButton renderButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -198,13 +210,13 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
}).setSize(148, 20).setI18nLabel("replaymod.gui.render");
|
||||
}).setSize(100, 20).setI18nLabel("replaymod.gui.render");
|
||||
public final GuiButton cancelButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
}
|
||||
}).setSize(148, 20).setI18nLabel("replaymod.gui.cancel");
|
||||
}).setSize(100, 20).setI18nLabel("replaymod.gui.cancel");
|
||||
|
||||
{
|
||||
setBackground(Background.NONE);
|
||||
@@ -261,12 +273,10 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
this.timeline = timeline;
|
||||
|
||||
String json = getConfigProperty(ReplayModRender.instance.getConfiguration()).getString();
|
||||
RenderSettings settings = new GsonBuilder().registerTypeAdapter(RenderSettings.class, new InstanceCreator<RenderSettings>() {
|
||||
@Override
|
||||
public RenderSettings createInstance(Type type) {
|
||||
return getDefaultRenderSettings();
|
||||
}
|
||||
}).create().fromJson(json, RenderSettings.class);
|
||||
RenderSettings settings = new GsonBuilder()
|
||||
.registerTypeAdapter(RenderSettings.class, (InstanceCreator<RenderSettings>) type -> getDefaultRenderSettings())
|
||||
.registerTypeAdapter(ReadableColor.class, new Gson().getAdapter(Color.class))
|
||||
.create().fromJson(json, RenderSettings.class);
|
||||
load(settings);
|
||||
}
|
||||
|
||||
@@ -347,8 +357,8 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
public void load(RenderSettings settings) {
|
||||
renderMethodDropdown.setSelected(settings.getRenderMethod());
|
||||
encodingPresetDropdown.setSelected(settings.getEncodingPreset());
|
||||
videoWidth.setValue(settings.getVideoWidth());
|
||||
videoHeight.setValue(settings.getVideoHeight());
|
||||
videoWidth.setValue(settings.getTargetVideoWidth());
|
||||
videoHeight.setValue(settings.getTargetVideoHeight());
|
||||
frameRateSlider.setValue(settings.getFramesPerSecond() - 10);
|
||||
if (settings.getBitRate() % (1 << 20) == 0) {
|
||||
bitRateField.setValue(settings.getBitRate() >> 20);
|
||||
@@ -380,6 +390,7 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
chromaKeyingColor.setColor(settings.getChromaKeyingColor());
|
||||
}
|
||||
inject360Metadata.setChecked(settings.isInject360Metadata());
|
||||
antiAliasingDropdown.setSelected(settings.getAntiAliasing());
|
||||
exportCommand.setText(settings.getExportCommand());
|
||||
exportArguments.setText(settings.getExportArguments());
|
||||
|
||||
@@ -401,6 +412,7 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
stabilizeRoll.isChecked() && (serialize || stabilizeRoll.isEnabled()),
|
||||
chromaKeyingCheckbox.isChecked() ? chromaKeyingColor.getColor() : null,
|
||||
inject360Metadata.isChecked() && (serialize || inject360Metadata.isEnabled()),
|
||||
antiAliasingDropdown.getSelectedValue(),
|
||||
exportCommand.getText(),
|
||||
exportArguments.getText(),
|
||||
net.minecraft.client.gui.GuiScreen.isCtrlKeyDown()
|
||||
@@ -415,7 +427,7 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
|
||||
private RenderSettings getDefaultRenderSettings() {
|
||||
return new RenderSettings(RenderSettings.RenderMethod.DEFAULT, RenderSettings.EncodingPreset.MP4_DEFAULT, 1920, 1080, 60, 10 << 20, null,
|
||||
true, false, false, false, null, false, "", RenderSettings.EncodingPreset.MP4_DEFAULT.getValue(), false);
|
||||
true, false, false, false, null, false, RenderSettings.AntiAliasing.NONE, "", RenderSettings.EncodingPreset.MP4_DEFAULT.getValue(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -431,4 +443,8 @@ public class GuiRenderSettings extends GuiScreen implements Closeable {
|
||||
return configuration.get("rendersettings", "settings", "{}",
|
||||
"Last state of the render settings GUI. Internal use only.");
|
||||
}
|
||||
|
||||
public ReplayHandler getReplayHandler() {
|
||||
return replayHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ChunkLoadingRenderGlobal {
|
||||
|
||||
private final RenderGlobal hooked;
|
||||
private final ChunkRenderDispatcher renderDispatcher;
|
||||
private final JailingQueue<?> workerJailingQueue;
|
||||
private final JailingQueue<ChunkCompileTaskGenerator> workerJailingQueue;
|
||||
private final CustomChunkRenderWorker renderWorker;
|
||||
private int frame;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ChunkLoadingRenderGlobal {
|
||||
this.renderWorker = new CustomChunkRenderWorker(renderDispatcher, new RegionRenderCacheBuilder());
|
||||
|
||||
int workerThreads = renderDispatcher.listThreadedWorkers.size();
|
||||
BlockingQueue<Object> queueChunkUpdates = renderDispatcher.queueChunkUpdates;
|
||||
BlockingQueue<ChunkCompileTaskGenerator> queueChunkUpdates = renderDispatcher.queueChunkUpdates;
|
||||
workerJailingQueue = new JailingQueue<>(queueChunkUpdates);
|
||||
renderDispatcher.queueChunkUpdates = workerJailingQueue;
|
||||
ChunkCompileTaskGenerator element = new ChunkCompileTaskGenerator(null, null);
|
||||
@@ -51,7 +51,6 @@ public class ChunkLoadingRenderGlobal {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void updateChunks() {
|
||||
while (renderDispatcher.runChunkUploads(0)) {
|
||||
hooked.displayListEntitiesDirty = true;
|
||||
@@ -59,7 +58,7 @@ public class ChunkLoadingRenderGlobal {
|
||||
|
||||
while (!renderDispatcher.queueChunkUpdates.isEmpty()) {
|
||||
try {
|
||||
renderWorker.processTask((ChunkCompileTaskGenerator) renderDispatcher.queueChunkUpdates.poll());
|
||||
renderWorker.processTask(renderDispatcher.queueChunkUpdates.poll());
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(EffectRenderer.class)
|
||||
public abstract class MixinEffectRenderer {
|
||||
@Redirect(method = "renderParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;func_180434_a(Lnet/minecraft/client/renderer/WorldRenderer;Lnet/minecraft/entity/Entity;FFFFFF)V"))
|
||||
@Redirect(method = "renderParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;renderParticle(Lnet/minecraft/client/renderer/WorldRenderer;Lnet/minecraft/entity/Entity;FFFFFF)V"))
|
||||
private void renderNormalParticle(EntityFX fx, WorldRenderer worldRenderer, Entity view, float partialTicks,
|
||||
float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
|
||||
renderParticle(fx, worldRenderer, view, partialTicks, rotX, rotXZ, rotZ, rotYZ, rotXY);
|
||||
}
|
||||
|
||||
@Redirect(method = "renderLitParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;func_180434_a(Lnet/minecraft/client/renderer/WorldRenderer;Lnet/minecraft/entity/Entity;FFFFFF)V"))
|
||||
@Redirect(method = "renderLitParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;renderParticle(Lnet/minecraft/client/renderer/WorldRenderer;Lnet/minecraft/entity/Entity;FFFFFF)V"))
|
||||
private void renderLitParticle(EntityFX fx, WorldRenderer worldRenderer, Entity view, float partialTicks,
|
||||
float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
|
||||
renderParticle(fx, worldRenderer, view, partialTicks, rotX, rotXZ, rotZ, rotYZ, rotXY);
|
||||
@@ -42,6 +42,6 @@ public abstract class MixinEffectRenderer {
|
||||
rotYZ = (float) (-rotZ * Math.sin(pitch));
|
||||
rotXY = (float) (rotX * Math.sin(pitch));
|
||||
}
|
||||
fx.func_180434_a(worldRenderer, view, partialTicks, rotX, rotXZ, rotZ, rotYZ, rotXY);
|
||||
fx.renderParticle(worldRenderer, view, partialTicks, rotX, rotXZ, rotZ, rotYZ, rotXY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.render.rendering;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.pathing.player.AbstractTimelinePlayer;
|
||||
import com.replaymod.pathing.player.ReplayTimer;
|
||||
import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.render.RenderSettings;
|
||||
import com.replaymod.render.ReplayModRender;
|
||||
@@ -55,6 +56,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
private boolean debugInfoWasShown;
|
||||
private Map originalSoundLevels;
|
||||
|
||||
private TimelinePlayer timelinePlayer;
|
||||
private Future<Void> timelinePlayerFuture;
|
||||
private ChunkLoadingRenderGlobal chunkLoadingRenderGlobal;
|
||||
|
||||
@@ -174,7 +176,8 @@ public class VideoRenderer implements RenderInfo {
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
timelinePlayerFuture = new TimelinePlayer(replayHandler).start(timeline);
|
||||
timelinePlayer = new TimelinePlayer(replayHandler);
|
||||
timelinePlayerFuture = timelinePlayer.start(timeline);
|
||||
|
||||
if (!OpenGlHelper.isFramebufferEnabled()) {
|
||||
Display.setResizable(false);
|
||||
@@ -216,7 +219,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
|
||||
updateDisplaySize();
|
||||
|
||||
ScaledResolution scaled = new ScaledResolution(mc, displayWidth, displayHeight);
|
||||
ScaledResolution scaled = new ScaledResolution(mc);
|
||||
gui.toMinecraft().setWorldAndResolution(mc, scaled.getScaledWidth(), scaled.getScaledHeight());
|
||||
|
||||
chunkLoadingRenderGlobal = new ChunkLoadingRenderGlobal(mc.renderGlobal);
|
||||
@@ -229,6 +232,8 @@ public class VideoRenderer implements RenderInfo {
|
||||
if (!timelinePlayerFuture.isDone()) {
|
||||
timelinePlayerFuture.cancel(false);
|
||||
}
|
||||
// Tear down of the timeline player might only happen the next tick after it was cancelled
|
||||
timelinePlayer.onTick(new ReplayTimer.UpdatedEvent());
|
||||
|
||||
if (!OpenGlHelper.isFramebufferEnabled()) {
|
||||
Display.setResizable(true);
|
||||
@@ -281,7 +286,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
|
||||
ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
ScaledResolution scaled = new ScaledResolution(mc);
|
||||
gui.toMinecraft().setWorldAndResolution(mc, scaled.getScaledWidth(), scaled.getScaledHeight());
|
||||
|
||||
try {
|
||||
|
||||
12
src/main/java/com/replaymod/render/utils/RenderJob.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.replaymod.render.utils;
|
||||
|
||||
import com.replaymod.render.RenderSettings;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RenderJob {
|
||||
private String name;
|
||||
private Timeline timeline;
|
||||
private RenderSettings settings;
|
||||
}
|
||||
@@ -16,8 +16,6 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
@@ -45,7 +43,7 @@ public class NoGuiScreenshot {
|
||||
mc.getFramebuffer().bindFramebuffer(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
|
||||
mc.entityRenderer.updateCameraAndRender(mc.timer.renderPartialTicks);
|
||||
mc.entityRenderer.updateCameraAndRender(mc.timer.renderPartialTicks, System.nanoTime());
|
||||
|
||||
mc.getFramebuffer().unbindFramebuffer();
|
||||
GlStateManager.popMatrix();
|
||||
@@ -101,9 +99,7 @@ public class NoGuiScreenshot {
|
||||
// of the game loop. We cannot use the addScheduledTask method as it'll run the task if called
|
||||
// from the minecraft thread which is exactly what we want to avoid.
|
||||
synchronized (mc.scheduledTasks) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Queue<FutureTask> queue = mc.scheduledTasks;
|
||||
queue.add(ListenableFutureTask.create(runnable, null));
|
||||
mc.scheduledTasks.add(ListenableFutureTask.create(runnable, null));
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
@@ -209,6 +209,9 @@ public class ReplayHandler {
|
||||
*/
|
||||
public void spectateEntity(Entity e) {
|
||||
CameraEntity cameraEntity = getCameraEntity();
|
||||
if (cameraEntity == null) {
|
||||
return; // Cannot spectate if we have no camera
|
||||
}
|
||||
if (e == null || e == cameraEntity) {
|
||||
spectating = null;
|
||||
e = cameraEntity;
|
||||
@@ -311,7 +314,7 @@ public class ReplayHandler {
|
||||
mc.getFramebuffer().bindFramebuffer(true);
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
|
||||
ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
ScaledResolution resolution = new ScaledResolution(mc);
|
||||
guiScreen.setWorldAndResolution(mc, resolution.getScaledWidth(), resolution.getScaledHeight());
|
||||
guiScreen.drawScreen(0, 0, 0);
|
||||
|
||||
@@ -329,9 +332,7 @@ public class ReplayHandler {
|
||||
replaySender.setReplaySpeed(0);
|
||||
|
||||
mc.getNetHandler().getNetworkManager().processReceivedPackets();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Entity> entities = (List<Entity>) mc.theWorld.loadedEntityList;
|
||||
for (Entity entity : entities) {
|
||||
for (Entity entity : mc.theWorld.loadedEntityList) {
|
||||
if (entity instanceof EntityOtherPlayerMP) {
|
||||
EntityOtherPlayerMP e = (EntityOtherPlayerMP) entity;
|
||||
e.setPosition(e.otherPlayerMPX, e.otherPlayerMPY, e.otherPlayerMPZ);
|
||||
|
||||
@@ -6,7 +6,11 @@ import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.ModCompat;
|
||||
import com.replaymod.replay.camera.*;
|
||||
import com.replaymod.replay.camera.CameraController;
|
||||
import com.replaymod.replay.camera.CameraControllerRegistry;
|
||||
import com.replaymod.replay.camera.CameraEntity;
|
||||
import com.replaymod.replay.camera.ClassicCameraController;
|
||||
import com.replaymod.replay.camera.VanillaCameraController;
|
||||
import com.replaymod.replay.gui.overlay.GuiMarkerTimeline;
|
||||
import com.replaymod.replay.gui.screen.GuiModCompatWarning;
|
||||
import com.replaymod.replay.handler.GuiHandler;
|
||||
@@ -28,15 +32,17 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod(modid = ReplayModReplay.MOD_ID, useMetadata = true)
|
||||
@Mod(modid = ReplayModReplay.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModReplay {
|
||||
public static final String MOD_ID = "replaymod-replay";
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModReplay instance;
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
private ReplayMod core;
|
||||
|
||||
private final CameraControllerRegistry cameraControllerRegistry = new CameraControllerRegistry();
|
||||
|
||||
@@ -51,6 +57,7 @@ public class ReplayModReplay {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
@@ -96,6 +103,7 @@ public class ReplayModReplay {
|
||||
@Override
|
||||
public void onSuccess(NoGuiScreenshot result) {
|
||||
try {
|
||||
core.printInfoToChat("replaymod.chat.savingthumb");
|
||||
replayHandler.getReplayFile().writeThumb(result.getImage());
|
||||
core.printInfoToChat("replaymod.chat.savedthumb");
|
||||
} catch (IOException e) {
|
||||
@@ -106,6 +114,7 @@ public class ReplayModReplay {
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
core.printWarningToChat("replaymod.chat.failedthumb");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
if (p instanceof S40PacketDisconnect) {
|
||||
IChatComponent reason = ((S40PacketDisconnect) p).func_149165_c();
|
||||
IChatComponent reason = ((S40PacketDisconnect) p).getReason();
|
||||
if ("Please update to view this replay.".equals(reason.getUnformattedText())) {
|
||||
// This version of the mod supports replay restrictions so we are allowed
|
||||
// to remove this packet.
|
||||
@@ -368,7 +368,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(p instanceof S48PacketResourcePackSend) {
|
||||
S48PacketResourcePackSend packet = (S48PacketResourcePackSend) p;
|
||||
String url = packet.func_179783_a();
|
||||
String url = packet.getURL();
|
||||
if (url.startsWith("replay://")) {
|
||||
int id = Integer.parseInt(url.substring("replay://".length()));
|
||||
Map<Integer, String> index = replayFile.getResourcePackIndex();
|
||||
@@ -379,7 +379,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
if (!file.exists()) {
|
||||
IOUtils.copy(replayFile.getResourcePack(hash).get(), new FileOutputStream(file));
|
||||
}
|
||||
mc.getResourcePackRepository().func_177319_a(file);
|
||||
mc.getResourcePackRepository().setResourcePackInstance(file);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -403,8 +403,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(p instanceof S07PacketRespawn) {
|
||||
S07PacketRespawn respawn = (S07PacketRespawn) p;
|
||||
p = new S07PacketRespawn(respawn.func_149082_c(),
|
||||
respawn.func_149081_d(), respawn.func_149080_f(), GameType.SPECTATOR);
|
||||
p = new S07PacketRespawn(respawn.getDimensionID(),
|
||||
respawn.getDifficulty(), respawn.getWorldType(), GameType.SPECTATOR);
|
||||
|
||||
allowMovement = true;
|
||||
}
|
||||
@@ -431,8 +431,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
if(cent != null) {
|
||||
if(!allowMovement && !((Math.abs(cent.posX - ppl.func_148932_c()) > TP_DISTANCE_LIMIT) ||
|
||||
(Math.abs(cent.posZ - ppl.func_148933_e()) > TP_DISTANCE_LIMIT))) {
|
||||
if(!allowMovement && !((Math.abs(cent.posX - ppl.getX()) > TP_DISTANCE_LIMIT) ||
|
||||
(Math.abs(cent.posZ - ppl.getZ()) > TP_DISTANCE_LIMIT))) {
|
||||
return null;
|
||||
} else {
|
||||
allowMovement = false;
|
||||
@@ -451,7 +451,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
CameraEntity cent = replayHandler.getCameraEntity();
|
||||
cent.setCameraPosition(ppl.func_148932_c(), ppl.func_148928_d(), ppl.func_148933_e());
|
||||
cent.setCameraPosition(ppl.getX(), ppl.getY(), ppl.getZ());
|
||||
return null;
|
||||
}
|
||||
}.call();
|
||||
@@ -459,7 +459,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(p instanceof S2BPacketChangeGameState) {
|
||||
S2BPacketChangeGameState pg = (S2BPacketChangeGameState)p;
|
||||
int reason = pg.func_149138_c();
|
||||
int reason = pg.getGameState();
|
||||
|
||||
// only allow the following packets:
|
||||
// 1 - End raining
|
||||
@@ -695,7 +695,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
|
||||
if(p instanceof S0EPacketSpawnObject) {
|
||||
S0EPacketSpawnObject pso = (S0EPacketSpawnObject)p;
|
||||
int type = pso.func_148993_l();
|
||||
int type = pso.getType();
|
||||
if(type == 76) { // Firework rocket
|
||||
return null;
|
||||
}
|
||||
@@ -789,28 +789,28 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
private void convertLegacyEntityIds(Packet packet) {
|
||||
if (packet instanceof S0CPacketSpawnPlayer) {
|
||||
S0CPacketSpawnPlayer p = (S0CPacketSpawnPlayer) packet;
|
||||
if (p.field_148957_a == LEGACY_ENTITY_ID) {
|
||||
p.field_148957_a = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S18PacketEntityTeleport) {
|
||||
S18PacketEntityTeleport p = (S18PacketEntityTeleport) packet;
|
||||
if (p.field_149458_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149458_a = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S14PacketEntity.S17PacketEntityLookMove) {
|
||||
S14PacketEntity.S17PacketEntityLookMove p = (S14PacketEntity.S17PacketEntityLookMove) packet;
|
||||
if (p.field_149074_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149074_a = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S19PacketEntityHeadLook) {
|
||||
S19PacketEntityHeadLook p = (S19PacketEntityHeadLook) packet;
|
||||
if (p.field_149384_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149384_a = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S12PacketEntityVelocity) {
|
||||
S12PacketEntityVelocity p = (S12PacketEntityVelocity) packet;
|
||||
if (p.field_149417_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149417_a = actualID;
|
||||
if (p.entityID == LEGACY_ENTITY_ID) {
|
||||
p.entityID = actualID;
|
||||
}
|
||||
} else if (packet instanceof S0BPacketAnimation) {
|
||||
S0BPacketAnimation p = (S0BPacketAnimation) packet;
|
||||
@@ -819,26 +819,26 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
} else if (packet instanceof S04PacketEntityEquipment) {
|
||||
S04PacketEntityEquipment p = (S04PacketEntityEquipment) packet;
|
||||
if (p.field_149394_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149394_a = actualID;
|
||||
if (p.entityID == LEGACY_ENTITY_ID) {
|
||||
p.entityID = actualID;
|
||||
}
|
||||
} else if (packet instanceof S1BPacketEntityAttach) {
|
||||
S1BPacketEntityAttach p = (S1BPacketEntityAttach) packet;
|
||||
if (p.field_149408_a == LEGACY_ENTITY_ID) {
|
||||
p.field_149408_a = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
if (p.field_149406_b == LEGACY_ENTITY_ID) {
|
||||
p.field_149406_b = actualID;
|
||||
if (p.vehicleEntityId == LEGACY_ENTITY_ID) {
|
||||
p.vehicleEntityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S0DPacketCollectItem) {
|
||||
S0DPacketCollectItem p = (S0DPacketCollectItem) packet;
|
||||
if (p.field_149356_b == LEGACY_ENTITY_ID) {
|
||||
p.field_149356_b = actualID;
|
||||
if (p.entityId == LEGACY_ENTITY_ID) {
|
||||
p.entityId = actualID;
|
||||
}
|
||||
} else if (packet instanceof S13PacketDestroyEntities) {
|
||||
S13PacketDestroyEntities p = (S13PacketDestroyEntities) packet;
|
||||
if (p.field_149100_a.length == 1 && p.field_149100_a[0] == LEGACY_ENTITY_ID) {
|
||||
p.field_149100_a[0] = actualID;
|
||||
if (p.entityIDs.length == 1 && p.entityIDs[0] == LEGACY_ENTITY_ID) {
|
||||
p.entityIDs[0] = actualID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +252,15 @@ public class CameraEntity extends EntityPlayerSP {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible() {
|
||||
Entity view = mc.getRenderViewEntity();
|
||||
if (view != this) {
|
||||
return view.isInvisible();
|
||||
}
|
||||
return super.isInvisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getLocationSkin() {
|
||||
Entity view = mc.getRenderViewEntity();
|
||||
|
||||
@@ -16,6 +16,10 @@ import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.ReadablePoint;
|
||||
|
||||
public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> implements Typeable {
|
||||
private static GuiNumberField newGuiNumberField() {
|
||||
return new GuiNumberField().setSize(150, 20).setValidateOnFocusChange(true);
|
||||
}
|
||||
|
||||
private final ReplayHandler replayHandler;
|
||||
private final Marker marker;
|
||||
|
||||
@@ -23,15 +27,15 @@ public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> imp
|
||||
|
||||
public final GuiTextField nameField = new GuiTextField().setSize(150, 20);
|
||||
// TODO: Replace with a min/sec/msec field
|
||||
public final GuiNumberField timeField = new GuiNumberField().setSize(150, 20).setPrecision(0);
|
||||
public final GuiNumberField timeField = newGuiNumberField().setPrecision(0);
|
||||
|
||||
public final GuiNumberField xField = new GuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField yField = new GuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField zField = new GuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField xField = newGuiNumberField().setPrecision(10);
|
||||
public final GuiNumberField yField = newGuiNumberField().setPrecision(10);
|
||||
public final GuiNumberField zField = newGuiNumberField().setPrecision(10);
|
||||
|
||||
public final GuiNumberField yawField = new GuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField pitchField = new GuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField rollField = new GuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField yawField = newGuiNumberField().setPrecision(5);
|
||||
public final GuiNumberField pitchField = newGuiNumberField().setPrecision(5);
|
||||
public final GuiNumberField rollField = newGuiNumberField().setPrecision(5);
|
||||
|
||||
public final GuiPanel inputs = GuiPanel.builder()
|
||||
.layout(new GridLayout().setColumns(2).setSpacingX(7).setSpacingY(3))
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.List;
|
||||
|
||||
public class GuiHandler {
|
||||
private static final int BUTTON_EXIT_SERVER = 1;
|
||||
private static final int BUTTON_RETURN_TO_GAME = 4;
|
||||
private static final int BUTTON_ACHIEVEMENTS = 5;
|
||||
private static final int BUTTON_STATS = 6;
|
||||
private static final int BUTTON_OPEN_TO_LAN = 7;
|
||||
@@ -49,6 +48,7 @@ public class GuiHandler {
|
||||
// Pause replay when menu is opened
|
||||
mod.getReplayHandler().getReplaySender().setReplaySpeed(0);
|
||||
|
||||
GuiButton achievements = null, stats = null, openToLan = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = event.buttonList;
|
||||
for(GuiButton b : new ArrayList<>(buttonList)) {
|
||||
@@ -60,15 +60,39 @@ public class GuiHandler {
|
||||
break;
|
||||
// Remove "Achievements", "Stats" and "Open to LAN" buttons
|
||||
case BUTTON_ACHIEVEMENTS:
|
||||
buttonList.remove(achievements = b);
|
||||
break;
|
||||
case BUTTON_STATS:
|
||||
buttonList.remove(stats = b);
|
||||
break;
|
||||
case BUTTON_OPEN_TO_LAN:
|
||||
buttonList.remove(b);
|
||||
}
|
||||
// Move all buttons except the "Return to game" button upwards
|
||||
if (b.id != BUTTON_RETURN_TO_GAME) {
|
||||
b.yPosition -= 48;
|
||||
buttonList.remove(openToLan = b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (achievements != null && stats != null) {
|
||||
moveAllButtonsDirectlyBelowUpwards(buttonList, achievements.yPosition,
|
||||
achievements.xPosition, stats.xPosition + stats.width);
|
||||
}
|
||||
if (openToLan != null) {
|
||||
moveAllButtonsDirectlyBelowUpwards(buttonList, openToLan.yPosition,
|
||||
openToLan.xPosition, openToLan.xPosition + openToLan.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves all buttons that are within a rectangle below a certain y coordinate upwards by 24 units.
|
||||
* @param buttons List of buttons
|
||||
* @param belowY The Y limit
|
||||
* @param xStart Left x limit of the rectangle
|
||||
* @param xEnd Right x limit of the rectangle
|
||||
*/
|
||||
private void moveAllButtonsDirectlyBelowUpwards(List<GuiButton> buttons, int belowY, int xStart, int xEnd) {
|
||||
for (GuiButton button : buttons) {
|
||||
if (button.yPosition >= belowY && button.xPosition <= xEnd && button.xPosition + button.width >= xStart) {
|
||||
button.yPosition -= 24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ArmorStandRenderer.class)
|
||||
public abstract class MixinArmorStandRenderer {
|
||||
@Inject(method = "func_177099_b", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "canRenderName", at = @At("HEAD"), cancellable = true)
|
||||
private void replayModReplay_canRenderInvisibleName(EntityArmorStand entity, CallbackInfoReturnable<Boolean> ci) {
|
||||
EntityPlayer thePlayer = Minecraft.getMinecraft().thePlayer;
|
||||
if (thePlayer instanceof CameraEntity && entity.isInvisible()) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(TileEntityEndPortalRenderer.class)
|
||||
public class MixinTileEntityEndPortalRenderer {
|
||||
@Redirect(method = "func_180544_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getSystemTime()J"))
|
||||
@Redirect(method = "renderTileEntityAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getSystemTime()J"))
|
||||
private long replayModReplay_getEnchantmentTime() {
|
||||
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
|
||||
if (replayHandler != null) {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.replaymod.simplepathing;
|
||||
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CatmullRomSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum InterpolatorType {
|
||||
DEFAULT("default", null, null),
|
||||
CATMULL_ROM("catmullrom", CatmullRomSplineInterpolator.class, () -> new CatmullRomSplineInterpolator(0.5)),
|
||||
CUBIC("cubic", CubicSplineInterpolator.class, CubicSplineInterpolator::new),
|
||||
LINEAR("linear", LinearInterpolator.class, LinearInterpolator::new);
|
||||
|
||||
@Getter
|
||||
private String localizationKey;
|
||||
|
||||
@Getter
|
||||
private Class<? extends Interpolator> interpolatorClass;
|
||||
|
||||
private Supplier<Interpolator> interpolatorConstructor;
|
||||
|
||||
public String getI18nName() {
|
||||
return String.format("replaymod.gui.editkeyframe.interpolator.%1$s.name", localizationKey);
|
||||
}
|
||||
|
||||
public String getI18nDescription() {
|
||||
return String.format("replaymod.gui.editkeyframe.interpolator.%1$s.desc", localizationKey);
|
||||
}
|
||||
|
||||
public static InterpolatorType fromString(String string) {
|
||||
for (InterpolatorType t : values()) {
|
||||
if (t.getI18nName().equals(string)) return t;
|
||||
}
|
||||
return CATMULL_ROM; //the default
|
||||
}
|
||||
|
||||
public static InterpolatorType fromClass(Class<? extends Interpolator> cls) {
|
||||
for (InterpolatorType type : values()) {
|
||||
if (cls.equals(type.getInterpolatorClass())) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
public Interpolator newInstance() {
|
||||
return interpolatorConstructor.get();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,41 @@
|
||||
package com.replaymod.simplepathing;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.events.SettingsChangedEvent;
|
||||
import com.replaymod.pathing.properties.CameraProperties;
|
||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||
import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.impl.TimelineImpl;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||
import com.replaymod.simplepathing.gui.GuiPathing;
|
||||
import com.replaymod.simplepathing.preview.PathPreview;
|
||||
import lombok.Getter;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Mod(modid = ReplayModSimplePathing.MOD_ID, useMetadata = true)
|
||||
public class ReplayModSimplePathing implements PathingRegistry {
|
||||
@Mod(modid = ReplayModSimplePathing.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
useMetadata = true)
|
||||
public class ReplayModSimplePathing {
|
||||
public static final String MOD_ID = "replaymod-simplepathing";
|
||||
|
||||
@Mod.Instance(ReplayMod.MOD_ID)
|
||||
private static ReplayMod core;
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static ReplayModSimplePathing instance;
|
||||
|
||||
private Logger logger;
|
||||
private ReplayMod core;
|
||||
|
||||
public static Logger LOGGER;
|
||||
|
||||
private GuiPathing guiPathing;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
LOGGER = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
@@ -47,88 +43,77 @@ public class ReplayModSimplePathing implements PathingRegistry {
|
||||
|
||||
PathPreview pathPreview = new PathPreview(this);
|
||||
pathPreview.register();
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.keyframerepository", Keyboard.KEY_X, () -> {
|
||||
if (guiPathing != null) guiPathing.keyframeRepoButtonPressed();
|
||||
});
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
||||
if (guiPathing != null) guiPathing.clearKeyframesButtonPressed();
|
||||
});
|
||||
core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
||||
if (guiPathing != null) guiPathing.syncTimeButtonPressed();
|
||||
});
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||
if (guiPathing != null) guiPathing.deleteButtonPressed();
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void postReplayOpen(ReplayOpenEvent.Post event) {
|
||||
clearCurrentTimeline();
|
||||
guiPathing = new GuiPathing(core, this, event.getReplayHandler());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onReplayClose(ReplayCloseEvent.Post event) {
|
||||
currentTimeline = null;
|
||||
guiPathing = null;
|
||||
currentTimeline = createTimeline();
|
||||
currentTimeline.createPath();
|
||||
currentTimeline.createPath();
|
||||
selectedKeyframe = null;
|
||||
selectedPath = null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSettingsChanged(SettingsChangedEvent event) {
|
||||
if (event.getKey() == Setting.LINEAR_INTERPOLATION) {
|
||||
if (event.getKey() == Setting.DEFAULT_INTERPOLATION) {
|
||||
if (currentTimeline != null && guiPathing != null) {
|
||||
currentTimeline.applyChange(guiPathing.updateInterpolators());
|
||||
updateDefaultInterpolatorType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Timeline currentTimeline = createTimeline(); { currentTimeline.createPath(); currentTimeline.createPath(); }
|
||||
private Keyframe selectedKeyframe;
|
||||
private SPTimeline currentTimeline;
|
||||
|
||||
public Keyframe getSelectedKeyframe() {
|
||||
return selectedKeyframe;
|
||||
@Getter
|
||||
private SPPath selectedPath;
|
||||
@Getter
|
||||
private long selectedTime;
|
||||
|
||||
public boolean isSelected(Keyframe keyframe) {
|
||||
return selectedPath != null && currentTimeline.getKeyframe(selectedPath, selectedTime) == keyframe;
|
||||
}
|
||||
|
||||
public void setSelectedKeyframe(Keyframe selected) {
|
||||
this.selectedKeyframe = selected;
|
||||
public void setSelected(SPPath path, long time) {
|
||||
selectedPath = path;
|
||||
selectedTime = time;
|
||||
}
|
||||
|
||||
public void setCurrentTimeline(Timeline currentTimeline) {
|
||||
if (this.currentTimeline != currentTimeline) {
|
||||
selectedKeyframe = null;
|
||||
}
|
||||
this.currentTimeline = currentTimeline;
|
||||
public void setCurrentTimeline(SPTimeline newTimeline) {
|
||||
selectedPath = null;
|
||||
currentTimeline = newTimeline;
|
||||
updateDefaultInterpolatorType();
|
||||
}
|
||||
|
||||
public Timeline getCurrentTimeline() {
|
||||
public void clearCurrentTimeline() {
|
||||
setCurrentTimeline(new SPTimeline());
|
||||
}
|
||||
|
||||
public SPTimeline getCurrentTimeline() {
|
||||
return currentTimeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timeline createTimeline() {
|
||||
Timeline timeline = new TimelineImpl();
|
||||
|
||||
timeline.registerProperty(TimestampProperty.PROPERTY);
|
||||
timeline.registerProperty(CameraProperties.POSITION);
|
||||
timeline.registerProperty(CameraProperties.ROTATION);
|
||||
timeline.registerProperty(SpectatorProperty.PROPERTY);
|
||||
|
||||
return timeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeInterpolator(JsonWriter writer, Interpolator interpolator) throws IOException {
|
||||
if (interpolator instanceof LinearInterpolator) {
|
||||
writer.value("linear");
|
||||
} else if (interpolator instanceof CubicSplineInterpolator) {
|
||||
writer.value("cubic-spline");
|
||||
} else {
|
||||
throw new IOException("Unknown interpolator type: " + interpolator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interpolator deserializeInterpolator(JsonReader reader) throws IOException {
|
||||
String type = reader.nextString();
|
||||
switch (type) {
|
||||
case "linear":
|
||||
return new LinearInterpolator();
|
||||
case "cubic-spline":
|
||||
return new CubicSplineInterpolator();
|
||||
default:
|
||||
throw new IOException("Unknown interpolation type: " + type);
|
||||
|
||||
}
|
||||
private void updateDefaultInterpolatorType() {
|
||||
InterpolatorType newDefaultType =
|
||||
InterpolatorType.fromString(core.getSettingsRegistry().get(Setting.DEFAULT_INTERPOLATION));
|
||||
currentTimeline.setDefaultInterpolatorType(newDefaultType);
|
||||
}
|
||||
|
||||
public ReplayMod getCore() {
|
||||
|
||||
680
src/main/java/com/replaymod/simplepathing/SPTimeline.java
Normal file
@@ -0,0 +1,680 @@
|
||||
package com.replaymod.simplepathing;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.pathing.properties.CameraProperties;
|
||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||
import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.change.AddKeyframe;
|
||||
import com.replaymod.replaystudio.pathing.change.Change;
|
||||
import com.replaymod.replaystudio.pathing.change.CombinedChange;
|
||||
import com.replaymod.replaystudio.pathing.change.SetInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.change.UpdateKeyframeProperties;
|
||||
import com.replaymod.replaystudio.pathing.impl.TimelineImpl;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CatmullRomSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.PathSegment;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.pathing.property.Property;
|
||||
import com.replaymod.replaystudio.util.EntityPositionTracker;
|
||||
import com.replaymod.replaystudio.util.Location;
|
||||
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.replaymod.replaystudio.pathing.change.RemoveKeyframe.create;
|
||||
import static com.replaymod.simplepathing.ReplayModSimplePathing.LOGGER;
|
||||
|
||||
/**
|
||||
* Simplified timeline abstraction used in the SimplePathing module.
|
||||
*/
|
||||
public class SPTimeline implements PathingRegistry {
|
||||
public enum SPPath {
|
||||
TIME,
|
||||
POSITION,
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final Timeline timeline;
|
||||
@Getter
|
||||
private final Path timePath;
|
||||
@Getter
|
||||
private final Path positionPath;
|
||||
|
||||
@Getter
|
||||
private EntityPositionTracker entityTracker;
|
||||
private InterpolatorType defaultInterpolatorType;
|
||||
|
||||
public SPTimeline() {
|
||||
this(createInitialTimeline());
|
||||
}
|
||||
|
||||
public SPTimeline(Timeline timeline) {
|
||||
this.timeline = timeline;
|
||||
this.timePath = timeline.getPaths().get(SPPath.TIME.ordinal());
|
||||
this.positionPath = timeline.getPaths().get(SPPath.POSITION.ordinal());
|
||||
}
|
||||
|
||||
public Path getPath(SPPath path) {
|
||||
switch (path) {
|
||||
case TIME:
|
||||
return getTimePath();
|
||||
case POSITION:
|
||||
return getPositionPath();
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown path " + path);
|
||||
}
|
||||
|
||||
public Keyframe getKeyframe(SPPath path, long keyframe) {
|
||||
return getPath(path).getKeyframe(keyframe);
|
||||
}
|
||||
|
||||
public void setEntityTracker(EntityPositionTracker entityTracker) {
|
||||
Preconditions.checkState(this.entityTracker == null, "Entity tracker already set");
|
||||
this.entityTracker = entityTracker;
|
||||
}
|
||||
|
||||
public void setDefaultInterpolatorType(InterpolatorType defaultInterpolatorType) {
|
||||
Validate.isTrue(defaultInterpolatorType != InterpolatorType.DEFAULT, "Must not be DEFAULT");
|
||||
this.defaultInterpolatorType = Validate.notNull(defaultInterpolatorType);
|
||||
|
||||
if (entityTracker != null) {
|
||||
timeline.pushChange(updateInterpolators());
|
||||
}
|
||||
}
|
||||
|
||||
public Change setDefaultInterpolator(Interpolator interpolator) {
|
||||
Preconditions.checkState(defaultInterpolatorType != null, "Default interpolator type not set.");
|
||||
Validate.isInstanceOf(defaultInterpolatorType.getInterpolatorClass(), interpolator);
|
||||
|
||||
registerPositionInterpolatorProperties(interpolator);
|
||||
|
||||
Change change = CombinedChange.create(
|
||||
positionPath.getSegments().stream()
|
||||
// Ignore explicitly set segments
|
||||
.filter(s -> !s.getStartKeyframe().getValue(ExplicitInterpolationProperty.PROPERTY).isPresent())
|
||||
// Ignore spectator segments
|
||||
.filter(s -> !isSpectatorSegment(s))
|
||||
// Update interpolator for every remaining segment
|
||||
// This will create a fragmented interpolator which is split by the updateInterpolators call
|
||||
.map(s -> SetInterpolator.create(s, interpolator)).toArray(Change[]::new)
|
||||
);
|
||||
change.apply(timeline);
|
||||
return CombinedChange.createFromApplied(change, updateInterpolators());
|
||||
}
|
||||
|
||||
public boolean isTimeKeyframe(long time) {
|
||||
return timePath.getKeyframe(time) != null;
|
||||
}
|
||||
|
||||
public boolean isPositionKeyframe(long time) {
|
||||
return positionPath.getKeyframe(time) != null;
|
||||
}
|
||||
|
||||
public boolean isSpectatorKeyframe(long time) {
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
return keyframe != null && keyframe.getValue(SpectatorProperty.PROPERTY).isPresent();
|
||||
}
|
||||
|
||||
public void addPositionKeyframe(long time, double posX, double posY, double posZ,
|
||||
float yaw, float pitch, float roll, int spectated) {
|
||||
LOGGER.debug("Adding position keyframe at {} pos {}/{}/{} rot {}/{}/{} entId {}",
|
||||
time, posX, posY, posZ, yaw, pitch, roll, spectated);
|
||||
|
||||
Path path = positionPath;
|
||||
|
||||
Preconditions.checkState(positionPath.getKeyframe(time) == null, "Keyframe already exists");
|
||||
|
||||
Change change = AddKeyframe.create(path, time);
|
||||
change.apply(timeline);
|
||||
Keyframe keyframe = path.getKeyframe(time);
|
||||
|
||||
UpdateKeyframeProperties.Builder builder = UpdateKeyframeProperties.create(path, keyframe);
|
||||
builder.setValue(CameraProperties.POSITION, Triple.of(posX, posY, posZ));
|
||||
builder.setValue(CameraProperties.ROTATION, Triple.of(yaw, pitch, roll));
|
||||
if (spectated != -1) {
|
||||
builder.setValue(SpectatorProperty.PROPERTY, spectated);
|
||||
}
|
||||
UpdateKeyframeProperties updateChange = builder.done();
|
||||
updateChange.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, updateChange);
|
||||
|
||||
// If this new keyframe formed the first segment of the path
|
||||
if (path.getSegments().size() == 1) {
|
||||
// then create an initial interpolator of default type
|
||||
PathSegment segment = path.getSegments().iterator().next();
|
||||
Interpolator interpolator = createDefaultInterpolator();
|
||||
SetInterpolator setInterpolator = SetInterpolator.create(segment, interpolator);
|
||||
setInterpolator.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, setInterpolator);
|
||||
}
|
||||
|
||||
// Update interpolators for spectator keyframes
|
||||
// while this is overkill, it is far simpler than updating differently for every possible case
|
||||
change = CombinedChange.createFromApplied(change, updateInterpolators());
|
||||
|
||||
Change specPosUpdate = updateSpectatorPositions();
|
||||
specPosUpdate.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, specPosUpdate);
|
||||
|
||||
timeline.pushChange(change);
|
||||
}
|
||||
|
||||
public Change updatePositionKeyframe(long time, double posX, double posY, double posZ,
|
||||
float yaw, float pitch, float roll) {
|
||||
LOGGER.debug("Updating position keyframe at {} to pos {}/{}/{} rot {}/{}/{}",
|
||||
time, posX, posY, posZ, yaw, pitch, roll);
|
||||
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exists");
|
||||
Preconditions.checkState(!keyframe.getValue(SpectatorProperty.PROPERTY).isPresent(), "Cannot update spectator keyframe");
|
||||
|
||||
Change change = UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(CameraProperties.POSITION, Triple.of(posX, posY, posZ))
|
||||
.setValue(CameraProperties.ROTATION, Triple.of(yaw, pitch, roll))
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
public void removePositionKeyframe(long time) {
|
||||
LOGGER.debug("Removing position keyframe at {}", time);
|
||||
|
||||
Path path = positionPath;
|
||||
Keyframe keyframe = path.getKeyframe(time);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "No keyframe at that time");
|
||||
|
||||
Change change = create(path, keyframe);
|
||||
change.apply(timeline);
|
||||
|
||||
// Update interpolators for spectator keyframes
|
||||
// while this is overkill, it is far simpler than updating differently for every possible case
|
||||
change = CombinedChange.createFromApplied(change, updateInterpolators());
|
||||
|
||||
Change specPosUpdate = updateSpectatorPositions();
|
||||
specPosUpdate.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, specPosUpdate);
|
||||
|
||||
timeline.pushChange(change);
|
||||
}
|
||||
|
||||
public void addTimeKeyframe(long time, int replayTime) {
|
||||
LOGGER.debug("Adding time keyframe at {} time {}", time, replayTime);
|
||||
|
||||
Path path = timePath;
|
||||
|
||||
Preconditions.checkState(path.getKeyframe(time) == null, "Keyframe already exists");
|
||||
|
||||
Change change = AddKeyframe.create(path, time);
|
||||
change.apply(timeline);
|
||||
Keyframe keyframe = path.getKeyframe(time);
|
||||
|
||||
UpdateKeyframeProperties updateChange = UpdateKeyframeProperties.create(path, keyframe)
|
||||
.setValue(TimestampProperty.PROPERTY, replayTime)
|
||||
.done();
|
||||
updateChange.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, updateChange);
|
||||
|
||||
// If this new keyframe formed the first segment of the path
|
||||
if (path.getSegments().size() == 1) {
|
||||
// then create an initial interpolator
|
||||
PathSegment segment = path.getSegments().iterator().next();
|
||||
Interpolator interpolator = new LinearInterpolator();
|
||||
interpolator.registerProperty(TimestampProperty.PROPERTY);
|
||||
SetInterpolator setInterpolator = SetInterpolator.create(segment, interpolator);
|
||||
setInterpolator.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, setInterpolator);
|
||||
}
|
||||
|
||||
Change specPosUpdate = updateSpectatorPositions();
|
||||
specPosUpdate.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, specPosUpdate);
|
||||
|
||||
timeline.pushChange(change);
|
||||
}
|
||||
|
||||
public Change updateTimeKeyframe(long time, int replayTime) {
|
||||
LOGGER.debug("Updating time keyframe at {} to time {}", time, replayTime);
|
||||
|
||||
Keyframe keyframe = timePath.getKeyframe(time);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exists");
|
||||
|
||||
Change change = UpdateKeyframeProperties.create(timePath, keyframe)
|
||||
.setValue(TimestampProperty.PROPERTY, replayTime)
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
public void removeTimeKeyframe(long time) {
|
||||
LOGGER.debug("Removing time keyframe at {}", time);
|
||||
|
||||
Path path = timePath;
|
||||
Keyframe keyframe = path.getKeyframe(time);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "No keyframe at that time");
|
||||
|
||||
Change change = create(path, keyframe);
|
||||
change.apply(timeline);
|
||||
|
||||
Change specPosUpdate = updateSpectatorPositions();
|
||||
specPosUpdate.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, specPosUpdate);
|
||||
|
||||
timeline.pushChange(change);
|
||||
}
|
||||
|
||||
public Change setInterpolatorToDefault(long time) {
|
||||
LOGGER.debug("Setting interpolator of position keyframe at {} to the default", time);
|
||||
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exists");
|
||||
|
||||
Change change = UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.removeProperty(ExplicitInterpolationProperty.PROPERTY)
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return CombinedChange.createFromApplied(change, updateInterpolators());
|
||||
}
|
||||
|
||||
public Change setInterpolator(long time, Interpolator interpolator) {
|
||||
LOGGER.debug("Setting interpolator of position keyframe at {} to {}", time, interpolator);
|
||||
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exists");
|
||||
PathSegment segment = positionPath.getSegments().stream().filter(s -> s.getStartKeyframe() == keyframe)
|
||||
.findFirst().orElseThrow(() -> new IllegalStateException("Keyframe has no following segment."));
|
||||
|
||||
registerPositionInterpolatorProperties(interpolator);
|
||||
|
||||
Change change = CombinedChange.create(
|
||||
UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(ExplicitInterpolationProperty.PROPERTY, ObjectUtils.NULL)
|
||||
.done(),
|
||||
SetInterpolator.create(segment, interpolator)
|
||||
);
|
||||
change.apply(timeline);
|
||||
return CombinedChange.createFromApplied(change, updateInterpolators());
|
||||
}
|
||||
|
||||
public Change moveKeyframe(SPPath spPath, long oldTime, long newTime) {
|
||||
LOGGER.debug("Moving keyframe on {} from {} to {}", spPath, oldTime, newTime);
|
||||
Path path = getPath(spPath);
|
||||
Keyframe keyframe = path.getKeyframe(oldTime);
|
||||
|
||||
Preconditions.checkState(keyframe != null, "No keyframe at specified time");
|
||||
|
||||
// Interpolator of the first segment might be required later if it is the only one
|
||||
Optional<Interpolator> firstInterpolator =
|
||||
path.getSegments().stream().findFirst().map(PathSegment::getInterpolator);
|
||||
|
||||
// The interpolator that will be lost once we remove the old keyframe and has to be restored afterwards
|
||||
Optional<Interpolator> lostInterpolator = path.getSegments().stream().filter(s -> {
|
||||
// If this is the last keyframe,
|
||||
if (Iterables.getLast(path.getKeyframes()) == keyframe) {
|
||||
return s.getEndKeyframe() == keyframe; // the previous interpolator will be lost
|
||||
} else { // otherwise
|
||||
return s.getStartKeyframe() == keyframe; // the following interpolator will be lost
|
||||
}
|
||||
}).findFirst().map(PathSegment::getInterpolator);
|
||||
|
||||
// First remove the old keyframe
|
||||
Change removeChange = create(path, keyframe);
|
||||
removeChange.apply(timeline);
|
||||
|
||||
// and add a new one at the correct time
|
||||
Change addChange = AddKeyframe.create(path, newTime);
|
||||
addChange.apply(timeline);
|
||||
|
||||
// Then copy over all properties
|
||||
UpdateKeyframeProperties.Builder builder = UpdateKeyframeProperties.create(path, path.getKeyframe(newTime));
|
||||
for (Property property : keyframe.getProperties()) {
|
||||
copyProperty(property, keyframe, builder);
|
||||
}
|
||||
Change propertyChange = builder.done();
|
||||
propertyChange.apply(timeline);
|
||||
|
||||
|
||||
Change restoreInterpolatorChange;
|
||||
Keyframe newKf = path.getKeyframe(newTime);
|
||||
if (Iterables.getLast(path.getKeyframes()) != newKf) { // Unless this is the last keyframe
|
||||
// the interpolator of the following segment has been lost and needs to be restored
|
||||
restoreInterpolatorChange = lostInterpolator.<Change>flatMap(interpolator ->
|
||||
path.getSegments().stream().filter(s -> s.getStartKeyframe() == newKf).findFirst().map(segment ->
|
||||
SetInterpolator.create(segment, interpolator)
|
||||
)
|
||||
).orElseGet(CombinedChange::create);
|
||||
} else { // If it is the last keyframe however,
|
||||
// the interpolator of the previous segment has been lost and needs to be restored
|
||||
restoreInterpolatorChange = path.getSegments().stream().filter(s -> s.getEndKeyframe() == newKf)
|
||||
.findFirst().flatMap(segment -> lostInterpolator.map(interpolator -> {
|
||||
// additionally, if the interpolation of this keyframe was set to explicit, that property
|
||||
// has to be transferred to the start keyframe of the new segment
|
||||
if (newKf.getValue(ExplicitInterpolationProperty.PROPERTY).isPresent()) {
|
||||
return CombinedChange.create(
|
||||
SetInterpolator.create(segment, interpolator),
|
||||
UpdateKeyframeProperties.create(path, segment.getStartKeyframe())
|
||||
.setValue(ExplicitInterpolationProperty.PROPERTY, ObjectUtils.NULL).done()
|
||||
);
|
||||
} else {
|
||||
return SetInterpolator.create(segment, interpolator);
|
||||
}
|
||||
})).orElseGet(CombinedChange::create);
|
||||
}
|
||||
restoreInterpolatorChange.apply(timeline);
|
||||
|
||||
// Finally update the interpolators
|
||||
Change interpolatorUpdateChange;
|
||||
if (spPath == SPPath.POSITION) {
|
||||
// Position / Spectator keyframes need special handling
|
||||
interpolatorUpdateChange = updateInterpolators();
|
||||
} else {
|
||||
// Time keyframes only need updating when only one segment of them exists
|
||||
if (path.getSegments().size() == 1) {
|
||||
assert firstInterpolator.isPresent() : "One segment should have existed before as well";
|
||||
interpolatorUpdateChange = SetInterpolator.create(path.getSegments().iterator().next(), firstInterpolator.get());
|
||||
} else {
|
||||
interpolatorUpdateChange = CombinedChange.create(); // Noop change
|
||||
}
|
||||
interpolatorUpdateChange.apply(timeline);
|
||||
}
|
||||
|
||||
// and update spectator positions
|
||||
Change spectatorChange = updateSpectatorPositions();
|
||||
spectatorChange.apply(timeline);
|
||||
|
||||
return CombinedChange.createFromApplied(removeChange, addChange, propertyChange,
|
||||
restoreInterpolatorChange, interpolatorUpdateChange, spectatorChange);
|
||||
}
|
||||
|
||||
// Helper method because generics cannot be defined on blocks
|
||||
private <T> void copyProperty(Property<T> property, Keyframe from, UpdateKeyframeProperties.Builder to) {
|
||||
from.getValue(property).ifPresent(value -> to.setValue(property, value));
|
||||
}
|
||||
|
||||
private Change updateInterpolators() {
|
||||
Collection<PathSegment> pathSegments = positionPath.getSegments();
|
||||
// Contains updated pathsegment-interpolator mappings, may be changed multiple times over the course of this method
|
||||
Map<PathSegment, Interpolator> updates = new HashMap<>();
|
||||
|
||||
// First, setup spectator interpolators
|
||||
Interpolator interpolator = null;
|
||||
// Iterate through all segments
|
||||
for (PathSegment segment : pathSegments) {
|
||||
if (isSpectatorSegment(segment)) {
|
||||
// If the last segment was a spectator segment, then use its interpolator for this segment as well
|
||||
if (interpolator == null) {
|
||||
// otherwise create a new interpolator
|
||||
interpolator = new LinearInterpolator();
|
||||
interpolator.registerProperty(SpectatorProperty.PROPERTY);
|
||||
}
|
||||
// Now that we have an interpolator, set it for the current segment
|
||||
updates.put(segment, interpolator);
|
||||
} else {
|
||||
// Not a spectator segment, make sure we don't re-use the last interpolator (it would not be continuous)
|
||||
interpolator = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Then, if required, replace old default interpolators with new ones
|
||||
pathSegments.stream()
|
||||
// Ignore explicitly set segments
|
||||
.filter(s -> !s.getStartKeyframe().getValue(ExplicitInterpolationProperty.PROPERTY).isPresent())
|
||||
// Ignore spectator segments
|
||||
.filter(s -> !isSpectatorSegment(s))
|
||||
// Ignore already correct segments, should ignore all if default hasn't changed
|
||||
.filter(s -> !s.getInterpolator().getClass().equals(defaultInterpolatorType.getInterpolatorClass()))
|
||||
// Finally, set the interpolators
|
||||
// This will create one interpolator per segment, they will be merged later
|
||||
.forEach(segment -> updates.put(segment, createDefaultInterpolator()));
|
||||
|
||||
// All interpolators should now be set appropriately but may still be fragmented.
|
||||
// Cleaning that up is a two step process
|
||||
|
||||
// Firstly, all interpolators that are not continuous need to be split up
|
||||
Interpolator lastInterpolator = null;
|
||||
Set<Interpolator> used = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
for (PathSegment segment : pathSegments) {
|
||||
if (isSpectatorSegment(segment)) {
|
||||
lastInterpolator = null;
|
||||
continue; // Chain broken by spectator segment
|
||||
}
|
||||
|
||||
Interpolator currentInterpolator = updates.getOrDefault(segment, segment.getInterpolator());
|
||||
if (lastInterpolator == currentInterpolator) {
|
||||
continue; // All fine, interpolator is still continuous
|
||||
}
|
||||
|
||||
// New interpolator, make sure it hasn't been used before
|
||||
if (!used.add(interpolator)) {
|
||||
// It has been used before, we need to clone it and use the clone instead
|
||||
// This will create a new interpolator for each segment which will be merged later
|
||||
currentInterpolator = cloneInterpolator(currentInterpolator);
|
||||
updates.put(segment, currentInterpolator);
|
||||
}
|
||||
lastInterpolator = currentInterpolator;
|
||||
}
|
||||
|
||||
// Secondly, all neighbouring interpolators that are equal need to be merged
|
||||
lastInterpolator = null;
|
||||
String lastInterpolatorSerialized = null;
|
||||
for (PathSegment segment : pathSegments) {
|
||||
if (isSpectatorSegment(segment)) {
|
||||
lastInterpolator = null;
|
||||
lastInterpolatorSerialized = null;
|
||||
continue; // Spectator segments are continuous by construction
|
||||
}
|
||||
Interpolator currentInterpolator = updates.getOrDefault(segment, segment.getInterpolator());
|
||||
String serialized = serializeInterpolator(currentInterpolator);
|
||||
if (lastInterpolator != currentInterpolator && serialized.equals(lastInterpolatorSerialized)) {
|
||||
// This interpolator is equal to the last one but not the same, needs merging
|
||||
updates.put(segment, lastInterpolator);
|
||||
continue;
|
||||
}
|
||||
// New interpolator, not related to the previous one, merged by definition
|
||||
lastInterpolator = currentInterpolator;
|
||||
lastInterpolatorSerialized = serialized;
|
||||
}
|
||||
|
||||
Change change = CombinedChange.create(updates.entrySet().stream()
|
||||
.map(e -> SetInterpolator.create(e.getKey(), e.getValue())).toArray(Change[]::new));
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
private boolean isSpectatorSegment(PathSegment segment) {
|
||||
return segment.getStartKeyframe().getValue(SpectatorProperty.PROPERTY).isPresent()
|
||||
&& segment.getEndKeyframe().getValue(SpectatorProperty.PROPERTY).isPresent();
|
||||
}
|
||||
|
||||
private Change updateSpectatorPositions() {
|
||||
List<Change> changes = new ArrayList<>();
|
||||
timePath.updateAll();
|
||||
for (Keyframe keyframe : positionPath.getKeyframes()) {
|
||||
Optional<Integer> spectator = keyframe.getValue(SpectatorProperty.PROPERTY);
|
||||
if (spectator.isPresent()) {
|
||||
Optional<Integer> time = timePath.getValue(TimestampProperty.PROPERTY, keyframe.getTime());
|
||||
if (!time.isPresent()) {
|
||||
continue; // No time keyframes set at this video time, cannot determine replay time
|
||||
}
|
||||
Location expected = entityTracker.getEntityPositionAtTimestamp(spectator.get(), time.get());
|
||||
if (expected == null) {
|
||||
continue; // We don't have any data on this entity for some reason
|
||||
}
|
||||
Triple<Double, Double, Double> pos = keyframe.getValue(CameraProperties.POSITION).orElse(Triple.of(0D, 0D, 0D));
|
||||
Triple<Float, Float, Float> rot = keyframe.getValue(CameraProperties.ROTATION).orElse(Triple.of(0F, 0F, 0F));
|
||||
Location actual = new Location(pos.getLeft(), pos.getMiddle(), pos.getRight(), rot.getLeft(), rot.getRight());
|
||||
if (!expected.equals(actual)) {
|
||||
changes.add(UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(CameraProperties.POSITION, Triple.of(expected.getX(), expected.getY(), expected.getZ()))
|
||||
.setValue(CameraProperties.ROTATION, Triple.of(expected.getYaw(), expected.getPitch(), 0f)).done()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CombinedChange.create(changes.toArray(new Change[changes.size()]));
|
||||
}
|
||||
|
||||
private Interpolator createDefaultInterpolator() {
|
||||
return registerPositionInterpolatorProperties(defaultInterpolatorType.newInstance());
|
||||
}
|
||||
|
||||
private Interpolator registerPositionInterpolatorProperties(Interpolator interpolator) {
|
||||
interpolator.registerProperty(CameraProperties.POSITION);
|
||||
interpolator.registerProperty(CameraProperties.ROTATION);
|
||||
return interpolator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timeline createTimeline() {
|
||||
return createTimelineStatic();
|
||||
}
|
||||
|
||||
private static Timeline createInitialTimeline() {
|
||||
Timeline timeline = createTimelineStatic();
|
||||
timeline.createPath();
|
||||
timeline.createPath();
|
||||
return timeline;
|
||||
}
|
||||
|
||||
private static Timeline createTimelineStatic() {
|
||||
Timeline timeline = new TimelineImpl();
|
||||
|
||||
timeline.registerProperty(TimestampProperty.PROPERTY);
|
||||
timeline.registerProperty(CameraProperties.POSITION);
|
||||
timeline.registerProperty(CameraProperties.ROTATION);
|
||||
timeline.registerProperty(SpectatorProperty.PROPERTY);
|
||||
timeline.registerProperty(ExplicitInterpolationProperty.PROPERTY);
|
||||
|
||||
return timeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeInterpolator(JsonWriter writer, Interpolator interpolator) throws IOException {
|
||||
if (interpolator instanceof LinearInterpolator) {
|
||||
writer.value("linear");
|
||||
} else if (interpolator instanceof CubicSplineInterpolator) {
|
||||
writer.value("cubic-spline");
|
||||
} else if (interpolator instanceof CatmullRomSplineInterpolator) {
|
||||
writer.beginObject();
|
||||
writer.name("type").value("catmull-rom-spline");
|
||||
writer.name("alpha").value(((CatmullRomSplineInterpolator) interpolator).getAlpha());
|
||||
writer.endObject();
|
||||
} else {
|
||||
throw new IOException("Unknown interpolator type: " + interpolator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interpolator deserializeInterpolator(JsonReader reader) throws IOException {
|
||||
String type;
|
||||
JsonObject args;
|
||||
switch (reader.peek()) {
|
||||
case STRING:
|
||||
type = reader.nextString();
|
||||
args = null;
|
||||
break;
|
||||
case BEGIN_OBJECT:
|
||||
args = new JsonParser().parse(reader).getAsJsonObject();
|
||||
type = args.get("type").getAsString();
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unexpected token: " + reader.peek());
|
||||
}
|
||||
switch (type) {
|
||||
case "linear":
|
||||
return new LinearInterpolator();
|
||||
case "cubic-spline":
|
||||
return new CubicSplineInterpolator();
|
||||
case "catmull-rom-spline":
|
||||
if (args == null || !args.has("alpha")) {
|
||||
throw new IOException("Missing alpha value for catmull-rom-spline.");
|
||||
}
|
||||
return new CatmullRomSplineInterpolator(args.get("alpha").getAsDouble());
|
||||
default:
|
||||
throw new IOException("Unknown interpolation type: " + type);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones an interpolator by de- and re-serializing it.
|
||||
* @param interpolator The interpolator to clone
|
||||
* @return The cloned interpolator
|
||||
*/
|
||||
private Interpolator cloneInterpolator(Interpolator interpolator) {
|
||||
Interpolator cloned = deserializeInterpolator(serializeInterpolator(interpolator));
|
||||
interpolator.getKeyframeProperties().forEach(cloned::registerProperty);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the specific interpolator to String.
|
||||
* Does <b>not</b> serialize the registered keyframe properties.
|
||||
* @param interpolator The interpolator to serialize.
|
||||
* @return The serialized interpolator
|
||||
*/
|
||||
private String serializeInterpolator(Interpolator interpolator) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
JsonWriter jsonWriter = new JsonWriter(new PrintWriter(baos));
|
||||
try {
|
||||
jsonWriter.beginArray();
|
||||
serializeInterpolator(jsonWriter, interpolator);
|
||||
jsonWriter.endArray();
|
||||
jsonWriter.flush();
|
||||
} catch (IOException e) {
|
||||
CrashReport crash = CrashReport.makeCrashReport(e, "Serializing interpolator");
|
||||
CrashReportCategory category = crash.makeCategory("Serializing interpolator");
|
||||
category.addCrashSectionCallable("Interpolator", interpolator::toString);
|
||||
throw new ReportedException(crash);
|
||||
}
|
||||
|
||||
return baos.toString();
|
||||
}
|
||||
|
||||
private Interpolator deserializeInterpolator(String json) {
|
||||
JsonReader jsonReader = new JsonReader(new StringReader(json));
|
||||
try {
|
||||
jsonReader.beginArray();
|
||||
return deserializeInterpolator(jsonReader);
|
||||
} catch (IOException e) {
|
||||
CrashReport crash = CrashReport.makeCrashReport(e, "De-serializing interpolator");
|
||||
CrashReportCategory category = crash.makeCategory("De-serializing interpolator");
|
||||
category.addCrashSection("Interpolator", json);
|
||||
throw new ReportedException(crash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,25 @@ package com.replaymod.simplepathing;
|
||||
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class Setting<T> extends SettingsRegistry.SettingKeys<T> {
|
||||
public static final Setting<Boolean> PATH_PREVIEW = make("pathpreview", "pathpreview", true);
|
||||
public static final Setting<Boolean> LINEAR_INTERPOLATION = make("linear_interpolation", "linearinterpolation", false);
|
||||
public static final SettingsRegistry.MultipleChoiceSettingKeys<String> DEFAULT_INTERPOLATION;
|
||||
|
||||
static {
|
||||
String format = "replaymod.gui.editkeyframe.interpolator.%s.name";
|
||||
DEFAULT_INTERPOLATION = new SettingsRegistry.MultipleChoiceSettingKeys<>(
|
||||
"simplepathing", "interpolator", "replaymod.gui.settings.interpolator",
|
||||
String.format(format, InterpolatorType.fromString("invalid returns default").getLocalizationKey())
|
||||
);
|
||||
DEFAULT_INTERPOLATION.setChoices(
|
||||
Arrays.stream(InterpolatorType.values()).filter(i -> i != InterpolatorType.DEFAULT)
|
||||
.map(i -> String.format(format, i.getLocalizationKey()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
private static <T> Setting<T> make(String key, String displayName, T defaultValue) {
|
||||
return new Setting<>(key, displayName, defaultValue);
|
||||
|
||||
@@ -5,14 +5,27 @@ import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replaystudio.pathing.change.Change;
|
||||
import com.replaymod.replaystudio.pathing.change.CombinedChange;
|
||||
import com.replaymod.replaystudio.pathing.change.UpdateKeyframeProperties;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CatmullRomSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.PathSegment;
|
||||
import com.replaymod.simplepathing.InterpolatorType;
|
||||
import com.replaymod.simplepathing.SPTimeline;
|
||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||
import com.replaymod.simplepathing.Setting;
|
||||
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiNumberField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiClickable;
|
||||
import de.johni0702.minecraft.gui.element.IGuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.function.Typeable;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
@@ -20,10 +33,16 @@ import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.ReadablePoint;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static de.johni0702.minecraft.gui.utils.Utils.link;
|
||||
|
||||
public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends AbstractGuiPopup<T> implements Typeable {
|
||||
@@ -31,6 +50,11 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
return new GuiNumberField().setPrecision(0).setValidateOnFocusChange(true);
|
||||
}
|
||||
|
||||
protected static final Logger logger = LogManager.getLogger();
|
||||
|
||||
protected final GuiPathing guiPathing;
|
||||
|
||||
protected final long time;
|
||||
protected final Keyframe keyframe;
|
||||
protected final Path path;
|
||||
|
||||
@@ -63,15 +87,16 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
|
||||
popup.setLayout(new VerticalLayout().setSpacing(10))
|
||||
.addElements(new VerticalLayout.Data(0.5), title, inputs, timePanel, buttons);
|
||||
.addElements(new VerticalLayout.Data(0.5, false), title, inputs, timePanel, buttons);
|
||||
}
|
||||
|
||||
public GuiEditKeyframe(GuiPathing gui, Path path, Keyframe keyframe, String type) {
|
||||
public GuiEditKeyframe(GuiPathing gui, SPPath path, long time, String type) {
|
||||
super(ReplayModReplay.instance.getReplayHandler().getOverlay());
|
||||
this.keyframe = keyframe;
|
||||
this.path = path;
|
||||
this.guiPathing = gui;
|
||||
this.time = time;
|
||||
this.path = gui.getMod().getCurrentTimeline().getPath(path);
|
||||
this.keyframe = this.path.getKeyframe(time);
|
||||
|
||||
long time = keyframe.getTime();
|
||||
Consumer<String> updateSaveButtonState = s -> saveButton.setEnabled(canSave());
|
||||
timeMinField.setValue(time / 1000 / 60).onTextChanged(updateSaveButtonState);
|
||||
timeSecField.setValue(time / 1000 % 60).onTextChanged(updateSaveButtonState);
|
||||
@@ -81,10 +106,14 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
saveButton.onClick(() -> {
|
||||
Change change = save();
|
||||
long newTime = (timeMinField.getInteger() * 60 + timeSecField.getInteger()) * 1000 + timeMSecField.getInteger();
|
||||
if (newTime != keyframe.getTime()) {
|
||||
change = CombinedChange.createFromApplied(change, gui.moveKeyframe(path, keyframe, newTime));
|
||||
if (newTime != time) {
|
||||
change = CombinedChange.createFromApplied(change,
|
||||
gui.getMod().getCurrentTimeline().moveKeyframe(path, time, newTime));
|
||||
if (gui.getMod().getSelectedPath() == path && gui.getMod().getSelectedTime() == time) {
|
||||
gui.getMod().setSelected(path, newTime);
|
||||
}
|
||||
}
|
||||
path.getTimeline().pushChange(change);
|
||||
gui.getMod().getCurrentTimeline().getTimeline().pushChange(change);
|
||||
close();
|
||||
});
|
||||
}
|
||||
@@ -114,7 +143,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
protected abstract Change save();
|
||||
|
||||
public static class Spectator extends GuiEditKeyframe<Spectator> {
|
||||
public Spectator(GuiPathing gui, Path path, Keyframe keyframe) {
|
||||
public Spectator(GuiPathing gui, SPPath path, long keyframe) {
|
||||
super(gui, path, keyframe, "spec");
|
||||
|
||||
link(timeMinField, timeSecField, timeMSecField);
|
||||
@@ -147,10 +176,10 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
timestampMSecField, new GuiLabel().setI18nText("replaymod.gui.milliseconds"));
|
||||
}
|
||||
|
||||
public Time(GuiPathing gui, Path path, Keyframe keyframe) {
|
||||
public Time(GuiPathing gui, SPPath path, long keyframe) {
|
||||
super(gui, path, keyframe, "time");
|
||||
|
||||
keyframe.getValue(TimestampProperty.PROPERTY).ifPresent(time -> {
|
||||
this.keyframe.getValue(TimestampProperty.PROPERTY).ifPresent(time -> {
|
||||
timestampMinField.setValue(time / 1000 / 60);
|
||||
timestampSecField.setValue(time / 1000 % 60);
|
||||
timestampMSecField.setValue(time % 1000);
|
||||
@@ -165,11 +194,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
protected Change save() {
|
||||
int time = (timestampMinField.getInteger() * 60 + timestampSecField.getInteger()) * 1000
|
||||
+ timestampMSecField.getInteger();
|
||||
Change change = UpdateKeyframeProperties.create(path, keyframe)
|
||||
.setValue(TimestampProperty.PROPERTY, time)
|
||||
.done();
|
||||
change.apply(path.getTimeline());
|
||||
return change;
|
||||
return guiPathing.getMod().getCurrentTimeline().updateTimeKeyframe(keyframe.getTime(), time);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,16 +204,19 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
}
|
||||
|
||||
public static class Position extends GuiEditKeyframe<Position> {
|
||||
public final GuiNumberField xField = newGuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField yField = newGuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField zField = newGuiNumberField().setSize(150, 20).setPrecision(10);
|
||||
public final GuiNumberField xField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
public final GuiNumberField yField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
public final GuiNumberField zField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
|
||||
public final GuiNumberField yawField = newGuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField pitchField = newGuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField rollField = newGuiNumberField().setSize(150, 20).setPrecision(5);
|
||||
public final GuiNumberField yawField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
public final GuiNumberField pitchField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
public final GuiNumberField rollField = newGuiNumberField().setSize(60, 20).setPrecision(5);
|
||||
|
||||
public final InterpolationPanel interpolationPanel = new InterpolationPanel();
|
||||
|
||||
{
|
||||
inputs.setLayout(new GridLayout().setCellsEqualSize(false).setColumns(4).setSpacingX(3).setSpacingY(5))
|
||||
GuiPanel positionInputs = new GuiPanel()
|
||||
.setLayout(new GridLayout().setCellsEqualSize(false).setColumns(4).setSpacingX(3).setSpacingY(5))
|
||||
.addElements(new GridLayout.Data(1, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.xpos"), xField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.camyaw"), yawField,
|
||||
@@ -196,17 +224,20 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.campitch"), pitchField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.zpos"), zField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.camroll"), rollField);
|
||||
|
||||
inputs.setLayout(new VerticalLayout().setSpacing(10)).addElements(new VerticalLayout.Data(0.5, false),
|
||||
positionInputs, interpolationPanel);
|
||||
}
|
||||
|
||||
public Position(GuiPathing gui, Path path, Keyframe keyframe) {
|
||||
public Position(GuiPathing gui, SPPath path, long keyframe) {
|
||||
super(gui, path, keyframe, "pos");
|
||||
|
||||
keyframe.getValue(CameraProperties.POSITION).ifPresent(pos -> {
|
||||
this.keyframe.getValue(CameraProperties.POSITION).ifPresent(pos -> {
|
||||
xField.setValue(pos.getLeft());
|
||||
yField.setValue(pos.getMiddle());
|
||||
zField.setValue(pos.getRight());
|
||||
});
|
||||
keyframe.getValue(CameraProperties.ROTATION).ifPresent(rot -> {
|
||||
this.keyframe.getValue(CameraProperties.ROTATION).ifPresent(rot -> {
|
||||
yawField.setValue(rot.getLeft());
|
||||
pitchField.setValue(rot.getMiddle());
|
||||
rollField.setValue(rot.getRight());
|
||||
@@ -219,17 +250,181 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
|
||||
@Override
|
||||
protected Change save() {
|
||||
Change change = UpdateKeyframeProperties.create(path, keyframe)
|
||||
.setValue(CameraProperties.POSITION, Triple.of(xField.getDouble(), yField.getDouble(), zField.getDouble()))
|
||||
.setValue(CameraProperties.ROTATION, Triple.of(yawField.getFloat(), pitchField.getFloat(), rollField.getFloat()))
|
||||
.done();
|
||||
change.apply(path.getTimeline());
|
||||
return change;
|
||||
SPTimeline timeline = guiPathing.getMod().getCurrentTimeline();
|
||||
Change positionChange = timeline.updatePositionKeyframe(time,
|
||||
xField.getDouble(), yField.getDouble(), zField.getDouble(),
|
||||
yawField.getFloat(), pitchField.getFloat(), rollField.getFloat()
|
||||
);
|
||||
if (interpolationPanel.getSettingsPanel() == null) {
|
||||
// The last keyframe doesn't have interpolator settings because there is no segment following it
|
||||
return positionChange;
|
||||
}
|
||||
Interpolator interpolator = interpolationPanel.getSettingsPanel().createInterpolator();
|
||||
if (interpolationPanel.getInterpolatorType() == InterpolatorType.DEFAULT) {
|
||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolatorToDefault(time),
|
||||
timeline.setDefaultInterpolator(interpolator));
|
||||
} else {
|
||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolator(time, interpolator));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Position getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public class InterpolationPanel extends AbstractGuiContainer<InterpolationPanel> {
|
||||
|
||||
@Getter
|
||||
private SettingsPanel settingsPanel;
|
||||
|
||||
private GuiDropdownMenu<InterpolatorType> dropdown;
|
||||
|
||||
public InterpolationPanel() {
|
||||
setLayout(new VerticalLayout());
|
||||
|
||||
dropdown = new GuiDropdownMenu<InterpolatorType>()
|
||||
.setToString(s -> I18n.format(s.getI18nName()))
|
||||
.setValues(InterpolatorType.values()).setHeight(20)
|
||||
.onSelection(i -> setSettingsPanel(dropdown.getSelectedValue()));
|
||||
|
||||
// set hover tooltips
|
||||
for (Map.Entry<InterpolatorType, IGuiClickable> e : dropdown.getDropdownEntries().entrySet()) {
|
||||
e.getValue().setTooltip(new GuiTooltip().setI18nText(e.getKey().getI18nDescription()));
|
||||
}
|
||||
|
||||
GuiPanel dropdownPanel = new GuiPanel()
|
||||
.setLayout(new GridLayout().setCellsEqualSize(false).setColumns(2).setSpacingX(3).setSpacingY(5))
|
||||
.addElements(new GridLayout.Data(1, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.interpolator"), dropdown);
|
||||
|
||||
|
||||
addElements(new VerticalLayout.Data(0.5, false), dropdownPanel);
|
||||
|
||||
Optional<PathSegment> segment = path.getSegments().stream()
|
||||
.filter(s -> s.getStartKeyframe() == keyframe).findFirst();
|
||||
if (segment.isPresent()) {
|
||||
Interpolator interpolator = segment.get().getInterpolator();
|
||||
InterpolatorType type = InterpolatorType.fromClass(interpolator.getClass());
|
||||
if (keyframe.getValue(ExplicitInterpolationProperty.PROPERTY).isPresent()) {
|
||||
dropdown.setSelected(type); // trigger the callback once to display settings panel
|
||||
} else {
|
||||
setSettingsPanel(InterpolatorType.DEFAULT);
|
||||
type = InterpolatorType.DEFAULT;
|
||||
}
|
||||
if (getInterpolatorTypeNoDefault(type).getInterpolatorClass().isInstance(interpolator)) {
|
||||
//noinspection unchecked
|
||||
settingsPanel.loadSettings(interpolator);
|
||||
}
|
||||
} else {
|
||||
// Disable dropdown if this is the last keyframe
|
||||
dropdown.setDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSettingsPanel(InterpolatorType type) {
|
||||
removeElement(this.settingsPanel);
|
||||
|
||||
switch (getInterpolatorTypeNoDefault(type)) {
|
||||
case CATMULL_ROM:
|
||||
settingsPanel = new CatmullRomSettingsPanel();
|
||||
break;
|
||||
case CUBIC:
|
||||
settingsPanel = new CubicSettingsPanel();
|
||||
break;
|
||||
case LINEAR:
|
||||
settingsPanel = new LinearSettingsPanel();
|
||||
break;
|
||||
}
|
||||
|
||||
addElements(new GridLayout.Data(0.5, 0.5), settingsPanel);
|
||||
}
|
||||
|
||||
protected InterpolatorType getInterpolatorTypeNoDefault(InterpolatorType interpolatorType) {
|
||||
if (interpolatorType == InterpolatorType.DEFAULT || interpolatorType == null) {
|
||||
InterpolatorType defaultType = InterpolatorType.fromString(
|
||||
guiPathing.getMod().getCore().getSettingsRegistry().get(Setting.DEFAULT_INTERPOLATION));
|
||||
return defaultType;
|
||||
}
|
||||
return interpolatorType;
|
||||
}
|
||||
|
||||
public InterpolatorType getInterpolatorType() {
|
||||
return dropdown.getSelectedValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InterpolationPanel getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract class SettingsPanel<I extends Interpolator, T extends SettingsPanel<I, T>> extends AbstractGuiContainer<T> {
|
||||
|
||||
public abstract void loadSettings(I interpolator);
|
||||
|
||||
public abstract I createInterpolator();
|
||||
}
|
||||
|
||||
public class CatmullRomSettingsPanel extends SettingsPanel<CatmullRomSplineInterpolator, CatmullRomSettingsPanel> {
|
||||
public final GuiLabel alphaLabel = new GuiLabel().setColor(Colors.BLACK)
|
||||
.setI18nText("replaymod.gui.editkeyframe.interpolator.catmullrom.alpha");
|
||||
public final GuiNumberField alphaField = new GuiNumberField().setSize(100, 20).setPrecision(5)
|
||||
.setMinValue(0).setValidateOnFocusChange(true);
|
||||
|
||||
{
|
||||
setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER));
|
||||
addElements(new HorizontalLayout.Data(0.5), alphaLabel, alphaField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSettings(CatmullRomSplineInterpolator interpolator) {
|
||||
alphaField.setValue(interpolator.getAlpha());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatmullRomSplineInterpolator createInterpolator() {
|
||||
return new CatmullRomSplineInterpolator(alphaField.getDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CatmullRomSettingsPanel getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class CubicSettingsPanel extends SettingsPanel<CubicSplineInterpolator, CubicSettingsPanel> {
|
||||
|
||||
@Override
|
||||
public void loadSettings(CubicSplineInterpolator interpolator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CubicSplineInterpolator createInterpolator() {
|
||||
return new CubicSplineInterpolator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CubicSettingsPanel getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class LinearSettingsPanel extends SettingsPanel<LinearInterpolator, LinearSettingsPanel> {
|
||||
|
||||
@Override
|
||||
public void loadSettings(LinearInterpolator interpolator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinearInterpolator createInterpolator() {
|
||||
return new LinearInterpolator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LinearSettingsPanel getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.replaymod.simplepathing.gui;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.pathing.properties.CameraProperties;
|
||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||
@@ -11,9 +9,10 @@ import com.replaymod.replaystudio.pathing.change.Change;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.PathSegment;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.pathing.property.Property;
|
||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||
import com.replaymod.simplepathing.SPTimeline;
|
||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.element.advanced.AbstractGuiTimeline;
|
||||
import de.johni0702.minecraft.gui.function.Draggable;
|
||||
@@ -23,7 +22,6 @@ import org.lwjgl.util.Point;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
import org.lwjgl.util.ReadablePoint;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -37,14 +35,14 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
private final GuiPathing gui;
|
||||
|
||||
/**
|
||||
* The keyframe that was last clicked on using the left mouse button.
|
||||
* The keyframe (time on timeline) that was last clicked on using the left mouse button.
|
||||
*/
|
||||
private Keyframe lastClickedKeyframe;
|
||||
private long lastClickedKeyframe;
|
||||
|
||||
/**
|
||||
* Id of the path of {@link #lastClickedKeyframe}.
|
||||
* Path of {@link #lastClickedKeyframe}.
|
||||
*/
|
||||
private int lastClickedPath;
|
||||
private SPPath lastClickedPath;
|
||||
|
||||
/**
|
||||
* The time at which {@link #lastClickedKeyframe} was updated.
|
||||
@@ -89,18 +87,13 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
|
||||
renderer.bindTexture(ReplayMod.TEXTURE);
|
||||
|
||||
for (Keyframe keyframe : Iterables.concat(Iterables.transform(mod.getCurrentTimeline().getPaths(), new Function<Path, Iterable<Keyframe>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Iterable<Keyframe> apply(@Nullable Path input) {
|
||||
assert input != null;
|
||||
return input.getKeyframes();
|
||||
}
|
||||
}))) {
|
||||
SPTimeline timeline = mod.getCurrentTimeline();
|
||||
|
||||
timeline.getTimeline().getPaths().stream().flatMap(path -> path.getKeyframes().stream()).forEach(keyframe -> {
|
||||
if (keyframe.getTime() >= startTime && keyframe.getTime() <= endTime) {
|
||||
double relativeTime = keyframe.getTime() - startTime;
|
||||
int positonX = BORDER_LEFT + (int) (relativeTime / visibleTime * visibleWidth) - KEYFRAME_SIZE / 2;
|
||||
int u = KEYFRAME_TEXTURE_X + (mod.getSelectedKeyframe() == keyframe ? KEYFRAME_SIZE : 0);
|
||||
int u = KEYFRAME_TEXTURE_X + (mod.isSelected(keyframe) ? KEYFRAME_SIZE : 0);
|
||||
int v = KEYFRAME_TEXTURE_Y;
|
||||
if (keyframe.getValue(CameraProperties.POSITION).isPresent()) {
|
||||
if (keyframe.getValue(SpectatorProperty.PROPERTY).isPresent()) {
|
||||
@@ -113,10 +106,10 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
renderer.drawTexturedRect(positonX, BORDER_TOP + KEYFRAME_SIZE, u, v, KEYFRAME_SIZE, KEYFRAME_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Draw colored quads on spectator path segments
|
||||
for (PathSegment segment : mod.getCurrentTimeline().getPaths().get(GuiPathing.POSITION_PATH).getSegments()) {
|
||||
for (PathSegment segment : timeline.getPositionPath().getSegments()) {
|
||||
if (segment.getInterpolator() == null
|
||||
|| !segment.getInterpolator().getKeyframeProperties().contains(SpectatorProperty.PROPERTY)) {
|
||||
continue; // Not a spectator segment
|
||||
@@ -125,7 +118,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
|
||||
// Draw red quads on time path segments that would require time going backwards
|
||||
for (PathSegment segment : mod.getCurrentTimeline().getPaths().get(GuiPathing.TIME_PATH).getSegments()) {
|
||||
for (PathSegment segment : timeline.getTimePath().getSegments()) {
|
||||
long startTimestamp = segment.getStartKeyframe().getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||
long endTimestamp = segment.getEndKeyframe().getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||
if (endTimestamp >= startTimestamp) {
|
||||
@@ -162,29 +155,28 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
* @param position The raw position
|
||||
* @return Pair of path id and keyframe or null when no keyframe was clicked
|
||||
*/
|
||||
private Pair<Integer, Keyframe> getKeyframe(ReadablePoint position) {
|
||||
private Pair<SPPath, Long> getKeyframe(ReadablePoint position) {
|
||||
int time = getTimeAt(position.getX(), position.getY());
|
||||
if (time != -1) {
|
||||
Point mouse = new Point(position);
|
||||
getContainer().convertFor(this, mouse);
|
||||
int mouseY = mouse.getY();
|
||||
if (mouseY > BORDER_TOP && mouseY < BORDER_TOP + 2 * KEYFRAME_SIZE) {
|
||||
Timeline timeline = gui.getMod().getCurrentTimeline();
|
||||
int path;
|
||||
SPPath path;
|
||||
if (mouseY <= BORDER_TOP + KEYFRAME_SIZE) {
|
||||
// Position keyframe
|
||||
path = GuiPathing.POSITION_PATH;
|
||||
path = SPPath.POSITION;
|
||||
} else {
|
||||
// Time keyframe
|
||||
path = GuiPathing.TIME_PATH;
|
||||
path = SPPath.TIME;
|
||||
}
|
||||
int visibleTime = (int) (getZoom() * getLength());
|
||||
int tolerance = visibleTime * KEYFRAME_SIZE / (size.getWidth() - BORDER_LEFT - BORDER_RIGHT) / 2;
|
||||
Optional<Keyframe> keyframe = timeline.getPaths().get(path).getKeyframes().stream()
|
||||
int tolerance = visibleTime * KEYFRAME_SIZE / (getLastSize().getWidth() - BORDER_LEFT - BORDER_RIGHT) / 2;
|
||||
Optional<Keyframe> keyframe = gui.getMod().getCurrentTimeline().getPath(path).getKeyframes().stream()
|
||||
.filter(k -> Math.abs(k.getTime() - time) <= tolerance)
|
||||
.sorted(Comparator.comparing(k -> Math.abs(k.getTime() - time)))
|
||||
.findFirst();
|
||||
return Pair.of(path, keyframe.orElse(null));
|
||||
return Pair.of(path, keyframe.map(Keyframe::getTime).orElse(null));
|
||||
}
|
||||
}
|
||||
return Pair.of(null, null);
|
||||
@@ -193,30 +185,31 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
@Override
|
||||
public boolean mouseClick(ReadablePoint position, int button) {
|
||||
int time = getTimeAt(position.getX(), position.getY());
|
||||
Pair<Integer, Keyframe> pathKeyframePair = getKeyframe(position);
|
||||
Pair<SPPath, Long> pathKeyframePair = getKeyframe(position);
|
||||
if (pathKeyframePair.getRight() != null) {
|
||||
SPPath path = pathKeyframePair.getLeft();
|
||||
// Clicked on keyframe
|
||||
Keyframe keyframe = pathKeyframePair.getRight();
|
||||
long keyframeTime = pathKeyframePair.getRight();
|
||||
if (button == 0) { // Left click
|
||||
long now = Minecraft.getSystemTime();
|
||||
if (lastClickedKeyframe == keyframe) {
|
||||
if (lastClickedKeyframe == keyframeTime) {
|
||||
// Clicked the same keyframe again, potentially a double click
|
||||
if (now - lastClickedTime < DOUBLE_CLICK_INTERVAL) {
|
||||
// Yup, double click, open the edit keyframe gui
|
||||
Path path = gui.getMod().getCurrentTimeline().getPaths().get(pathKeyframePair.getLeft());
|
||||
gui.openEditKeyframePopup(path, keyframe);
|
||||
gui.openEditKeyframePopup(path, keyframeTime);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Not a double click, just update the click time and selection
|
||||
lastClickedTime = now;
|
||||
lastClickedKeyframe = keyframe;
|
||||
lastClickedPath = pathKeyframePair.getLeft();
|
||||
gui.getMod().setSelectedKeyframe(lastClickedKeyframe);
|
||||
lastClickedKeyframe = keyframeTime;
|
||||
lastClickedPath = path;
|
||||
gui.getMod().setSelected(lastClickedPath, lastClickedKeyframe);
|
||||
// We might be dragging
|
||||
draggingStartX = position.getX();
|
||||
dragging = true;
|
||||
} else if (button == 1) { // Right click
|
||||
Keyframe keyframe = gui.getMod().getCurrentTimeline().getKeyframe(path, keyframeTime);
|
||||
for (Property property : keyframe.getProperties()) {
|
||||
applyPropertyToGame(property, keyframe);
|
||||
}
|
||||
@@ -226,12 +219,11 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
// Clicked on timeline but not on any keyframe
|
||||
if (button == 0) { // Left click
|
||||
setCursorPosition(time);
|
||||
gui.getMod().setSelectedKeyframe(null);
|
||||
gui.getMod().setSelected(null, 0);
|
||||
} else if (button == 1) { // Right click
|
||||
if (pathKeyframePair.getLeft() != null) {
|
||||
// Apply the value of the clicked path at the clicked position
|
||||
Timeline timeline = gui.getMod().getCurrentTimeline();
|
||||
Path path = timeline.getPaths().get(pathKeyframePair.getLeft());
|
||||
Path path = gui.getMod().getCurrentTimeline().getPath(pathKeyframePair.getLeft());
|
||||
path.getKeyframes().stream().flatMap(k -> k.getProperties().stream()).distinct().forEach(
|
||||
p -> applyPropertyToGame(p, path, time));
|
||||
}
|
||||
@@ -280,12 +272,13 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
}
|
||||
if (actuallyDragging) {
|
||||
if (!gui.ensureEntityTracker(() -> mouseDrag(position, button, timeSinceLastCall))) return true;
|
||||
// Threshold passed
|
||||
Path path = gui.getMod().getCurrentTimeline().getPaths().get(lastClickedPath);
|
||||
SPTimeline timeline = gui.getMod().getCurrentTimeline();
|
||||
Point mouse = new Point(position);
|
||||
getContainer().convertFor(this, mouse);
|
||||
int mouseX = mouse.getX();
|
||||
int width = size.getWidth();
|
||||
int width = getLastSize().getWidth();
|
||||
int bodyWidth = width - BORDER_LEFT - BORDER_RIGHT;
|
||||
double segmentLength = getLength() * getZoom();
|
||||
double segmentTime = segmentLength * (mouseX - BORDER_LEFT) / bodyWidth;
|
||||
@@ -295,24 +288,21 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
}
|
||||
|
||||
// If there already is a keyframe at the target time, then increase the time by one until there is none
|
||||
while (path.getKeyframe(newTime) != null) {
|
||||
while (timeline.getKeyframe(lastClickedPath, newTime) != null) {
|
||||
newTime++;
|
||||
}
|
||||
|
||||
// First undo any previous changes
|
||||
if (draggingChange != null) {
|
||||
draggingChange.undo(gui.getMod().getCurrentTimeline());
|
||||
draggingChange.undo(timeline.getTimeline());
|
||||
}
|
||||
|
||||
// Move keyframe to new position and
|
||||
// store change for later undoing / pushing to history
|
||||
draggingChange = gui.moveKeyframe(path, lastClickedKeyframe, newTime);
|
||||
draggingChange = timeline.moveKeyframe(lastClickedPath, lastClickedKeyframe, newTime);
|
||||
|
||||
// Selected keyframe has been replaced
|
||||
gui.getMod().setSelectedKeyframe(path.getKeyframe(newTime));
|
||||
|
||||
// Path has been changed
|
||||
path.updateAll();
|
||||
gui.getMod().setSelected(lastClickedPath, newTime);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -321,7 +311,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
||||
public boolean mouseRelease(ReadablePoint position, int button) {
|
||||
if (dragging) {
|
||||
if (actuallyDragging) {
|
||||
gui.getMod().getCurrentTimeline().pushChange(draggingChange);
|
||||
gui.getMod().getCurrentTimeline().getTimeline().pushChange(draggingChange);
|
||||
draggingChange = null;
|
||||
actuallyDragging = false;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.replaymod.simplepathing.gui;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.pathing.gui.GuiKeyframeRepository;
|
||||
import com.replaymod.pathing.player.RealtimeTimelinePlayer;
|
||||
import com.replaymod.pathing.properties.CameraProperties;
|
||||
@@ -14,24 +16,26 @@ import com.replaymod.render.gui.GuiRenderSettings;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.camera.CameraEntity;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import com.replaymod.replaystudio.pathing.change.*;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.PathSegment;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.pathing.property.Property;
|
||||
import com.replaymod.replaystudio.pathing.serialize.TimelineSerialization;
|
||||
import com.replaymod.replaystudio.util.EntityPositionTracker;
|
||||
import com.replaymod.replaystudio.util.Location;
|
||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||
import com.replaymod.simplepathing.Setting;
|
||||
import com.replaymod.simplepathing.SPTimeline;
|
||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.element.AbstractGuiClickable;
|
||||
import de.johni0702.minecraft.gui.element.AbstractGuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiHorizontalScrollbar;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTexturedButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiClickable;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiTimelineTime;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
@@ -41,9 +45,8 @@ import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -55,19 +58,17 @@ import org.lwjgl.util.WritablePoint;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.error;
|
||||
import static com.replaymod.simplepathing.ReplayModSimplePathing.LOGGER;
|
||||
|
||||
|
||||
/**
|
||||
* Gui plug-in to the GuiReplayOverlay for simple pathing.
|
||||
*/
|
||||
public class GuiPathing {
|
||||
public static final int TIME_PATH = 0;
|
||||
public static final int POSITION_PATH = 1;
|
||||
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
public final GuiTexturedButton playPauseButton = new GuiTexturedButton() {
|
||||
@@ -91,7 +92,20 @@ public class GuiPathing {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!preparePathsForPlayback()) return;
|
||||
new GuiRenderSettings(replayHandler, mod.getCurrentTimeline()).display();
|
||||
|
||||
// Clone the timeline passed to the settings gui as it may be stored for later rendering in a queue
|
||||
SPTimeline spTimeline = mod.getCurrentTimeline();
|
||||
Timeline timeline;
|
||||
try {
|
||||
TimelineSerialization serialization = new TimelineSerialization(spTimeline, null);
|
||||
String serialized = serialization.serialize(Collections.singletonMap("", spTimeline.getTimeline()));
|
||||
timeline = serialization.deserialize(serialized).get("");
|
||||
} catch (Throwable t) {
|
||||
error(LOGGER, replayHandler.getOverlay(), CrashReport.makeCrashReport(t, "Cloning timeline"), () -> {});
|
||||
return;
|
||||
}
|
||||
|
||||
new GuiRenderSettings(replayHandler, timeline).display();
|
||||
}
|
||||
}).setSize(20, 20).setTexture(ReplayMod.TEXTURE, ReplayMod.TEXTURE_SIZE).setTexturePosH(40, 0)
|
||||
.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.ingame.menu.renderpath"));
|
||||
@@ -243,6 +257,7 @@ public class GuiPathing {
|
||||
}
|
||||
};
|
||||
|
||||
private final ReplayMod core;
|
||||
private final ReplayModSimplePathing mod;
|
||||
private final ReplayHandler replayHandler;
|
||||
private final RealtimeTimelinePlayer player;
|
||||
@@ -252,6 +267,7 @@ public class GuiPathing {
|
||||
private SettableFuture<Void> entityTrackerFuture;
|
||||
|
||||
public GuiPathing(final ReplayMod core, final ReplayModSimplePathing mod, final ReplayHandler replayHandler) {
|
||||
this.core = core;
|
||||
this.mod = mod;
|
||||
this.replayHandler = replayHandler;
|
||||
this.player = new RealtimeTimelinePlayer(replayHandler);
|
||||
@@ -278,27 +294,34 @@ public class GuiPathing {
|
||||
if (player.isActive()) {
|
||||
player.getFuture().cancel(false);
|
||||
} else {
|
||||
Timeline timeline = mod.getCurrentTimeline();
|
||||
Path timePath = timeline.getPaths().get(TIME_PATH);
|
||||
Path timePath = mod.getCurrentTimeline().getTimePath();
|
||||
|
||||
if (!preparePathsForPlayback()) return;
|
||||
|
||||
timePath.setActive(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT));
|
||||
// Start from cursor time unless the control key is pressed (then start from beginning)
|
||||
int startTime = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)? 0 : GuiPathing.this.timeline.getCursorPosition();
|
||||
ListenableFuture<Void> future = player.start(timeline, startTime);
|
||||
ListenableFuture<Void> future = player.start(mod.getCurrentTimeline().getTimeline(), startTime);
|
||||
overlay.setCloseable(false);
|
||||
overlay.setMouseVisible(true);
|
||||
core.printInfoToChat("replaymod.chat.pathstarted");
|
||||
Futures.addCallback(future, new FutureCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Void result) {
|
||||
if (future.isCancelled()) {
|
||||
core.printInfoToChat("replaymod.chat.pathinterrupted");
|
||||
} else {
|
||||
core.printInfoToChat("replaymod.chat.pathfinished");
|
||||
}
|
||||
overlay.setCloseable(true);
|
||||
timePath.setActive(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
overlay.setCloseable(true);
|
||||
timePath.setActive(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -308,26 +331,28 @@ public class GuiPathing {
|
||||
positionKeyframeButton.setTexturePosH(new ReadablePoint() {
|
||||
@Override
|
||||
public int getX() {
|
||||
Keyframe keyframe = mod.getSelectedKeyframe();
|
||||
if (keyframe == null || !keyframe.getValue(CameraProperties.POSITION).isPresent()) {
|
||||
SPPath keyframePath = mod.getSelectedPath();
|
||||
long keyframeTime = mod.getSelectedTime();
|
||||
if (keyframePath != SPPath.POSITION) {
|
||||
// No keyframe or wrong path
|
||||
keyframe = mod.getCurrentTimeline().getPaths().get(POSITION_PATH).getKeyframe(timeline.getCursorPosition());
|
||||
keyframeTime = timeline.getCursorPosition();
|
||||
keyframePath = mod.getCurrentTimeline().isPositionKeyframe(keyframeTime) ? SPPath.POSITION : null;
|
||||
}
|
||||
if (keyframe == null) {
|
||||
if (keyframePath != SPPath.POSITION) {
|
||||
return replayHandler.isCameraView() ? 0 : 40;
|
||||
} else {
|
||||
return keyframe.getValue(SpectatorProperty.PROPERTY).isPresent() ? 40 : 0;
|
||||
return mod.getCurrentTimeline().isSpectatorKeyframe(keyframeTime) ? 40 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
Keyframe keyframe = mod.getSelectedKeyframe();
|
||||
if (keyframe == null || !keyframe.getValue(CameraProperties.POSITION).isPresent()) {
|
||||
SPPath keyframePath = mod.getSelectedPath();
|
||||
if (keyframePath != SPPath.POSITION) {
|
||||
// No keyframe selected but there might be one at exactly the position of the cursor
|
||||
keyframe = mod.getCurrentTimeline().getPaths().get(POSITION_PATH).getKeyframe(timeline.getCursorPosition());
|
||||
keyframePath = mod.getCurrentTimeline().isPositionKeyframe(timeline.getCursorPosition()) ? SPPath.POSITION : null;
|
||||
}
|
||||
return keyframe != null && keyframe.getValue(CameraProperties.POSITION).isPresent() ? 60 : 40;
|
||||
return keyframePath == SPPath.POSITION ? 60 : 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,7 +362,7 @@ public class GuiPathing {
|
||||
}).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateKeyframe(false);
|
||||
updateKeyframe(SPPath.POSITION);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -349,12 +374,12 @@ public class GuiPathing {
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
Keyframe keyframe = mod.getSelectedKeyframe();
|
||||
if (keyframe == null || !keyframe.getValue(TimestampProperty.PROPERTY).isPresent()) {
|
||||
SPPath keyframePath = mod.getSelectedPath();
|
||||
if (keyframePath != SPPath.TIME) {
|
||||
// No keyframe selected but there might be one at exactly the position of the cursor
|
||||
keyframe = mod.getCurrentTimeline().getPaths().get(TIME_PATH).getKeyframe(timeline.getCursorPosition());
|
||||
keyframePath = mod.getCurrentTimeline().isTimeKeyframe(timeline.getCursorPosition()) ? SPPath.TIME : null;
|
||||
}
|
||||
return keyframe != null && keyframe.getValue(TimestampProperty.PROPERTY).isPresent() ? 100 : 80;
|
||||
return keyframePath == SPPath.TIME ? 100 : 80;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -364,7 +389,7 @@ public class GuiPathing {
|
||||
}).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateKeyframe(true);
|
||||
updateKeyframe(SPPath.TIME);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -378,94 +403,90 @@ public class GuiPathing {
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.keyframerepository", Keyboard.KEY_X, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!overlay.isVisible()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GuiKeyframeRepository gui = new GuiKeyframeRepository(
|
||||
mod, replayHandler.getReplayFile(), mod.getCurrentTimeline());
|
||||
Futures.addCallback(gui.getFuture(), new FutureCallback<Timeline>() {
|
||||
@Override
|
||||
public void onSuccess(Timeline result) {
|
||||
if (result != null) {
|
||||
mod.setCurrentTimeline(result);
|
||||
}
|
||||
}
|
||||
startLoadingEntityTracker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
core.printWarningToChat("Error loading timeline: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
gui.display();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
core.printWarningToChat("Error loading timeline: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.clearkeyframes", Keyboard.KEY_C, () -> {
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(overlay,
|
||||
new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK)
|
||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||
public void keyframeRepoButtonPressed() {
|
||||
try {
|
||||
GuiKeyframeRepository gui = new GuiKeyframeRepository(
|
||||
mod.getCurrentTimeline(), replayHandler.getReplayFile(), mod.getCurrentTimeline().getTimeline());
|
||||
Futures.addCallback(gui.getFuture(), new FutureCallback<Timeline>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean delete) {
|
||||
if (delete) {
|
||||
Timeline timeline = mod.createTimeline();
|
||||
timeline.createPath();
|
||||
timeline.createPath();
|
||||
mod.setCurrentTimeline(timeline);
|
||||
public void onSuccess(Timeline result) {
|
||||
if (result != null) {
|
||||
mod.setCurrentTimeline(new SPTimeline(result));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
core.printWarningToChat("Error loading timeline: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
});
|
||||
gui.display();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
core.printWarningToChat("Error loading timeline: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
core.getKeyBindingRegistry().registerRepeatedKeyBinding("replaymod.input.synctimeline", Keyboard.KEY_V, () -> {
|
||||
// Current replay time
|
||||
int time = replayHandler.getReplaySender().currentTimeStamp();
|
||||
// Position of the cursor
|
||||
int cursor = timeline.getCursorPosition();
|
||||
// Get the last time keyframe before the cursor
|
||||
mod.getCurrentTimeline().getPaths().get(TIME_PATH).getKeyframes().stream()
|
||||
.filter(it -> it.getTime() <= cursor).reduce((__, last) -> last).ifPresent(keyframe -> {
|
||||
// Cursor position at the keyframe
|
||||
int keyframeCursor = (int) keyframe.getTime();
|
||||
// Replay time at the keyframe
|
||||
// This is a keyframe from the time path, so it _should_ always have a time property
|
||||
int keyframeTime = keyframe.getValue(TimestampProperty.PROPERTY).get();
|
||||
// Replay time passed
|
||||
int timePassed = time - keyframeTime;
|
||||
// Speed (set to 1 when shift is held)
|
||||
double speed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : overlay.getSpeedSliderValue();
|
||||
// Cursor time passed
|
||||
int cursorPassed = (int) (timePassed / speed);
|
||||
// Move cursor to new position
|
||||
timeline.setCursorPosition(keyframeCursor + cursorPassed);
|
||||
// Deselect keyframe to allow the user to add a new one right away
|
||||
mod.setSelectedKeyframe(null);
|
||||
});
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||
if (!overlay.isVisible()) {
|
||||
return;
|
||||
public void clearKeyframesButtonPressed() {
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(replayHandler.getOverlay(),
|
||||
new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK)
|
||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean delete) {
|
||||
if (delete) {
|
||||
mod.clearCurrentTimeline();
|
||||
if (entityTracker != null) {
|
||||
mod.getCurrentTimeline().setEntityTracker(entityTracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mod.getSelectedKeyframe() != null) {
|
||||
updateKeyframe(mod.getSelectedKeyframe().getValue(TimestampProperty.PROPERTY).isPresent());
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void syncTimeButtonPressed() {
|
||||
// Current replay time
|
||||
int time = replayHandler.getReplaySender().currentTimeStamp();
|
||||
// Position of the cursor
|
||||
int cursor = timeline.getCursorPosition();
|
||||
// Get the last time keyframe before the cursor
|
||||
mod.getCurrentTimeline().getTimePath().getKeyframes().stream()
|
||||
.filter(it -> it.getTime() <= cursor).reduce((__, last) -> last).ifPresent(keyframe -> {
|
||||
// Cursor position at the keyframe
|
||||
int keyframeCursor = (int) keyframe.getTime();
|
||||
// Replay time at the keyframe
|
||||
// This is a keyframe from the time path, so it _should_ always have a time property
|
||||
int keyframeTime = keyframe.getValue(TimestampProperty.PROPERTY).get();
|
||||
// Replay time passed
|
||||
int timePassed = time - keyframeTime;
|
||||
// Speed (set to 1 when shift is held)
|
||||
double speed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : replayHandler.getOverlay().getSpeedSliderValue();
|
||||
// Cursor time passed
|
||||
int cursorPassed = (int) (timePassed / speed);
|
||||
// Move cursor to new position
|
||||
timeline.setCursorPosition(keyframeCursor + cursorPassed);
|
||||
// Deselect keyframe to allow the user to add a new one right away
|
||||
mod.setSelected(null, 0);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteButtonPressed() {
|
||||
if (mod.getSelectedPath() != null) {
|
||||
updateKeyframe(mod.getSelectedPath());
|
||||
}
|
||||
}
|
||||
|
||||
private void startLoadingEntityTracker() {
|
||||
Preconditions.checkState(entityTrackerFuture == null);
|
||||
// Start loading entity tracker
|
||||
entityTrackerFuture = SettableFuture.create();
|
||||
new Thread(() -> {
|
||||
@@ -478,12 +499,13 @@ public class GuiPathing {
|
||||
}
|
||||
});
|
||||
logger.info("Loaded entity tracker in " + (System.currentTimeMillis() - start) + "ms");
|
||||
} catch (IOException e) {
|
||||
} catch (Throwable e) {
|
||||
logger.error("Loading entity tracker:", e);
|
||||
mod.getCore().runLater(() -> {
|
||||
mod.getCore().printWarningToChat("Error loading entity tracker: %s", e.getLocalizedMessage());
|
||||
entityTrackerFuture.setException(e);
|
||||
});
|
||||
return;
|
||||
}
|
||||
entityTracker = tracker;
|
||||
mod.getCore().runLater(() -> {
|
||||
@@ -493,13 +515,12 @@ public class GuiPathing {
|
||||
}
|
||||
|
||||
private boolean preparePathsForPlayback() {
|
||||
Timeline timeline = mod.getCurrentTimeline();
|
||||
timeline.getPaths().get(TIME_PATH).updateAll();
|
||||
timeline.getPaths().get(POSITION_PATH).updateAll();
|
||||
SPTimeline timeline = mod.getCurrentTimeline();
|
||||
timeline.getTimeline().getPaths().forEach(Path::updateAll);
|
||||
|
||||
// Make sure time keyframes's values are monotonically increasing
|
||||
int lastTime = 0;
|
||||
for (Keyframe keyframe : timeline.getPaths().get(TIME_PATH).getKeyframes()) {
|
||||
for (Keyframe keyframe : timeline.getTimePath().getKeyframes()) {
|
||||
int time = keyframe.getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||
if (time < lastTime) {
|
||||
// We are going backwards in time
|
||||
@@ -512,6 +533,13 @@ public class GuiPathing {
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
// Make sure there are at least two position- and two time-keyframes
|
||||
if (timeline.getPositionPath().getSegments().isEmpty()
|
||||
|| timeline.getTimePath().getSegments().isEmpty()) {
|
||||
GuiInfoPopup.open(replayHandler.getOverlay(), "replaymod.chat.morekeyframes");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -519,204 +547,85 @@ public class GuiPathing {
|
||||
scrollbar.setZoom(scrollbar.getZoom() * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either one of the property buttons is pressed.
|
||||
* @param isTime {@code true} for the time property button, {@code false} for the place property button
|
||||
*/
|
||||
private void updateKeyframe(final boolean isTime) {
|
||||
public boolean ensureEntityTracker(Runnable withDelayedTracker) {
|
||||
if (entityTracker == null) {
|
||||
LOGGER.debug("Entity tracker not yet loaded, delaying...");
|
||||
LoadEntityTrackerPopup popup = new LoadEntityTrackerPopup(replayHandler.getOverlay());
|
||||
entityTrackerLoadingProgress = p -> popup.progressBar.setProgress(p.floatValue());
|
||||
Futures.addCallback(entityTrackerFuture, new FutureCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Void result) {
|
||||
popup.close();
|
||||
updateKeyframe(isTime);
|
||||
if (mod.getCurrentTimeline().getEntityTracker() == null) {
|
||||
mod.getCurrentTimeline().setEntityTracker(entityTracker);
|
||||
}
|
||||
withDelayedTracker.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable t) {
|
||||
popup.close();
|
||||
String message = "Failed to load entity tracker, pathing will be unavailable.";
|
||||
GuiReplayOverlay overlay = replayHandler.getOverlay();
|
||||
Utils.error(LOGGER, overlay, CrashReport.makeCrashReport(t, message), popup::close);
|
||||
}
|
||||
});
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (mod.getCurrentTimeline().getEntityTracker() == null) {
|
||||
mod.getCurrentTimeline().setEntityTracker(entityTracker);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either one of the property buttons is pressed.
|
||||
* @param path {@code TIME} for the time property button, {@code POSITION} for the place property button
|
||||
*/
|
||||
private void updateKeyframe(SPPath path) {
|
||||
LOGGER.debug("Updating keyframe on path {}" + path);
|
||||
if (!ensureEntityTracker(() -> updateKeyframe(path))) return;
|
||||
|
||||
int time = timeline.getCursorPosition();
|
||||
Timeline timeline = mod.getCurrentTimeline();
|
||||
Path path = timeline.getPaths().get(isTime ? TIME_PATH : POSITION_PATH);
|
||||
SPTimeline timeline = mod.getCurrentTimeline();
|
||||
|
||||
Keyframe keyframe = mod.getSelectedKeyframe();
|
||||
if (keyframe != null && keyframe.getValue(TimestampProperty.PROPERTY).isPresent() ^ isTime) {
|
||||
// Keyframe is on the wrong timeline
|
||||
keyframe = null;
|
||||
}
|
||||
if (keyframe == null) {
|
||||
// No keyframe selected but there may still be one at this exact time
|
||||
keyframe = path.getKeyframe(time);
|
||||
}
|
||||
Change change;
|
||||
if (keyframe == null) {
|
||||
change = AddKeyframe.create(path, time);
|
||||
change.apply(timeline);
|
||||
keyframe = path.getKeyframe(time);
|
||||
} else {
|
||||
change = RemoveKeyframe.create(path, keyframe);
|
||||
change.apply(timeline);
|
||||
keyframe = null;
|
||||
}
|
||||
|
||||
if (keyframe != null) {
|
||||
UpdateKeyframeProperties.Builder builder = UpdateKeyframeProperties.create(path, keyframe);
|
||||
if (isTime) {
|
||||
builder.setValue(TimestampProperty.PROPERTY, replayHandler.getReplaySender().currentTimeStamp());
|
||||
} else {
|
||||
CameraEntity camera = replayHandler.getCameraEntity();
|
||||
builder.setValue(CameraProperties.POSITION, Triple.of(camera.posX, camera.posY, camera.posZ));
|
||||
builder.setValue(CameraProperties.ROTATION, Triple.of(camera.rotationYaw, camera.rotationPitch, camera.roll));
|
||||
if (!replayHandler.isCameraView()) {
|
||||
Entity spectated = replayHandler.getOverlay().getMinecraft().getRenderViewEntity();
|
||||
builder.setValue(SpectatorProperty.PROPERTY, spectated.getEntityId());
|
||||
switch (path) {
|
||||
case TIME:
|
||||
if (mod.getSelectedPath() == path) {
|
||||
LOGGER.debug("Selected keyframe is time keyframe -> removing keyframe");
|
||||
timeline.removeTimeKeyframe(mod.getSelectedTime());
|
||||
mod.setSelected(null, 0);
|
||||
} else if (timeline.isTimeKeyframe(time)) {
|
||||
LOGGER.debug("Keyframe at cursor position is time keyframe -> removing keyframe");
|
||||
timeline.removeTimeKeyframe(time);
|
||||
mod.setSelected(null, 0);
|
||||
} else {
|
||||
LOGGER.debug("No time keyframe found -> adding new keyframe");
|
||||
timeline.addTimeKeyframe(time, replayHandler.getReplaySender().currentTimeStamp());
|
||||
mod.setSelected(path, time);
|
||||
}
|
||||
}
|
||||
UpdateKeyframeProperties updateChange = builder.done();
|
||||
updateChange.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, updateChange);
|
||||
|
||||
// If this new keyframe formed the first segment of the time path
|
||||
if (isTime && path.getSegments().size() == 1) {
|
||||
PathSegment segment = path.getSegments().iterator().next();
|
||||
Interpolator interpolator = new LinearInterpolator();
|
||||
interpolator.registerProperty(TimestampProperty.PROPERTY);
|
||||
SetInterpolator setInterpolator = SetInterpolator.create(segment, interpolator);
|
||||
setInterpolator.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, setInterpolator);
|
||||
}
|
||||
}
|
||||
|
||||
// Update interpolators for spectator keyframes
|
||||
// while this is overkill, it is far simpler than updating differently for every possible case
|
||||
if (!isTime) {
|
||||
Change interpolators = updateInterpolators();
|
||||
interpolators.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, interpolators);
|
||||
}
|
||||
|
||||
Change specPosUpdate = updateSpectatorPositions();
|
||||
specPosUpdate.apply(timeline);
|
||||
change = CombinedChange.createFromApplied(change, specPosUpdate);
|
||||
|
||||
timeline.pushChange(change);
|
||||
|
||||
mod.setSelectedKeyframe(keyframe);
|
||||
}
|
||||
|
||||
public Change updateInterpolators() {
|
||||
boolean linearInterpolation = mod.getCore().getSettingsRegistry().get(Setting.LINEAR_INTERPOLATION);
|
||||
List<Change> changes = new ArrayList<>();
|
||||
Interpolator interpolator = null;
|
||||
boolean isSpectatorInterpolator = false;
|
||||
for (PathSegment segment : mod.getCurrentTimeline().getPaths().get(POSITION_PATH).getSegments()) {
|
||||
if (segment.getStartKeyframe().getValue(SpectatorProperty.PROPERTY).isPresent()
|
||||
&& segment.getEndKeyframe().getValue(SpectatorProperty.PROPERTY).isPresent()) {
|
||||
// Spectator segment
|
||||
if (!isSpectatorInterpolator) {
|
||||
isSpectatorInterpolator = true;
|
||||
interpolator = new LinearInterpolator();
|
||||
interpolator.registerProperty(SpectatorProperty.PROPERTY);
|
||||
break;
|
||||
case POSITION:
|
||||
if (mod.getSelectedPath() == path) {
|
||||
LOGGER.debug("Selected keyframe is position keyframe -> removing keyframe");
|
||||
timeline.removePositionKeyframe(mod.getSelectedTime());
|
||||
mod.setSelected(null, 0);
|
||||
} else if (timeline.isPositionKeyframe(time)) {
|
||||
LOGGER.debug("Keyframe at cursor position is position keyframe -> removing keyframe");
|
||||
timeline.removePositionKeyframe(time);
|
||||
mod.setSelected(null, 0);
|
||||
} else {
|
||||
LOGGER.debug("No position keyframe found -> adding new keyframe");
|
||||
CameraEntity camera = replayHandler.getCameraEntity();
|
||||
int spectatedId = -1;
|
||||
if (!replayHandler.isCameraView()) {
|
||||
spectatedId = replayHandler.getOverlay().getMinecraft().getRenderViewEntity().getEntityId();
|
||||
}
|
||||
timeline.addPositionKeyframe(time, camera.posX, camera.posY, camera.posZ,
|
||||
camera.rotationYaw, camera.rotationPitch, camera.roll, spectatedId);
|
||||
mod.setSelected(path, time);
|
||||
}
|
||||
changes.add(SetInterpolator.create(segment, interpolator));
|
||||
} else {
|
||||
// Normal segment
|
||||
if (isSpectatorInterpolator || interpolator == null) {
|
||||
isSpectatorInterpolator = false;
|
||||
interpolator = linearInterpolation ? new LinearInterpolator() : new CubicSplineInterpolator();
|
||||
interpolator.registerProperty(CameraProperties.POSITION);
|
||||
interpolator.registerProperty(CameraProperties.ROTATION);
|
||||
}
|
||||
changes.add(SetInterpolator.create(segment, interpolator));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return CombinedChange.create(changes.toArray(new Change[changes.size()]));
|
||||
}
|
||||
|
||||
public Change updateSpectatorPositions() {
|
||||
List<Change> changes = new ArrayList<>();
|
||||
Path positionPath = mod.getCurrentTimeline().getPaths().get(POSITION_PATH);
|
||||
Path timePath = mod.getCurrentTimeline().getPaths().get(TIME_PATH);
|
||||
timePath.updateAll();
|
||||
for (Keyframe keyframe : positionPath.getKeyframes()) {
|
||||
Optional<Integer> spectator = keyframe.getValue(SpectatorProperty.PROPERTY);
|
||||
if (spectator.isPresent()) {
|
||||
Optional<Integer> time = timePath.getValue(TimestampProperty.PROPERTY, keyframe.getTime());
|
||||
if (!time.isPresent()) {
|
||||
continue; // No time keyframes set at this video time, cannot determine replay time
|
||||
}
|
||||
Location expected = entityTracker.getEntityPositionAtTimestamp(spectator.get(), time.get());
|
||||
if (expected == null) {
|
||||
continue; // We don't have any data on this entity for some reason
|
||||
}
|
||||
Triple<Double, Double, Double> pos = keyframe.getValue(CameraProperties.POSITION).orElse(Triple.of(0D, 0D, 0D));
|
||||
Triple<Float, Float, Float> rot = keyframe.getValue(CameraProperties.ROTATION).orElse(Triple.of(0F, 0F, 0F));
|
||||
Location actual = new Location(pos.getLeft(), pos.getMiddle(), pos.getRight(), rot.getLeft(), rot.getRight());
|
||||
if (!expected.equals(actual)) {
|
||||
changes.add(UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(CameraProperties.POSITION, Triple.of(expected.getX(), expected.getY(), expected.getZ()))
|
||||
.setValue(CameraProperties.ROTATION, Triple.of(expected.getYaw(), expected.getPitch(), 0f)).done()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CombinedChange.create(changes.toArray(new Change[changes.size()]));
|
||||
}
|
||||
|
||||
public Change moveKeyframe(Path path, Keyframe keyframe, long newTime) {
|
||||
Timeline timeline = mod.getCurrentTimeline();
|
||||
// Interpolator might be required later (only if path is the time path)
|
||||
Optional<Interpolator> interpolator =
|
||||
path.getSegments().stream().findFirst().map(PathSegment::getInterpolator);
|
||||
|
||||
// First remove the old keyframe
|
||||
Change removeChange = RemoveKeyframe.create(path, keyframe);
|
||||
removeChange.apply(timeline);
|
||||
|
||||
// and add a new one at the correct time
|
||||
Change addChange = AddKeyframe.create(path, newTime);
|
||||
addChange.apply(timeline);
|
||||
path.getKeyframe(newTime);
|
||||
|
||||
// Then copy over all properties
|
||||
UpdateKeyframeProperties.Builder builder = UpdateKeyframeProperties.create(path, path.getKeyframe(newTime));
|
||||
for (Property property : keyframe.getProperties()) {
|
||||
copyProperty(property, keyframe, builder);
|
||||
}
|
||||
Change propertyChange = builder.done();
|
||||
propertyChange.apply(timeline);
|
||||
|
||||
// Finally set the interpolators
|
||||
Change interpolatorChange;
|
||||
if (path.getTimeline().getPaths().indexOf(path) == GuiPathing.POSITION_PATH) {
|
||||
// Position / Spectator keyframes need special handling
|
||||
interpolatorChange = updateInterpolators();
|
||||
} else {
|
||||
// Time keyframes only need updating when only one segment of them exists
|
||||
if (path.getSegments().size() == 1) {
|
||||
interpolatorChange = SetInterpolator.create(path.getSegments().iterator().next(), interpolator.get());
|
||||
} else {
|
||||
interpolatorChange = CombinedChange.create(); // Noop change
|
||||
}
|
||||
}
|
||||
interpolatorChange.apply(timeline);
|
||||
// and update spectator positions
|
||||
Change spectatorChange = updateSpectatorPositions();
|
||||
spectatorChange.apply(timeline);
|
||||
|
||||
return CombinedChange.createFromApplied(removeChange, addChange, propertyChange, interpolatorChange, spectatorChange);
|
||||
}
|
||||
|
||||
// Helper method because generics cannot be defined on blocks
|
||||
private <T> void copyProperty(Property<T> property, Keyframe from, UpdateKeyframeProperties.Builder to) {
|
||||
from.getValue(property).ifPresent(value -> to.setValue(property, value));
|
||||
}
|
||||
|
||||
public ReplayModSimplePathing getMod() {
|
||||
@@ -727,13 +636,15 @@ public class GuiPathing {
|
||||
return entityTracker;
|
||||
}
|
||||
|
||||
public void openEditKeyframePopup(Path path, Keyframe keyframe) {
|
||||
public void openEditKeyframePopup(SPPath path, long time) {
|
||||
if (!ensureEntityTracker(() -> openEditKeyframePopup(path, time))) return;
|
||||
Keyframe keyframe = mod.getCurrentTimeline().getKeyframe(path, time);
|
||||
if (keyframe.getProperties().contains(SpectatorProperty.PROPERTY)) {
|
||||
new GuiEditKeyframe.Spectator(this, path, keyframe).open();
|
||||
new GuiEditKeyframe.Spectator(this, path, keyframe.getTime()).open();
|
||||
} else if (keyframe.getProperties().contains(CameraProperties.POSITION)) {
|
||||
new GuiEditKeyframe.Position(this, path, keyframe).open();
|
||||
new GuiEditKeyframe.Position(this, path, keyframe.getTime()).open();
|
||||
} else {
|
||||
new GuiEditKeyframe.Time(this, path, keyframe).open();
|
||||
new GuiEditKeyframe.Time(this, path, keyframe.getTime()).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,16 @@ import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.PathSegment;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.util.EntityPositionTracker;
|
||||
import com.replaymod.replaystudio.util.Location;
|
||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||
import com.replaymod.simplepathing.SPTimeline;
|
||||
import com.replaymod.simplepathing.gui.GuiPathing;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
@@ -67,11 +68,11 @@ public class PathPreviewRenderer {
|
||||
if (guiPathing == null) return;
|
||||
EntityPositionTracker entityTracker = guiPathing.getEntityTracker();
|
||||
|
||||
Timeline timeline = mod.getCurrentTimeline();
|
||||
SPTimeline timeline = mod.getCurrentTimeline();
|
||||
if (timeline == null) return;
|
||||
Path path = timeline.getPaths().get(GuiPathing.POSITION_PATH);
|
||||
Path path = timeline.getPositionPath();
|
||||
if (path.getKeyframes().isEmpty()) return;
|
||||
Path timePath = timeline.getPaths().get(GuiPathing.TIME_PATH);
|
||||
Path timePath = timeline.getTimePath();
|
||||
|
||||
path.update();
|
||||
|
||||
@@ -96,8 +97,8 @@ public class PathPreviewRenderer {
|
||||
if (spectator && entityTracker == null) {
|
||||
continue; // Cannot render spectator positions when entity tracker is not yet loaded
|
||||
}
|
||||
// Spectator segments have 20 lines per second whereas normal segments have a fixed 100
|
||||
long steps = spectator ? diff / 50 : 100;
|
||||
// Spectator segments have 20 lines per second (at least 10) whereas normal segments have a fixed 100
|
||||
long steps = spectator ? Math.max(diff / 50, 10) : 100;
|
||||
Triple<Double, Double, Double> prevPos = null;
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
long time = start.getTime() + diff * i / steps;
|
||||
@@ -203,26 +204,35 @@ public class PathPreviewRenderer {
|
||||
if (distanceSquared(view, pos2) > renderDistanceSquared) return;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer renderer = tessellator.getWorldRenderer();
|
||||
renderer.setTranslation(-view.getLeft(), -view.getMiddle(), -view.getRight());
|
||||
WorldRenderer vertexBuffer = tessellator.getWorldRenderer();
|
||||
vertexBuffer.setTranslation(-view.getLeft(), -view.getMiddle(), -view.getRight());
|
||||
|
||||
renderer.startDrawing(GL11.GL_LINES);
|
||||
renderer.setColorRGBA_I(color, 255);
|
||||
vertexBuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||
|
||||
renderer.addVertex(pos1.getLeft(), pos1.getMiddle(), pos1.getRight());
|
||||
renderer.addVertex(pos2.getLeft(), pos2.getMiddle(), pos2.getRight());
|
||||
vertexBuffer.pos(pos1.getLeft(), pos1.getMiddle(), pos1.getRight()).color(
|
||||
color >> 16 & 0xff,
|
||||
color >> 8 & 0xff,
|
||||
color & 0xff,
|
||||
255
|
||||
).endVertex();
|
||||
vertexBuffer.pos(pos2.getLeft(), pos2.getMiddle(), pos2.getRight()).color(
|
||||
color >> 16 & 0xff,
|
||||
color >> 8 & 0xff,
|
||||
color & 0xff,
|
||||
255
|
||||
).endVertex();
|
||||
|
||||
GL11.glLineWidth(3);
|
||||
tessellator.draw();
|
||||
renderer.setTranslation(0, 0, 0);
|
||||
vertexBuffer.setTranslation(0, 0, 0);
|
||||
}
|
||||
|
||||
private void drawPoint(Triple<Double, Double, Double> view,
|
||||
Triple<Double, Double, Double> pos,
|
||||
Keyframe keyframe) {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer renderer = tessellator.getWorldRenderer();
|
||||
renderer.setTranslation(0, 0, 0);
|
||||
WorldRenderer vertexBuffer = tessellator.getWorldRenderer();
|
||||
vertexBuffer.setTranslation(0, 0, 0);
|
||||
|
||||
mc.renderEngine.bindTexture(TEXTURE);
|
||||
|
||||
@@ -230,7 +240,7 @@ public class PathPreviewRenderer {
|
||||
float posY = 0f;
|
||||
float size = 10f / ReplayMod.TEXTURE_SIZE;
|
||||
|
||||
if (keyframe == mod.getSelectedKeyframe()) {
|
||||
if (mod.isSelected(keyframe)) {
|
||||
posY += size;
|
||||
}
|
||||
|
||||
@@ -243,12 +253,12 @@ public class PathPreviewRenderer {
|
||||
float maxX = 0.5f;
|
||||
float maxY = 0.5f;
|
||||
|
||||
renderer.startDrawingQuads();
|
||||
vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
|
||||
renderer.addVertexWithUV(minX, minY, 0, posX + size, posY + size);
|
||||
renderer.addVertexWithUV(minX, maxY, 0, posX + size, posY);
|
||||
renderer.addVertexWithUV(maxX, maxY, 0, posX, posY);
|
||||
renderer.addVertexWithUV(maxX, minY, 0, posX, posY + size);
|
||||
vertexBuffer.pos(minX, minY, 0).tex(posX + size, posY + size).endVertex();
|
||||
vertexBuffer.pos(minX, maxY, 0).tex(posX + size, posY).endVertex();
|
||||
vertexBuffer.pos(maxX, maxY, 0).tex(posX, posY).endVertex();
|
||||
vertexBuffer.pos(maxX, minY, 0).tex(posX, posY + size).endVertex();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
@@ -270,8 +280,8 @@ public class PathPreviewRenderer {
|
||||
Triple<Double, Double, Double> pos,
|
||||
Triple<Float, Float, Float> rot) {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer renderer = tessellator.getWorldRenderer();
|
||||
renderer.setTranslation(0, 0, 0);
|
||||
WorldRenderer vertexBuffer = tessellator.getWorldRenderer();
|
||||
vertexBuffer.setTranslation(0, 0, 0);
|
||||
|
||||
mc.renderEngine.bindTexture(CAMERA_HEAD);
|
||||
|
||||
@@ -289,12 +299,10 @@ public class PathPreviewRenderer {
|
||||
|
||||
//draw the position line
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
renderer.startDrawing(GL11.GL_LINES);
|
||||
vertexBuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||
|
||||
renderer.setColorRGBA_I(0x00ff00, 170);
|
||||
|
||||
renderer.addVertex(0, 0, 0);
|
||||
renderer.addVertex(0, 0, 2);
|
||||
vertexBuffer.pos(0, 0, 0).color(0, 255, 0, 170).endVertex();
|
||||
vertexBuffer.pos(0, 0, 2).color(0, 255, 0, 170).endVertex();
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
@@ -305,45 +313,43 @@ public class PathPreviewRenderer {
|
||||
|
||||
double r = -cubeSize/2;
|
||||
|
||||
renderer.startDrawingQuads();
|
||||
|
||||
renderer.setColorRGBA_I(0xffffff, 200);
|
||||
vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
|
||||
//back
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r, 3 * 8 / 64f, 8 / 64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r, 4*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r, r, 4*8/64f, 2*8/64f);
|
||||
renderer.addVertexWithUV(r, r, r, 3*8/64f, 2*8/64f);
|
||||
vertexBuffer.pos(r, r + cubeSize, r).tex(3 * 8 / 64f, 8 / 64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r).tex(4*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r, r).tex(4*8/64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r).tex(3*8/64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
//front
|
||||
renderer.addVertexWithUV(r + cubeSize, r, r + cubeSize, 2 * 8 / 64f, 2*8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r + cubeSize, 2 * 8 / 64f, 8/64f);
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r + cubeSize, 8 / 64f, 8 / 64f);
|
||||
renderer.addVertexWithUV(r, r, r + cubeSize, 8 / 64f, 2*8/64f);
|
||||
vertexBuffer.pos(r + cubeSize, r, r + cubeSize).tex(2 * 8 / 64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r + cubeSize).tex(2 * 8 / 64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r + cubeSize, r + cubeSize).tex(8 / 64f, 8 / 64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r + cubeSize).tex(8 / 64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
//left
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r, 0, 8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r + cubeSize, 8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r, r + cubeSize, 8/64f, 2*8/64f);
|
||||
renderer.addVertexWithUV(r+cubeSize, r, r, 0, 2*8/64f);
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r).tex(0, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r + cubeSize).tex(8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r, r + cubeSize).tex(8/64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r+cubeSize, r, r).tex(0, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
//right
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r + cubeSize, 2*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r, 3*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r, r, r, 3*8/64f, 2*8/64f);
|
||||
renderer.addVertexWithUV(r, r, r + cubeSize, 2 * 8 / 64f, 2 * 8 / 64f);
|
||||
vertexBuffer.pos(r, r + cubeSize, r + cubeSize).tex(2*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r + cubeSize, r).tex(3*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r).tex(3*8/64f, 2*8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r + cubeSize).tex(2 * 8 / 64f, 2 * 8 / 64f).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
//bottom
|
||||
renderer.addVertexWithUV(r + cubeSize, r, r, 3*8/64f, 0);
|
||||
renderer.addVertexWithUV(r + cubeSize, r, r + cubeSize, 3*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r, r, r + cubeSize, 2*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r, r, r, 2 * 8 / 64f, 0);
|
||||
vertexBuffer.pos(r + cubeSize, r, r).tex(3*8/64f, 0).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r, r + cubeSize).tex(3*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r + cubeSize).tex(2*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r, r).tex(2 * 8 / 64f, 0).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
//top
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r, 8/64f, 0);
|
||||
renderer.addVertexWithUV(r, r + cubeSize, r + cubeSize, 8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r + cubeSize, 2*8/64f, 8/64f);
|
||||
renderer.addVertexWithUV(r + cubeSize, r + cubeSize, r, 2 * 8 / 64f, 0);
|
||||
vertexBuffer.pos(r, r + cubeSize, r).tex(8/64f, 0).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r, r + cubeSize, r + cubeSize).tex(8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r + cubeSize).tex(2*8/64f, 8/64f).color(255, 255, 255, 200).endVertex();
|
||||
vertexBuffer.pos(r + cubeSize, r + cubeSize, r).tex(2 * 8 / 64f, 0).color(255, 255, 255, 200).endVertex();
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.replaymod.simplepathing.properties;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.replaystudio.pathing.property.AbstractProperty;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyPart;
|
||||
import lombok.NonNull;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Property indicating that the next path segment's interpolator is fixed
|
||||
*/
|
||||
public class ExplicitInterpolationProperty extends AbstractProperty<Object> {
|
||||
public static final ExplicitInterpolationProperty PROPERTY = new ExplicitInterpolationProperty();
|
||||
|
||||
private ExplicitInterpolationProperty() {
|
||||
super("interpolationFixed", "<internal>", null, new Object());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Object>> getParts() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Object value, @NonNull Object replayHandler) {
|
||||
// dummy property, do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Object value) throws IOException {
|
||||
writer.nullValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromJson(JsonReader reader) throws IOException {
|
||||
reader.nextNull();
|
||||
return ObjectUtils.NULL;
|
||||
}
|
||||
}
|
||||