Skip to content

Commit

Permalink
fix: do not use Timeline and/or Playhead for effect timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Oct 15, 2023
1 parent efd579b commit c2c730a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import team.unnamed.hephaestus.animation.timeline.bone.BoneTimeline;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsTimeline;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsTimeline;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.NotNull;
import team.unnamed.hephaestus.animation.timeline.bone.BoneTimeline;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsTimeline;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsTimeline;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import team.unnamed.hephaestus.animation.timeline.bone.BoneTimeline;
import team.unnamed.hephaestus.animation.timeline.bone.BoneTimelinePlayhead;
import team.unnamed.hephaestus.animation.timeline.Timeline;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsFrame;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsTimeline;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsTimelinePlayhead;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsFrame;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsTimeline;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsTimelinePlayhead;
import team.unnamed.hephaestus.util.Quaternion;
import team.unnamed.hephaestus.util.Vectors;
import team.unnamed.hephaestus.view.BaseBoneView;
Expand Down Expand Up @@ -195,6 +195,7 @@ public synchronized void tick(Quaternion initialRotation, Vector3Float initialPo
Sound[] sounds = effectsFrame.sounds();

for (Sound sound : sounds) {
System.out.println("play ");
view.playSound(sound);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.hephaestus.animation.timeline.effects;
package team.unnamed.hephaestus.animation.timeline.effect;

import net.kyori.adventure.sound.Sound;
import net.kyori.examination.Examinable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.hephaestus.animation.timeline.effects;
package team.unnamed.hephaestus.animation.timeline.effect;

import net.kyori.adventure.sound.Sound;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import team.unnamed.hephaestus.animation.interpolation.Interpolator;
import team.unnamed.hephaestus.animation.timeline.Timeline;

import java.util.Collections;
import java.util.Map;

/**
*
Expand All @@ -41,18 +42,14 @@ public interface EffectsTimeline {

static @NotNull EffectsTimeline.Builder empty() {
return effectsTimeline()
.sounds(Timeline.<Sound[]>timeline()
.initial(new Sound[0])
.defaultInterpolator(Interpolator.staticInterpolator(new Sound[0]))
.build()
);
.sounds(Collections.emptyMap());
}

default @NotNull EffectsTimelinePlayhead createPlayhead() {
return new EffectsTimelinePlayhead(this);
}

@NotNull Timeline<Sound[]> sounds();
@NotNull Map<Integer, Sound[]> sounds();

interface Builder {

Expand All @@ -64,7 +61,7 @@ interface Builder {
* @since 1.0.0
*/
@Contract("_ -> this")
@NotNull Builder sounds(final @NotNull Timeline<Sound[]> sounds);
@NotNull Builder sounds(final @NotNull Map<Integer, Sound[]> sounds);

@NotNull EffectsTimeline build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.hephaestus.animation.timeline.effects;
package team.unnamed.hephaestus.animation.timeline.effect;

import net.kyori.adventure.sound.Sound;
import org.jetbrains.annotations.NotNull;
import team.unnamed.hephaestus.animation.timeline.Timeline;

import java.util.Map;

import static java.util.Objects.requireNonNull;

final class EffectsTimelineImpl implements EffectsTimeline {

private final Timeline<Sound[]> sounds;
private final Map<Integer, Sound[]> sounds;

EffectsTimelineImpl(Timeline<Sound[]> sounds) {
EffectsTimelineImpl(Map<Integer, Sound[]> sounds) {
this.sounds = requireNonNull(sounds, "sounds");
}

@Override
public @NotNull Timeline<Sound[]> sounds() {
public @NotNull Map<Integer, Sound[]> sounds() {
return sounds;
}

Expand All @@ -51,13 +52,13 @@ public String toString() {

static final class BuilderImpl implements Builder {

private Timeline<Sound[]> sounds;
private Map<Integer, Sound[]> sounds;

BuilderImpl() {
}

@Override
public @NotNull Builder sounds(@NotNull Timeline<Sound[]> sounds) {
public @NotNull Builder sounds(@NotNull Map<Integer, Sound[]> sounds) {
this.sounds = requireNonNull(sounds, "sounds");
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.hephaestus.animation.timeline.effects;
package team.unnamed.hephaestus.animation.timeline.effect;

import net.kyori.adventure.sound.Sound;
import team.unnamed.hephaestus.animation.timeline.playhead.Playhead;

public class EffectsTimelinePlayhead {

private final Playhead<Sound[]> sounds;
private final EffectsTimeline timeline;
private int tick = -1;

public EffectsTimelinePlayhead(EffectsTimeline effectsTimeline) {
this.sounds = effectsTimeline.sounds().createPlayhead();
public EffectsTimelinePlayhead(EffectsTimeline timeline) {
this.timeline = timeline;
}

public int tick() {
Expand All @@ -42,7 +41,7 @@ public int tick() {
public EffectsFrame next() {
tick++;
return new EffectsFrame(
sounds.next()
timeline.sounds().getOrDefault(tick, new Sound[0])
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import team.unnamed.hephaestus.animation.interpolation.Interpolator;
import team.unnamed.hephaestus.animation.timeline.bone.BoneTimeline;
import team.unnamed.hephaestus.animation.timeline.Timeline;
import team.unnamed.hephaestus.animation.timeline.effects.EffectsTimeline;
import team.unnamed.hephaestus.animation.timeline.effect.EffectsTimeline;
import team.unnamed.hephaestus.process.ElementScale;

import java.io.IOException;
Expand Down Expand Up @@ -93,9 +93,7 @@ static void readAnimations(
String type = animatorJson.get("type").getAsString();

if (type.equals("effect")) {
Timeline.Builder<Sound[]> soundsTimeline = Timeline.<Sound[]>timeline()
.initial(new Sound[0])
.defaultInterpolator(Interpolator.staticInterpolator(new Sound[0]));
Map<Integer, Sound[]> soundsTimeline = new HashMap<>();

for (JsonElement keyFrameElement : animatorJson.get("keyframes").getAsJsonArray()) {
JsonObject keyframeJson = keyFrameElement.getAsJsonObject();
Expand All @@ -119,12 +117,12 @@ static void readAnimations(
);
}

soundsTimeline.keyFrame(time, sounds);
soundsTimeline.put(time, sounds);
break;
}
}

effectsTimeline.sounds(soundsTimeline.build());
effectsTimeline.sounds(soundsTimeline);
} else if (type.equals("bone")) {
Timeline.Builder<Vector3Float> positionsTimeline = Timeline.<Vector3Float>timeline()
.initial(Vector3Float.ZERO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public Collection<Player> viewers() {

@Override
public void playSound(Sound sound) {
System.out.println("play sound");
for (Player viewer : viewers()) {
viewer.playSound(sound, position);
}
Expand Down

0 comments on commit c2c730a

Please sign in to comment.