feat: 完善粒子播放

Signed-off-by: MiaoWoo <admin@yumc.pw>
backup
MiaoWoo 2023-02-08 16:23:05 +08:00
parent d9dffa704d
commit 65832c9fae
3 changed files with 50 additions and 52 deletions

View File

@ -23,6 +23,11 @@ export namespace particle {
private extra: number = 0;
private data: Object = null;
/**
* Only Show To Player
*/
private player: any
constructor() {
this.uuid = UUID.randomUUID().toString()
}
@ -105,6 +110,15 @@ export namespace particle {
return this
}
getPlayer() {
return this.player
}
setPlayer(player) {
this.player = player
return this
}
/**
* 使
*
@ -112,9 +126,14 @@ export namespace particle {
*/
spawn(location: any) {
if (!this.spawner) throw new Error(`particle ${this.uuid} not set spawner can't spawn!`)
this.spawner.spawn(location, this)
if (this.player) {
this.spawner.spawnToPlayer(this.player, location, this)
} else {
this.spawner.spawn(location, this)
}
}
}
/**
* 线
*
@ -158,8 +177,7 @@ export namespace particle {
show() {
for (let i = 0; i < this.length; i += this.step) {
let vectorTemp = this.vector.clone().multiply(i)
this.spawn(this.start.clone().add(vectorTemp))
this.spawn(this.start.clone().add(this.vector.clone().multiply(i)))
}
}
@ -234,15 +252,6 @@ export namespace particle {
this.length = this.vector.length()
this.vector.normalize()
}
public static buildLine(locA: any, locB: any, step: number, particle: any) {
let vectorAB = locB.clone().subtract(locA).toVector()
let vectorLength = vectorAB.length()
vectorAB.normalize()
for (let i = 0; i < vectorLength; i += step) {
ParticleManager.globalSpawner.spawn(locA.clone().add(vectorAB.clone().multiply(i)), particle)
}
}
}
/**
*
@ -331,9 +340,10 @@ export namespace particle {
@injectable()
export abstract class ParticleManager {
public static globalSpawner: ParticleSpawner = undefined
@Autowired()
private taskManager: task.TaskManager
@Autowired()
private particleSpawner: particle.ParticleSpawner
protected taskId: java.util.concurrent.atomic.AtomicInteger
protected cacheTasks = new Map<string, ParticleTask>()
@ -354,6 +364,10 @@ export namespace particle {
return this.taskManager
}
public getParticleSpawner() {
return this.particleSpawner
}
public create(particle: Particle, plugin?: plugin.Plugin) {
let uuid = particle.getUUID()
if (this.cacheTasks.has(uuid)) {
@ -389,14 +403,12 @@ export namespace particle {
}
}
protected create0(owner: plugin.Plugin, particle: Particle): ParticleTask {
particle.setSpawner(this.getGlobalSpawner())
particle.setSpawner(this.getParticleSpawner())
return new ParticleTask(owner, particle, this)
}
protected abstract getGlobalSpawner(): ParticleSpawner
}
export class ParticleTask {
private particle: Particle
private isAsync: boolean = false
private interval: number = 0
@ -487,8 +499,9 @@ export namespace particle {
}
}
@injectable()
export abstract class ParticleSpawner {
abstract spawnParticle(location: any, particle: any, count: number)
abstract spawn(location: any, particle: Particle)
abstract spawnToPlayer(player: any, location: any, particle: Particle)
}
}

View File

@ -3,20 +3,11 @@ import { particle } from '@ccms/api'
@provideSingleton(particle.ParticleManager)
export class BukkitParticleManager extends particle.ParticleManager {
private globalSpawner = new BukkitParticleSpawner()
constructor() {
super()
particle.ParticleManager.globalSpawner = this.globalSpawner
}
protected getGlobalSpawner() {
return this.globalSpawner
}
}
@provideSingleton(particle.ParticleSpawner)
export class BukkitParticleSpawner extends particle.ParticleSpawner {
spawnParticle(location: any, particle: any, count: number = 1) {
location.getWorld().spawnParticle(particle, location, count)
}
spawn(location: any, particle: particle.Particle) {
spawn(location: org.bukkit.Location, particle: particle.Particle) {
location.getWorld().spawnParticle(
particle.getParticle(),
location,
@ -28,4 +19,15 @@ export class BukkitParticleSpawner extends particle.ParticleSpawner {
particle.getData()
)
}
spawnToPlayer(player: org.bukkit.entity.Player, location: org.bukkit.Location, particle: particle.Particle) {
player.spawnParticle(
particle.getParticle(),
location,
particle.getCount(),
particle.getOffsetX(),
particle.getOffsetY(),
particle.getOffsetZ(),
particle.getExtra(),
particle.getData())
}
}

View File

@ -1,32 +1,15 @@
import { provideSingleton } from '@ccms/container'
import { particle, plugin } from '@ccms/api'
import { particle } from '@ccms/api'
@provideSingleton(particle.ParticleManager)
export class SpongeParticleManager extends particle.ParticleManager {
private globalSpawner = new SpongeParticleSpawner()
constructor() {
super()
particle.ParticleManager.globalSpawner = this.globalSpawner
}
protected getGlobalSpawner() {
return this.globalSpawner
}
}
@provideSingleton(particle.ParticleSpawner)
export class SpongeParticleSpawner extends particle.ParticleSpawner {
spawnParticle(location: org.spongepowered.api.world.Location<any>, particle: any, count: number = 1) {
location.getPosition()
// location.getWorld().spawnParticle(particle, location, count)
}
spawn(location: any, particle: particle.Particle) {
location.getWorld().spawnParticle(
particle.getParticle(),
location,
particle.getCount(),
particle.getOffsetX(),
particle.getOffsetY(),
particle.getOffsetZ(),
particle.getExtra(),
particle.getData()
)
throw new Error('Not Impl.')
}
spawnToPlayer(player: any, location: any, particle: particle.Particle) {
throw new Error('Not Impl.')
}
}