/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.steamwar.lobby.particle;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.List;
@RequiredArgsConstructor
@AllArgsConstructor
@Getter
public class ParticleTickData {
private final World world;
private final Player player;
private Location location;
private final double deg;
private final boolean isMoving;
private final List viewers;
private boolean onlySelf = false;
private boolean onlyOthers = false;
// Set for entries placed relative to the body, null for world placement
private BodyFrame frame;
// Where a point sits along its shape, from 0 to 1; when set, gradients colour by it instead of by time
private Double shade;
public ParticleTickData withLocation(Location location) {
ParticleTickData particleTickData = copy();
particleTickData.location = location;
return particleTickData;
}
public ParticleTickData withFrame(BodyFrame frame) {
ParticleTickData particleTickData = copy();
particleTickData.frame = frame;
particleTickData.location = frame.getOrigin().clone();
return particleTickData;
}
public ParticleTickData withShade(double shade) {
ParticleTickData particleTickData = copy();
particleTickData.shade = shade;
return particleTickData;
}
// The gradient position for this tick: along the shape when a shade is set, otherwise moving with time
public double gradientPosition() {
return shade != null ? Math.min(shade, 0.9999) * 360 : (deg * 10) % 360;
}
public ParticleTickData onlySelf() {
ParticleTickData particleTickData = copy();
particleTickData.onlySelf = true;
return particleTickData;
}
public ParticleTickData onlyOthers() {
ParticleTickData particleTickData = copy();
particleTickData.onlyOthers = true;
return particleTickData;
}
public Location getLocation() {
if (location == null) {
return player.getLocation();
}
return location;
}
public ParticleTickData copy() {
return new ParticleTickData(world, player, location, deg, isMoving, viewers, onlySelf, onlyOthers, frame, shade);
}
}